$darkmode
DENOPTIM
FSEParametersForm.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2020 Marco Foscato <marco.foscato@uib.no>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package denoptim.gui;
20
21import java.awt.BorderLayout;
22import java.awt.Dimension;
23import java.awt.FlowLayout;
24import java.awt.event.ActionEvent;
25import java.awt.event.ActionListener;
26import java.util.HashMap;
27import java.util.Map;
28
29import javax.swing.BoxLayout;
30import javax.swing.JButton;
31import javax.swing.JComboBox;
32import javax.swing.JLabel;
33import javax.swing.JOptionPane;
34import javax.swing.JPanel;
35import javax.swing.JRadioButton;
36import javax.swing.JScrollPane;
37import javax.swing.JSeparator;
38import javax.swing.JTextField;
39import javax.swing.SwingConstants;
40import javax.swing.UIManager;
41import javax.swing.table.DefaultTableModel;
42
49{
50
54 private static final long serialVersionUID = 1L;
55
60 private Map<String,Object> mapKeyFieldToValueField;
61
62 JPanel block;
66
68 JRadioButton rdbSrcOrNew;
69
72 JTextField txtFSESource;
73 JButton btnFSESource;
75
76 String keyPar2 = "FSE-MaxLevel";
77 JPanel linePar2;
78 JLabel lblPar2;
79 JTextField txtPar2;
80
81 String keyPar7 = "FSE-NumOfProcessors";
82 JPanel linePar7;
83 JLabel lblPar7;
84 JTextField txtPar7;
85
86 String keyPar3 = "FSE-UIDFile";
87 JPanel linePar3;
88 JLabel lblPar3;
89 JTextField txtPar3;
90 JButton btnPar3;
91
92 String keyPar9 = "FSE-RootGraphs";
93 JPanel linePar9;
94 JLabel lblPar9;
95 JTextField txtPar9;
96 JButton btnPar9;
97
98 String keyPar8 = "FSE-Verbosity";
99 JPanel linePar8;
100 JLabel lblPar8;
101 JTextField txtPar8;
102
103 String keyPar1 = "FSE-WorkDir";
104 JPanel linePar1;
105 JLabel lblPar1;
106 JTextField txtPar1;
107 JButton btnPar1;
108
109 String keyPar4 = "FSE-DBRootFolder";
110 JPanel linePar4;
111 JLabel lblPar4;
112 JTextField txtPar4;
113 JButton btnPar4;
114
115 String keyPar5 = "FSE-MaxWait";
116 JPanel linePar5;
117 JLabel lblPar5;
118 JTextField txtPar5;
119
120 String keyPar6 = "FSE-WaitStep";
121 JPanel linePar6;
122 JLabel lblPar6;
123 JTextField txtPar6;
124
125 String keyPar11 = "FSE-CheckPointStepLength";
126 JPanel linePar11;
127 JLabel lblPar11;
128 JTextField txtPar11;
129
130 String keyPar12 = "FSE-RestartFromCheckpoint";
131 JPanel linePar12;
132 JLabel lblPar12;
133 JTextField txtPar12;
134 JButton btnPar12;
135
136 //HEREGOFIELDS this is only to facilitate automated insertion of code
137
138
139 String NL = System.getProperty("line.separator");
140
141 public FSEParametersForm(Dimension d)
142 {
143 //Initialize this instance
144 mapKeyFieldToValueField = new HashMap<String,Object>();
145
146 //Build form
147 this.setLayout(new BorderLayout()); //Needed to allow dynamic resizing!
148
149 block = new JPanel();
150 JScrollPane scrollablePane = new JScrollPane(block);
151 block.setLayout(new BoxLayout(block, SwingConstants.VERTICAL));
152
153 localBlock1 = new JPanel();
154 localBlock1.setVisible(false);
155 localBlock1.setLayout(new BoxLayout(localBlock1, SwingConstants.VERTICAL));
156
157 localBlock2 = new JPanel();
158 localBlock2.setVisible(true);
159 localBlock2.setLayout(new BoxLayout(localBlock2, SwingConstants.VERTICAL));
160
161 advOptsBlock = new JPanel();
162 advOptsBlock.setVisible(false);
163 advOptsBlock.setLayout(new BoxLayout(advOptsBlock, SwingConstants.VERTICAL));
164
165 String toolTipSrcOrNew = "Tick here to use settings from file.";
166 lineSrcOrNew = new JPanel(new FlowLayout(FlowLayout.LEFT));
167 rdbSrcOrNew = new JRadioButton("Use parameters from existing file");
168 rdbSrcOrNew.setToolTipText(toolTipSrcOrNew);
169 rdbSrcOrNew.addActionListener(new ActionListener(){
170 public void actionPerformed(ActionEvent e){
171 if (rdbSrcOrNew.isSelected())
172 {
173 localBlock1.setVisible(true);
174 localBlock2.setVisible(false);
175 }
176 else
177 {
178 localBlock1.setVisible(false);
179 localBlock2.setVisible(true);
180 }
181 }
182 });
184 block.add(lineSrcOrNew);
185 block.add(localBlock1);
186 block.add(localBlock2);
187
188 String toolTipFSESource = "<html>Pathname of a DENOPTIM's parameter file with FSE settings.</html>";
189 lineFSESource = new JPanel(new FlowLayout(FlowLayout.LEFT));
190 lblFSESource = new JLabel("Use parameters from file:", SwingConstants.LEFT);
191 lblFSESource.setToolTipText(toolTipFSESource);
192 txtFSESource = new JTextField();
193 txtFSESource.setToolTipText(toolTipFSESource);
194 txtFSESource.setPreferredSize(fileFieldSize);
195 btnFSESource = new JButton("Browse");
196 btnFSESource.addActionListener(new ActionListener() {
197 public void actionPerformed(ActionEvent e) {
200 }
201 });
202 btnLoadFSESource = new JButton("Load...");
203 txtFSESource.setToolTipText("<html>Specify the file containing the "
204 + "parameters to be loaded in this form.</html>");
205 btnLoadFSESource.addActionListener(new ActionListener() {
206 public void actionPerformed(ActionEvent e) {
207 try
208 {
210 }
211 catch (Exception e1)
212 {
213 if (e1.getMessage().equals("") || e1.getMessage() == null)
214 {
215 e1.printStackTrace();
216 JOptionPane.showMessageDialog(btnLoadFSESource,
217 "<html>Exception occurred while importing parameters.<br>Please, report this to the DENOPTIM team.</html>",
218 "Error",
219 JOptionPane.ERROR_MESSAGE,
220 UIManager.getIcon("OptionPane.errorIcon"));
221 }
222 else
223 {
224 JOptionPane.showMessageDialog(btnLoadFSESource,
225 e1.getMessage(),
226 "Error",
227 JOptionPane.ERROR_MESSAGE,
228 UIManager.getIcon("OptionPane.errorIcon"));
229 }
230 return;
231 }
232 }
233 });
239
240 String toolTipPar2 = "<html>Specifies up to which level we'll add layers of fragments.<br>Note that the root (i.e., scaffold or root graph) is assigned <code>level = -1</code>.<br>Therefore, if the maximum level permitted is 3, then we will try to append <br>up to 4 layers of fragments (levels = 0, 1, 2, and 3).</html>";
241 linePar2 = new JPanel(new FlowLayout(FlowLayout.LEFT));
242 lblPar2 = new JLabel("Maximum level number to consider:", SwingConstants.LEFT);
243 lblPar2.setPreferredSize(fileLabelSize);
244 lblPar2.setToolTipText(toolTipPar2);
245 txtPar2 = new JTextField();
246 txtPar2.setToolTipText(toolTipPar2);
247 txtPar2.setPreferredSize(strFieldSize);
248 txtPar2.getDocument().addDocumentListener(fieldListener);
249 mapKeyFieldToValueField.put(keyPar2.toUpperCase(),txtPar2);
250 linePar2.add(lblPar2);
251 linePar2.add(txtPar2);
253
254 String toolTipPar7 = "<html>Specifies the number of asynchronous processes that can be <br>run in parallel. Usually this number corresponds to the number of slave cores,<br>i.e., one slave core corresponds to 1 external task.</html>";
255 linePar7 = new JPanel(new FlowLayout(FlowLayout.LEFT));
256 lblPar7 = new JLabel("Mas. number parallel tasks:", SwingConstants.LEFT);
257 lblPar7.setPreferredSize(fileLabelSize);
258 lblPar7.setToolTipText(toolTipPar7);
259 txtPar7 = new JTextField();
260 txtPar7.setToolTipText(toolTipPar7);
261 txtPar7.setPreferredSize(strFieldSize);
262 txtPar7.getDocument().addDocumentListener(fieldListener);
263 mapKeyFieldToValueField.put(keyPar7.toUpperCase(),txtPar7);
264 linePar7.add(lblPar7);
265 linePar7.add(txtPar7);
267
268 String toolTipPar3 = "Specifies the pathname of the file with unique chemical entity ID.";
269 linePar3 = new JPanel(new FlowLayout(FlowLayout.LEFT));
270 lblPar3 = new JLabel("File with known UIDs:", SwingConstants.LEFT);
271 lblPar3.setPreferredSize(fileLabelSize);
272 lblPar3.setToolTipText(toolTipPar3);
273 txtPar3 = new JTextField();
274 txtPar3.setToolTipText(toolTipPar3);
275 txtPar3.setPreferredSize(fileFieldSize);
276 txtPar3.getDocument().addDocumentListener(fieldListener);
277 mapKeyFieldToValueField.put(keyPar3.toUpperCase(),txtPar3);
278 btnPar3 = new JButton("Browse");
279 btnPar3.addActionListener(new ActionListener() {
280 public void actionPerformed(ActionEvent e) {
282 }
283 });
284 linePar3.add(lblPar3);
285 linePar3.add(txtPar3);
286 linePar3.add(btnPar3);
288
289 String toolTipPar9 = "Specifies the pathname of a file containing the list of graphs that will be expanded.";
290 linePar9 = new JPanel(new FlowLayout(FlowLayout.LEFT));
291 lblPar9 = new JLabel("Library of root graphs:", SwingConstants.LEFT);
292 lblPar9.setPreferredSize(fileLabelSize);
293 lblPar9.setToolTipText(toolTipPar9);
294 txtPar9 = new JTextField();
295 txtPar9.setToolTipText(toolTipPar9);
296 txtPar9.setPreferredSize(fileFieldSize);
297 txtPar9.getDocument().addDocumentListener(fieldListener);
298 mapKeyFieldToValueField.put(keyPar9.toUpperCase(),txtPar9);
299 btnPar9 = new JButton("Browse");
300 btnPar9.addActionListener(new ActionListener() {
301 public void actionPerformed(ActionEvent e) {
303 }
304 });
305 linePar9.add(lblPar9);
306 linePar9.add(txtPar9);
307 linePar9.add(btnPar9);
309
310 //HEREGOESIMPLEMENTATION this is only to facilitate automated insertion of code
311
312
313 // From here it's all about advanced options
314
315 String toolTipPar8 = "Specifies the verbosity level.";
316 linePar8 = new JPanel(new FlowLayout(FlowLayout.LEFT));
317 lblPar8 = new JLabel("Logging level:", SwingConstants.LEFT);
318 lblPar8.setPreferredSize(fileLabelSize);
319 lblPar8.setToolTipText(toolTipPar8);
320 txtPar8 = new JTextField();
321 txtPar8.setToolTipText(toolTipPar8);
322 txtPar8.setPreferredSize(strFieldSize);
323 txtPar8.getDocument().addDocumentListener(fieldListener);
324 mapKeyFieldToValueField.put(keyPar8.toUpperCase(),txtPar8);
325 linePar8.add(lblPar8);
326 linePar8.add(txtPar8);
328
329 String toolTipPar1 = "Specifies the pathname of the directory where files will be created";
330 linePar1 = new JPanel(new FlowLayout(FlowLayout.LEFT));
331 lblPar1 = new JLabel("Work space:", SwingConstants.LEFT);
332 lblPar1.setPreferredSize(fileLabelSize);
333 lblPar1.setToolTipText(toolTipPar1);
334 txtPar1 = new JTextField();
335 txtPar1.setToolTipText(toolTipPar1);
336 txtPar1.setPreferredSize(fileFieldSize);
337 txtPar1.getDocument().addDocumentListener(fieldListener);
338 mapKeyFieldToValueField.put(keyPar1.toUpperCase(),txtPar1);
339 btnPar1 = new JButton("Browse");
340 btnPar1.addActionListener(new ActionListener() {
341 public void actionPerformed(ActionEvent e) {
343 }
344 });
345 linePar1.add(lblPar1);
346 linePar1.add(txtPar1);
347 linePar1.add(btnPar1);
349
350 String toolTipPar4 = "Specifies the pathname to the root of the folder tree of generated graphs.";
351 linePar4 = new JPanel(new FlowLayout(FlowLayout.LEFT));
352 lblPar4 = new JLabel("Location of DENOPTIMGraph database:", SwingConstants.LEFT);
353 lblPar4.setPreferredSize(fileLabelSize);
354 lblPar4.setToolTipText(toolTipPar4);
355 txtPar4 = new JTextField();
356 txtPar4.setToolTipText(toolTipPar4);
357 txtPar4.setPreferredSize(fileFieldSize);
358 txtPar4.getDocument().addDocumentListener(fieldListener);
359 mapKeyFieldToValueField.put(keyPar4.toUpperCase(),txtPar4);
360 btnPar4 = new JButton("Browse");
361 btnPar4.addActionListener(new ActionListener() {
362 public void actionPerformed(ActionEvent e) {
364 }
365 });
366 linePar4.add(lblPar4);
367 linePar4.add(txtPar4);
368 linePar4.add(btnPar4);
370
371 String toolTipPar5 = "Specifies the wall time limit (in seconds) for completion of one or more tasks. Accepts only integer number";
372 linePar5 = new JPanel(new FlowLayout(FlowLayout.LEFT));
373 lblPar5 = new JLabel("Max. time for fitness evaluation:", SwingConstants.LEFT);
374 lblPar5.setPreferredSize(fileLabelSize);
375 lblPar5.setToolTipText(toolTipPar5);
376 txtPar5 = new JTextField();
377 txtPar5.setToolTipText(toolTipPar5);
378 txtPar5.setPreferredSize(strFieldSize);
379 txtPar5.getDocument().addDocumentListener(fieldListener);
380 mapKeyFieldToValueField.put(keyPar5.toUpperCase(),txtPar5);
381 linePar5.add(lblPar5);
382 linePar5.add(txtPar5);
384
385 String toolTipPar6 = "<html>Specifies the sleeping time (or time step, in seconds) between <br>checks for completion of one or more tasks. Accepts only integer number<html>";
386 linePar6 = new JPanel(new FlowLayout(FlowLayout.LEFT));
387 lblPar6 = new JLabel("Time between checks for completion:", SwingConstants.LEFT);
388 lblPar6.setPreferredSize(fileLabelSize);
389 lblPar6.setToolTipText(toolTipPar6);
390 txtPar6 = new JTextField();
391 txtPar6.setToolTipText(toolTipPar6);
392 txtPar6.setPreferredSize(strFieldSize);
393 txtPar6.getDocument().addDocumentListener(fieldListener);
394 mapKeyFieldToValueField.put(keyPar6.toUpperCase(),txtPar6);
395 linePar6.add(lblPar6);
396 linePar6.add(txtPar6);
398
399 String toolTipPar11 = "<html>Specifies to update the checkpoint information every # generated graphs.</html>";
400 linePar11 = new JPanel(new FlowLayout(FlowLayout.LEFT));
401 lblPar11 = new JLabel("Make checkpoint every # graphs:", SwingConstants.LEFT);
402 lblPar11.setPreferredSize(fileLabelSize);
403 lblPar11.setToolTipText(toolTipPar11);
404 txtPar11 = new JTextField();
405 txtPar11.setToolTipText(toolTipPar11);
406 txtPar11.setPreferredSize(strFieldSize);
407 txtPar11.getDocument().addDocumentListener(fieldListener);
408 mapKeyFieldToValueField.put(keyPar11.toUpperCase(),txtPar11);
409 linePar11.add(lblPar11);
410 linePar11.add(txtPar11);
412
413 String toolTipPar12 = "<html>Specifies the pathname of the checkpoint file, <br> and makes FragSpaceExplorer restart from such file.</html>";
414 linePar12 = new JPanel(new FlowLayout(FlowLayout.LEFT));
415 lblPar12 = new JLabel("Restart from checkpoint file: ", SwingConstants.LEFT);
416 lblPar12.setPreferredSize(fileLabelSize);
417 lblPar12.setToolTipText(toolTipPar12);
418 txtPar12 = new JTextField();
419 txtPar12.setToolTipText(toolTipPar12);
420 txtPar12.setPreferredSize(fileFieldSize);
421 txtPar12.getDocument().addDocumentListener(fieldListener);
422 mapKeyFieldToValueField.put(keyPar12.toUpperCase(),txtPar12);
423 btnPar12 = new JButton("Browse");
424 btnPar12.addActionListener(new ActionListener() {
425 public void actionPerformed(ActionEvent e) {
427 }
428 });
429 linePar12.add(lblPar12);
430 linePar12.add(txtPar12);
431 linePar12.add(btnPar12);
433
434 //HEREGOESADVIMPLEMENTATION this is only to facilitate automated insertion of code
435
436 JButton advOptShow = new JButton("Advanced Settings");
437 advOptShow.addActionListener(new ActionListener(){
438 public void actionPerformed(ActionEvent e){
439 if (advOptsBlock.isVisible())
440 {
441 advOptsBlock.setVisible(false);
442 advOptShow.setText("Show Advanced Settings");
443 }
444 else
445 {
446 advOptsBlock.setVisible(true);
447 advOptShow.setText("Hide Advanced Settings");
448 scrollablePane.validate();
449 scrollablePane.repaint();
450 scrollablePane.getVerticalScrollBar().setValue(
451 scrollablePane.getVerticalScrollBar().getValue() + (int) preferredHeight*2/3);
452 }
453 }
454 });
455
456 JPanel advOptsController = new JPanel();
457 advOptsController.add(advOptShow);
458 localBlock2.add(new JSeparator());
459 localBlock2.add(advOptsController);
461
462 block.add(super.getPanelForUnformattedInput());
463
464 this.add(scrollablePane);
465 }
466
467//-----------------------------------------------------------------------------
468
478 @Override
479 public void importParametersFromDenoptimParamsFile(String fileName) throws Exception
480 {
483
484 rdbSrcOrNew.setSelected(false);
485 localBlock1.setVisible(false);
486 localBlock2.setVisible(true);
487 advOptsBlock.setVisible(true);
488
489 showUnknownKeyWarning(this, "FragSpaceExplorer");
490 }
491
492//-----------------------------------------------------------------------------
493
494 @SuppressWarnings("unchecked")
495 @Override
496 public void importSingleParameter(String key, String value) throws Exception
497 {
498 Object valueField;
499 String valueFieldClass;
500 if (mapKeyFieldToValueField.containsKey(key.toUpperCase()))
501 {
502 valueField = mapKeyFieldToValueField.get(key.toUpperCase());
503 valueFieldClass = valueField.getClass().toString();
504 }
505 else
506 {
507 addToUnformattedTxt(key, value);
508 return;
509 }
510
511 switch (valueFieldClass)
512 {
513 case "class javax.swing.JTextField":
514 ((JTextField) valueField).setText(value);
515 break;
516
517 case "class javax.swing.JRadioButton":
518 ((JRadioButton) valueField).setSelected(true);
519 break;
520
521 case "class javax.swing.JComboBox":
522 ((JComboBox<String>) valueField).setSelectedItem(value);
523 break;
524
525 case "class javax.swing.table.DefaultTableModel":
526
527 //WARNING: there might be cases where we do not take all the records
528
529 ((DefaultTableModel) valueField).addRow(value.split(" "));
530 break;
531
532 default:
533 throw new Exception("<html>Unexpected type for parameter: "
534 + key + " (" + valueFieldClass
535 + ").<br>Please report this to"
536 + "the DEMOPTIM team.</html>");
537 }
538
539 }
540
541//-----------------------------------------------------------------------------
542
543 @Override
544 public void putParametersToString(StringBuilder sb) throws Exception
545 {
546 sb.append("# FragSpaceExplorer - parameters").append(NL);
547
548 if (rdbSrcOrNew.isSelected())
549 {
550 if (txtFSESource.getText().equals("") || txtFSESource.getText() == null)
551 {
552 throw new Exception("<html>No source specified for FSE parameters.<br>Please, specify the file name.</html>");
553 }
555 }
556
568
569 sb.append(getTextForUnformattedSettings()).append(NL);
570
571 //HEREGOESPRINT this is only to facilitate automated insertion of code
572 }
573}
Form collecting input parameters for a combinatorial/virtual screening experiment performed by FragSp...
Map< String, Object > mapKeyFieldToValueField
Map connecting the parameter keyword and the field containing the parameter value.
void importParametersFromDenoptimParamsFile(String fileName)
Imports parameters from a properly formatted parameters file.
void importSingleParameter(String key, String value)
static final long serialVersionUID
Version.
void putParametersToString(StringBuilder sb)
File opener for DENOPTIM GUI.
static File pickFolderForTxtField(JTextField txtField, Component parent)
static File pickFileForTxtField(JTextField txtField, Component parent)
General structure of a form for collecting input parameters of various nature.
final Dimension strFieldSize
Default sizes for short pathname fields (i.e., string or number)
FieldListener fieldListener
Listener for changes in parameters of this form.
final Dimension fileLabelSize
Default sizes for file pathname labels.
final int preferredHeight
Default text field height.
void addToUnformattedTxt(String key, String value)
void showUnknownKeyWarning(Component parent, String paramType)
Shown a warning dialog that informs the user about having found text that is not present in the Param...
final Dimension fileFieldSize
Default sizes for file pathname fields.
String getStringIfNotEmpty(String key, JTextField field, String prefix, String suffix)
Produced the KEY:VALUE string for a general text field.