-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSelectOutputDirectory.java
executable file
·97 lines (81 loc) · 4.02 KB
/
SelectOutputDirectory.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
public class SelectOutputDirectory extends WizardPanel {
java.io.File outputDirectory;
/** Creates new form SelectOutputFile */
public SelectOutputDirectory(String stepText) {
super(stepText);
initComponents();
setFirstFocusable(selectButton);
}
/** 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.
*/
private void initComponents() {//GEN-BEGIN:initComponents
selectFileLabel = new javax.swing.JLabel();
selectFilePanel = new javax.swing.JPanel();
imageTextField = new javax.swing.JTextField();
selectButton = new javax.swing.JButton();
setLayout(new java.awt.BorderLayout());
selectFileLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
selectFileLabel.setText("Select the output directory");
selectFileLabel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 2));
add(selectFileLabel, java.awt.BorderLayout.CENTER);
selectFilePanel.setLayout(new java.awt.BorderLayout());
selectFilePanel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 2));
selectFilePanel.add(imageTextField, java.awt.BorderLayout.CENTER);
selectButton.setMnemonic('D');
selectButton.setText("Select Directory");
selectButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
selectButtonActionPerformed(evt);
}
});
selectFilePanel.add(selectButton, java.awt.BorderLayout.EAST);
add(selectFilePanel, java.awt.BorderLayout.SOUTH);
}//GEN-END:initComponents
private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectButtonActionPerformed
// Add your handling code here:
// Add your handling code here:
javax.swing.JFileChooser chooser = new javax.swing.JFileChooser(".");
if(imageTextField.getText() != null)
chooser.setSelectedFile(new java.io.File(imageTextField.getText()));
chooser.setFileSelectionMode(javax.swing.JFileChooser.DIRECTORIES_ONLY);
if( chooser.showOpenDialog(this) == javax.swing.JFileChooser.APPROVE_OPTION){
outputDirectory = chooser.getSelectedFile();
imageTextField.setText(outputDirectory.getAbsolutePath());
}
}//GEN-LAST:event_selectButtonActionPerformed
public boolean doValidation() {
if( imageTextField.getText().length() == 0 ) {
javax.swing.JOptionPane.showMessageDialog(this,"Select an output directory");
selectButton.requestFocus();
return false;
}else if( new java.io.File(imageTextField.getText()) == null ){
javax.swing.JOptionPane.showMessageDialog(this,"Select an valid directory/path");
selectButton.requestFocus();
return false;
}else if( ! new java.io.File(imageTextField.getText()).exists() ){
javax.swing.JOptionPane.showMessageDialog(this,"Directory does not exist!");
selectButton.requestFocus();
return false;
}else if( ! new java.io.File(imageTextField.getText()).isDirectory() ){
javax.swing.JOptionPane.showMessageDialog(this,"File is not a directory!");
selectButton.requestFocus();
return false;
}
return true;
}
/** Getter for property outputDirectory.
* @return Value of property outputDirectory.
*/
public java.io.File getOutputDirectory() {
return outputDirectory;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel selectFileLabel;
private javax.swing.JTextField imageTextField;
private javax.swing.JButton selectButton;
private javax.swing.JPanel selectFilePanel;
// End of variables declaration//GEN-END:variables
}