-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirectoryInputGui.java
More file actions
225 lines (203 loc) · 8.09 KB
/
Copy pathDirectoryInputGui.java
File metadata and controls
225 lines (203 loc) · 8.09 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
package file_organizer_gui;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JButton;
import javax.swing.JDialog;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Font;
import java.awt.Color;
import javax.swing.JTextField;
import java.awt.Choice;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JComboBox;
public class DirectoryInputGui {
/**
* Frame and all of its contents
*/
private JFrame DirectoryWatcherFrame;
private JTextField Directory1;
private JTextField Directory2;
private JTextField Directory3;
private JTextField Directory4;
private JTextField Directory5;
private JTextField Directory6;
private JTextField Directory7;
private JTextField Directory8;
private JTextField Directory9;
private JTextField Directory10;
private EnterTextFieldHandler handler;
private JButton btnClickForHelp;
private JComboBox RecursiveOrNotSelection;
private static ConfigFileReader initializer;
public JFrame getFrame() {
return DirectoryWatcherFrame;
}
/**
* Create the application.
*/
public DirectoryInputGui() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
DirectoryWatcherFrame = new JFrame("File To Our File Organizer!");
DirectoryWatcherFrame.setTitle("Welcome To Our File Organizer!");
DirectoryWatcherFrame.getContentPane().setForeground(Color.WHITE);
DirectoryWatcherFrame.setForeground(Color.CYAN);
DirectoryWatcherFrame.setBackground(new Color(0, 0, 255));
DirectoryWatcherFrame.getContentPane().setBackground(Color.GRAY);
DirectoryWatcherFrame.getContentPane().setFont(new Font("Times New Roman", Font.BOLD, 13));
DirectoryWatcherFrame.setBounds(100, 100, 450, 300);
DirectoryWatcherFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
DirectoryWatcherFrame.getContentPane().setLayout(null);
JButton directoryInstrctionsButton = new JButton("Input The Directories You Want To Watch");
directoryInstrctionsButton.setForeground(Color.WHITE);
directoryInstrctionsButton.setBackground(Color.BLUE);
directoryInstrctionsButton.setFont(new Font("Times New Roman", Font.BOLD, 13));
directoryInstrctionsButton.setBounds(12, 13, 396, 26);
DirectoryWatcherFrame.getContentPane().add(directoryInstrctionsButton);
/*
* instance of the EnterTestFieldHandler class. Used as an action listener that registers appropriate directories
*/
handler = new EnterTextFieldHandler();
Directory1 = new JTextField();
Directory1.setForeground(Color.BLUE);
Directory1.setBackground(Color.WHITE);
Directory1.setText("Place Directory Here");
Directory1.setBounds(12, 52, 132, 22);
DirectoryWatcherFrame.getContentPane().add(Directory1);
Directory1.setColumns(10);
Directory1.addActionListener(handler);
Directory2 = new JTextField();
Directory2.setForeground(Color.BLUE);
Directory2.setBackground(Color.WHITE);
Directory2.setText("Place Directory Here");
Directory2.setBounds(12, 87, 132, 22);
DirectoryWatcherFrame.getContentPane().add(Directory2);
Directory2.setColumns(10);
Directory2.addActionListener(handler);
Directory3 = new JTextField();
Directory3.setForeground(Color.BLUE);
Directory3.setBackground(Color.WHITE);
Directory3.setText("Place Directory Here");
Directory3.setBounds(12, 122, 132, 22);
DirectoryWatcherFrame.getContentPane().add(Directory3);
Directory3.setColumns(10);
Directory3.addActionListener(handler);
Directory4 = new JTextField();
Directory4.setForeground(Color.BLUE);
Directory4.setBackground(Color.WHITE);
Directory4.setText("Place Directory Here");
Directory4.setBounds(12, 157, 132, 22);
DirectoryWatcherFrame.getContentPane().add(Directory4);
Directory4.setColumns(10);
Directory4.addActionListener(handler);
Directory5 = new JTextField();
Directory5.setForeground(Color.BLUE);
Directory5.setBackground(Color.WHITE);
Directory5.setText("Place Directory Here");
Directory5.setBounds(12, 192, 132, 22);
DirectoryWatcherFrame.getContentPane().add(Directory5);
Directory5.setColumns(10);
Directory5.addActionListener(handler);
Directory6 = new JTextField();
Directory6.setForeground(Color.BLUE);
Directory6.setBackground(Color.WHITE);
Directory6.setText("Place Directory Here");
Directory6.setBounds(268, 52, 140, 22);
DirectoryWatcherFrame.getContentPane().add(Directory6);
Directory6.setColumns(10);
Directory6.addActionListener(handler);
Directory7 = new JTextField();
Directory7.setForeground(Color.BLUE);
Directory7.setBackground(Color.WHITE);
Directory7.setText("Place Directory Here");
Directory7.setBounds(268, 87, 140, 22);
DirectoryWatcherFrame.getContentPane().add(Directory7);
Directory7.setColumns(10);
Directory7.addActionListener(handler);
Directory8 = new JTextField();
Directory8.setForeground(Color.BLUE);
Directory8.setBackground(Color.WHITE);
Directory8.setText("Place Directory Here");
Directory8.setBounds(268, 122, 140, 22);
DirectoryWatcherFrame.getContentPane().add(Directory8);
Directory8.setColumns(10);
Directory8.addActionListener(handler);
Directory9 = new JTextField();
Directory9.setForeground(Color.BLUE);
Directory9.setBackground(Color.WHITE);
Directory9.setText("Place Directory Here");
Directory9.setBounds(268, 157, 140, 22);
DirectoryWatcherFrame.getContentPane().add(Directory9);
Directory9.setColumns(10);
Directory9.addActionListener(handler);
Directory10 = new JTextField();
Directory10.setForeground(Color.BLUE);
Directory10.setBackground(Color.WHITE);
Directory10.setText("Place Directory Here");
Directory10.setBounds(268, 192, 140, 22);
DirectoryWatcherFrame.getContentPane().add(Directory10);
Directory10.setColumns(10);
Directory10.addActionListener(handler);
btnClickForHelp = new JButton("Help");
btnClickForHelp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFrame f=new JFrame("How To Register");
f.setBounds(300, 200, 350,100);
JTextArea jd = new JTextArea("To register a file/directory, go to the file explorer\nand navigate to the file/directory you want to register\nthen copy the path and paste it in one of the watch boxes.");
jd.setSize(400, 200);
f.getContentPane().add(jd);
f.setVisible(true);
}
});
btnClickForHelp.setBounds(171, 85, 70, 26);
DirectoryWatcherFrame.getContentPane().add(btnClickForHelp);
String[] recursive = new String[]{"Recursive?","Yes","No"};
RecursiveOrNotSelection = new JComboBox(recursive);
RecursiveOrNotSelection.setToolTipText("Recursive Search?");
RecursiveOrNotSelection.setBounds(156, 146, 100, 33);
DirectoryWatcherFrame.getContentPane().add(RecursiveOrNotSelection);
}
/**
* @author Joshua Lamke
* ActionHandler that will validate and register appropriate directories to the file watcher
*/
private class EnterTextFieldHandler implements ActionListener{
@Override
public void actionPerformed(ActionEvent enter) {
String s="";
boolean wantsRecursive;
JTextField tf = (JTextField) enter.getSource();
s = tf.getText();
Path p = Paths.get(s);
try {
if(((String)RecursiveOrNotSelection.getSelectedItem()).equals("Recursive?") || ((String)RecursiveOrNotSelection.getSelectedItem()).equals("No")) {
wantsRecursive=false;
}
else {
wantsRecursive=true;
}
DirectoryValidator.validate(p);
new ConfigFileStreamer(p,wantsRecursive);
JOptionPane.showMessageDialog(null, "Directory Registered Successfully", "Success", JOptionPane.INFORMATION_MESSAGE);
}
catch(DirectoryNotFoundException e) {
e.getExceptionPopUp();
}
catch(Exception e) {
JOptionPane.showMessageDialog(null, "Something has gone wrong", "Error", JOptionPane.INFORMATION_MESSAGE);
}
}
}
}