-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGui.java
More file actions
362 lines (279 loc) · 12 KB
/
Gui.java
File metadata and controls
362 lines (279 loc) · 12 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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
import java.awt.*;
import java.net.URL;
import javax.swing.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.border.EmptyBorder;
import javax.swing.border.MatteBorder;
//TODO Delete all imports at the end and then add them one by one because dark voodoo reasons
public class Gui extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JMenuBar menuBar;
private JMenu file;
private JMenu options;
private JMenu help;
private ImageIcon icon;
Container contentPane;
private JTextField queryField;
public static void main(String[] args) {
JFrame gui = new Gui();
}
public Gui() {
super("Pirex");
contentPane = getContentPane();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(600, 400);
setIcon();
setupPanels();
setupMenu();
this.setVisible(true);
}
private void setIcon() {
URL iconUrl = Gui.class.getResource("assets/logo.png");
icon = new ImageIcon(iconUrl);
this.setIconImage(icon.getImage());
}
private void setupMenu() {
menuBar = new JMenuBar();
getContentPane().add(menuBar, BorderLayout.NORTH);
setupFileMenu();
setupOptionsMenu();
setupHelpMenu();
menuBar.add(file);
menuBar.add(options);
menuBar.add(help);
}
private void setupFileMenu()
{
file = new JMenu("File");
JMenuItem loadQuery = new JMenuItem("Load Query");
JMenuItem export = new JMenuItem("Export");
JMenuItem exit = new JMenuItem("Exit");
loadQuery.addActionListener((event) -> JOptionPane.showMessageDialog(null, "Function not available"));
export.addActionListener((event) -> JOptionPane.showMessageDialog(null, "Function not available"));
exit.addActionListener((event) -> System.exit(0));
file.add(loadQuery);
file.add(export);
file.add(exit);
}
private void setupOptionsMenu()
{
options = new JMenu("Options");
JMenuItem documents = new JMenuItem("Documents");
options.add(documents);
documents.addActionListener(new ActionListener() {
JFileChooser chooser;
String choosertitle;
public void actionPerformed(ActionEvent e) {
chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File("."));
chooser.setDialogTitle(choosertitle);
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
if (chooser.showOpenDialog(documents) == JFileChooser.APPROVE_OPTION) {
chooser.getCurrentDirectory();
chooser.getSelectedFile();
}
}
});
}
private void setupHelpMenu()
{
help = new JMenu("Help");
JMenuItem index = new JMenuItem("Index");
JMenuItem about = new JMenuItem("About");
about.addActionListener((event) -> JOptionPane.showMessageDialog(null, "Made by Group 3"));
index.addActionListener((event) -> JOptionPane.showMessageDialog(null, "Function not available"));
help.add(index);
help.add(about);
}
private void setupPanels() {
getContentPane().setLayout(new BorderLayout(0, 0));
JPanel borderPanel = new JPanel();
borderPanel.setBorder(new EmptyBorder(0, 8, 8, 8));
getContentPane().add(borderPanel);
borderPanel.setLayout(new BorderLayout(0, 0));
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
borderPanel.add(tabbedPane);
JPanel searchPanel = new JPanel();
tabbedPane.addTab("Search Documents", null, searchPanel, null);
searchPanel.setLayout(new BorderLayout(0, 0));
JPanel queryPanel = new JPanel();
searchPanel.add(queryPanel, BorderLayout.NORTH);
queryPanel.setLayout(new BoxLayout(queryPanel, BoxLayout.X_AXIS));
Component horizontalStrut_1 = Box.createHorizontalStrut(20);
horizontalStrut_1.setPreferredSize(new Dimension(10, 0));
queryPanel.add(horizontalStrut_1);
JLabel query = new JLabel("Query:");
query.setHorizontalAlignment(SwingConstants.LEFT);
queryPanel.add(query);
Component horizontalStrut_2 = Box.createHorizontalStrut(20);
horizontalStrut_2.setPreferredSize(new Dimension(10, 0));
queryPanel.add(horizontalStrut_2);
queryField = new JTextField();
queryField.setHorizontalAlignment(SwingConstants.LEFT);
queryPanel.add(queryField);
queryField.setColumns(10);
JButton btnClear = new JButton("clear");
btnClear.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
queryField.setText("");
}
});
Component horizontalStrut = Box.createHorizontalStrut(20);
queryPanel.add(horizontalStrut);
btnClear.setHorizontalAlignment(SwingConstants.RIGHT);
queryPanel.add(btnClear);
JPanel textPanel = new JPanel();
textPanel.setBorder(new EmptyBorder(0, 25, 0, 25));
searchPanel.add(textPanel, BorderLayout.CENTER);
textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.Y_AXIS));
Component verticalStrut_1 = Box.createVerticalStrut(20);
textPanel.add(verticalStrut_1);
JTextArea textTop = new JTextArea();
textTop.setBorder(BorderFactory.createLineBorder(Color.black));
textTop.setEditable(false);
textPanel.add(textTop);
Component verticalStrut = Box.createVerticalStrut(20);
textPanel.add(verticalStrut);
JTextArea textBot = new JTextArea();
textBot.setBorder(BorderFactory.createLineBorder(Color.black));
textBot.setEditable(false);
textPanel.add(textBot);
Component verticalStrut_2 = Box.createVerticalStrut(20);
textPanel.add(verticalStrut_2);
Component horizontalStrut_4 = Box.createHorizontalStrut(20);
textPanel.add(horizontalStrut_4);
// Load tab code starts here
JPanel loadPanel = new JPanel();
tabbedPane.addTab("Load Documents", null, loadPanel, null);
loadPanel.setLayout(new BorderLayout(0, 0));
JPanel loadFilePanel = new JPanel();
loadPanel.add(loadFilePanel, BorderLayout.NORTH);
loadFilePanel.setLayout(new BoxLayout(loadFilePanel, BoxLayout.Y_AXIS));
JPanel textFilePanel = new JPanel();
loadFilePanel.add(textFilePanel);
textFilePanel.setLayout(new BoxLayout(textFilePanel, BoxLayout.X_AXIS));
Component textFilePanelStrut_0 = Box.createHorizontalStrut(20);
textFilePanelStrut_0.setPreferredSize(new Dimension(10, 0));
textFilePanel.add(textFilePanelStrut_0);
JLabel textFile = new JLabel("Text File: ");
textFile.setHorizontalAlignment(SwingConstants.LEFT);
textFilePanel.add(textFile);
Component textFilePanelStrut_1 = Box.createHorizontalStrut(20);
textFilePanelStrut_1.setPreferredSize(new Dimension(10, 0));
textFilePanel.add(textFilePanelStrut_1);
JTextField textFilePath = new JTextField();
textFilePath.setHorizontalAlignment(SwingConstants.LEFT);
textFilePath.setColumns(10);
textFilePanel.add(textFilePath);
Component textFilePanelStrut_2 = Box.createHorizontalStrut(20);
textFilePanelStrut_2.setPreferredSize(new Dimension(10, 0));
textFilePanel.add(textFilePanelStrut_2);
JButton browse = new JButton("Browse");
textFilePanel.add(browse);
browse.addActionListener(new ActionListener() {
JFileChooser chooser;
String chooserTitle;
public void actionPerformed(ActionEvent e) {
chooser = new JFileChooser();
chooser.setCurrentDirectory(new java.io.File("."));
chooser.setDialogTitle(chooserTitle);
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setAcceptAllFileFilterUsed(false);
if (chooser.showOpenDialog(browse) == JFileChooser.APPROVE_OPTION) {
chooser.getCurrentDirectory();
chooser.getSelectedFile();
}
}
});
Component textFilePanelStrut_3 = Box.createHorizontalStrut(20);
textFilePanelStrut_3.setPreferredSize(new Dimension(10, 0));
textFilePanel.add(textFilePanelStrut_3);
Component textFilePanelSpacer_1 = Box.createVerticalStrut(10);
loadFilePanel.add(textFilePanelSpacer_1);
JPanel textFileTypePanel = new JPanel();
loadFilePanel.add(textFileTypePanel);
textFileTypePanel.setLayout(new BoxLayout(textFileTypePanel, BoxLayout.X_AXIS));
Component textFileTypeStrut_1 = Box.createHorizontalStrut(20);
textFileTypeStrut_1.setPreferredSize(new Dimension(10, 0));
textFileTypePanel.add(textFileTypeStrut_1);
JLabel textFileType = new JLabel("Text File Type: ");
textFile.setHorizontalAlignment(SwingConstants.LEFT);
textFileTypePanel.add(textFileType);
Component textFileTypeStrut_2 = Box.createHorizontalStrut(20);
textFileTypeStrut_2.setPreferredSize(new Dimension(10, 0));
textFileTypePanel.add(textFileTypeStrut_2);
Component loadFileVertStrut_1 = Box.createVerticalStrut(10);
loadFilePanel.add(loadFileVertStrut_1);
JComboBox<String> fileType;
String fileTypes[] = {"Project Gutenberg File", ".txt", ".rtf"};
fileType = new JComboBox<String> (fileTypes);
fileType.setBackground(Color.WHITE);
textFileTypePanel.add(fileType);
Component titleAuthorStrut_1 = Box.createHorizontalStrut(20);
titleAuthorStrut_1.setPreferredSize(new Dimension(10, 0));
textFileTypePanel.add(titleAuthorStrut_1);
JPanel titleAuthorPanel = new JPanel();
loadFilePanel.add(titleAuthorPanel);
titleAuthorPanel.setLayout(new BoxLayout(titleAuthorPanel, BoxLayout.X_AXIS));
Component loadFileVertStrut_2 = Box.createVerticalStrut(10);
loadFilePanel.add(loadFileVertStrut_2);
Component titleAuthorStrut_2 = Box.createHorizontalStrut(20);
titleAuthorStrut_2.setPreferredSize(new Dimension(10, 0));
titleAuthorPanel.add(titleAuthorStrut_2);
JLabel title = new JLabel("Title: ");
title.setHorizontalAlignment(SwingConstants.LEFT);
titleAuthorPanel.add(title);
Component titleAuthorStrut_3 = Box.createHorizontalStrut(20);
titleAuthorStrut_3.setPreferredSize(new Dimension(10, 0));
titleAuthorPanel.add(titleAuthorStrut_3);
JTextArea titleField = new JTextArea();
titleField.setBorder(BorderFactory.createLineBorder(Color.black));
titleField.setEditable(true);
titleAuthorPanel.add(titleField);
Component titleAuthorStrut_4= Box.createHorizontalStrut(20);
titleAuthorStrut_4.setPreferredSize(new Dimension(10, 0));
titleAuthorPanel.add(titleAuthorStrut_4);
JLabel author = new JLabel("Author: ");
author.setHorizontalAlignment(SwingConstants.LEFT);
titleAuthorPanel.add(author);
Component titleAuthorStrut_5 = Box.createHorizontalStrut(20);
titleAuthorStrut_5.setPreferredSize(new Dimension(10, 0));
titleAuthorPanel.add(titleAuthorStrut_5);
JTextArea authorField = new JTextArea();
authorField.setBorder(BorderFactory.createLineBorder(Color.black));
authorField.setEditable(true);
titleAuthorPanel.add(authorField);
Component titleAuthorStrut_6 = Box.createHorizontalStrut(20);
titleAuthorStrut_6.setPreferredSize(new Dimension(10, 0));
titleAuthorPanel.add(titleAuthorStrut_6);
loadFilePanel.add(new JSeparator(SwingConstants.HORIZONTAL));
Component loadFileVertStrut_3 = Box.createVerticalStrut(10);
loadFilePanel.add(loadFileVertStrut_3);
JPanel processPanel = new JPanel();
processPanel.setBorder(new EmptyBorder(0, 10, 0, 10));
loadFilePanel.add(processPanel);
processPanel.setLayout(new BoxLayout(processPanel, BoxLayout.X_AXIS));
JButton process = new JButton("Process");
process.setAlignmentX(Component.LEFT_ALIGNMENT);
processPanel.add(process);
process.addActionListener((event) -> JOptionPane.showMessageDialog(null, "Process function disabled/not available."));
Component loadFileVertStrut_4 = Box.createVerticalStrut(10);
processPanel.add(loadFileVertStrut_4);
JPanel processTextPanel = new JPanel();
processTextPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
loadPanel.add(processTextPanel);
processTextPanel.setLayout(new BorderLayout());
JTextArea processedText = new JTextArea();
processedText.setBorder(BorderFactory.createLineBorder(Color.black));
processedText.setEditable(false);
processTextPanel.add(processedText);
//End Load tab code
JPanel summPanel = new JPanel();
tabbedPane.addTab("Summarize Documents", null, summPanel, null);
}
}