$darkmode
DENOPTIM
GUIAPClassDefinitionDialog.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.Component;
22import java.awt.Dimension;
23import java.awt.FlowLayout;
24import java.awt.event.ActionEvent;
25import java.awt.event.ActionListener;
26
27import javax.swing.BoxLayout;
28import javax.swing.JComboBox;
29import javax.swing.JLabel;
30import javax.swing.JOptionPane;
31import javax.swing.JPanel;
32import javax.swing.JTextField;
33import javax.swing.SwingConstants;
34
35import denoptim.constants.DENOPTIMConstants;
36import denoptim.graph.APClass;
37import denoptim.graph.Edge.BondType;
38
40{
41
45 private static final long serialVersionUID = 3L;
46
50 final Dimension fileLabelSize = new Dimension(250,28);
51
55 final int preferredHeight =
56 (int) (new JTextField()).getPreferredSize().getHeight();
57
58 final Dimension strFieldSize = new Dimension(500,preferredHeight);
59
60 private JPanel centralPanel;
61
62 private String apcStringSyntax = "The valid syntax for APClass "
63 + "strings is:<br><br><code>rule"
64 + DENOPTIMConstants.SEPARATORAPPROPSCL
65 + "subClass</code><br><br> where "
66 + "<ul><li><code>rule</code>"
67 + " is a string with no spaces</li>"
68 + "<li><code>subClass</code> is "
69 + "an integer</li></ul><br>";
70
71 private JPanel pnlAPCName;
72 private JLabel lblAPCName;
73 private JTextField txtAPCName;
74
75 private JPanel pnlAPC2BO;
76 private JComboBox<BondType> cmbAPC2BO;
77 private JLabel lblAPC2BO;
78
79
80//------------------------------------------------------------------------------
81
82 public GUIAPClassDefinitionDialog(Component refForPlacement, boolean askForBO)
83 {
84 super(refForPlacement);
85 setTitle("APClass Definition");
86 centralPanel = new JPanel();
87 centralPanel.setLayout(new BoxLayout(
88 centralPanel, SwingConstants.VERTICAL));
89
90 pnlAPCName = new JPanel(new FlowLayout(FlowLayout.LEFT));
91 lblAPCName = new JLabel("APClass: ");
92 lblAPCName.setToolTipText("<html>"+apcStringSyntax+"</html>");
93 txtAPCName = new JTextField();
94 txtAPCName.setPreferredSize(strFieldSize);
95 txtAPCName.setToolTipText("<html>"+apcStringSyntax+"</html>");
99
100 pnlAPC2BO = new JPanel(new FlowLayout(FlowLayout.LEFT));
101 lblAPC2BO = new JLabel("Bond type: ");
102 String tt = "<html>Chose a type of bond to generate from "
103 + "<br>attachment points belonging to this APClass.</html>";
104 lblAPC2BO.setToolTipText(tt);
105 cmbAPC2BO = new JComboBox<BondType>(BondType.values());
106 cmbAPC2BO.setToolTipText(tt);
107 cmbAPC2BO.setSelectedItem(APClass.DEFAULTBT);
108 if (askForBO)
109 {
110 pnlAPC2BO.add(lblAPC2BO);
111 pnlAPC2BO.add(cmbAPC2BO);
113 }
114
116
117 // Customise the buttons of the modal dialog
118 this.btnDone.setText("OK");
119 this.btnDone.setToolTipText("Confirm the definition of the APClass");
120 this.getRootPane().setDefaultButton(btnDone);
121 for (ActionListener al : this.btnDone.getActionListeners())
122 this.btnDone.removeActionListener(al);
123 this.btnDone.addActionListener(new ActionListener() {
124
125 @Override
126 public void actionPerformed(ActionEvent e) {
127 String currApClass = txtAPCName.getText();
128 if (!APClass.isValidAPClassString(currApClass))
129 {
130 String msg = "<html>'" + currApClass + "' is not a valid "
131 + "string for making an APClass.<br>"
133 + "Please, provide a valid string.</html>";
134
135 JOptionPane.showConfirmDialog(btnDone, msg, "Invalid Input",
136 JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
137 } else {
138 Object[] choice = new Object[2];
139 choice[0] = currApClass;
140 choice[1] = cmbAPC2BO.getSelectedItem();
141 result = choice;
142 close();
143 }
144 }
145 });
146
147 this.btnCanc.setEnabled(false);
148 this.btnCanc.setVisible(false);
149
150 pack();
151
152 }
153
154//------------------------------------------------------------------------------
155
160 public void setPreDefinedAPClass(String text)
161 {
162 txtAPCName.setText(text);
163 }
164
165//------------------------------------------------------------------------------
166
167}
static boolean isValidAPClassString(String s)
Evaluate is a candidate string can be used as APClass.
Definition: APClass.java:412
static final BondType DEFAULTBT
Default bond type for all but APClasses of RCVs.
Definition: APClass.java:109
GUIAPClassDefinitionDialog(Component refForPlacement, boolean askForBO)
final int preferredHeight
Default text field height.
final Dimension fileLabelSize
Default sizes for file pathname labels.
void setPreDefinedAPClass(String text)
Sets the content of the text field with the given predefined text.
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,...
Object result
The result to be returned once the dialog is closed.
void close()
Closes the dialog window.
Possible chemical bond types an edge can represent.
Definition: Edge.java:303