-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJXAddressView.java
More file actions
122 lines (97 loc) · 3.6 KB
/
JXAddressView.java
File metadata and controls
122 lines (97 loc) · 3.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package nl.hz.ict.ding0033.jxplorer;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
/**
* Dit is de klasse die een JXplorefile representeerd die verschillende aspecten
* van de files beheert
*
*
* ik heb ervoor gekozen om de volgende klassen te importeren om de GUI op te
* bouwen
*
* @author Mark Dingemanse
* @version 0,1 Concept
*/
public class JXAddressView extends JXploreView implements ActionListener {
private static final long serialVersionUID = 1L;
private JLabel addresLabel;
private JTextField addresTextField;
private JButton goButton;
// de construcor zet eerst de JXplorer vast en maakt daarna de GUI aan.
public JXAddressView(JXplorer data) {
this.setData(data);
buildGUI();
}
// deze methode is verantwoordelijk voor het aanmaken van de GUI
@Override
protected void buildGUI() {
// maakt een JLabel aan en stopt deze in addresLabel
addresLabel = new JLabel("Address");
// wanneer de currentfile een directory is zet de pathnaam en wanneer het een file is zet de perant in het textveld
if (this.getData().getCurrentFile().getFile().isDirectory() == true){
addresTextField = new JTextField(this.getData().getCurrentFile().getPath(), 40);
}
else{
addresTextField = new JTextField(this.getData().getCurrentFile().getFile().getParent(), 40);
}
ImageIcon icon = new ImageIcon("src/nl/hz/ict/ding0033/jxplorer/resources/65.png");
// maakt een nieuw JButton aan en zet deze in de goButton
goButton = new JButton("go",icon);
// voeg een actionllissener toe aan de button en geeft het huidige object mee
goButton.addActionListener(this);
// zet ook een lissener op het textveld zodat je op enter kan klikken
addresTextField.addActionListener(this);
// zet de layout als BorderLayout
this.setLayout(new BorderLayout());
// zet de size voor het JPannel
this.setPreferredSize(new Dimension(640, 30));
//voeg alle onderdelen toe aan het pannel
this.add(addresLabel, BorderLayout.LINE_START);
this.add(addresTextField, BorderLayout.CENTER);
this.add(goButton, BorderLayout.LINE_END);
}
@Override
protected void updateGUI(){
if(this.getData().getCurrentFile().getFile().isDirectory() != true ){
addresTextField.setText(this.getData().getCurrentFile().getFile().getParent());
}
else{
addresTextField.setText(this.getData().getCurrentFile().getFile().getAbsolutePath());
}
}
// faciliteerd de go knop en geeft foutmelding met invallid path
public void actionPerformed(ActionEvent actie) {
if(!addresTextField.getText().equals(this.getData().getCurrentFile().getPath())){
this.getData().clearForward();
// get het textveld
this.getData().setCurrentFile(addresTextField.getText());
// check of we een geen directory zien of niet
if (this.getData().getCurrentFile().getFile().isDirectory() == false) {
// bestaad het?
if(this.getData().getCurrentFile().getFile().exists() == true){
this.getData().setCurrentFile(this.getData().getCurrentFile().getFile().getParent());
this.getData().showMessageDialog(fileMessage());
}
// als het niet bestaad
else{
this.getData().showMessageDialog("invalid pathname");
return;
}
}
// als het een directory is
else{
this.getData().setCurrentFile(this.getData().getCurrentFile());
}
}
}
// haalt het filemessage op
private String fileMessage() {
return this.getData().generateFileMessage(this.getData().getCurrentFile());
}
}