1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package fr.ens.transcriptome.doelan.gui;
23
24 import java.awt.BorderLayout;
25 import java.awt.GridBagConstraints;
26 import java.awt.GridBagLayout;
27 import java.awt.event.KeyEvent;
28 import java.util.HashMap;
29 import java.util.Map;
30
31 import javax.swing.JButton;
32 import javax.swing.JComboBox;
33 import javax.swing.JDialog;
34 import javax.swing.JLabel;
35 import javax.swing.JPanel;
36 import javax.swing.JTextField;
37
38 import fr.ens.transcriptome.nividic.platform.module.Module;
39 import fr.ens.transcriptome.nividic.platform.module.ModuleLocation;
40 import fr.ens.transcriptome.nividic.platform.module.ModuleManager;
41 import fr.ens.transcriptome.nividic.util.SystemUtils;
42
43 /***
44 * Widget for creating new WorkflowElement.
45 * @author Laurent Jourdren
46 */
47 public class NewWorkflowElementWidget extends JDialog {
48
49 private javax.swing.JPanel jContentPane;
50
51 private JLabel algoLabel;
52 private JComboBox algoComboBox;
53 private Map mapIdModuleLocation = new HashMap();
54 private ModuleLocation[] moduleLocations;
55 private boolean ok;
56
57 private JPanel jPanel;
58 private JPanel jPanel1;
59 private JButton cancelButton;
60 private JButton okButton;
61 private JTextField idTextField;
62
63 private JLabel idLabel;
64
65 /***
66 * This is the default constructor
67 * @param moduleLocations Module location of the algorithms
68 */
69 public NewWorkflowElementWidget(final ModuleLocation[] moduleLocations) {
70 super();
71 this.moduleLocations = moduleLocations;
72 initialize();
73 }
74
75 /***
76 * This method initializes this
77 */
78 private void initialize() {
79
80 this.setContentPane(getJContentPane());
81 this.setSize(this.algoLabel.getPreferredSize().width
82 + this.algoComboBox.getPreferredSize().width, 150);
83
84 this.setResizable(false);
85
86 }
87
88 /***
89 * This method initializes jContentPane
90 * @return javax.swing.JPanel
91 */
92 private javax.swing.JPanel getJContentPane() {
93 if (jContentPane == null) {
94 BorderLayout gridLayout22 = new BorderLayout();
95 algoLabel = new JLabel();
96 jContentPane = new javax.swing.JPanel();
97 jContentPane.setLayout(gridLayout22);
98 algoLabel.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
99 algoLabel.setText("Algorithm");
100 algoLabel.setDisplayedMnemonic(KeyEvent.VK_A);
101 algoLabel.setLabelFor(getAlgoComboBox());
102 jContentPane.add(getJPanel(), BorderLayout.CENTER);
103 jContentPane.add(getJPanel1(), BorderLayout.SOUTH);
104
105 }
106 return jContentPane;
107 }
108
109 /***
110 * This method initializes jComboBox
111 * @return javax.swing.JComboBox
112 */
113 private JComboBox getAlgoComboBox() {
114 if (algoComboBox == null) {
115 algoComboBox = new JComboBox();
116
117 if (moduleLocations != null)
118 for (int i = 0; i < moduleLocations.length; i++) {
119 final String key = moduleLocationNameShow(moduleLocations[i]);
120 getAlgoComboBox().addItem(key);
121 this.mapIdModuleLocation.put(key, moduleLocations[i]);
122 }
123
124 }
125 return algoComboBox;
126 }
127
128 private static String moduleLocationNameShow(
129 final ModuleLocation moduleLocation) {
130 if (moduleLocation == null)
131 return null;
132
133 Module m = ModuleManager.getManager().loadModule(moduleLocation);
134
135 return m.aboutModule().getShortDescription();
136 }
137
138 /***
139 * Get the module location of the selected algorithm.
140 * @return The module location of the selected algorithm
141 */
142 public ModuleLocation getModuleLocationSelected() {
143 return (ModuleLocation) this.mapIdModuleLocation.get(getAlgoComboBox()
144 .getSelectedItem());
145 }
146
147 /***
148 * Get the identifier of the new algorithm.
149 * @return The identifier of the algorithm
150 */
151 public String getIdentifier() {
152 return getIdTextField().getText();
153 }
154
155 /***
156 * This method initializes jPanel
157 * @return javax.swing.JPanel
158 */
159 private JPanel getJPanel() {
160 if (jPanel == null) {
161 idLabel = new JLabel();
162 GridBagConstraints gridBagConstraints23 = new GridBagConstraints();
163 GridBagConstraints gridBagConstraints21 = new GridBagConstraints();
164 GridBagConstraints gridBagConstraints17 = new GridBagConstraints();
165 GridBagConstraints gridBagConstraints16 = new GridBagConstraints();
166 jPanel = new JPanel();
167 jPanel.setLayout(new GridBagLayout());
168 gridBagConstraints16.gridx = 1;
169 gridBagConstraints16.gridy = 2;
170 gridBagConstraints16.insets = new java.awt.Insets(5, 0, 5, 0);
171 gridBagConstraints17.gridx = 2;
172 gridBagConstraints17.gridy = 2;
173 gridBagConstraints17.weightx = 1.0;
174 gridBagConstraints17.fill = java.awt.GridBagConstraints.HORIZONTAL;
175 gridBagConstraints17.ipadx = 186;
176 gridBagConstraints17.insets = new java.awt.Insets(1, 0, 0, 0);
177 gridBagConstraints21.gridx = 2;
178 gridBagConstraints21.gridy = 1;
179 gridBagConstraints21.weightx = 1.0;
180 gridBagConstraints21.fill = java.awt.GridBagConstraints.HORIZONTAL;
181 gridBagConstraints23.gridx = 1;
182 gridBagConstraints23.gridy = 1;
183 idLabel.setText("Identifer");
184 idLabel.setDisplayedMnemonic(KeyEvent.VK_I);
185 idLabel.setLabelFor(getIdTextField());
186 idLabel.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
187 jPanel.add(algoLabel, gridBagConstraints16);
188 jPanel.add(getAlgoComboBox(), gridBagConstraints17);
189 jPanel.add(getIdTextField(), gridBagConstraints21);
190 jPanel.add(idLabel, gridBagConstraints23);
191 }
192 return jPanel;
193 }
194
195 /***
196 * This method initializes jPanel1
197 * @return javax.swing.JPanel
198 */
199 private JPanel getJPanel1() {
200 if (jPanel1 == null) {
201 jPanel1 = new JPanel();
202 jPanel1.add(getOkButton(), null);
203 jPanel1.add(getCancelButton(), null);
204 }
205 return jPanel1;
206 }
207
208 /***
209 * This method initializes jButton1
210 * @return javax.swing.JButton
211 */
212 private JButton getCancelButton() {
213 if (cancelButton == null) {
214 cancelButton = new JButton();
215 cancelButton.setText("Cancel");
216 if (!SystemUtils.isMacOsX())
217 cancelButton.setMnemonic(KeyEvent.VK_C);
218 cancelButton.addActionListener(new java.awt.event.ActionListener() {
219 public void actionPerformed(final java.awt.event.ActionEvent e) {
220 hide();
221 }
222 });
223 }
224 return cancelButton;
225 }
226
227 /***
228 * This method initializes jButton2
229 * @return javax.swing.JButton
230 */
231 private JButton getOkButton() {
232 if (okButton == null) {
233 okButton = new JButton();
234 okButton.setText("OK");
235 if (!SystemUtils.isMacOsX())
236 okButton.setMnemonic(KeyEvent.VK_O);
237 okButton.addActionListener(new java.awt.event.ActionListener() {
238 public void actionPerformed(final java.awt.event.ActionEvent e) {
239 ok = true;
240 hide();
241 }
242 });
243 }
244 return okButton;
245 }
246
247 /***
248 * This method initializes jTextField
249 * @return javax.swing.JTextField
250 */
251 private JTextField getIdTextField() {
252 if (idTextField == null) {
253 idTextField = new JTextField();
254 }
255 return idTextField;
256 }
257
258 /***
259 * Hide the widget.
260 */
261 public void close() {
262 this.hide();
263 }
264
265 /***
266 * Test if ok.
267 * @return Returns the ok
268 */
269 public boolean isOk() {
270 return ok;
271 }
272 }