-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwikiAnalyzerGUI.java
More file actions
278 lines (235 loc) · 9.06 KB
/
wikiAnalyzerGUI.java
File metadata and controls
278 lines (235 loc) · 9.06 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
import java.awt.EventQueue;
import javax.swing.JFrame;
import java.awt.GridBagLayout;
import javax.swing.JComboBox;
import java.awt.GridBagConstraints;
import javax.swing.DefaultComboBoxModel;
import java.awt.Insets;
import java.awt.BorderLayout;
import javax.swing.JTextArea;
import javax.swing.JLabel;
import javax.swing.JSplitPane;
import javax.swing.JPanel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneConstants;
public class wikiAnalyzerGUI {
private JFrame frmChaesWikipediaMovie;
private JTextField txtOption;
private JTextField txtOptionHere;
private JTextArea textArea;
private wikiGUIController control;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
wikiAnalyzerGUI window = new wikiAnalyzerGUI();
window.frmChaesWikipediaMovie.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public wikiAnalyzerGUI() {
this.control = new wikiGUIController();
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frmChaesWikipediaMovie = new JFrame();
frmChaesWikipediaMovie.setTitle("Chae's Wikipedia Movie Analyzer");
frmChaesWikipediaMovie.setBounds(100, 100, 920, 600);
frmChaesWikipediaMovie.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
GridBagLayout gridBagLayout = new GridBagLayout();
gridBagLayout.columnWidths = new int[] { 702, 0 };
gridBagLayout.rowHeights = new int[] { 100, 50, 0, 80, 178, 0 };
gridBagLayout.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 1.0,
Double.MIN_VALUE };
frmChaesWikipediaMovie.getContentPane().setLayout(gridBagLayout);
final JComboBox comboBox = new JComboBox();
comboBox
.setModel(new DefaultComboBoxModel(
new String[] {
"<html><center>List all movies nominated for the Best Picture award for which one of the (OPTION1) was (OPTION2)</center></html>",
"<html><center>For the Best Original Screenplay award, list the writers for the movie that was nominated/won title (OPTION1)</center></html>",
"<html><center>List all actors nominated for a Best Leading Actor award whose role was playing (a/an) (OPTION1)</center></html>",
"<html><center>For the year (OPTION1), list all actresses nominated for a Best Leading Actress award along with the movie and their age that year</center></html>",
"<html><center>List all directors (with the corresponding movies) that have been nominated for at least (OPTION1) Best Director awards</center></html>",
"<html><center>List the country (with the corresponding movies) that has been nominated the most number of times for Best Foreign Language Film award</center></html>",
"<html><center>List all movies nominated for the (OPTION1) award that starred (OPTION2)</center></html>",
"<html><center>List all movies that were nominated for Best Picture, Best Director, Best Leading Actor, and Best Leading Actress along with the number of awards won by each movie</center></html>",
"<html><center>How many movies have been nominated for Best Picture?</center></html>",
"<html><center>How many nominations have been handed out for Best Actor?</center></html>"}));
GridBagConstraints gbc_comboBox = new GridBagConstraints();
gbc_comboBox.fill = GridBagConstraints.BOTH;
gbc_comboBox.insets = new Insets(0, 0, 5, 0);
gbc_comboBox.gridx = 0;
gbc_comboBox.gridy = 0;
frmChaesWikipediaMovie.getContentPane().add(comboBox, gbc_comboBox);
;
JSplitPane splitPane = new JSplitPane();
GridBagConstraints gbc_splitPane = new GridBagConstraints();
gbc_splitPane.insets = new Insets(0, 0, 5, 0);
gbc_splitPane.fill = GridBagConstraints.BOTH;
gbc_splitPane.gridx = 0;
gbc_splitPane.gridy = 1;
frmChaesWikipediaMovie.getContentPane().add(splitPane, gbc_splitPane);
JButton btnClearAll = new JButton("Clear All");
btnClearAll.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
textArea.setText("");
txtOption.setText("");
txtOptionHere.setText("");
}
});
splitPane.setLeftComponent(btnClearAll);
JButton btnSubmit = new JButton("Submit!");
btnSubmit.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
String option1 = "", option2 = "", response = "";
String comboText = comboBox.getSelectedItem().toString();
final Pattern oneOption = Pattern.compile("(.*).OPTION1.(.*)");
final Pattern twoOption = Pattern
.compile("(.*).OPTION1.(.*).OPTION2.(.*)");
Matcher oneMatcher = oneOption.matcher(comboText);
Matcher twoMatcher = twoOption.matcher(comboText);
// get option values from text boxes
try {
option1 = txtOption.getText().trim();
} catch (NullPointerException ex) {
}
try {
option2 = txtOptionHere.getText().trim();
} catch (NullPointerException ex) {
}
// put question top in result box
if (twoMatcher.find()) {
comboText = twoMatcher.group(1) + option1 + twoMatcher.group(2)
+ option2 + twoMatcher.group(3);
} else if (oneMatcher.find()) {
comboText = oneMatcher.group(1) + option1 + oneMatcher.group(2);
}
comboText = comboText.split(">")[2].split("<")[0];
int comboValue = comboBox.getSelectedIndex() + 1; // this will agree
// with numbering
// of questions
// on assignment
try {
switch (comboValue) {
case 1:
response = control.bestPictureSearch(option1, option2);
break;
case 2:
response = control.bestOrigScreenplay(option1);
break;
case 3:
response = control.bestActorRole(option1);
break;
case 4:
response = control.actressAge(option1);
break;
case 5:
response = control.directorThreshold(option1);
break;
case 6:
response = control.topForeign();
break;
case 7:
response = control.nomStarring(option1, option2);
break;
case 8:
response = control.quadThreat();
break;
case 9:
response = control.bestPictureCount();
break;
case 10:
response = control.bestActorCount();
break;
}
} catch (BadArgumentException excep) {
if (excep.getMessage().equals(null)) {
JOptionPane
.showMessageDialog(
null,
"No Results! Either the search is null or your syntax is wrong! Consult README",
"Whoops!", JOptionPane.ERROR_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, excep.getMessage(),
"Whoops!", JOptionPane.ERROR_MESSAGE);
}
} catch (Exception excep) {
excep.printStackTrace();
JOptionPane.showMessageDialog(null,
"Please check correct syntax! Consult README", "Whoops!",
JOptionPane.ERROR_MESSAGE);
}
textArea.setText(comboText + "\n\n" + response);
}
});
// generated GUI code
splitPane.setRightComponent(btnSubmit);
JPanel panel = new JPanel();
GridBagConstraints gbc_panel = new GridBagConstraints();
gbc_panel.insets = new Insets(0, 0, 5, 0);
gbc_panel.fill = GridBagConstraints.BOTH;
gbc_panel.gridx = 0;
gbc_panel.gridy = 2;
frmChaesWikipediaMovie.getContentPane().add(panel, gbc_panel);
panel.setLayout(new BorderLayout(0, 0));
JLabel lblOptionBelow = new JLabel(" Option 1 Below");
panel.add(lblOptionBelow, BorderLayout.WEST);
JLabel lblOptionBelow_1 = new JLabel("Option 2 Below (if necessary) ");
panel.add(lblOptionBelow_1, BorderLayout.EAST);
JPanel panel_1 = new JPanel();
GridBagConstraints gbc_panel_1 = new GridBagConstraints();
gbc_panel_1.insets = new Insets(0, 0, 5, 0);
gbc_panel_1.fill = GridBagConstraints.BOTH;
gbc_panel_1.gridx = 0;
gbc_panel_1.gridy = 3;
frmChaesWikipediaMovie.getContentPane().add(panel_1, gbc_panel_1);
panel_1.setLayout(new BoxLayout(panel_1, BoxLayout.X_AXIS));
JPanel panel_2 = new JPanel();
panel_1.add(panel_2);
panel_2.setLayout(new BorderLayout(0, 0));
txtOption = new JTextField();
panel_2.add(txtOption);
txtOption.setColumns(10);
JPanel panel_3 = new JPanel();
panel_1.add(panel_3);
panel_3.setLayout(new BorderLayout(0, 0));
txtOptionHere = new JTextField();
panel_3.add(txtOptionHere);
txtOptionHere.setColumns(10);
JScrollPane scrollPane = new JScrollPane();
scrollPane
.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
GridBagConstraints gbc_scrollPane = new GridBagConstraints();
gbc_scrollPane.fill = GridBagConstraints.BOTH;
gbc_scrollPane.gridx = 0;
gbc_scrollPane.gridy = 4;
frmChaesWikipediaMovie.getContentPane().add(scrollPane, gbc_scrollPane);
textArea = new JTextArea();
scrollPane.setViewportView(textArea);
textArea.setEditable(false);
}
}