annotate SMART/Java/ProgramOption.java @ 31:0ab839023fe4

Uploaded
author m-zytnicki
date Tue, 30 Apr 2013 14:33:21 -0400
parents 769e306b7933
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
1 /**
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
2 *
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
3 * Copyright INRA-URGI 2009-2010
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
4 *
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
5 * This software is governed by the CeCILL license under French law and
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
6 * abiding by the rules of distribution of free software. You can use,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
7 * modify and/ or redistribute the software under the terms of the CeCILL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
8 * license as circulated by CEA, CNRS and INRIA at the following URL
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
9 * "http://www.cecill.info".
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
10 *
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
11 * As a counterpart to the access to the source code and rights to copy,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
12 * modify and redistribute granted by the license, users are provided only
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
13 * with a limited warranty and the software's author, the holder of the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
14 * economic rights, and the successive licensors have only limited
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
15 * liability.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
16 *
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
17 * In this respect, the user's attention is drawn to the risks associated
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
18 * with loading, using, modifying and/or developing or reproducing the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
19 * software by the user in light of its specific status of free software,
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
20 * that may mean that it is complicated to manipulate, and that also
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
21 * therefore means that it is reserved for developers and experienced
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
22 * professionals having in-depth computer knowledge. Users are therefore
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
23 * encouraged to load and test the software's suitability as regards their
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
24 * requirements in conditions enabling the security of their systems and/or
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
25 * data to be ensured and, more generally, to use and operate it in the
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
26 * same conditions as regards security.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
27 *
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
28 * The fact that you are presently reading this means that you have had
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
29 * knowledge of the CeCILL license and that you accept its terms.
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
30 *
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
31 */
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
32 import java.util.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
33 import java.awt.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
34 import java.awt.event.ActionEvent;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
35 import java.awt.event.ActionListener;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
36 import java.io.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
37 import javax.swing.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
38 import javax.swing.filechooser.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
39 import javax.swing.border.*;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
40 import javax.swing.SwingUtilities;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
41
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
42
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
43 public class ProgramOption {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
44 boolean input;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
45 String identifier;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
46 String type;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
47 String comment;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
48 boolean compulsory;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
49 String[] format;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
50 String formatIdentifier;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
51 ProgramOption associatedOption;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
52 String defaultValue;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
53 String[] choices;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
54 JComponent component;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
55 JPanel panel;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
56
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
57
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
58 public ProgramOption() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
59 this.input = true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
60 this.identifier = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
61 this.type = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
62 this.comment = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
63 this.compulsory = false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
64 this.format = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
65 this.formatIdentifier = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
66 this.associatedOption = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
67 this.defaultValue = "";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
68 this.choices = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
69 this.component = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
70 this.panel = null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
71 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
72
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
73
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
74 public void setInput(boolean input) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
75 this.input = input;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
76 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
77
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
78
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
79 public void setIdentifier(String identifier) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
80 this.identifier = identifier;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
81 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
82
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
83
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
84 public void setType(String type) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
85 this.type = type;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
86 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
87
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
88
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
89 public void setComment(String comment) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
90 this.comment = comment;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
91 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
92
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
93
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
94 public void setCompulsory(boolean compulsory) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
95 this.compulsory = compulsory;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
96 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
97
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
98
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
99 public void setFormat(String[] format) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
100 this.format = format;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
101 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
102
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
103
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
104 public void setFormat(String format) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
105 this.format = new String[1];
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
106 this.format[0] = format;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
107 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
108
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
109
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
110 public void setFormatIdentifier(String formatIdentifier) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
111 this.formatIdentifier = formatIdentifier;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
112 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
113
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
114
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
115 public void setAssociatedOption(ProgramOption option) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
116 this.associatedOption = option;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
117 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
118
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
119
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
120 public void setChoices(String[] choices) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
121 this.choices = new String[choices.length+1];
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
122 this.choices[0] = "---";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
123 for (int i = 0; i < choices.length; i++) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
124 this.choices[i+1] = choices[i];
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
125 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
126 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
127
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
128
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
129 public void setDefault(String defaultValue) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
130 this.defaultValue = defaultValue;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
131 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
132
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
133
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
134 public boolean isInput() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
135 return this.input;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
136 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
137
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
138
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
139 public boolean checkSettings() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
140 if (this.identifier == null) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
141 return false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
142 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
143 if (this.type == null) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
144 return false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
145 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
146 if (this.comment == null) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
147 return false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
148 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
149 if (this.comment == null) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
150 return false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
151 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
152 if (("choice".compareToIgnoreCase(this.type) == 0) && (this.choices == null)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
153 return false;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
154 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
155 return true;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
156 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
157
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
158
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
159 public JPanel getPanel() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
160 if (this.panel != null) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
161 return this.panel;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
162 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
163 String comment = this.comment;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
164 if (this.compulsory) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
165 comment += " [*]";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
166 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
167
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
168 GridLayout horizontalLayout = new GridLayout(1, 0);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
169 this.panel = new JPanel(false);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
170 this.panel.setLayout(horizontalLayout);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
171 JLabel label = new JLabel(comment);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
172
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
173 if (this.type == null) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
174 System.out.println("Error! Option '" + this.identifier + "' is not set!");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
175 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
176
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
177 if (("int".compareToIgnoreCase(this.type) == 0) || ("float".compareToIgnoreCase(this.type) == 0) || ("string".compareToIgnoreCase(this.type) == 0) || (("file".compareToIgnoreCase(this.type) == 0) && (!this.input))) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
178 this.component = new JTextField();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
179 if (this.defaultValue != null) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
180 ((JTextField) this.component).setText(this.defaultValue);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
181 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
182 label.setLabelFor(this.component);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
183 this.panel.add(label);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
184 this.panel.add(this.component);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
185 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
186 else if ("file".compareToIgnoreCase(this.type) == 0) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
187 this.component = new JComboBox(Global.fileNames);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
188 label.setLabelFor(this.component);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
189 this.panel.add(label);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
190 this.panel.add(this.component);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
191 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
192 else if ("boolean".compareToIgnoreCase(this.type) == 0) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
193 this.component = new JCheckBox();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
194 if ((this.defaultValue != null) && (this.defaultValue.compareToIgnoreCase("true") == 0)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
195 ((JCheckBox) this.component).setSelected(true);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
196 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
197 label.setLabelFor(this.component);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
198 this.panel.add(label);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
199 this.panel.add(this.component);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
200 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
201 else if ("format".compareToIgnoreCase(this.type) == 0) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
202 Vector < String > formats = new Vector < String > ();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
203 for (String format: this.format) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
204 if (Global.formats.getFormats(format) == null) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
205 System.out.println("Do not know how to handle format '" + format + "'.");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
206 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
207 formats.addAll(Global.formats.getFormats(format).getFormats());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
208 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
209 this.component = new JComboBox(formats);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
210 label.setLabelFor(this.component);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
211 this.panel.add(label);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
212 this.panel.add(this.component);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
213 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
214 else if ("files".compareToIgnoreCase(this.type) == 0) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
215 JButton button = new JButton("file...");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
216 this.component = new JTextField();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
217 label.setLabelFor(this.component);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
218 this.panel.add(label);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
219 this.panel.add(this.component);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
220 this.panel.add(button);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
221 Global.otherFileConcatenationChooser.put(button, (JTextField) this.component);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
222 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
223 else if ("directory".compareToIgnoreCase(this.type) == 0) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
224 JButton button = new JButton("directory...");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
225 this.component = new JTextField();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
226 label.setLabelFor(this.component);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
227 this.panel.add(label);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
228 JPanel rightPanel = new JPanel(false);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
229 rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.LINE_AXIS));
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
230 rightPanel.add(this.component);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
231 rightPanel.add(button);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
232 this.panel.add(rightPanel);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
233 Global.otherDirectoriesChooser.put(button, (JTextField) this.component);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
234 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
235 else if ("choice".compareToIgnoreCase(this.type) == 0) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
236 this.component = new JComboBox(this.choices);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
237 label.setLabelFor(this.component);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
238 this.panel.add(label);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
239 this.panel.add(this.component);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
240 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
241 else {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
242 System.out.println("Do not know how to read type " + this.type);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
243 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
244
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
245 return this.panel;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
246 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
247
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
248
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
249 public JComponent getComponent() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
250 if (component == null) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
251 this.getPanel();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
252 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
253 return this.component;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
254 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
255
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
256
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
257 private String getValue() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
258 if (("int".equals(this.type)) || ("float".equals(this.type)) || ("string".equals(this.type)) || (("file".equals(this.type)) && (! this.input)) || ("directory".equals(this.type)) || ("files".equals(this.type))) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
259 String s = ((JTextField) this.component).getText();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
260 if ("None".equals(s)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
261 return "";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
262 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
263 return s;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
264 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
265 if ("file".equals(this.type)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
266 return (String) ((JComboBox) this.component).getSelectedItem();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
267 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
268 if ("boolean".equals(this.type)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
269 return ((JCheckBox) this.component).isSelected()? "true": "false";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
270 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
271 if ("format".equals(this.type)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
272 return (String) ((JComboBox) this.component).getSelectedItem();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
273 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
274 if ("choice".equals(this.type)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
275 String s = (String) ((JComboBox) this.component).getSelectedItem();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
276 if ("---".equals(s)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
277 return "";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
278 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
279 return s;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
280 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
281 System.out.println("Do not know how to get value of '" + this.type + "' (" + this.identifier + ").");
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
282 return null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
283 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
284
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
285
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
286 public String checkValue() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
287 String value = this.getValue();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
288 if ((this.compulsory) && ((value == null) || ("".equals(value)))) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
289 return "Option '" + this.comment + "' has no value... Please specify it.\n";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
290 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
291 if ("int".equals(this.type)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
292 if ((value != null) && (! "".equals(value)) && (! "None".equals(value))) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
293 try {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
294 int i = Integer.parseInt(value);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
295 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
296 catch (NumberFormatException e) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
297 return "Option '" + this.comment + "' should be an integer... Please correct it.\n";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
298 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
299 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
300 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
301 else if ("float".equals(this.type)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
302 if ((value != null) && (! "".equals(value))) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
303 try {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
304 float i = Float.parseFloat(value);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
305 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
306 catch (NumberFormatException e) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
307 return "Option '" + this.comment + "' should be a float... Please correct it.\n";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
308 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
309 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
310 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
311 return null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
312 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
313
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
314
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
315 public LinkedList <String> getCommand() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
316 LinkedList <String> list = new LinkedList <String> ();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
317
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
318 if (("int".equals(this.type)) || ("float".equals(this.type)) || ("string".equals(this.type)) || (("file".equals(this.type)) && (! this.input)) || ("format".equals(this.type)) || ("directory".equals(this.type)) || ("files".equals(this.type)) || ("choice".equals(this.type))) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
319 String value = this.getValue();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
320 if (value.length() == 0) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
321 return list;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
322 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
323 list.add(this.identifier);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
324 list.add(value);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
325 return list;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
326 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
327 if ("file".equals(this.type)) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
328 String fileName = (String) ((JComboBox) this.component).getSelectedItem();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
329 if (fileName == null) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
330 return list;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
331 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
332 list.add(this.identifier);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
333 list.add(this.getValue());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
334 return list;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
335 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
336 if (("boolean".equals(this.type)) || ("bool".equals(this.type))) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
337 if ("true".equals(this.getValue())) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
338 list.add(this.identifier);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
339 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
340 return list;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
341 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
342 System.out.println("Cannot get type of option " + this.type + " (" + this.identifier + "): " + this.getValue());
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
343 return null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
344 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
345
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
346
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
347 public File getOutputFile() {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
348 if (this.input) return null;
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
349 String format = "";
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
350 if (this.format != null) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
351 format = this.format[0];
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
352 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
353 if (this.associatedOption != null) {
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
354 format = this.associatedOption.getValue();
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
355 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
356 return new File(this.getValue(), Global.formats.getFormatType(format), format);
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
357 }
769e306b7933 Change the repository level.
yufei-luo
parents:
diff changeset
358 }