diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoCluster.java b/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoCluster.java index d9eb0bb43fe679776a1dc773319d45cfa4d75027..0292e6191940a05e24628c8f5a150c3adcb72fff 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoCluster.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoCluster.java @@ -97,7 +97,7 @@ public class YoshikoCluster { /** * Attempt to select the nodes belonging to this cluster in the original Graph given that they still exist */ - public void select() { + public void highlightInOriginalGraph() { try { List<CyRow> allRows = originalGraph.getDefaultNodeTable().getAllRows(); for (CyRow r: allRows) { @@ -114,16 +114,17 @@ public class YoshikoCluster { } - public void applyImage(JLabel label, int width, int height) { + public void applyImage(JLabel label, int width, int height) throws Exception { if (net == null) { - return; + throw new Exception("Can't have an image without having a network associated"); } if (img != null) { - getImage(width,height,label); label.setIcon(new ImageIcon(img)); - return; + } + else { + getImage(width,height,label); } } @@ -160,7 +161,6 @@ public class YoshikoCluster { public void run() { img = renderingEngine.createImage(width,height); label.setIcon(new ImageIcon(img)); - renderingEngine.dispose(); view.dispose(); } diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ClusterView.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ClusterView.java index 79a1fbf3bbdd8c7e76210ba0ab4db6c0a1526293..c0fa84ef54617765af5a558d8eb0c10cf796c231 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ClusterView.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ClusterView.java @@ -22,14 +22,17 @@ package de.hhu.ba.yoshikoWrapper.swing.components; import java.awt.Color; +import java.awt.Dimension; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.BorderFactory; import javax.swing.Box; import javax.swing.BoxLayout; +import javax.swing.GroupLayout; import javax.swing.JLabel; import javax.swing.JPanel; +import javax.swing.GroupLayout.Alignment; import javax.swing.border.Border; import org.cytoscape.model.CyNode; @@ -43,12 +46,14 @@ import de.hhu.ba.yoshikoWrapper.swing.SwingUtil; @SuppressWarnings("serial") public class ClusterView extends JPanel { + private final static int CLUSTER_ICON_SIZE = 128; + private final JLabel title; private final JLabel clusterSize; private final JLabel icon; private final BasicCollapsiblePanel nodeList; - private final Border regularBorder = BorderFactory.createLineBorder(Color.GRAY,1); + private final Border regularBorder = BorderFactory.createLineBorder(Color.GRAY,3); private final Border highlightBorder = BorderFactory.createLineBorder(GraphicsLoader.yoshikoGreen,3); private final Border selectedBorder = BorderFactory.createLineBorder(Color.BLUE,3); @@ -59,18 +64,18 @@ public class ClusterView extends JPanel { */ private YoshikoCluster cluster; - public ClusterView(YoshikoCluster c) { + public ClusterView(YoshikoCluster c) throws Exception { this.cluster = c; //Swing init - this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS)); title = new JLabel(LocalizationManager.get("cluster")+" "+(c.getID()+1)); clusterSize = new JLabel(LocalizationManager.get("clusterSize")+" "+c.getSize()); icon = new JLabel(); + icon.setPreferredSize(new Dimension(CLUSTER_ICON_SIZE,CLUSTER_ICON_SIZE)); icon.setBorder(BorderFactory.createLineBorder(Color.BLACK)); - cluster.applyImage(icon,128, 128); + cluster.applyImage(icon,CLUSTER_ICON_SIZE, CLUSTER_ICON_SIZE); SwingUtil.addAll(this,title,clusterSize,icon); this.add(Box.createVerticalStrut(4)); @@ -80,18 +85,41 @@ public class ClusterView extends JPanel { //Loop over nodes in the cluster and add them to the view for (CyNode n : c.getSubNetwork().getNodeList()) { nodeList.add( - new JLabel( - c.getNodeName(n) - ) - ); + new JLabel( + c.getNodeName(n) + ) + ); } this.add(nodeList); this.addMouseListener(mouseListener); - this.setBorder(regularBorder); + GroupLayout layout = new GroupLayout(this); + layout.setHorizontalGroup(layout.createParallelGroup() + .addGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup() + .addComponent(title) + .addComponent(clusterSize) + ) + .addComponent(icon) + ) + .addComponent(nodeList) + ); + layout.setVerticalGroup(layout.createSequentialGroup() + .addGroup(layout.createParallelGroup(Alignment.CENTER) + .addGroup(layout.createSequentialGroup() + .addComponent(title) + .addComponent(clusterSize) + ) + .addComponent(icon) + ) + .addComponent(nodeList) + ); + + this.setLayout(layout); + } private MouseListener mouseListener = new MouseListener() { @@ -101,7 +129,7 @@ public class ClusterView extends JPanel { @Override public void mousePressed(MouseEvent e) { - cluster.select(); + cluster.highlightInOriginalGraph(); } @Override diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ClusterViewList.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ClusterViewList.java new file mode 100644 index 0000000000000000000000000000000000000000..610c525255b055fd31a1853af1bc0880bd4eed8f --- /dev/null +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ClusterViewList.java @@ -0,0 +1,36 @@ +package de.hhu.ba.yoshikoWrapper.swing.components; + +import java.awt.Dimension; +import java.awt.Rectangle; + +import javax.swing.JPanel; +import javax.swing.Scrollable; + +public class ClusterViewList extends JPanel implements Scrollable { + + @Override + public Dimension getPreferredScrollableViewportSize() { + return this.getPreferredSize(); + } + + @Override + public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) { + return 16; + } + + @Override + public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) { + return 16; + } + + @Override + public boolean getScrollableTracksViewportWidth() { + return true; + } + + @Override + public boolean getScrollableTracksViewportHeight() { + return false; + } + +} diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ResultPanel.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ResultPanel.java index d541c1aa21cbe80473fd9acf39f626d2c7be9efe..f8830e9c98e656d3d0465b9ec5050541c3ce81c1 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ResultPanel.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ResultPanel.java @@ -59,7 +59,7 @@ public class ResultPanel extends JPanel implements CytoPanelComponent{ private final YoshikoResult result; - public ResultPanel(YoshikoResult result) { + public ResultPanel(YoshikoResult result) throws Exception { this.result = result; @@ -159,7 +159,7 @@ public class ResultPanel extends JPanel implements CytoPanelComponent{ super.setVisible(false); } - private void addSolutionTab(YoshikoSolution s) { + private void addSolutionTab(YoshikoSolution s) throws Exception { SolutionTab tab = new SolutionTab(s); solutionTabs.add( LocalizationManager.get("solution")+" "+(s.getId()+1), diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/SolutionTab.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/SolutionTab.java index 2f593cdceb8081c1b0936b67bafa8f1960cf523f..1577d93daf7f5f1318dc8b4f1a9a5451823dd0d0 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/SolutionTab.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/SolutionTab.java @@ -21,16 +21,22 @@ ******************************************************************************/ package de.hhu.ba.yoshikoWrapper.swing.components; -import java.awt.Dimension; +import static javax.swing.GroupLayout.DEFAULT_SIZE; +import static javax.swing.GroupLayout.PREFERRED_SIZE; + +import java.awt.ScrollPane; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.Comparator; import javax.swing.BoxLayout; +import javax.swing.GroupLayout; +import javax.swing.GroupLayout.Alignment; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; +import javax.swing.ScrollPaneConstants; import org.cytoscape.work.TaskIterator; @@ -45,19 +51,18 @@ import de.hhu.ba.yoshikoWrapper.tasks.CreateMetaGraphTask; public class SolutionTab extends JPanel { private final JScrollPane scrollPane; - private final JPanel scrollPaneContent; + private final ClusterViewList scrollPaneContent; private final JLabel clusterCount; private final JButton createMetaGraph; private final YoshikoSolution solution; - public SolutionTab(YoshikoSolution s) { + public SolutionTab(YoshikoSolution s) throws Exception { this.solution = s; - this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS)); //init swing components - scrollPaneContent = new JPanel(); + scrollPaneContent = new ClusterViewList(); scrollPaneContent.setLayout(new BoxLayout(scrollPaneContent,BoxLayout.Y_AXIS)); //Sort cluster by size, descending @@ -83,7 +88,7 @@ public class SolutionTab extends JPanel { scrollPane = new JScrollPane(scrollPaneContent); - scrollPane.setPreferredSize(new Dimension(150,400)); + scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); clusterCount = new JLabel(LocalizationManager.get("clusterFound")+" "+s.cluster.size()); @@ -101,6 +106,21 @@ public class SolutionTab extends JPanel { }); SwingUtil.addAll(this,clusterCount,scrollPane,createMetaGraph); + + //Layout + GroupLayout layout = new GroupLayout(this); + layout.setHorizontalGroup(layout.createParallelGroup(Alignment.LEADING,true) + .addComponent(clusterCount,DEFAULT_SIZE,DEFAULT_SIZE,DEFAULT_SIZE) + .addComponent(scrollPane,PREFERRED_SIZE,PREFERRED_SIZE,PREFERRED_SIZE) + .addComponent(createMetaGraph,DEFAULT_SIZE,DEFAULT_SIZE,DEFAULT_SIZE) + ); + layout.setVerticalGroup(layout.createSequentialGroup() + .addComponent(clusterCount,DEFAULT_SIZE,DEFAULT_SIZE,PREFERRED_SIZE) + .addComponent(scrollPane,DEFAULT_SIZE,DEFAULT_SIZE,PREFERRED_SIZE) + .addComponent(createMetaGraph,DEFAULT_SIZE,DEFAULT_SIZE,PREFERRED_SIZE) + ); + + this.setLayout(layout); } } diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/CreateMetaGraphTask.java b/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/CreateMetaGraphTask.java index 6f75831a8157f92f61ea52be8aa7e9739c7aa7db..0eb0e0eb5702af49799a933af91475173db669f5 100644 --- a/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/CreateMetaGraphTask.java +++ b/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/CreateMetaGraphTask.java @@ -47,8 +47,6 @@ public class CreateMetaGraphTask extends AbstractTask { //Add nodes for (YoshikoCluster c: solution.getCluster()) { - - CyNode clusterNode = metaGraph.addNode(); CySubNetwork subnet = c.getSubNetwork(); CyCore.networkManager.addNetwork(subnet); @@ -127,12 +125,12 @@ public class CreateMetaGraphTask extends AbstractTask { }); CyCore.dialogTaskManager.execute( - it + it ); CyCore.networkManager.addNetwork(metaGraph); CyCore.networkViewManager.addNetworkView( - view + view ); view.updateView();