-
Notifications
You must be signed in to change notification settings - Fork 2
/
SelectDataToEmbed.java
executable file
·198 lines (162 loc) · 8.04 KB
/
SelectDataToEmbed.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
public class SelectDataToEmbed extends WizardPanel {
private java.io.File selectedFile;
private boolean textOrFile;
private String embeddedText;
/** Creates new form SelectDataToEmbed */
public SelectDataToEmbed(String display) {
super(display);
initComponents();
choiceButtonGroup.add(selectFileRadioButton);
choiceButtonGroup.add(enterTextRadioButton);
setFirstFocusable(selectFileRadioButton);
}
/** 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
choiceButtonGroup = new javax.swing.ButtonGroup();
choicePanel = new javax.swing.JPanel();
selectFileRadioButton = new javax.swing.JRadioButton();
enterTextRadioButton = new javax.swing.JRadioButton();
optionsPanel = new javax.swing.JPanel();
selectFilePanel = new javax.swing.JPanel();
selectFileLabel = new javax.swing.JLabel();
chooseFilePanel = new javax.swing.JPanel();
embedFileTextField = new javax.swing.JTextField();
selectButton = new javax.swing.JButton();
enterTextPanel = new javax.swing.JPanel();
enterTextScrollPane = new javax.swing.JScrollPane();
embedTextArea = new javax.swing.JTextArea();
embedLabel = new javax.swing.JLabel();
setLayout(new java.awt.BorderLayout());
choicePanel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 2));
selectFileRadioButton.setMnemonic('S');
selectFileRadioButton.setSelected(true);
selectFileRadioButton.setText("Select File");
selectFileRadioButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
selectFileRadioButtonActionPerformed(evt);
}
});
choicePanel.add(selectFileRadioButton);
enterTextRadioButton.setMnemonic('E');
enterTextRadioButton.setText("Enter Text");
enterTextRadioButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
enterTextRadioButtonActionPerformed(evt);
}
});
choicePanel.add(enterTextRadioButton);
add(choicePanel, java.awt.BorderLayout.NORTH);
optionsPanel.setLayout(new java.awt.CardLayout());
optionsPanel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 2));
selectFilePanel.setLayout(new java.awt.BorderLayout());
selectFileLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
selectFileLabel.setText("Select the file to embed");
selectFileLabel.setBorder(new javax.swing.border.LineBorder(new java.awt.Color(0, 0, 0), 2));
selectFilePanel.add(selectFileLabel, java.awt.BorderLayout.CENTER);
chooseFilePanel.setLayout(new java.awt.BorderLayout());
embedFileTextField.setEditable(false);
chooseFilePanel.add(embedFileTextField, java.awt.BorderLayout.CENTER);
selectButton.setMnemonic('F');
selectButton.setText("Select File");
selectButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
selectButtonActionPerformed(evt);
}
});
chooseFilePanel.add(selectButton, java.awt.BorderLayout.EAST);
selectFilePanel.add(chooseFilePanel, java.awt.BorderLayout.SOUTH);
optionsPanel.add(selectFilePanel, "card3");
enterTextPanel.setLayout(new java.awt.BorderLayout());
enterTextScrollPane.setViewportView(embedTextArea);
enterTextPanel.add(enterTextScrollPane, java.awt.BorderLayout.CENTER);
embedLabel.setText("Enter the text to be embedded into the image");
enterTextPanel.add(embedLabel, java.awt.BorderLayout.SOUTH);
optionsPanel.add(enterTextPanel, "card2");
add(optionsPanel, java.awt.BorderLayout.CENTER);
}//GEN-END:initComponents
private void selectButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectButtonActionPerformed
// Add your handling code here:
javax.swing.JFileChooser chooser = new javax.swing.JFileChooser(".");
if( embedFileTextField.getText() != null)
chooser.setSelectedFile(new java.io.File(embedFileTextField.getText()));
if( chooser.showOpenDialog(this) == javax.swing.JFileChooser.APPROVE_OPTION){
selectedFile = chooser.getSelectedFile();
embedFileTextField.setText(selectedFile.getAbsolutePath());
}
}//GEN-LAST:event_selectButtonActionPerformed
private void enterTextRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enterTextRadioButtonActionPerformed
// Add your handling code here:
((java.awt.CardLayout)optionsPanel.getLayout()).previous(optionsPanel);
textOrFile = true;
}//GEN-LAST:event_enterTextRadioButtonActionPerformed
private void selectFileRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_selectFileRadioButtonActionPerformed
// Add your handling code here:
((java.awt.CardLayout)optionsPanel.getLayout()).next(optionsPanel);
textOrFile = false;
}//GEN-LAST:event_selectFileRadioButtonActionPerformed
public boolean doValidation() {
embeddedText = embedTextArea.getText().trim();
if( selectFileRadioButton.isSelected() ){
if( embedFileTextField.getText().length() == 0 ) {
javax.swing.JOptionPane.showMessageDialog(this,"Select an input file");
selectButton.requestFocus();
return false;
}else if( ! new java.io.File(embedFileTextField.getText()).exists() ){
javax.swing.JOptionPane.showMessageDialog(this,"File not found! Select an valid file");
selectButton.requestFocus();
return false;
}
}else if( enterTextRadioButton.isSelected() ){
if( embeddedText.length() == 0 ){
javax.swing.JOptionPane.showMessageDialog(this,"Enter some text to embed");
embedTextArea.requestFocus();
return false;
}
}
return true;
}
/** Getter for property textOrFile.
* @return Value of property textOrFile.
*/
public boolean isTextOrFile() {
return textOrFile;
}
/** Setter for property textOrFile.
* @param textOrFile New value of property textOrFile.
*/
public void setTextOrFile(boolean textOrFile) {
this.textOrFile = textOrFile;
}
/** Getter for property embeddedText.
* @return Value of property embeddedText.
*/
public java.lang.String getEmbeddedText() {
return embeddedText;
}
/** Getter for property selectedFile.
* @return Value of property selectedFile.
*/
public java.io.File getSelectedFile() {
return selectedFile;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel selectFileLabel;
private javax.swing.JRadioButton enterTextRadioButton;
private javax.swing.JPanel choicePanel;
private javax.swing.JPanel enterTextPanel;
private javax.swing.JLabel embedLabel;
private javax.swing.JScrollPane enterTextScrollPane;
private javax.swing.JTextField embedFileTextField;
private javax.swing.JRadioButton selectFileRadioButton;
private javax.swing.JTextArea embedTextArea;
private javax.swing.JPanel chooseFilePanel;
private javax.swing.JButton selectButton;
private javax.swing.JPanel selectFilePanel;
private javax.swing.ButtonGroup choiceButtonGroup;
private javax.swing.JPanel optionsPanel;
// End of variables declaration//GEN-END:variables
}