22import java.awt.BorderLayout;
23import java.awt.CardLayout;
25import java.awt.Cursor;
26import java.awt.Dimension;
27import java.awt.FlowLayout;
28import java.awt.GridLayout;
30import java.awt.event.ActionEvent;
31import java.awt.event.ActionListener;
32import java.awt.event.ComponentAdapter;
33import java.awt.event.ComponentEvent;
34import java.awt.geom.Ellipse2D;
36import java.io.FileFilter;
37import java.util.ArrayList;
38import java.util.Comparator;
39import java.util.HashMap;
42import java.util.concurrent.atomic.AtomicInteger;
44import javax.swing.DefaultListModel;
45import javax.swing.GroupLayout;
46import javax.swing.JButton;
47import javax.swing.JCheckBox;
48import javax.swing.JComboBox;
49import javax.swing.JComponent;
50import javax.swing.JLabel;
51import javax.swing.JList;
52import javax.swing.JOptionPane;
53import javax.swing.JPanel;
54import javax.swing.JScrollPane;
55import javax.swing.JSplitPane;
56import javax.swing.ListSelectionModel;
57import javax.swing.SwingConstants;
58import javax.swing.UIManager;
60import org.jfree.chart.ChartFactory;
61import org.jfree.chart.ChartMouseEvent;
62import org.jfree.chart.ChartMouseListener;
63import org.jfree.chart.ChartPanel;
64import org.jfree.chart.JFreeChart;
65import org.jfree.chart.editor.ChartEditor;
66import org.jfree.chart.editor.ChartEditorManager;
67import org.jfree.chart.entity.PlotEntity;
68import org.jfree.chart.entity.XYItemEntity;
69import org.jfree.chart.labels.XYToolTipGenerator;
70import org.jfree.chart.plot.DatasetRenderingOrder;
71import org.jfree.chart.plot.PlotOrientation;
72import org.jfree.chart.plot.SeriesRenderingOrder;
73import org.jfree.chart.plot.XYPlot;
74import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
75import org.jfree.data.xy.DefaultXYDataset;
76import org.jfree.data.xy.XYDataset;
78import denoptim.constants.DENOPTIMConstants;
79import denoptim.exception.DENOPTIMException;
80import denoptim.graph.CandidateLW;
81import denoptim.io.DenoptimIO;
160 super.setLayout(
new BorderLayout());
172 this.setLayout(
new BorderLayout());
182 JButton rstView =
new JButton(
"Reset Chart View");
183 rstView.addActionListener(
new ActionListener() {
184 public void actionPerformed(ActionEvent e) {
191 "Plot Sorted List of Candidates",
192 "Plot Candidates by Level"});
193 cmbPlotType.addActionListener(
new ActionListener() {
194 public void actionPerformed(ActionEvent e) {
209 openGraph =
new JButton(
"Open Candidate's Graph");
211 openGraph.setToolTipText(
"Open a new tab for inspecting the "
212 +
"DENOPTIMGraph of the selected candidate.");
213 openGraph.addActionListener(
new ActionListener() {
214 public void actionPerformed(ActionEvent e) {
215 mainPanel.setCursor(Cursor.getPredefinedCursor(
216 Cursor.WAIT_CURSOR));
220 mainPanel.setCursor(Cursor.getPredefinedCursor(
221 Cursor.DEFAULT_CURSOR));
228 lblTotItems.setHorizontalAlignment(SwingConstants.RIGHT);
229 lblTotItems.setPreferredSize(
new Dimension(300,28));
232 GroupLayout lyoCtrlPanel =
new GroupLayout(
ctrlPanel);
234 lyoCtrlPanel.setAutoCreateGaps(
true);
235 lyoCtrlPanel.setAutoCreateContainerGaps(
true);
236 lyoCtrlPanel.setHorizontalGroup(lyoCtrlPanel.createSequentialGroup()
239 lyoCtrlPanel.setVerticalGroup(lyoCtrlPanel.createParallelGroup()
246 centralPanel.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
258 this.add(commandsPane, BorderLayout.SOUTH);
259 JButton btnCanc =
new JButton(
"Close Tab");
260 btnCanc.setToolTipText(
"Closes this FSERun Inspector.");
262 commandsPane.
add(btnCanc);
264 JButton btnHelp =
new JButton(
"?");
265 btnHelp.setToolTipText(
"<html>Hover over buttons and fields "
266 +
"to get a tip.<br>"
267 +
"Click the '?' button for further instructions.</html>");
268 btnHelp.addActionListener(
new ActionListener() {
269 public void actionPerformed(ActionEvent e) {
270 String txt =
"<html><body width='%1s'>"
271 +
"<p>Selection of candidates:"
273 +
"<li>Click on a dot in the chart to disply the "
274 +
"corresponding molecular "
275 +
"representation.</li>"
276 +
"<li>Click away from any dot to reset the molecular "
281 +
"<li>zoom in: click-and-drag "
282 +
"from the top-left to the bottom-right "
283 +
"corners of the new region of the plot to focus on."
285 +
"<li>Use the <code>Reset Chart View</code> to reset "
287 +
"<li>Right-click to get advanced controls and "
291 JOptionPane.showMessageDialog(btnHelp, String.format(txt, 300),
293 JOptionPane.PLAIN_MESSAGE);
296 commandsPane.
add(btnHelp);
318 chartByLevel.getXYPlot().getRangeAxis().setAutoRange(
true);
340 if (!folder.isDirectory() || !folder.exists())
342 JOptionPane.showMessageDialog(
this,
343 "Could not read data from folder '" + folder+
"'!",
345 JOptionPane.PLAIN_MESSAGE,
346 UIManager.getIcon(
"OptionPane.errorIcon"));
349 mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
351 System.out.println(
"Importing data from '" + folder +
"'... ");
353 allItems =
new ArrayList<CandidateLW>();
354 boolean skippFurtherErrors =
false;
355 for (File itemFile : folder.listFiles(
new FileFilter() {
358 public boolean accept(File pathname) {
359 if (pathname.getName().startsWith(
361 && pathname.getName().endsWith(
363 && !pathname.isDirectory())
376 if (!skippFurtherErrors)
378 e1.printStackTrace();
379 mainPanel.setCursor(Cursor.getPredefinedCursor(
380 Cursor.DEFAULT_CURSOR));
382 JPanel msgPanel =
new JPanel(
new GridLayout(2, 1));
383 String msg =
"<html><body width='%1s'>Could not read data "
384 +
"from '" + itemFile +
"'. Hint on cause: "
385 + e1.getMessage() +
" Should we try to "
386 +
"visualize the results anyway?</html>";
387 JLabel text =
new JLabel(String.format(msg, 450));
388 JCheckBox cb =
new JCheckBox(
"Remember decision");
389 cb.setSelected(
false);
392 String[] options =
new String[]{
"Yes",
"Abandon"};
393 int res = JOptionPane.showOptionDialog(
this,
396 JOptionPane.DEFAULT_OPTION,
397 JOptionPane.QUESTION_MESSAGE,
398 UIManager.getIcon(
"OptionPane.errorIcon"),
403 skippFurtherErrors =
true;
433 System.out.println(
"Imported "+
allItems.size()+
" individuals.");
442 for (
int i=0; i<
allItems.size(); i++)
457 itemsWithFitnessDataPerLevel[0][j] = item.
getLevel();
458 itemsWithFitnessDataPerLevel[1][j] = item.
getFitness();
461 sorted =
new ArrayList<CandidateLW>();
463 sorted.sort(
new Comparator<CandidateLW>() {
469 allItems.sort(
new Comparator<CandidateLW>() {
471 int byGen = Integer.compare(c1.
getLevel(),
489 itemsWithFitnessDataSorted[0][i] = i;
490 itemsWithFitnessDataSorted[1][i] = item.
getFitness();
495 itemsWithFitnessDataPerLevel);
499 itemsWithFitnessDataSorted);
511 PlotOrientation.VERTICAL,
522 PlotOrientation.VERTICAL,
530 plotBL.getDomainAxis().setLowerBound(-0.5);
531 plotBL.setBackgroundPaint(Color.WHITE);
532 plotBL.setDomainGridlinePaint(Color.LIGHT_GRAY);
533 plotBL.setRangeGridlinePaint(Color.LIGHT_GRAY);
534 plotBL.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
535 plotBL.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
537 Shape shape0 =
new Ellipse2D.Double(
542 XYLineAndShapeRenderer renderer0 =
543 (XYLineAndShapeRenderer) plotBL.getRenderer();
544 renderer0.setSeriesShape(0, shape0);
545 renderer0.setSeriesPaint(0,
new Color(192, 192, 192, 60));
546 renderer0.setSeriesFillPaint(0,
new Color(192, 192, 192, 60));
547 renderer0.setSeriesOutlinePaint(0, Color.GRAY);
548 renderer0.setUseOutlinePaint(
true);
549 renderer0.setUseFillPaint(
true);
552 Shape shape1 =
new Ellipse2D.Double(
557 XYLineAndShapeRenderer renderer1 =
new XYLineAndShapeRenderer();
559 plotBL.setRenderer(1, renderer1);
560 renderer1.setSeriesShape(0, shape1);
561 renderer1.setSeriesPaint(0, Color.red);
562 renderer1.setSeriesFillPaint(0, Color.red);
563 renderer1.setSeriesOutlinePaint(0, Color.BLACK);
564 renderer1.setUseOutlinePaint(
true);
565 renderer1.setUseFillPaint(
true);
569 plotS.getDomainAxis().setLowerBound(-0.5);
570 plotS.setBackgroundPaint(Color.WHITE);
571 plotS.setDomainGridlinePaint(Color.LIGHT_GRAY);
572 plotS.setRangeGridlinePaint(Color.LIGHT_GRAY);
573 plotS.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
574 plotS.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
576 XYLineAndShapeRenderer rendererS0 =
577 (XYLineAndShapeRenderer) plotS.getRenderer();
578 rendererS0.setSeriesShape(0, shape0);
579 rendererS0.setSeriesPaint(0, Color.decode(
"#848482"));
580 rendererS0.setSeriesOutlinePaint(0, Color.gray);
583 XYLineAndShapeRenderer rendererS1 =
new XYLineAndShapeRenderer();
584 plotS.setRenderer(1, rendererS1);
585 rendererS1.setSeriesShape(0, shape1);
586 rendererS1.setSeriesPaint(0, Color.red);
587 rendererS1.setSeriesFillPaint(0, Color.red);
588 rendererS1.setSeriesOutlinePaint(0, Color.BLACK);
589 rendererS1.setUseOutlinePaint(
true);
590 rendererS1.setUseFillPaint(
true);
599 rightPanel.addComponentListener(
new ComponentAdapter() {
601 public void componentResized(ComponentEvent e) {
603 e.getComponent().getHeight());
605 e.getComponent().getWidth());
607 e.getComponent().getWidth());
609 e.getComponent().getHeight());
611 e.getComponent().getHeight());
613 e.getComponent().getWidth());
615 e.getComponent().getWidth());
617 e.getComponent().getHeight());
622 ChartEditor ceL = ChartEditorManager.getChartEditor(
625 ChartEditor ceS = ChartEditorManager.getChartEditor(
633 XYToolTipGenerator ttg =
new XYToolTipGenerator() {
634 public String generateToolTip(XYDataset data,
int sId,
int itemId)
639 chartByLevel.getXYPlot().getRenderer().setSeriesToolTipGenerator(0,
641 chartBySorted.getXYPlot().getRenderer().setSeriesToolTipGenerator(0,
647 public void chartMouseMoved(ChartMouseEvent e) {
651 public void chartMouseClicked(ChartMouseEvent e)
653 if (e.getEntity() instanceof XYItemEntity)
655 int serId = ((XYItemEntity)e.getEntity()).getSeriesIndex();
658 int itemId = ((XYItemEntity) e.getEntity()).getItem();
665 int initPos =
allItems.indexOf(item);
667 .getRangeAxis().getRange().getLength() * 0.02);
670 List<CandidateLW> overlappingItems =
671 new ArrayList<CandidateLW>();
672 while (nItems<maxItems &&
683 if (delta > tolerance)
685 overlappingItems.add(c);
689 while (nItems<maxItems && (initPos-nItems)>-1)
699 if (delta > tolerance)
701 overlappingItems.add(0,c);
706 if (choosenItem!=
null)
711 else if (e.getEntity() instanceof PlotEntity)
720 public void chartMouseMoved(ChartMouseEvent e) {
724 public void chartMouseClicked(ChartMouseEvent e)
726 if (e.getEntity() instanceof XYItemEntity)
728 int serId = ((XYItemEntity)e.getEntity()).getSeriesIndex();
731 int itemId = ((XYItemEntity) e.getEntity()).getItem();
736 else if (e.getEntity() instanceof PlotEntity)
752 mainPanel.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
759 List<CandidateLW> overlappingItems)
761 switch (overlappingItems.size())
766 return overlappingItems.get(0);
769 DefaultListModel<String> listModel =
new DefaultListModel<String>();
770 JList<String> optionsList =
new JList<String>(listModel);
771 overlappingItems.stream().forEach(c -> listModel.addElement(c.getName()));
772 optionsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
774 JPanel chooseItem =
new JPanel();
775 JLabel header =
new JLabel(
"Select item to visualize:");
776 JScrollPane scrollPane =
new JScrollPane(optionsList);
777 chooseItem.add(header);
778 chooseItem.add(scrollPane);
780 int res = JOptionPane.showConfirmDialog(parent,
782 "Choose Among Overlapping Items",
783 JOptionPane.OK_CANCEL_OPTION,
784 JOptionPane.PLAIN_MESSAGE,
786 if (res != JOptionPane.OK_OPTION)
790 return overlappingItems.get(optionsList.getSelectedIndex());
800 double[][] selectedCandsDataLev =
new double[2][1];
801 selectedCandsDataLev[0][0] = item.
getLevel();
802 selectedCandsDataLev[1][0] = item.
getFitness();
807 double[][] selectedCandsDataOrd =
new double[2][1];
808 selectedCandsDataOrd[0][0] =
sorted.indexOf(item);
809 selectedCandsDataOrd[1][0] = item.
getFitness();
General set of constants used in DENOPTIM.
static final String FITFILENAMEPREFIX
Prefix of filenames for input/output files related to fitness.
static final String FITFILENAMEEXTOUT
Ending and extension of output file of external fitness provider.
A light-weight candidate is a very low-demanding collection of data upon a specific candidate item.
int getLevel()
Returns the level that generated this graph in a fragment space exploration experiment.
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 that understands DENOPTIM graphs and allows to create and edit them.
void importGraphsFromFile(File file)
Imports graphs from file.
A panel that allows to inspect the output of an combinatorial experiment exploring a fragment space.
ChartPanel chartPanelByLevel
ChartPanel chartPanelSorted
DefaultXYDataset datasetSorted
static AtomicInteger fseInspectorTabUID
Unique identified for instances of this handler.
static final long serialVersionUID
Version UID.
MoleculeViewPanel molViewer
JButton openGraph
Button offering the possibility to load the graph inspector for a selected item.
void renderViewWithSelectedItem(CandidateLW item)
String pathToSelectedItem
Storage of pathname to the item selected in the chart.
DefaultXYDataset datasetSelectedOrd
ArrayList< CandidateLW > allItems
void renderViewWithoutSelectedItems()
DefaultXYDataset datasetAllFit
JComboBox< String > cmbPlotType
void initialize()
Initialize the panel and add buttons.
GUIInspectFSERun(GUIMainPanel mainPanel)
Constructor.
Map< Integer, CandidateLW > mapItemsInByLevel
void importFSERunData(File folder)
CandidateLW choseAmongPossiblyOverlapping(JComponent parent, List< CandidateLW > overlappingItems)
void resetViewInPlotByLevel()
void resetViewInPlotOfSortedList()
ArrayList< CandidateLW > sorted
DefaultXYDataset datasetSelectedLev
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.
The collection of tunable preferences.
static int chartPointSize
Evolutionary Inspector: size of points.
A panel with a molecular viewer and data table.
void clearAll(boolean dataIsComing)
Removes the currently visualized molecule and AP table.
void loadChemicalStructureFromFile(String pathName)
Loads a structure in the Jmol viewer.
Utility methods for input/output.
static List< CandidateLW > readLightWeightCandidate(File file)
Read only selected data from a GA produced items.