$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.JPanel;
34import javax.swing.JScrollPane;
35import javax.swing.JTextField;
36import javax.swing.SwingConstants;
37
38
47{
48
52 private static final long serialVersionUID = 2579606720045728971L;
53
57 public static AtomicInteger testFitnessTabUID = new AtomicInteger(1);
58
59//------------------------------------------------------------------------------
60
65 super(mainPanel, "Prepare Fitness Runner #" + testFitnessTabUID.getAndIncrement());
66 initialize();
67 }
68
69//------------------------------------------------------------------------------
70
74 private void initialize() {
75
76 InputForm inputParsPane = new InputForm(mainPanel.getSize());
77 super.allParams.add(inputParsPane);
78 super.tabbedPane.addTab("Input/Output Files", null, inputParsPane, null);
79
81 mainPanel.getSize());
82 super.allParams.add(fitParsPane);
83 super.tabbedPane.addTab("Fitness Provider", null, fitParsPane, null);
84
85 }
86
87//------------------------------------------------------------------------------
88
89 private class InputForm extends ParametersForm
90 {
94 private static final long serialVersionUID = 1L;
95
96 JPanel block;
97
102 private Map<String,Object> mapKeyFieldToValueField;
103
104 String keyInFile = "FR-Input";
105 JTextField txtInFile;
106
107 String keyOutFile = "FR-Output";
108 JTextField txtOutFile;
109
110 String NL = System.getProperty("line.separator");
111
112 public InputForm(Dimension d)
113 {
114 mapKeyFieldToValueField = new HashMap<String,Object>();
115 this.setLayout(new BorderLayout()); //Needed to allow dynamic resizing!
116
117 block = new JPanel();
118 JScrollPane scrollablePane = new JScrollPane(block);
119 block.setLayout(new BoxLayout(block, SwingConstants.VERTICAL));
120
121 String toolTipInFile = "Pathname of the SDF file with the candidate to evaluate.";
122 JPanel LineInFile = new JPanel(new FlowLayout(FlowLayout.LEFT));
123 JLabel lblInFile = new JLabel("Input SDF file:", SwingConstants.LEFT);
124 lblInFile.setPreferredSize(fileLabelSize);
125 lblInFile.setToolTipText(toolTipInFile);
126 txtInFile = new JTextField();
127 txtInFile.setToolTipText(toolTipInFile);
128 txtInFile.setPreferredSize(fileFieldSize);
129 txtInFile.getDocument().addDocumentListener(fieldListener);
130 JButton btnInFile = new JButton("Browse");
131 btnInFile.addActionListener(new ActionListener() {
132 public void actionPerformed(ActionEvent e) {
134 }
135 });
136 LineInFile.add(lblInFile);
137 LineInFile.add(txtInFile);
138 LineInFile.add(btnInFile);
139
140 mapKeyFieldToValueField.put(keyInFile.toUpperCase(), txtInFile);
141
142 block.add(LineInFile);
143
144 String toolTipOutFile = "Pathname of the SDF file where to write the results of the evaluation.";
145 JPanel LineOutFile = new JPanel(new FlowLayout(FlowLayout.LEFT));
146 JLabel lblOutFile = new JLabel("Output SDF file:", SwingConstants.LEFT);
147 lblOutFile.setPreferredSize(fileLabelSize);
148 lblOutFile.setToolTipText(toolTipOutFile);
149 txtOutFile = new JTextField();
150 txtOutFile.setToolTipText(toolTipOutFile);
151 txtOutFile.setPreferredSize(fileFieldSize);
152 txtOutFile.getDocument().addDocumentListener(fieldListener);
153 JButton btnOutFile = new JButton("Browse");
154 btnOutFile.addActionListener(new ActionListener() {
155 public void actionPerformed(ActionEvent e) {
157 }
158 });
159 LineOutFile.add(lblOutFile);
160 LineOutFile.add(txtOutFile);
161 LineOutFile.add(btnOutFile);
162
164
165 block.add(LineOutFile);
166
167 block.add(super.getPanelForUnformattedInput());
168
169 this.add(scrollablePane);
170 }
171
172 //--------------------------------------------------------------------------
173
181 @Override
182 public void importParametersFromDenoptimParamsFile(String fileName)
183 throws Exception
184 {
187 showUnknownKeyWarning(this, "Fitness Runner");
188 }
189
190 //--------------------------------------------------------------------------
191
192
193 @Override
194 public void importSingleParameter(String key, String value)
195 throws Exception
196 {
197 Object valueField;
198 String valueFieldClass;
199 if (mapKeyFieldToValueField.containsKey(key.toUpperCase()))
200 {
201 valueField = mapKeyFieldToValueField.get(key.toUpperCase());
202 valueFieldClass = valueField.getClass().toString();
203 }
204 else
205 {
206 addToUnformattedTxt(key, value);
207 return;
208 }
209
210 switch (valueFieldClass)
211 {
212 case "class javax.swing.JTextField":
213 if (key.toUpperCase().equals(keyInFile.toUpperCase()))
214 {
215 value = value.trim();
216 }
217 ((JTextField) valueField).setText(value);
218 break;
219
220 default:
221 throw new Exception("<html>Unexpected type for parameter: "
222 + key + " (" + valueFieldClass
223 + ").<br>Please report this to"
224 + "the DEMOPTIM team.</html>");
225 }
226 }
227
228 //-----------------------------------------------------------------------------
229
230 @Override
231 public void putParametersToString(StringBuilder sb) throws Exception
232 {
233 sb.append(NL);
234 sb.append("# Fitness Runner - parameters").append(NL);
237 sb.append(NL);
238
239 sb.append(getTextForUnformattedSettings()).append(NL);
240 }
241 }
242
243//------------------------------------------------------------------------------
244
245}
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:52
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.