$darkmode
DENOPTIM
MainToolBar.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.CardLayout;
22import java.awt.Color;
23import java.awt.Cursor;
24import java.awt.Desktop;
25import java.awt.GridLayout;
26import java.awt.event.ActionEvent;
27import java.awt.event.ActionListener;
28import java.awt.event.MouseAdapter;
29import java.awt.event.MouseEvent;
30import java.io.File;
31import java.io.IOException;
32import java.net.URI;
33import java.net.URISyntaxException;
34import java.util.HashMap;
35import java.util.Map;
36import java.util.Map.Entry;
37
38import javax.swing.Box;
39import javax.swing.JComboBox;
40import javax.swing.JLabel;
41import javax.swing.JMenu;
42import javax.swing.JMenuBar;
43import javax.swing.JMenuItem;
44import javax.swing.JOptionPane;
45import javax.swing.JPanel;
46import javax.swing.JProgressBar;
47import javax.swing.UIManager;
48import javax.swing.event.MenuEvent;
49import javax.swing.event.MenuListener;
50
51import denoptim.files.FileFormat;
52import denoptim.files.FileUtils;
53import denoptim.io.DenoptimIO;
54import denoptim.logging.Version;
55import denoptim.task.StaticTaskManager;
56
57
64public class MainToolBar extends JMenuBar
65{
66
70 private static final long serialVersionUID = 3L;
71
75 private JMenu menuDenoptim;
76
80 private JMenu menuFile;
81
85 private JMenu openRecent;
86
90 private JMenu activeTabsMenu;
91
95 private JProgressBar queueStatusBar;
96
100 private Map<GUICardPanel,JMenuItem> activeTabsAndRefs;
101
105 protected GUI gui;
106
111
112//-----------------------------------------------------------------------------
113
117 public MainToolBar()
118 {
119 activeTabsAndRefs = new HashMap<GUICardPanel,JMenuItem>();
120 initialize();
121 }
122
123//-----------------------------------------------------------------------------
124
129 {
130 this.gui = gui;
131 }
132
133//-----------------------------------------------------------------------------
134
140 {
141 this.mainPanel = mainPanel;
142 }
143
144//-----------------------------------------------------------------------------
145
149 private void initialize()
150 {
151 menuDenoptim = new JMenu("DENOPTIM");
152 this.add(menuDenoptim);
153
154 JMenuItem prefs = new JMenuItem("Preferences");
155 prefs.addActionListener(new ActionListener() {
156 public void actionPerformed(ActionEvent e) {
157 // NB: if the component used to place the dialog JMenuItem, the
158 // dialog is NOT placed close to the menu (e.g., in other screen).
161 prefDialog.pack();
162 prefDialog.setVisible(true);
163 }
164 });
165 menuDenoptim.add(prefs);
166
167 JMenuItem about = new JMenuItem("About");
168 about.addActionListener(new ActionListener() {
169 public void actionPerformed(ActionEvent e) {
170 JOptionPane.showMessageDialog(about,
171 getAboutPanel(),
172 "About DENOPTIM",
173 JOptionPane.PLAIN_MESSAGE);
174 }
175
176 private JPanel getAboutPanel() {
177 JPanel abtPanel = new JPanel();
178 abtPanel.setLayout(new GridLayout(4, 1, 3, 0));
179
180 JPanel row0 = new JPanel();
181 JLabel t0 = new JLabel("Version "+Version.VERSION);
182 row0.add(t0);
183 abtPanel.add(row0);
184
185 JPanel row1 = new JPanel();
186 JLabel t1 = new JLabel("DENOPTIM is open source software "
187 +" (Affero GPL-3.0).");
188 row1.add(t1);
189 abtPanel.add(row1);
190
191 JPanel row2 = new JPanel();
192 JLabel t2 = new JLabel("Get involved at ");
193 JLabel h2 = new JLabel("http://github.com/denoptim-project");
194 h2.setForeground(Color.BLUE.darker());
195 h2.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
196 h2.addMouseListener(new MouseAdapter() {
197 @Override
198 public void mouseClicked(MouseEvent e) {
199 try {
200 Desktop.getDesktop().browse(new URI(
201 "http://github.com/denoptim-project"));
202 } catch (IOException | URISyntaxException e1) {
203 e1.printStackTrace();
204 }
205 }
206 });
207 row2.add(t2);
208 row2.add(h2);
209 abtPanel.add(row2);
210
211 JPanel row3 = new JPanel();
212 JLabel t3 = new JLabel("Cite ");
213 JLabel h3 = new JLabel("http://doi.org/10.1021/"
214 + "acs.jcim.9b00516");
215 h3.setForeground(Color.BLUE.darker());
216 h3.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
217 h3.addMouseListener(new MouseAdapter() {
218 @Override
219 public void mouseClicked(MouseEvent e) {
220 try {
221 String url = "https://doi.org/10.1021/"
222 +" acs.jcim.9b00516";
223 Desktop.getDesktop().browse(new URI(url));
224 } catch (IOException | URISyntaxException e1) {
225 e1.printStackTrace();
226 }
227 }
228 });
229 row3.add(t3);
230 row3.add(h3);
231 abtPanel.add(row3);
232
233 return abtPanel;
234 }
235 });
236 menuDenoptim.add(about);
237
238 menuDenoptim.addSeparator();
239
240 JMenuItem exit = new JMenuItem("Exit");
241 exit.addActionListener(new ActionListener() {
242 public void actionPerformed(ActionEvent e) {
244 }
245 });
246 menuDenoptim.add(exit);
247
248 menuFile = new JMenu("File");
249 this.add(menuFile);
250
251 JMenu newMenu = new JMenu("New");
252
253 menuFile.add(newMenu);
254 JMenuItem newGA = new JMenuItem("New Evolutionary De Novo Design");
255 newGA.addActionListener(new ActionListener() {
256 public void actionPerformed(ActionEvent e) {
258 }
259 });
260 newMenu.add(newGA);
261 JMenuItem newVS = new JMenuItem("New Virtual Screening");
262 newVS.addActionListener(new ActionListener() {
263 public void actionPerformed(ActionEvent e) {
265 }
266 });
267 newMenu.add(newVS);
268 JMenuItem newFr = new JMenuItem("New Molecular Fragments");
269 newFr.addActionListener(new ActionListener() {
270 public void actionPerformed(ActionEvent e) {
272 }
273 });
274 newMenu.add(newFr);
275 JMenuItem newCPM = new JMenuItem("New Compatibility Matrix");
276 newCPM.addActionListener(new ActionListener() {
277 public void actionPerformed(ActionEvent e) {
279 }
280 });
281 newMenu.add(newCPM);
282 JMenuItem newGr = new JMenuItem("New Graphs");
283 newGr.addActionListener(new ActionListener() {
284 public void actionPerformed(ActionEvent e) {
286 }
287 });
288 newMenu.add(newGr);
289
290 JMenuItem open = new JMenuItem("Open...");
291 open.addActionListener(new ActionListener() {
292 public void actionPerformed(ActionEvent e) {
293 File file = GUIFileOpener.pickFileOrFolder(open);
294 try {
296 file));
297 } catch (Exception e1) {
298 e1.printStackTrace();
299 if (file == null)
300 {
301 return;
302 }
303 String[] options = {"Abandon",
304 "GA Parameters",
305 "FSE Parameters",
306 "FR Parameters",
307 "Compatibility Matrix",
308 "GA Output",
309 "FSE Output"};
310 FileFormat[] ffOpts = {null,
317 JComboBox<String> cmbFiletype =
318 new JComboBox<String>(options);
319 cmbFiletype.setSelectedIndex(0);
320 JLabel msgText = new JLabel(String.format(
321 "<html><body width='%1s'>"
322 + "Failed to detect file type automatically."
323 + "<br>Please, specify how to interpret file "
324 + "'" + file.getAbsolutePath() + "'.",270));
325 int res = JOptionPane.showConfirmDialog(open,
326 new Object[] {msgText,cmbFiletype},
327 "Select file type",
328 JOptionPane.OK_CANCEL_OPTION,
329 JOptionPane.ERROR_MESSAGE);
330 if (res != JOptionPane.OK_OPTION)
331 {
332 return;
333 }
334 else
335 {
336 if (cmbFiletype.getSelectedIndex() == 0)
337 {
338 return;
339 }
340 openFile(file,ffOpts[cmbFiletype.getSelectedIndex()]);
341 }
342 }
343 }
344 });
345 menuFile.add(open);
346
347 openRecent = new JMenu("Open Recent");
348 menuFile.add(openRecent);
349 menuFile.addMenuListener(new MenuListener() {
350 @Override
351 public void menuSelected(MenuEvent e)
352 {
354 }
355 @Override
356 public void menuDeselected(MenuEvent e) {}
357 @Override
358 public void menuCanceled(MenuEvent e) {}
359 });
360
361
362 activeTabsMenu = new JMenu("Active Tabs");
363 this.add(activeTabsMenu);
364
365 JMenu menuHelp = new JMenu("Help");
366 this.add(menuHelp);
367
368 JMenuItem usrManual = new JMenuItem("DENOPTIM user manual");
369 usrManual.addActionListener(new ActionListener() {
370 public void actionPerformed(ActionEvent e) {
371 try {
372 String url = "http://htmlpreview.github.io/?https://"
373 + "github.com/denoptim-project/DENOPTIM/blob/"
374 + "master/doc/user_manual.html";
375 Desktop.getDesktop().browse(new URI(url));
376 } catch (IOException | URISyntaxException e1) {
377 JOptionPane.showMessageDialog(usrManual,
378 "Could not launch the browser to open online "
379 + "version of the manual.",
380 "Error",
381 JOptionPane.ERROR_MESSAGE,
382 UIManager.getIcon("OptionPane.errorIcon"));
383 }
384 }
385 });
386 menuHelp.add(usrManual);
387
388 // From here the items will be added to the RIGHT of the menu bar
389 this.add(Box.createGlue());
390
391 queueStatusBar = new JProgressBar(0,1);
393 queueStatusBar.setMaximum(1);
394 queueStatusBar.setValue(1);
395 queueStatusBar.setToolTipText("Status of tasks");
396 this.add(queueStatusBar);
397 }
398
399//-----------------------------------------------------------------------------
400
404 private void updateOpenRecentMenu()
405 {
406 openRecent.removeAll();
407 Map<File,FileFormat> recentFiles = DenoptimIO.readRecentFilesMap();
408 if (recentFiles.size() == 0)
409 {
410 openRecent.setEnabled(false);
411 } else {
412 openRecent.setEnabled(true);
413 }
414 for (Entry<File, FileFormat> e : recentFiles.entrySet())
415 {
416 RecentFileItem item = new RecentFileItem(e.getKey(), e.getValue());
417 item.addActionListener(new ActionListener() {
418 public void actionPerformed(ActionEvent e) {
419 openFile(item.file, item.ff);
420 }
421 });
422 openRecent.add(item);
423 }
424 }
425
426//-----------------------------------------------------------------------------
427
428 @SuppressWarnings("serial")
429 private class RecentFileItem extends JMenuItem {
430 protected FileFormat ff;
431 protected File file;
432 public RecentFileItem(File file, FileFormat ff)
433 {
434 super(file.getAbsolutePath());
435 this.file = file;
436 this.ff = ff;
437 }
438 }
439
440//-----------------------------------------------------------------------------
441
449 void openFile(File file, FileFormat fileFormat)
450 {
451 switch (fileFormat)
452 {
453 case GA_PARAM:
454 GUIPrepareGARun gaParamsPanel = new GUIPrepareGARun(mainPanel);
455 mainPanel.add(gaParamsPanel);
456 gaParamsPanel.importParametersFromDenoptimParamsFile(file);
457 break;
458
459 case FSE_PARAM:
460 GUIPrepareFSERun fseParamsPanel =
462 mainPanel.add(fseParamsPanel);
463 fseParamsPanel.importParametersFromDenoptimParamsFile(file);
464 break;
465
466 case FR_PARAM:
467 GUIPrepareFitnessRunner frParamsPanel =
469 mainPanel.add(frParamsPanel);
470 frParamsPanel.importParametersFromDenoptimParamsFile(file);
471 break;
472
473 case VRTXSDF:
474 GUIVertexInspector fragPanel =
476 mainPanel.add(fragPanel);
477 fragPanel.importVerticesFromFile(file);
478 break;
479
480 case VRTXJSON:
481 GUIVertexInspector fragPanel2 =
483 mainPanel.add(fragPanel2);
484 fragPanel2.importVerticesFromFile(file);
485 break;
486
487 case CANDIDATESDF:
488 GUIGraphHandler graphPanel3 = new GUIGraphHandler(mainPanel);
489 mainPanel.add(graphPanel3);
490 graphPanel3.importGraphsFromFile(file);
491 break;
492
493 case GRAPHSDF:
494 GUIGraphHandler graphPanel = new GUIGraphHandler(mainPanel);
495 mainPanel.add(graphPanel);
496 graphPanel.importGraphsFromFile(file);
497 break;
498
499 case GRAPHJSON:
500 GUIGraphHandler graphPanel2 = new GUIGraphHandler(mainPanel);
501 mainPanel.add(graphPanel2);
502 graphPanel2.importGraphsFromFile(file);
503 break;
504
505 case COMP_MAP:
507 mainPanel.add(cpmap);
508 cpmap.importCPMapFromFile(mainPanel,file);
509 break;
510
511 case GA_RUN:
512 GUIInspectGARun eiPanel =
514 mainPanel.add(eiPanel);
515 eiPanel.importGARunData(file,mainPanel);
516 break;
517
518 case FSE_RUN:
520 mainPanel.add(fsei);
521 fsei.importFSERunData(file);
522 break;
523
524 case TXT:
526 mainPanel.add(txt);
527 txt.displayContent(file);
528 break;
529
530 case UNRECOGNIZED:
531 JOptionPane.showMessageDialog(this,
532 "File format '" + fileFormat + "' not recognized.",
533 "Error",
534 JOptionPane.ERROR_MESSAGE,
535 UIManager.getIcon("OptionPane.errorIcon"));
536 break;
537
538 default:
539 JOptionPane.showMessageDialog(this,String.format(
540 "<html><body width='%1s'>"
541 + "There is no specific visual representation of file"
542 + " format '" + fileFormat + "'. If you think there "
543 + "should be a way to visually inspect this file, "
544 + "please, write to the development team.",300),
545 "Error",
546 JOptionPane.ERROR_MESSAGE,
547 UIManager.getIcon("OptionPane.errorIcon"));
548 }
549 }
550
551//-----------------------------------------------------------------------------
552
558 public JMenu getMainMenu()
559 {
560 return menuDenoptim;
561 }
562
563//-----------------------------------------------------------------------------
564
573 public void addActiveTab(GUICardPanel panel)
574 {
575 JMenuItem refToPanel = new JMenuItem(panel.getName());
576 refToPanel.addActionListener((ActionEvent evt) -> {
577 ((CardLayout) mainPanel.getLayout()).show(
578 mainPanel,panel.getName());
579 });
580 activeTabsAndRefs.put(panel, refToPanel);
581 activeTabsMenu.add(refToPanel);
582 }
583
584//-----------------------------------------------------------------------------
585
593 public void removeActiveTab(GUICardPanel panel)
594 {
595 if (activeTabsAndRefs.containsKey(panel))
596 {
597 JMenuItem refToDel = activeTabsAndRefs.get(panel);
598 activeTabsMenu.remove(refToDel);
599 activeTabsAndRefs.remove(panel);
600 }
601 }
602
603//-----------------------------------------------------------------------------
604}
static FileFormat detectFileFormat(File inFile)
Inspects a file/folder and tries to detect if there is one of the data sources that is recognized by ...
Definition: FileUtils.java:399
Class of GUI panels meant to occupy one card in the deck-of-cards layout of the main panel.
A panel for handling of compatibility matrix.
void importCPMapFromFile(JComponent parent, File inFile)
File opener for DENOPTIM GUI.
static File pickFileOrFolder(Component parent)
A panel that understands DENOPTIM graphs and allows to create and edit them.
void importGraphsFromFile(File file)
Imports graphs from file.
Graphical User Interface of the DENOPTIM package.
Definition: GUI.java:57
void closeIfAllSaved()
Close GUI is there are no unsaved changes to the open components.
Definition: GUI.java:225
A panel that allows to inspect the output of an combinatorial experiment exploring a fragment space.
A panel that allows to inspect the output of an artificial evolution experiment.
void importGARunData(File file, JComponent parent)
The main panel is a deck of cards that occupies all the GUI frame.
Component add(Component comp)
Add a component and a reference to such component in the main tool bar.
Master form containing all sub-forms that need to be filled to define the input parameters for FragSp...
Form that allows to test the configuration of a fitness provider.
Master form containing all sub-forms that need to be filled to define the input parameters for Denopt...
void importParametersFromDenoptimParamsFile(File file)
A panel that allows to print the content of a text file into a GUI tab.
void displayContent(File file)
Print the content of the given file in this tab's pane.
A panel with a viewer capable of visualising DENOPTIM fragments and allows to create and edit fragmen...
void importVerticesFromFile(File file)
Imports fragments from a file.
RecentFileItem(File file, FileFormat ff)
Main tool bar of the DENOPTIM graphical user interface.
void initialize()
Initialize the contents of the tool bar.
void openFile(File file, FileFormat fileFormat)
Process a file that has a recognized file format and loads a suitable GUI card to visualize the file ...
static final long serialVersionUID
Version.
JProgressBar queueStatusBar
Progress bar indicating the queue of task to complete.
GUI gui
Reference to the GUI window.
JMenu getMainMenu()
Returns the main menu of the tool bar.
MainToolBar()
Constructor that build the tool bar.
JMenu activeTabsMenu
The menu listing the active panels in the deck of cards.
void setRefToMasterGUI(GUI gui)
Sets the reference to master GUI.
void removeActiveTab(GUICardPanel panel)
Remove the reference to an panel/tab in the menu listing active tabs.
Map< GUICardPanel, JMenuItem > activeTabsAndRefs
List of the active panels in the deck of cards.
void updateOpenRecentMenu()
Updated the the list of recent files in the "open Recent" menu.
JMenu menuDenoptim
Main DENOPTIM menu.
void setRefToMainPanel(GUIMainPanel mainPanel)
Sets the reference to main panel for creating functionality of menu items depending on main panel ide...
JMenu openRecent
Menu with list of recent files.
GUIMainPanel mainPanel
Reference to the main panel (cards deck)
void addActiveTab(GUICardPanel panel)
Add the reference to an active panel/tab in the menu listing active panel/tabs.
JMenu menuFile
Main File menu.
Utility methods for input/output.
static Map< File, FileFormat > readRecentFilesMap()
Reads the file defined in DENOPTIMConstants#RECENTFILESLIST and makes a map that contains the pathnam...
Class handling DENOPTIM's version identifier for headers.
Definition: Version.java:36
static final String VERSION
Version identifier (from pom.xml via Maven properties)
Definition: Version.java:48
Manager for tasks submitted by the GUI.
static void setLinkToProgressBar(JProgressBar bar)
Adds a reference to the given progress bar.
File formats identified by DENOPTIM.
Definition: FileFormat.java:32