diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java b/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java index 32acd96591d93e840b23c901388d7c3a201ff0ed..8512ade4cf00b1180679a1c0b0d46a38c1f1e60f 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/CyActivator.java @@ -3,14 +3,18 @@ package de.hhu.ba.yoshikoWrapper; import java.util.Properties; import org.cytoscape.application.CyApplicationManager; +import org.cytoscape.application.swing.CySwingApplication; import org.cytoscape.application.swing.CytoPanelComponent; +import org.cytoscape.model.CyNetworkFactory; import org.cytoscape.model.events.AddedEdgesListener; import org.cytoscape.model.events.ColumnCreatedListener; import org.cytoscape.model.events.ColumnDeletedListener; import org.cytoscape.model.events.NetworkAddedListener; import org.cytoscape.model.events.RemovedEdgesListener; import org.cytoscape.service.util.AbstractCyActivator; +import org.cytoscape.service.util.CyServiceRegistrar; import org.cytoscape.session.events.SessionLoadedListener; +import org.cytoscape.view.model.CyNetworkViewFactory; import org.cytoscape.work.swing.DialogTaskManager; import org.osgi.framework.BundleContext; @@ -20,7 +24,6 @@ import de.hhu.ba.yoshikoWrapper.core.LocalizationManager; import de.hhu.ba.yoshikoWrapper.core.NetChangeListener; import de.hhu.ba.yoshikoWrapper.core.YoshikoLoader; import de.hhu.ba.yoshikoWrapper.gui.MainPanel; -import de.hhu.ba.yoshikoWrapper.gui.SolutionsPanel; public class CyActivator extends AbstractCyActivator { @@ -35,12 +38,16 @@ public class CyActivator extends AbstractCyActivator { Properties propsReaderServiceProps = new Properties(); propsReaderServiceProps.setProperty("cyPropertyName", "yoshiko.props"); registerAllServices(context,cm,propsReaderServiceProps); - + //Create symbolic links to give other classes access CyCore.cy = getService(context, CyApplicationManager.class); CyCore.dialogTaskManager = getService(context, DialogTaskManager.class); + CyCore.registrar = getService(context, CyServiceRegistrar.class); CyCore.cm = cm; - + CyCore.networkViewFactory = getService(context, CyNetworkViewFactory.class); + CyCore.networkFactory = getService(context, CyNetworkFactory.class); + CyCore.swing = getService(context, CySwingApplication.class); + //Set language according to settings LocalizationManager.switchLanguage(cm.getProperties().getProperty("locale", "enUS")); @@ -53,11 +60,9 @@ public class CyActivator extends AbstractCyActivator { } - //main panel and result panel - SolutionsPanel solutionsPanel = new SolutionsPanel(); - MainPanel mainPanel = new MainPanel(solutionsPanel); + //main panel + MainPanel mainPanel = new MainPanel(); registerService(context,mainPanel,CytoPanelComponent.class, new Properties()); - registerService(context,solutionsPanel,CytoPanelComponent.class, new Properties()); //Listener for Network-Changes -> Updating possible columns for mapping NetChangeListener netChangeListener = new NetChangeListener(mainPanel.getColumnMapper()); diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/core/AlgorithmTask.java b/src/main/java/de/hhu/ba/yoshikoWrapper/core/AlgorithmTask.java index fd1bcbda4f041d6ad622d074bbcefc849307e9b5..d8a8a90fccd830eef69abbc328f50b6543477071 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/core/AlgorithmTask.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/core/AlgorithmTask.java @@ -1,5 +1,11 @@ package de.hhu.ba.yoshikoWrapper.core; +import java.util.Properties; + +import org.cytoscape.application.swing.CytoPanel; +import org.cytoscape.application.swing.CytoPanelComponent; +import org.cytoscape.application.swing.CytoPanelName; +import org.cytoscape.application.swing.CytoPanelState; import org.cytoscape.model.CyColumn; import org.cytoscape.model.CyNetwork; import org.cytoscape.model.CyNode; @@ -7,6 +13,8 @@ import org.cytoscape.work.AbstractTask; import org.cytoscape.work.TaskMonitor; import org.slf4j.Logger; +import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoResult; +import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoSolution; import de.hhu.ba.yoshikoWrapper.gui.ClusterView; import de.hhu.ba.yoshikoWrapper.gui.SolutionTab; import de.hhu.ba.yoshikoWrapper.gui.SolutionsPanel; @@ -14,6 +22,7 @@ import de.hhu.ba.yoshikoWrapper.logging.YoshikoLogger; import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface; import de.hhu.ba.yoshikoWrapper.swig.SWIGTYPE_p_std__vectorT_int_t; import de.hhu.ba.yoshikoWrapper.swig.SWIGTYPE_p_yskInput__LibraryInput; +import de.hhu.ba.yoshikoWrapper.swig.SWIGTYPE_p_ysk__ClusterEditingSolutions; public class AlgorithmTask extends AbstractTask { @@ -22,10 +31,10 @@ public class AlgorithmTask extends AbstractTask { private static Logger logger = YoshikoLogger.getInstance().getLogger(); //Parameters - private double insertionCostDefault; - private double deletionCostDefault; - private CyColumn permanentColumn; - private CyColumn forbiddenColumn; + private final double insertionCostDefault; + private final double deletionCostDefault; + private final CyColumn permanentColumn; + private final CyColumn forbiddenColumn; private CyColumn weightColumn; private int timeLimit; private CyNetwork net; @@ -35,10 +44,10 @@ public class AlgorithmTask extends AbstractTask { private boolean separateTriangles; private boolean useHeuristic; private int numberOfSolutions; - private SolutionsPanel solutionsPanel; - //temps + //temps, need to be freed in C++ private SWIGTYPE_p_yskInput__LibraryInput input; + private SWIGTYPE_p_ysk__ClusterEditingSolutions result; public AlgorithmTask( CyNetwork net, @@ -53,8 +62,7 @@ public class AlgorithmTask extends AbstractTask { boolean separatePartitionCuts, boolean separateTriangles, boolean useHeuristic, - int numberOfSolutions, - SolutionsPanel solutionsPanel + int numberOfSolutions ) { this.net = net; @@ -70,11 +78,12 @@ public class AlgorithmTask extends AbstractTask { this.separateTriangles = separateTriangles; this.useHeuristic = useHeuristic; this.numberOfSolutions = numberOfSolutions; - this.solutionsPanel = solutionsPanel; } @Override public void run(TaskMonitor taskMonitor) throws Exception { + + taskMonitor.setTitle(LocalizationManager.get("yoshTask")); taskMonitor.setProgress(0.0); //Get current network @@ -105,7 +114,7 @@ public class AlgorithmTask extends AbstractTask { LibraryInterface.LibraryInput_setDefaultInsertionCost(input, insertionCostDefault); //Call Yoshiko <<< Algorithm is performed here - CyCore.currentSolutions = LibraryInterface.processLibraryInput( + result = LibraryInterface.processLibraryInput( input, numberOfSolutions, bitMaskRules, @@ -115,34 +124,33 @@ public class AlgorithmTask extends AbstractTask { useHeuristic ); + taskMonitor.setProgress(0.9); - - this.solutionsPanel.reset(); - long numberOfSolutions = LibraryInterface.ClusterEditingSolutions_getNumberOfSolutions(CyCore.currentSolutions); - taskMonitor.setStatusMessage("Found: "+numberOfSolutions+" solutions!"); + long numberOfSolutions = LibraryInterface.ClusterEditingSolutions_getNumberOfSolutions(result); + taskMonitor.setStatusMessage("Found: "+numberOfSolutions+" solutions!"); //TODO localize + + YoshikoResult yoshikoResult = new YoshikoResult(); + + yoshikoResult.editingCost = LibraryInterface.ClusterEditingSolutions_getTotalCost(result); - double modificationCost = LibraryInterface.ClusterEditingSolutions_getTotalCost(CyCore.currentSolutions); - taskMonitor.setStatusMessage(LocalizationManager.get("paidCost")+modificationCost); - solutionsPanel.setCost(modificationCost); for (long i=0;i<numberOfSolutions;i++) { taskMonitor.setStatusMessage("Processing solution "+(i+1)+" of "+numberOfSolutions); - - SolutionTab tab = this.solutionsPanel.addSolutionTab(i); + YoshikoSolution solution = new YoshikoSolution(); String columnName = "YOSHIKO_SOLUTION_"+(i+1); net.getDefaultNodeTable().deleteColumn(columnName); net.getDefaultNodeTable().createColumn(columnName, String.class, false); - long numberOfClusters = LibraryInterface.ClusterEditingSolutions_getNumberOfClusters(CyCore.currentSolutions, i); - tab.setClusterNumber(numberOfClusters); - + //Fetch number of clusters in the solution + long numberOfClusters = LibraryInterface.ClusterEditingSolutions_getNumberOfClusters(result, i); + for (long k=0;k<numberOfClusters;k++) { ClusterView cV = tab.addCluster(k); cV.setTitle((k+1)); taskMonitor.setStatusMessage("Processing cluster "+(k+1)+" of "+numberOfClusters); - SWIGTYPE_p_std__vectorT_int_t cluster = LibraryInterface.ClusterEditingSolutions_getCluster(CyCore.currentSolutions, i, k); + SWIGTYPE_p_std__vectorT_int_t cluster = LibraryInterface.ClusterEditingSolutions_getCluster(solution, i, k); long sizeOfCluster = LibraryInterface.IntVector_size(cluster); cV.setClusterSize(sizeOfCluster); for (int l=0;l<sizeOfCluster;l++) { //Unsafe mismatch int long @@ -157,24 +165,39 @@ public class AlgorithmTask extends AbstractTask { net.getRow(node).set(columnName, ""+(k+1)); } } + yoshikoResult.solutions.add(solution); } LibraryInterface.delete_LibraryInput(input); - input = null; + LibraryInterface.delete_ClusterEditingSolutions(solution); //Provide some useful info - if (LibraryInterface.ClusterEditingSolutions_isTimedOut(CyCore.currentSolutions)) { + if (LibraryInterface.ClusterEditingSolutions_isTimedOut(solution)) { throw new Exception(LocalizationManager.get("timedOutMessage")); } - + //Generate solutionsPanel + SolutionsPanel solutionsPanel = new SolutionsPanel(processedSolution); + + //Show solution panel + CyCore.registrar.registerService(solutionsPanel,CytoPanelComponent.class, new Properties()); + //Focus solution panel + CytoPanel eastPanel = CyCore.swing.getCytoPanel(CytoPanelName.EAST); + eastPanel.setSelectedIndex(eastPanel.indexOfComponent(solutionsPanel)); + //Show (might be invisible) + eastPanel.setState(CytoPanelState.DOCK); + } @Override public void cancel() { + //Free C++ resources if (input != null) { LibraryInterface.delete_LibraryInput(input); } + if (solution != null) { + LibraryInterface.delete_ClusterEditingSolutions(solution); + } super.cancel(); } } diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/core/CyCore.java b/src/main/java/de/hhu/ba/yoshikoWrapper/core/CyCore.java index d12307a6f208838044c98f806c3a5fa42bc88975..48e10473143add793c89b78cbe6d12044eb8e680 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/core/CyCore.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/core/CyCore.java @@ -1,13 +1,26 @@ package de.hhu.ba.yoshikoWrapper.core; import org.cytoscape.application.CyApplicationManager; +import org.cytoscape.application.swing.CySwingApplication; +import org.cytoscape.model.CyNetworkFactory; +import org.cytoscape.service.util.CyServiceRegistrar; +import org.cytoscape.view.model.CyNetworkViewFactory; import org.cytoscape.work.swing.DialogTaskManager; +import org.osgi.framework.BundleContext; -import de.hhu.ba.yoshikoWrapper.swig.SWIGTYPE_p_ysk__ClusterEditingSolutions; - +/**Simple link collection to enable access to Cytoscape instances + * + */ public class CyCore { + //SYMBOLIC LINKS public static CyApplicationManager cy; public static DialogTaskManager dialogTaskManager; public static ConfigurationManager cm; - public static SWIGTYPE_p_ysk__ClusterEditingSolutions currentSolutions; + public static BundleContext context; + public static CyServiceRegistrar registrar; + public static CyNetworkViewFactory networkViewFactory; + public static CyNetworkFactory networkFactory; + public static CySwingApplication swing; + + // } diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoResult.java b/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoResult.java new file mode 100644 index 0000000000000000000000000000000000000000..e17301fbaf6a6cd2ae5ef9f06af5a5d09d759e0e --- /dev/null +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoResult.java @@ -0,0 +1,21 @@ +package de.hhu.ba.yoshikoWrapper.graphModel; + +import java.util.ArrayList; +import java.util.HashMap; + + +/**Basic data class that represents a CES instance internally. By using this class the C++ resources can be freed upon retrieval. + * + * + */ +public class YoshikoResult { + + public ArrayList<YoshikoSolution> solutions; + public double editingCost; + + + public YoshikoResult() { + solutions = new ArrayList<YoshikoSolution>; + } + +} diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoSolution.java b/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoSolution.java new file mode 100644 index 0000000000000000000000000000000000000000..487d7fb3be2af7aca2d238ac22c2dc12a367490f --- /dev/null +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoSolution.java @@ -0,0 +1,17 @@ +package de.hhu.ba.yoshikoWrapper.graphModel; + +import java.util.ArrayList; + +import org.cytoscape.model.CyNetwork; + + +public class YoshikoSolution { + + public ArrayList<CyNetwork> cluster; + public int id; + + public YoshikoSolution() { + cluster = new ArrayList<CyNetwork>(); + } + +} diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/package-info.java b/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/package-info.java new file mode 100644 index 0000000000000000000000000000000000000000..0c6ae2fb03e36bf77ba91b7589a8a8ba55e0d185 --- /dev/null +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/package-info.java @@ -0,0 +1,8 @@ +/** + * + */ +/** + * @author Philipp Spohr, Aug 27, 2017 + * + */ +package de.hhu.ba.yoshikoWrapper.graphModel; \ No newline at end of file diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ClusterView.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ClusterView.java index 5893ac4d57e1d6dd535335ee5040d7a7830e1bae..cbbf46d186f9931c9252e5d2653d505173d30cea 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ClusterView.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ClusterView.java @@ -12,8 +12,10 @@ import javax.swing.BoxLayout; import javax.swing.JLabel; import javax.swing.border.Border; +import org.cytoscape.model.CyNetwork; import org.cytoscape.model.CyNode; import org.cytoscape.model.CyRow; +import org.cytoscape.view.model.CyNetworkView; import de.hhu.ba.yoshikoWrapper.core.CyCore; import de.hhu.ba.yoshikoWrapper.core.LocalizationManager; @@ -24,6 +26,9 @@ public class ClusterView extends ComfortPanel { private final JLabel title; private final JLabel clusterSize; + private final CyNetworkView clusterView; + + private CyNetwork clusterSubNet; private final Border regularBorder = BorderFactory.createLineBorder(Color.GRAY); private final Border highlightBorder = BorderFactory.createLineBorder(Color.RED); @@ -42,6 +47,9 @@ public class ClusterView extends ComfortPanel { title = new JLabel("CLUSTERTITLE"); clusterSize = new JLabel("CLUSTERLABEL"); + this.clusterSubNet = CyCore.networkFactory.createNetwork(); + this.clusterView = CyCore.networkViewFactory.createNetworkView(this.clusterSubNet); + this.addAll(title,clusterSize); this.add(Box.createVerticalStrut(4)); diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/MainPanel.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/MainPanel.java index 805770fa963548efc5ae66f7d3f058928f053f3c..059fca65205ee4eca9fead2fb9f89028841d0162 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/MainPanel.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/MainPanel.java @@ -16,14 +16,11 @@ import org.cytoscape.application.swing.CytoPanelComponent; import org.cytoscape.application.swing.CytoPanelName; import org.cytoscape.work.AbstractTask; import org.cytoscape.work.TaskIterator; -import org.slf4j.Logger; import de.hhu.ba.yoshikoWrapper.core.AlgorithmTask; import de.hhu.ba.yoshikoWrapper.core.CyCore; import de.hhu.ba.yoshikoWrapper.core.LocalizationManager; import de.hhu.ba.yoshikoWrapper.core.YoshikoLoader; -import de.hhu.ba.yoshikoWrapper.logging.YoshikoLogger; -import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface; /**This class describes the Swing Panel that the user interacts with in cytoscape * @author Philipp Spohr, Aug 6, 2017 @@ -52,19 +49,13 @@ public class MainPanel extends ComfortPanel implements CytoPanelComponent { private final SolutionNumberChooser solutionNumberChooser; - - //SYMBOLIC LINKS - private final SolutionsPanel solutionsPanel; - private final Logger logger = YoshikoLogger.getInstance().getLogger(); - + /** * Main constructor, creates a new Panel and initializes subcomponents * @param solPanel */ - public MainPanel(SolutionsPanel solPanel) { - - this.solutionsPanel = solPanel; - + public MainPanel( ) { + //SWING INIT this.setLayout(new BoxLayout(this,BoxLayout.PAGE_AXIS)); @@ -123,21 +114,6 @@ public class MainPanel extends ComfortPanel implements CytoPanelComponent { @Override public void actionPerformed(ActionEvent e) { if (YoshikoLoader.isLibraryLoaded()){ - //Check if a solution exists, WARN THE USER!!! - if (CyCore.currentSolutions != null) { - int dialogResult = JOptionPane.showConfirmDialog ( - null, - LocalizationManager.get("overrideSolution"), - LocalizationManager.get("warning"), - JOptionPane.YES_NO_OPTION - ); - if (dialogResult != JOptionPane.YES_OPTION) { - return; - } - - LibraryInterface.delete_ClusterEditingSolutions(CyCore.currentSolutions); - } - solutionsPanel.setVisible(false); AbstractTask yoshiko = new AlgorithmTask( CyCore.cy.getCurrentNetwork(), timeLimitSetter.getTimeLimit(), @@ -151,12 +127,9 @@ public class MainPanel extends ComfortPanel implements CytoPanelComponent { useTriangleCutsBox.isSelected(), usePartitionCutsBox.isSelected(), useHeuristic.isSelected(), - solutionNumberChooser.getSolCount(), - solutionsPanel + solutionNumberChooser.getSolCount() ); CyCore.dialogTaskManager.execute(new TaskIterator(1,yoshiko)); - solutionsPanel.setVisible(true); - } else { JOptionPane.showMessageDialog( diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ReductionRulesChooser.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ReductionRulesChooser.java index 065fd92b8939128e81bc5f275ff2bb75c9da7a98..20b1a2f3f57a19c261a4c9d2384d629d6e3e0757 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ReductionRulesChooser.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ReductionRulesChooser.java @@ -4,9 +4,12 @@ import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; +import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.JCheckBox; import javax.swing.JLabel; +import javax.swing.border.Border; +import javax.swing.border.EtchedBorder; import de.hhu.ba.yoshikoWrapper.core.LocalizationManager; @@ -69,6 +72,10 @@ public class ReductionRulesChooser extends ComfortPanel{ ((JCheckBox)c).setSelected(true); } } + + //Create titled border + Border border = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED); + this.setBorder(BorderFactory.createTitledBorder(border, LocalizationManager.get("redRuleChooserTitle"))); } diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/SolutionTab.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/SolutionTab.java index 5eec7720e16831213c9e829ad6bc201d54bf513b..c1b82b1d3c3d6d3bc7614897e5ad6a4ee5acdb61 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/SolutionTab.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/SolutionTab.java @@ -8,6 +8,7 @@ import javax.swing.JLabel; import javax.swing.JScrollPane; import de.hhu.ba.yoshikoWrapper.core.LocalizationManager; +import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoSolution; @SuppressWarnings("serial") public class SolutionTab extends ComfortPanel { @@ -16,7 +17,12 @@ public class SolutionTab extends ComfortPanel { private final ComfortPanel scrollPaneContent; private final JLabel clusterCount; - public SolutionTab() { + private final YoshikoSolution solution; + + public SolutionTab(YoshikoSolution s) { + + this.solution = s; + this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS)); //init swing components scrollPaneContent = new ComfortPanel(); @@ -25,7 +31,7 @@ public class SolutionTab extends ComfortPanel { scrollPane.setPreferredSize(new Dimension(150,400)); - clusterCount = new JLabel("CLUSTERCOUNT"); + clusterCount = new JLabel(LocalizationManager.get("clusterFound")+s.cluster.size()); this.addAll(clusterCount,scrollPane); } @@ -36,12 +42,5 @@ public class SolutionTab extends ComfortPanel { scrollPaneContent.add(Box.createVerticalStrut(8)); return clusterView; } - - - public void setClusterNumber(long numberOfClusters) { - clusterCount.setText(LocalizationManager.get("clusterFound")+numberOfClusters); - } - - } diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/SolutionsPanel.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/SolutionsPanel.java index 0bdba5dfe44676771af9fc13b41c76a3775bfb25..b67040b910439fb27e13a56cc5ad5f979f567ca9 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/SolutionsPanel.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/SolutionsPanel.java @@ -1,16 +1,23 @@ package de.hhu.ba.yoshikoWrapper.gui; import java.awt.Component; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import javax.swing.BoxLayout; import javax.swing.Icon; +import javax.swing.JButton; import javax.swing.JLabel; +import javax.swing.JOptionPane; import javax.swing.JTabbedPane; import org.cytoscape.application.swing.CytoPanelComponent; import org.cytoscape.application.swing.CytoPanelName; +import de.hhu.ba.yoshikoWrapper.core.CyCore; import de.hhu.ba.yoshikoWrapper.core.LocalizationManager; +import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoResult; +import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoSolution; /**Swing component that contains ALL solutions that are found during one run. * Conforms to CY 3.5 by being a CytoPanelComponent which is the norm for "result" panels @@ -18,20 +25,71 @@ import de.hhu.ba.yoshikoWrapper.core.LocalizationManager; @SuppressWarnings("serial")//Will never be serialized public class SolutionsPanel extends ComfortPanel implements CytoPanelComponent{ - private JTabbedPane solutionTabs; - private JLabel costLabel; + private final JTabbedPane solutionTabs; + private final JLabel costLabel; + private final JButton destroyButton; + private final JButton metaGraphButton; - public SolutionsPanel() { - this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS)); + private final YoshikoResult result; + + public SolutionsPanel(YoshikoResult result) { + + this.result = result; + + setLayout(new BoxLayout(this,BoxLayout.Y_AXIS)); + + //Init subcomponents solutionTabs = new JTabbedPane(); - costLabel = new JLabel("COST"); - this.addAll(costLabel,solutionTabs); + for (YoshikoSolution s : result.solutions) { + SolutionTab tab = addSolutionTab(s); + } + + costLabel = new JLabel(); + setCost(result.editingCost); + + destroyButton = new JButton(LocalizationManager.get("discardSolution")); + destroyButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + deleteSolution(); + } + + }); + + metaGraphButton = new JButton(LocalizationManager.get("createMetaGraph")); + metaGraphButton.addActionListener(new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + deleteSolution(); + } + + }); + + addAll(costLabel,solutionTabs,destroyButton); + } + + public void deleteSolution() { + int dialogResult = JOptionPane.showConfirmDialog ( + null, + LocalizationManager.get("deleteSolution"), + LocalizationManager.get("warning"), + JOptionPane.YES_NO_OPTION + ); + if (dialogResult != JOptionPane.YES_OPTION) { + return; + } + + CyCore.registrar.unregisterService(this,CytoPanelComponent.class); + removeAll(); + super.setVisible(false); } - public SolutionTab addSolutionTab(long i) { - SolutionTab tab = new SolutionTab(); + public SolutionTab addSolutionTab(YoshikoSolution s) { + SolutionTab tab = new SolutionTab(s); solutionTabs.add( - LocalizationManager.get("solution")+" "+(i+1), + LocalizationManager.get("solution")+" "+(s.id+1), tab ); return tab; @@ -42,11 +100,7 @@ public class SolutionsPanel extends ComfortPanel implements CytoPanelComponent{ revalidate(); repaint(); } - - public void reset() { - solutionTabs.removeAll(); - } - + @Override public Component getComponent() { return this; diff --git a/src/main/resources/YoshikoStrings.properties b/src/main/resources/YoshikoStrings.properties index a6b05e6487bd7535068fdce2848f6a47483e8886..0386be728defd72faa97b31dc5f02dc9fbef5d14 100644 --- a/src/main/resources/YoshikoStrings.properties +++ b/src/main/resources/YoshikoStrings.properties @@ -11,10 +11,13 @@ clusterSize = Cluster Size: multFactor = Multiplicative Factor for SNR: paidCost = Paid a total modification cost of: clusterFound = Clusters found: -overrideSolution = Running Yoshiko will override previous solutions. Continue? +deleteSolution = Do you really want to delete this solution? warning = Warning timeLimitILP = Use time limit for ILP (s): timedOutTitle = Timeout timedOutMessage = The ILP exceeded the time-limit! cost = Cost: -nrSolutions = Number of Solutions: \ No newline at end of file +nrSolutions = Number of Solutions: +redRuleChooserTitle = Reduction Rules +discardSolution = Discard +createMetaGraph = Create Meta-Graph \ No newline at end of file