$darkmode
DENOPTIM
FSParamsDialog.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2022 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.Component;
22import java.awt.event.ActionEvent;
23import java.awt.event.ActionListener;
24
25import javax.swing.JOptionPane;
26import javax.swing.UIManager;
27
28import denoptim.exception.DENOPTIMException;
29import denoptim.fragspace.FragmentSpace;
30import denoptim.fragspace.FragmentSpaceParameters;
31
37{
41 private static final long serialVersionUID = 1L;
42
44
45//-----------------------------------------------------------------------------
46
50 public FSParamsDialog(Component refForPlacement)
51 {
52 super(refForPlacement);
53
54 fsParsForm = new FSParametersForm(this.getSize());
56
57 btnDone.setText("Create BB Space");
58 btnDone.setToolTipText(String.format("<html><body width='%1s'>"
59 + "Uses the parameters defined above to define a space"
60 + "of graph building blocks (BB Space) "
61 + "and makes it available to the graph handler.</html>",400));
62
63 // NB: Assumption: 1 action listener inherited from superclass.
64 // We want to remove it because we need to acquire full control over
65 // when the modal panel has to be closed.
66 btnDone.removeActionListener(btnDone.getActionListeners()[0]);
67 btnDone.addActionListener(new ActionListener() {
68 @Override
69 public void actionPerformed(ActionEvent e) {
70 try {
73 } catch (Exception e1) {
74 e1.printStackTrace();
75 String msg = "<html><body width='%1s'>"
76 + "These parameters did not allow to "
77 + "build a space of graph building blocks.<br>"
78 + "Possible cause of this problem: "
79 + "<br>";
80
81 if (e1.getCause() != null)
82 {
83 msg = msg + e1.getCause();
84 }
85 if (e1.getMessage() != null)
86 {
87 msg = msg + " " + e1.getMessage();
88 }
89 msg = msg + "<br>Please alter the "
90 + "settings and try again.</html>";
91
92 JOptionPane.showMessageDialog(btnDone,
93 String.format(msg,400),
94 "Error",
95 JOptionPane.ERROR_MESSAGE,
96 UIManager.getIcon("OptionPane.errorIcon"));
97 return;
98 }
99 close();
100 }
101 });
102
103 this.btnCanc.setToolTipText("Exit without creating any BB Space.");
104 }
105
106//-----------------------------------------------------------------------------
107
114 public FragmentSpace makeFragSpace() throws Exception
115 {
116 if (fsParsForm.txtPar1.getText().trim().equals(""))
117 {
118 throw new DENOPTIMException("No library of fragments");
119 }
120
121 StringBuilder sbPars = new StringBuilder();
123
124 String[] lines = sbPars.toString().split(System.getProperty(
125 "line.separator"));
126
128 for (String line : lines)
129 {
130 fsParams.readParameterLine(line);
131 }
132 // This creates the FragmentSpace object
133 fsParams.checkParameters();
134 fsParams.processParameters();
135 return fsParams.getFragmentSpace();
136 }
137
138//-----------------------------------------------------------------------------
139
140}
Class defining a space of building blocks.
Parameters defining the fragment space.
void processParameters()
Read the information collected in the parameters stored in this class and create the fragment space a...
void checkParameters()
Evaluate consistency of input parameters.
Form collecting input parameters for defining the fragment space.
void putParametersToString(StringBuilder sb)
A modal dialog to define a fragment space and load it.
FSParamsDialog(Component refForPlacement)
Constructor.
static final long serialVersionUID
Version ID.
FragmentSpace makeFragSpace()
Reads all the parameters, calls the interpreters, and eventually creates the static FragmentSpace obj...
JButton btnCanc
The button that is used to close the dialog without processing any input.
void addToCentralPane(JComponent comp)
Adds a component to the central part of this dialog frame.
JButton btnDone
The button that is used to launch the processing of the data given to the open dialog,...
void close()
Closes the dialog window.