$darkmode
DENOPTIM
GUICompatibilityMatrixTab.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.event.ActionEvent;
23import java.awt.event.ActionListener;
24import java.io.File;
25import java.util.Set;
26import java.util.concurrent.atomic.AtomicInteger;
27
28import javax.swing.JButton;
29import javax.swing.JComponent;
30import javax.swing.JOptionPane;
31
32import denoptim.files.FileFormat;
33import denoptim.files.FileUtils;
34
35
43{
47 private static final long serialVersionUID = 912850110991449553L;
48
52 public static AtomicInteger CPMapTabUID = new AtomicInteger(1);
53
57 private boolean unsavedChanges = false;
58
59 private JButton btnLoadCPMap;
60 private JButton btnImportAPClasses;
61
63
64
65//-----------------------------------------------------------------------------
66
71 {
72 super(mainPanel, "Compatibility Matrix #" + CPMapTabUID.getAndIncrement());
73 super.setLayout(new BorderLayout());
74 initialize();
75 }
76
77//-----------------------------------------------------------------------------
78
82 private void initialize() {
83
84 // BorderLayout is needed to allow dynamic resizing!
85 this.setLayout(new BorderLayout());
86
87 // This card structure includes center and south panels:
88 // - (Center) the CPMap handler
89 // - (South) general controls (load, save, close)
90
92 this.add(cpMapHandler, BorderLayout.CENTER);
93
94 // Panel with buttons to the bottom of the frame
95 ButtonsBar commandsPane = new ButtonsBar();
96 super.add(commandsPane, BorderLayout.SOUTH);
97
98
99 btnLoadCPMap = new JButton("Load Compatibility Matrix");
100 btnLoadCPMap.setToolTipText(String.format("<html><body width='%1s'>"
101 + "Reads from file all compatibility matrix data including: "
102 + "<ul><li>APClass compatibility rules</li>"
103 + "<li>APClass-to-Bond order rules</li>"
104 + "<li>Capping rules</li>"
105 + "<li>Forbidden ends definitions.</li></ul></html>",250));
106 btnLoadCPMap.addActionListener(new ActionListener() {
107 public void actionPerformed(ActionEvent e) {
108 File inFile = GUIFileOpener.pickFile(btnLoadCPMap);
109 if (inFile == null || inFile.getAbsolutePath().equals(""))
110 {
111 return;
112 }
114 }
115 });
116 commandsPane.add(btnLoadCPMap);
117
118 btnImportAPClasses = new JButton("Import APClasses");
119 btnImportAPClasses.setToolTipText(String.format("<html>"
120 + "<body width='%1s'>Appends all APClasses to the list of "
121 + "all classes in the current tab.</html>",300));
122 btnImportAPClasses.addActionListener(new ActionListener() {
123 public void actionPerformed(ActionEvent e) {
124 Set<File> files = GUIFileOpener.pickManyFiles(
126 if (files == null || files.size() == 0)
127 {
128 return;
129 }
130
131 String[] options = new String[]{"Cancel",
132 "Capping Groups",
133 "Scaffolds and Fragments"};
134 int res = JOptionPane.showOptionDialog(btnImportAPClasses,
135 "What type of building block are the imported "
136 + "APClasses meant for?",
137 "Select Role for Imported APClasses",
138 2,
139 JOptionPane.QUESTION_MESSAGE,
140 null,
141 options,
142 options[2]);
143
144 if (res == 1)
145 {
147 false);
148 } else if (res == 2) {
150 false);
151 }
152 }
153 });
154 commandsPane.add(btnImportAPClasses);
155
156
157 JButton btnSaveFrags = new JButton("Save Compatibility Matrix");
158 btnSaveFrags.setToolTipText(String.format("<html><body width='%1s'>"
159 + "Writes to file all compatibility matrix data including: "
160 + "<ul><li>APClass compatibility rules</li>"
161 + "<li>APClass-to-Bond order conversion rules</li>"
162 + "<li>Capping rules</li>"
163 + "<li>Definition of forbidden ends.</li></ul></html>",250));
164 btnSaveFrags.addActionListener(new ActionListener() {
165 public void actionPerformed(ActionEvent e) {
166 File outFile = GUIFileOpener.pickFileForSaving(btnSaveFrags);
167 if (outFile == null || cpMapHandler == null)
168 {
169 return;
170 }
171 cpMapHandler.writeCopatibilityMatrixFile(btnSaveFrags,outFile);
172 unsavedChanges = false;
174 }
175 });
176 commandsPane.add(btnSaveFrags);
177
178 JButton btnCanc = new JButton("Close Tab");
179 btnCanc.setToolTipText("Closes this compatibility matrix editor.");
180 btnCanc.addActionListener(new removeCardActionListener(this));
181 commandsPane.add(btnCanc);
182
183 JButton btnHelp = new JButton("?");
184 btnHelp.setToolTipText("<html>Hover over the buttons and fields "
185 + "to get a tip.</html>");
186 btnHelp.addActionListener(new ActionListener() {
187 public void actionPerformed(ActionEvent e) {
188 String txt = "<html><body width='%1s'>"
189 + "<p>The Compatibility Matrix tab allows to create, "
190 + "inspect, and edit "
191 + "compatibility matrix data, which includes: "
192 + "<ul>"
193 + "<li>the actual compatibility matrix,</li>"
194 + "<li>the APClass-to-bond order map,</li>"
195 + "<li>the APClass-capping rules,</li>"
196 + "<li>the list of APClasses that cannot be left "
197 + "unused (i.e., the forbidden ends)</li>"
198 + "</ul></p></html>";
199 JOptionPane.showMessageDialog(btnHelp,
200 String.format(txt, 400),
201 "Tips",
202 JOptionPane.PLAIN_MESSAGE);
203 }
204 });
205 commandsPane.add(btnHelp);
206 }
207
208//-----------------------------------------------------------------------------
209
210 public void importCPMapFromFile(JComponent parent, File inFile)
211 {
212 cpMapHandler.importCPMapFromFile(parent, inFile);
213 }
214
215//-----------------------------------------------------------------------------
216
222 public boolean hasUnsavedChanges()
223 {
224 return unsavedChanges;
225 }
226
227//-----------------------------------------------------------------------------
228
229}
static void addToRecentFiles(String fileName, FileFormat ff)
Appends an entry to the list of recent files.
Definition: FileUtils.java:67
Standardised horizontal bar with padded components, which are meant to be JButtons.
Definition: ButtonsBar.java:36
Component add(Component comp)
Definition: ButtonsBar.java:53
void importCPMapFromFile(JComponent parent, File inFile)
void importAllAPClassesFromCappingGroupLibs(Set< File > fragLibs, boolean cleanup)
Reads all the APClasses found in a list of files.
void writeCopatibilityMatrixFile(JComponent parent, File outFile)
Writes all the compatibility matrix data to the given file.
void importAllAPClassesFromFragmentLibs(Set< File > fragLibs, boolean cleanup)
Reads all the APClasses found in a list of files.
Remove the card from the deck of cards and takes care of removing also the entry in the list of activ...
Class of GUI panels meant to occupy one card in the deck-of-cards layout of the main panel.
GUIMainPanel mainPanel
The main panel (cards deck)
A panel for handling of compatibility matrix.
void importCPMapFromFile(JComponent parent, File inFile)
void initialize()
Initialize the panel and add buttons.
static AtomicInteger CPMapTabUID
Unique identified for instances of this inspector.
GUICompatibilityMatrixTab(GUIMainPanel mainPanel)
Constructor.
boolean unsavedChanges
Flag signaling that loaded data has changes since last save.
boolean hasUnsavedChanges()
Check whether there are unsaved changes.
File opener for DENOPTIM GUI.
static Set< File > pickManyFiles(Component parent)
static File pickFile(Component parent)
static File pickFileForSaving(Component parent)
The main panel is a deck of cards that occupies all the GUI frame.
File formats identified by DENOPTIM.
Definition: FileFormat.java:32