This repository has been archived by the owner on Jul 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ProgramUI.java
411 lines (360 loc) · 20.4 KB
/
ProgramUI.java
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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
package nmsvrscreenshotfix;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
/**
* Handles visual aspects of the main window as well as all program popups.
* @author Noah Ortega
*/
public class ProgramUI extends javax.swing.JFrame {
LogicController controller = LogicController.getInstance();
String[] fileErrorOptions = {"Okay","Okay, Skip Remaining Errors","Cancel Execution"};
public ProgramUI() {
initComponents();
resultFolderField.setText(controller.resultPath);
sourceFolderField.setText(controller.sourcePath);
behaviorTextArea.setText(controller.getCurrentBehaviorString());
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel3 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jLabel1 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
sourceFolderField = new javax.swing.JTextField();
sourceFolderButton = new javax.swing.JButton();
resultFolderField = new javax.swing.JTextField();
resultFolderButton = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
behaviorTextArea = new javax.swing.JTextArea();
settingsButton = new javax.swing.JButton();
executeButton = new javax.swing.JButton();
progressBar = new javax.swing.JProgressBar();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("NMS VR Screenshot Fix");
setResizable(false);
jLabel2.setText("Source Folder:");
jLabel1.setText("Behavior:");
jLabel1.setVerticalAlignment(javax.swing.SwingConstants.TOP);
jLabel3.setText("Result Folder:");
sourceFolderField.setText("err");
sourceFolderField.setMaximumSize(new java.awt.Dimension(2147483647, 32));
sourceFolderField.setMinimumSize(new java.awt.Dimension(14, 32));
sourceFolderField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sourceFolderFieldActionPerformed(evt);
}
});
sourceFolderButton.setText("...");
sourceFolderButton.setMaximumSize(new java.awt.Dimension(22, 22));
sourceFolderButton.setMinimumSize(new java.awt.Dimension(22, 22));
sourceFolderButton.setPreferredSize(new java.awt.Dimension(32, 32));
sourceFolderButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sourceFolderButtonActionPerformed(evt);
}
});
resultFolderField.setText("err");
resultFolderField.setMaximumSize(new java.awt.Dimension(2147483647, 32));
resultFolderField.setMinimumSize(new java.awt.Dimension(14, 32));
resultFolderField.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
resultFolderFieldActionPerformed(evt);
}
});
resultFolderButton.setText("...");
resultFolderButton.setMaximumSize(new java.awt.Dimension(22, 22));
resultFolderButton.setMinimumSize(new java.awt.Dimension(22, 22));
resultFolderButton.setPreferredSize(new java.awt.Dimension(32, 32));
resultFolderButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
resultFolderButtonActionPerformed(evt);
}
});
behaviorTextArea.setEditable(false);
behaviorTextArea.setColumns(20);
behaviorTextArea.setLineWrap(true);
behaviorTextArea.setRows(5);
behaviorTextArea.setText("• Make copies of converted screenshots\n• Add prefix \" new_\" to the new image\n• Ex: \"image.png\" -> \"new_image.png\"\n");
jScrollPane2.setViewportView(behaviorTextArea);
settingsButton.setText("Behavior Settings");
settingsButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
settingsButtonActionPerformed(evt);
}
});
executeButton.setText("Execute");
executeButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
executeButtonActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
jPanel3.setLayout(jPanel3Layout);
jPanel3Layout.setHorizontalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(executeButton)
.addComponent(jLabel3)
.addComponent(jLabel2)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(settingsButton))
.addComponent(resultFolderField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
.addComponent(sourceFolderField, javax.swing.GroupLayout.PREFERRED_SIZE, 315, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(sourceFolderButton, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(resultFolderButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(256, 256, 256))
);
jPanel3Layout.setVerticalGroup(
jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel3Layout.createSequentialGroup()
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addGap(24, 24, 24)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(sourceFolderButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(sourceFolderField, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addGap(23, 23, 23)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(17, 17, 17)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
.addGap(1, 1, 1)
.addComponent(resultFolderField, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE))
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(resultFolderButton, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(settingsButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(progressBar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(executeButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(12, 12, 12))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 462, javax.swing.GroupLayout.PREFERRED_SIZE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void executeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_executeButtonActionPerformed
if(controller.getIsExecuting()) {
controller.cancelExecution();
}
else {
controller.sourcePath = sourceFolderField.getText();
controller.resultPath = resultFolderField.getText();
if (controller.hasValidDirectoryPaths()) {
controller.execute();
}
else {
errorInvalidPath();
}
}
}//GEN-LAST:event_executeButtonActionPerformed
private void settingsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_settingsButtonActionPerformed
new SettingsUI(this,true).setVisible(true);
behaviorTextArea.setText(controller.getCurrentBehaviorString());
}//GEN-LAST:event_settingsButtonActionPerformed
private void resultFolderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resultFolderButtonActionPerformed
JFileChooser jfc = new JFileChooser();
jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int optionCode = jfc.showSaveDialog(null);
if (optionCode == JFileChooser.APPROVE_OPTION) {
controller.resultPath = jfc.getSelectedFile().getAbsolutePath();
resultFolderField.setText(controller.resultPath);
behaviorTextArea.setText(controller.getCurrentBehaviorString());
}
}//GEN-LAST:event_resultFolderButtonActionPerformed
private void resultFolderFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resultFolderFieldActionPerformed
controller.resultPath = resultFolderField.getText();
behaviorTextArea.setText(controller.getCurrentBehaviorString());
}//GEN-LAST:event_resultFolderFieldActionPerformed
private void sourceFolderButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sourceFolderButtonActionPerformed
JFileChooser jfc = new JFileChooser();
jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int optionCode = jfc.showSaveDialog(null);
if (optionCode == JFileChooser.APPROVE_OPTION) {
controller.sourcePath = jfc.getSelectedFile().getAbsolutePath();
sourceFolderField.setText(controller.sourcePath);
behaviorTextArea.setText(controller.getCurrentBehaviorString());
}
}//GEN-LAST:event_sourceFolderButtonActionPerformed
private void sourceFolderFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sourceFolderFieldActionPerformed
controller.sourcePath = sourceFolderField.getText();
behaviorTextArea.setText(controller.getCurrentBehaviorString());
}//GEN-LAST:event_sourceFolderFieldActionPerformed
/**
* enables or disables all interactive UI elements except for the execute/cancel button
* depending on if the program is executing. prevents editing settings while executing.
*/
public void toggleUI() {
boolean shouldEnable = !controller.getIsExecuting();
settingsButton.setEnabled(shouldEnable);
sourceFolderField.setEnabled(shouldEnable);
sourceFolderButton.setEnabled(shouldEnable);
resultFolderField.setEnabled(shouldEnable);
resultFolderButton.setEnabled(shouldEnable);
if(controller.getIsExecuting()) {
executeButton.setText("cancel");
} else {
executeButton.setText("execute");
}
}
/**
* Allows the logic controller to change the value of the progress bar
* @param value percentage the progress bar should be filled. (max 100)
*/
public void updateProgressBar(int value) {
progressBar.setValue(value);
}
/**
* Popup triggered when execution is completed. If no files were converted the
* user is given a warning popup instead of a success popup.
* @param converted number of converted files during execution
*/
public void completePopup(int converted) {
if(converted != 0) {
JOptionPane.showMessageDialog(this,
("" + converted + " images were converted successfully."),
"Complete", JOptionPane.INFORMATION_MESSAGE);
progressBar.setValue(0);
} else {
JOptionPane.showMessageDialog(this,
("No images were able to be converted from in the source folder."),
"Error: No images found", JOptionPane.WARNING_MESSAGE);
progressBar.setValue(0);
}
}
/**
* Popup triggered if execution is canceled before completion.
* Tells the user how many files were converted before cancellation.
* @param converted number of files converted before cancellation
*/
public void cancelPopup(int converted) {
JOptionPane.showMessageDialog(this,
"Converted " + converted + " files before canceling.",
"Canceled", JOptionPane.ERROR_MESSAGE);
}
/**
* If the user chooses a settings combination which will result in replacing
* their original screenshots this warning will give them one last chance to
* change their mind by canceling execution.
*/
public void warningReplacingFiles(){
int choice = JOptionPane.showOptionDialog(this,
"By continuing you will be replacing your original screenshots. This cannot be undone.\n"
+ "Please press Cancel and change the behavior settings if this was not intended.",
"Replacing Files",JOptionPane.OK_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE,
null,null,null);
if(choice != 0) {
controller.cancelExecution();
}
}
/**
* Popup triggers on attempted execution when the source or destination
* folder path is invalid.
*/
public void errorInvalidPath() {
JOptionPane.showMessageDialog(this,
"One or both of the folder paths do not lead to a valid folder.\n"
+ "Make sure the source and destination folders you choose exist.",
"Error: invalid folder path", JOptionPane.WARNING_MESSAGE);
}
/**
* Popup triggers during execution when an image cannot be read due to corruption.
* Gives user the option to skip remaining errors or cancel the operation.
* @param fileName the name of the corrupt image file
*/
public void errorCorruptImage(String fileName) {
int choice = JOptionPane.showOptionDialog(this,
"The image file '" + fileName + "' cannot be read and may be corrupt.",
"Corrupt File Error: Cancel Execution?",JOptionPane.DEFAULT_OPTION,JOptionPane.ERROR_MESSAGE,
null,fileErrorOptions,fileErrorOptions[0]);
controller.userErrorResponse(choice);
}
/**
* Popup triggers if an image cannot be read from the source folder.
* Gives user the option to skip remaining errors or cancel the operation.
*/
public void errorReading(String fileName) {
int choice = JOptionPane.showOptionDialog(this,
"There was a problem reading the file, '"+fileName+"' from the source folder.",
"Read Error: Cancel Execution?",JOptionPane.DEFAULT_OPTION,JOptionPane.ERROR_MESSAGE,
null,fileErrorOptions,fileErrorOptions[0]);
controller.userErrorResponse(choice);
}
/**
* Popup triggers if an image cannot be written to the destination folder
* Gives user the option to skip remaining errors or cancel the operation.
*/
public void errorWriting(String fileName) {
int choice = JOptionPane.showOptionDialog(this,
"There was a problem writing the file '"+fileName+"' to the destination folder.",
"Write Error: Cancel Execution?",JOptionPane.DEFAULT_OPTION,JOptionPane.ERROR_MESSAGE,
null,fileErrorOptions,fileErrorOptions[0]);
controller.userErrorResponse(choice);
}
//////////////////////////////////////////////////////////////////////
// Settings Menu: text addition issue warning popups
/////////////////////////////////////////////////////////////////////
public void warningEmptyText() {
JOptionPane.showMessageDialog(this,
"The 'Text to be added' field cannot be left empty.",
"Text left empty", JOptionPane.WARNING_MESSAGE);
}
public void warningExceededTextLimit() {
JOptionPane.showMessageDialog(this,
"Added text cannot exceed "+controller.MAX_ADD_TEXT_LENGTH+" characters.",
"Text too long", JOptionPane.WARNING_MESSAGE);
}
public void warningInvalidText(char invalidChar) {
JOptionPane.showMessageDialog(this,
"Text must contain only alphanumeric characters, '_', and '-'.\nInvalid character: '"+invalidChar+"'.",
"Invalid character in the text", JOptionPane.WARNING_MESSAGE);
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextArea behaviorTextArea;
private javax.swing.JButton executeButton;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel3;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JProgressBar progressBar;
private javax.swing.JButton resultFolderButton;
private javax.swing.JTextField resultFolderField;
private javax.swing.JButton settingsButton;
private javax.swing.JButton sourceFolderButton;
private javax.swing.JTextField sourceFolderField;
// End of variables declaration//GEN-END:variables
}