Skip to content
Snippets Groups Projects
Commit 7f2fed63 authored by Philipp Spohr's avatar Philipp Spohr
Browse files

Finished refactor ... a lot cleaner and flexible now

parent 9de897ad
Branches
Tags
No related merge requests found
......@@ -13,11 +13,10 @@ import org.cytoscape.work.AbstractTask;
import org.cytoscape.work.TaskMonitor;
import org.slf4j.Logger;
import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoCluster;
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;
import de.hhu.ba.yoshikoWrapper.gui.ResultPanel;
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;
......@@ -134,6 +133,7 @@ public class AlgorithmTask extends AbstractTask {
yoshikoResult.editingCost = LibraryInterface.ClusterEditingSolutions_getTotalCost(result);
//Loop over (multiple) solutions
for (long i=0;i<numberOfSolutions;i++) {
taskMonitor.setStatusMessage("Processing solution "+(i+1)+" of "+numberOfSolutions);
......@@ -146,38 +146,39 @@ public class AlgorithmTask extends AbstractTask {
//Fetch number of clusters in the solution
long numberOfClusters = LibraryInterface.ClusterEditingSolutions_getNumberOfClusters(result, i);
//Loop over cluster
for (long k=0;k<numberOfClusters;k++) {
ClusterView cV = tab.addCluster(k);
cV.setTitle((k+1));
//Create java instance
YoshikoCluster cluster = new YoshikoCluster(k);
taskMonitor.setStatusMessage("Processing cluster "+(k+1)+" of "+numberOfClusters);
SWIGTYPE_p_std__vectorT_int_t cluster = LibraryInterface.ClusterEditingSolutions_getCluster(solution, i, k);
long sizeOfCluster = LibraryInterface.IntVector_size(cluster);
cV.setClusterSize(sizeOfCluster);
SWIGTYPE_p_std__vectorT_int_t clusterVector = LibraryInterface.ClusterEditingSolutions_getCluster(result, i, k);
long sizeOfCluster = LibraryInterface.IntVector_size(clusterVector);
for (int l=0;l<sizeOfCluster;l++) { //Unsafe mismatch int long
taskMonitor.setStatusMessage("Processing entry "+(l+1)+ " of "+sizeOfCluster);
int nodeID = LibraryInterface.IntVector_get(cluster, l);
int nodeID = LibraryInterface.IntVector_get(clusterVector, l);
CyNode node = nodeMap.indexOf(nodeID); //<<< Another int/long conversion
cV.addNode(node);
if (node == null) {
logger.error("FATAL ERROR: Node was not previously mapped!");
return;
}
net.getRow(node).set(columnName, ""+(k+1));
cluster.nodes.add(node);
net.getRow(node).set(columnName, ""+(k+1)); //Add Cluster ID in table (Remove in final version?)
}
solution.cluster.add(cluster);
}
yoshikoResult.solutions.add(solution);
}
//At this point the C++ objects can be freed, in case that the algorithm terminates beforehand they need to be cleaned-up elsewhere
LibraryInterface.delete_LibraryInput(input);
LibraryInterface.delete_ClusterEditingSolutions(solution);
LibraryInterface.delete_ClusterEditingSolutions(result);
//Provide some useful info
if (LibraryInterface.ClusterEditingSolutions_isTimedOut(solution)) {
if (LibraryInterface.ClusterEditingSolutions_isTimedOut(result)) {
throw new Exception(LocalizationManager.get("timedOutMessage"));
}
//Generate solutionsPanel
SolutionsPanel solutionsPanel = new SolutionsPanel(processedSolution);
ResultPanel solutionsPanel = new ResultPanel(yoshikoResult);
//Show solution panel
CyCore.registrar.registerService(solutionsPanel,CytoPanelComponent.class, new Properties());
......@@ -195,8 +196,8 @@ public class AlgorithmTask extends AbstractTask {
if (input != null) {
LibraryInterface.delete_LibraryInput(input);
}
if (solution != null) {
LibraryInterface.delete_ClusterEditingSolutions(solution);
if (result != null) {
LibraryInterface.delete_ClusterEditingSolutions(result);
}
super.cancel();
}
......
package de.hhu.ba.yoshikoWrapper.graphModel;
import java.util.ArrayList;
import org.cytoscape.model.CyNode;
public class YoshikoCluster {
public long id;
public ArrayList<CyNode> nodes;
public YoshikoCluster(long id) {
this.id = id;
this.nodes = new ArrayList<CyNode>();
}
}
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.
......@@ -15,7 +14,7 @@ public class YoshikoResult {
public YoshikoResult() {
solutions = new ArrayList<YoshikoSolution>;
solutions = new ArrayList<YoshikoSolution>();
}
}
......@@ -2,16 +2,13 @@ package de.hhu.ba.yoshikoWrapper.graphModel;
import java.util.ArrayList;
import org.cytoscape.model.CyNetwork;
public class YoshikoSolution {
public ArrayList<CyNetwork> cluster;
public ArrayList<YoshikoCluster> cluster;
public int id;
public YoshikoSolution() {
cluster = new ArrayList<CyNetwork>();
cluster = new ArrayList<YoshikoCluster>();
}
}
......@@ -3,7 +3,6 @@ package de.hhu.ba.yoshikoWrapper.gui;
import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.List;
import javax.swing.BorderFactory;
......@@ -19,6 +18,7 @@ import org.cytoscape.view.model.CyNetworkView;
import de.hhu.ba.yoshikoWrapper.core.CyCore;
import de.hhu.ba.yoshikoWrapper.core.LocalizationManager;
import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoCluster;
@SuppressWarnings("serial")
public class ClusterView extends ComfortPanel {
......@@ -38,14 +38,16 @@ public class ClusterView extends ComfortPanel {
/**Simple array list containing references to the nodes that are represented by this cluster view
*
*/
private ArrayList<CyNode> nodes;
private YoshikoCluster cluster;
public ClusterView() {
public ClusterView(YoshikoCluster c) {
this.cluster = c;
//Swing init
this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
title = new JLabel("CLUSTERTITLE");
clusterSize = new JLabel("CLUSTERLABEL");
title = new JLabel(LocalizationManager.get("cluster")+" "+(c.id+1));
clusterSize = new JLabel(LocalizationManager.get("clusterSize")+" "+c.nodes.size());
this.clusterSubNet = CyCore.networkFactory.createNetwork();
this.clusterView = CyCore.networkViewFactory.createNetworkView(this.clusterSubNet);
......@@ -53,32 +55,20 @@ public class ClusterView extends ComfortPanel {
this.addAll(title,clusterSize);
this.add(Box.createVerticalStrut(4));
this.addMouseListener(mouseListener);
this.setBorder(regularBorder);
//Other init
nodes = new ArrayList<CyNode>();
}
public void addNode(CyNode node) {
//Loop over nodes in the cluster and add them to the view
for (CyNode n : c.nodes) {
this.add(
new JLabel(
CyCore.cy.getCurrentNetwork().getRow(node).get("name", String.class)
CyCore.cy.getCurrentNetwork().getRow(n).get("name", String.class)
)
);
//Add symbolic link
nodes.add(node);
}
public void setTitle(long x) {
this.title.setText(LocalizationManager.get("cluster")+" "+x);
}
public void setClusterSize(long x) {
this.clusterSize.setText(LocalizationManager.get("clusterSize")+" "+x);
}
this.addMouseListener(mouseListener);
this.setBorder(regularBorder);
}
private MouseListener mouseListener = new MouseListener() {
......@@ -94,7 +84,7 @@ public class ClusterView extends ComfortPanel {
r.set("selected", false);
}
//Select nodes corresponding to the cluster
for (CyNode n : nodes) {
for (CyNode n : cluster.nodes) {
CyCore.cy.getCurrentNetwork().getRow(n).set("selected", true);
}
}
......
......@@ -23,16 +23,15 @@ import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoSolution;
* Conforms to CY 3.5 by being a CytoPanelComponent which is the norm for "result" panels
*/
@SuppressWarnings("serial")//Will never be serialized
public class SolutionsPanel extends ComfortPanel implements CytoPanelComponent{
public class ResultPanel extends ComfortPanel implements CytoPanelComponent{
private final JTabbedPane solutionTabs;
private final JLabel costLabel;
private final JButton destroyButton;
private final JButton metaGraphButton;
private final YoshikoResult result;
public SolutionsPanel(YoshikoResult result) {
public ResultPanel(YoshikoResult result) {
this.result = result;
......@@ -41,7 +40,7 @@ public class SolutionsPanel extends ComfortPanel implements CytoPanelComponent{
//Init subcomponents
solutionTabs = new JTabbedPane();
for (YoshikoSolution s : result.solutions) {
SolutionTab tab = addSolutionTab(s);
addSolutionTab(s);
}
costLabel = new JLabel();
......@@ -57,16 +56,6 @@ public class SolutionsPanel extends ComfortPanel implements CytoPanelComponent{
});
metaGraphButton = new JButton(LocalizationManager.get("createMetaGraph"));
metaGraphButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
deleteSolution();
}
});
addAll(costLabel,solutionTabs,destroyButton);
}
......@@ -86,13 +75,12 @@ public class SolutionsPanel extends ComfortPanel implements CytoPanelComponent{
super.setVisible(false);
}
public SolutionTab addSolutionTab(YoshikoSolution s) {
private void addSolutionTab(YoshikoSolution s) {
SolutionTab tab = new SolutionTab(s);
solutionTabs.add(
LocalizationManager.get("solution")+" "+(s.id+1),
tab
);
return tab;
}
public void setCost(double modificationCost) {
......
......@@ -4,10 +4,12 @@ import java.awt.Dimension;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import de.hhu.ba.yoshikoWrapper.core.LocalizationManager;
import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoCluster;
import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoSolution;
@SuppressWarnings("serial")
......@@ -16,6 +18,7 @@ public class SolutionTab extends ComfortPanel {
private final JScrollPane scrollPane;
private final ComfortPanel scrollPaneContent;
private final JLabel clusterCount;
private final JButton createMetaGraph;
private final YoshikoSolution solution;
......@@ -27,20 +30,19 @@ public class SolutionTab extends ComfortPanel {
//init swing components
scrollPaneContent = new ComfortPanel();
scrollPaneContent.setLayout(new BoxLayout(scrollPaneContent,BoxLayout.Y_AXIS));
for (YoshikoCluster c: solution.cluster) {
ClusterView clusterView = new ClusterView(c);
scrollPaneContent.add(clusterView);
scrollPaneContent.add(Box.createVerticalStrut(8));
}
scrollPane = new JScrollPane(scrollPaneContent);
scrollPane.setPreferredSize(new Dimension(150,400));
clusterCount = new JLabel(LocalizationManager.get("clusterFound")+s.cluster.size());
this.addAll(clusterCount,scrollPane);
}
clusterCount = new JLabel(LocalizationManager.get("clusterFound")+" "+s.cluster.size());
public ClusterView addCluster(long k) {
ClusterView clusterView = new ClusterView();
scrollPaneContent.add(clusterView);
scrollPaneContent.add(Box.createVerticalStrut(8));
return clusterView;
createMetaGraph = new JButton(LocalizationManager.get("createMetaGraph"));
this.addAll(clusterCount,scrollPane);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment