21import java.awt.Dimension;
22import java.awt.FlowLayout;
23import java.awt.Component;
24import java.awt.event.ActionEvent;
25import java.awt.event.ActionListener;
26import java.awt.event.FocusEvent;
27import java.awt.event.FocusListener;
29import java.io.BufferedReader;
30import java.io.FileReader;
31import java.io.IOException;
32import java.util.HashMap;
35import javax.swing.BoxLayout;
36import javax.swing.JEditorPane;
37import javax.swing.JLabel;
38import javax.swing.JOptionPane;
39import javax.swing.JPanel;
40import javax.swing.JRadioButton;
41import javax.swing.JScrollPane;
42import javax.swing.JSeparator;
43import javax.swing.JSpinner;
44import javax.swing.JTable;
45import javax.swing.JTextArea;
46import javax.swing.JTextField;
47import javax.swing.SwingConstants;
48import javax.swing.UIManager;
49import javax.swing.event.ChangeEvent;
50import javax.swing.event.ChangeListener;
51import javax.swing.event.DocumentEvent;
52import javax.swing.event.DocumentListener;
53import javax.swing.event.TableModelEvent;
54import javax.swing.event.TableModelListener;
56import denoptim.constants.DENOPTIMConstants;
57import denoptim.files.FileUtils;
84 (int) (
new JTextField()).getPreferredSize().getHeight();
99 private final String
NL = System.getProperty(
"line.separator");
131 protected Map<String,Boolean>
checkedFlags =
new HashMap<String,Boolean>();
145 "Write additional text for the input file here...";
176 String prefix, String suffix)
178 StringBuilder sb =
new StringBuilder();
179 if (!field.getText().equals(
""))
181 sb.append(key).append(
"=");
182 sb.append(prefix).append(field.getText()).append(suffix).append(
NL);
184 return sb.toString();
200 boolean multipleLines)
202 StringBuilder sb =
new StringBuilder();
203 if (!field.getText().equals(
""))
207 String[] lines = field.getText().split(
208 System.getProperty(
"line.separator"));
209 for (
int i=0; i<lines.length; i++)
211 sb.append(key).append(
"=").append(lines[i]).append(
NL);
214 sb.append(key).append(
"=").append(field.getText()).append(
NL);
217 return sb.toString();
232 StringBuilder sb =
new StringBuilder();
233 if (!field.getText().equals(
""))
235 sb.append(key).append(
"=").append(field.getText()).append(
NL);
237 return sb.toString();
252 StringBuilder sb =
new StringBuilder();
253 String value = spinner.getValue().toString();
254 if (!value.equals(
""))
256 sb.append(key).append(
"=").append(value).append(
NL);
258 return sb.toString();
272 StringBuilder sb =
new StringBuilder();
273 if (btn.isSelected())
276 sb.append(key).append(
NL);
278 return sb.toString();
353 String sep,
boolean skipHeader)
355 StringBuilder sb =
new StringBuilder();
361 for (
int i=firstRow; i<tab.getRowCount(); i++)
364 for (
int j=0; j<fields.length; j++)
368 val = tab.getValueAt(i, fields[j]).toString();
372 val = val + sep + tab.getValueAt(i, fields[j]).toString();
375 sb.append(key).append(
"=").append(val).append(
NL);
377 return sb.toString();
385 System.err.println(
"WARNING: runnin empty method "
386 +
"'importParametersFromDenoptimParamsFile'. "
387 +
"A subclass is not overwriting it. "
388 +
"Report this bug to the development team.");
402 String keyRoot)
throws Exception
404 if (keyRoot.equals(
"") || keyRoot ==
null)
406 throw new Exception(
"<html>Root of DENOPTIM keywords not defined."
407 +
"<br>Bugus use of method "
408 +
"'importParametersFromDenoptimParamsFile'!</html>");
410 String parType = keyRoot.replaceAll(
"-",
"");
413 throw new Exception(
"<html>Source file for the " + parType
414 +
" parameters is not found!<br>Please, specify another"
421 BufferedReader br =
null;
424 br =
new BufferedReader(
new FileReader(fileName));
425 while ((line = br.readLine()) !=
null)
427 if ((line.trim()).length() == 0)
432 if (line.startsWith(
"#"))
439 if (line.toUpperCase().startsWith(flag.toUpperCase()))
443 if (line.toUpperCase().startsWith(keyRoot.toUpperCase()))
449 catch (IOException ioe)
451 throw new Exception(
"Unable to read file '" + fileName +
"'", ioe);
463 catch (IOException ioe)
465 throw new Exception(
"Unable to close file '" + fileName +
"'",
498 String key = line.trim();
500 if (line.contains(
"="))
502 key = line.substring(0,line.indexOf(
"=")).trim();
503 value = line.substring(line.indexOf(
"=") + 1).trim();
514 System.err.println(
"WARNING: running empty method "
515 +
"'importSingleParameter'. "
516 +
"A subclass is not overwriting it. "
517 +
"Report this bug to the development team.");
622 JOptionPane.showMessageDialog(parent,
623 String.format(
"<html><body width='%1s'>"
624 +
"Found text that is either not recognized "
625 +
" as " + paramType +
" parameters "
626 +
"or pertains settings that cannot yet be "
627 +
"controlled from the GUI. "
628 +
"You can edit/delete this content in the "
629 +
"parameter editor located at the bottom of the "
630 +
"parameter's form. <br>"
631 +
"Content of the unformatted content:"
632 +
"</body></html>", 400)
636 JOptionPane.WARNING_MESSAGE,
637 UIManager.getIcon(
"OptionPane.errorIcon"));
659 JPanel blockUnformatted =
new JPanel();
660 blockUnformatted.setLayout(
new BoxLayout(blockUnformatted,
661 SwingConstants.VERTICAL));
662 blockUnformatted.add(
new JSeparator());
663 String toolTip = String.format(
664 "<html><body width='%1s'>Here you can find/write any "
665 +
"further text lines that can be written/found in the "
666 +
"parameter's file. Such text may contain comments (i.e., "
667 +
"start with '#') and any keyword that is not controllable by "
668 +
"the GUI.</body></html>", 400);
669 blockUnformatted.setToolTipText(toolTip);
670 JPanel lineHeader =
new JPanel(
new FlowLayout(FlowLayout.LEFT));
671 JLabel lbl =
new JLabel(
672 "Additional input file content not controlled by GUI",
673 SwingConstants.LEFT);
675 blockUnformatted.add(lineHeader);
682 public void focusGained(FocusEvent e)
688 public void focusLost(FocusEvent e)
695 blockUnformatted.add(scroller);
697 return blockUnformatted;
716 }
else if (txt.isBlank()) {
General set of constants used in DENOPTIM.
static final String EOL
new line character
static boolean checkExists(String fileName)