$darkmode
DENOPTIM
GUIPrepareFitnessRunner.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;
28import java.util.concurrent.atomic.AtomicInteger;
29
30import javax.swing.BoxLayout;
31import javax.swing.JButton;
32import javax.swing.JLabel;
33import javax.swing.JOptionPane;
34import javax.swing.JPanel;
35import javax.swing.JScrollPane;
36import javax.swing.JTextField;
37import javax.swing.SwingConstants;
38import javax.swing.UIManager;
39
40
49{
50
54 private static final long serialVersionUID = 2579606720045728971L;
55
59 public static AtomicInteger testFitnessTabUID = new AtomicInteger(1);
60
61//------------------------------------------------------------------------------
62
67 super(mainPanel, "Prepare Fitness Runner #" + testFitnessTabUID.getAndIncrement());
68 initialize();
69 }
70
71//------------------------------------------------------------------------------
72
76 private void initialize() {
77
78 InputForm inputParsPane = new InputForm(mainPanel.getSize());
79 super.allParams.add(inputParsPane);
80 super.tabbedPane.addTab("Input/Output Files", null, inputParsPane, null);
81
83 mainPanel.getSize());
84 super.allParams.add(fitParsPane);
85 super.tabbedPane.addTab("Fitness Provider", null, fitParsPane, null);
86
87 }
88
89//------------------------------------------------------------------------------
90
91 private class InputForm extends ParametersForm
92 {
96 private static final long serialVersionUID = 1L;
97
98 JPanel block;
99
104 private Map<String,Object> mapKeyFieldToValueField;
105
106 String keyInFile = "FR-Input";
107 JTextField txtInFile;
108
109 String keyOutFile = "FR-Output";
110 JTextField txtOutFile;
111
112 String NL = System.getProperty("line.separator");
113
114 public InputForm(Dimension d)
115 {
116 mapKeyFieldToValueField = new HashMap<String,Object>();
117 this.setLayout(new BorderLayout()); //Needed to allow dynamic resizing!
118
119 block = new JPanel();
120 JScrollPane scrollablePane = new JScrollPane(block);
121 block.setLayout(new BoxLayout(block, SwingConstants.VERTICAL));
122
123 String toolTipInFile = "Pathname of the SDF file with the candidate to evaluate.";
124 JPanel LineInFile = new JPanel(new FlowLayout(FlowLayout.LEFT));
125 JLabel lblInFile = new JLabel("Input SDF file:", SwingConstants.LEFT);
126 lblInFile.setPreferredSize(fileLabelSize);
127 lblInFile.setToolTipText(toolTipInFile);
128 txtInFile = new JTextField();
129 txtInFile.setToolTipText(toolTipInFile);
130 txtInFile.setPreferredSize(fileFieldSize);
131 txtInFile.getDocument().addDocumentListener(fieldListener);
132 JButton btnInFile = new JButton("Browse");
133 btnInFile.addActionListener(new ActionListener() {
134 public void actionPerformed(ActionEvent e) {
136 }
137 });
138 LineInFile.add(lblInFile);
139 LineInFile.add(txtInFile);
140 LineInFile.add(btnInFile);
141
142 mapKeyFieldToValueField.put(keyInFile.toUpperCase(), txtInFile);
143
144 block.add(LineInFile);
145
146 String toolTipOutFile = "Pathname of the SDF file where to write the results of the evaluation.";
147 JPanel LineOutFile = new JPanel(new FlowLayout(FlowLayout.LEFT));
148 JLabel lblOutFile = new JLabel("Output SDF file:", SwingConstants.LEFT);
149 lblOutFile.setPreferredSize(fileLabelSize);
150 lblOutFile.setToolTipText(toolTipOutFile);
151 txtOutFile = new JTextField();
152 txtOutFile.setToolTipText(toolTipOutFile);
153 txtOutFile.setPreferredSize(fileFieldSize);
154 txtOutFile.getDocument().addDocumentListener(fieldListener);
155 JButton btnOutFile = new JButton("Browse");
156 btnOutFile.addActionListener(new ActionListener() {
157 public void actionPerformed(ActionEvent e) {
159 }
160 });
161 LineOutFile.add(lblOutFile);
162 LineOutFile.add(txtOutFile);
163 LineOutFile.add(btnOutFile);
164
166
167 block.add(LineOutFile);
168
169 block.add(super.getPanelForUnformattedInput());
170
171 this.add(scrollablePane);
172 }
173
174 //--------------------------------------------------------------------------
175
183 @Override
184 public void importParametersFromDenoptimParamsFile(String fileName)
185 throws Exception
186 {
189 showUnknownKeyWarning(this, "Fitness Runner");
190 }
191
192 //--------------------------------------------------------------------------
193
194
195 @Override
196 public void importSingleParameter(String key, String value)
197 throws Exception
198 {
199 Object valueField;
200 String valueFieldClass;
201 if (mapKeyFieldToValueField.containsKey(key.toUpperCase()))
202 {
203 valueField = mapKeyFieldToValueField.get(key.toUpperCase());
204 valueFieldClass = valueField.getClass().toString();
205 }
206 else
207 {
208 addToUnformattedTxt(key, value);
209 return;
210 }
211
212 switch (valueFieldClass)
213 {
214 case "class javax.swing.JTextField":
215 if (key.toUpperCase().equals(keyInFile.toUpperCase()))
216 {
217 value = value.trim();
218 }
219 ((JTextField) valueField).setText(value);
220 break;
221
222 default:
223 throw new Exception("<html>Unexpected type for parameter: "
224 + key + " (" + valueFieldClass
225 + ").<br>Please report this to"
226 + "the DEMOPTIM team.</html>");
227 }
228 }
229
230 //-----------------------------------------------------------------------------
231
232 @Override
233 public void putParametersToString(StringBuilder sb) throws Exception
234 {
235 sb.append(NL);
236 sb.append("# Fitness Runner - parameters").append(NL);
239 sb.append(NL);
240
241 sb.append(getTextForUnformattedSettings()).append(NL);
242 }
243 }
244
245//------------------------------------------------------------------------------
246
247}
Form collecting input parameters for a setting-up the fitness provider.
GUIMainPanel mainPanel
The main panel (cards deck)
File opener for DENOPTIM GUI.
static File pickFileForTxtField(JTextField txtField, Component parent)
The main panel is a deck of cards that occupies all the GUI frame.
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.
Form that allows to test the configuration of a fitness provider.
static final long serialVersionUID
Version UID.
void initialize()
Initialize the contents of the frame.
static AtomicInteger testFitnessTabUID
Unique identified for instances of this form.
GUIPrepareFitnessRunner(GUIMainPanel mainPanel)
Constructor.
Class representing the general structure of a form including a specific set of parameter collections.
Definition: GUIPrepare.java:59
General structure of a form for collecting input parameters of various nature.
FieldListener fieldListener
Listener for changes in parameters of this form.
final Dimension fileLabelSize
Default sizes for file pathname labels.
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.