From b2b1c705bc2c2eb12d166bba5f968e101993ce62 Mon Sep 17 00:00:00 2001
From: Philipp Spohr <spohr.philipp@web.de>
Date: Mon, 4 Dec 2017 13:38:15 +0100
Subject: [PATCH] Added support for hiding single node clusters

---
 .../ba/yoshikoWrapper/core/YoshikoLoader.java |  1 -
 .../swing/components/ClusterViewList.java     | 12 ++++++
 .../LanguageSwitcherPanel.java                | 17 +++------
 .../swing/components/MainPanel.java           | 23 +++++++----
 .../swing/components/SolutionTab.java         | 38 ++++++++++++++++++-
 src/main/resources/YoshikoStrings.properties  |  1 +
 6 files changed, 70 insertions(+), 22 deletions(-)
 rename src/main/java/de/hhu/ba/yoshikoWrapper/swing/{ => components}/LanguageSwitcherPanel.java (71%)

diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/core/YoshikoLoader.java b/src/main/java/de/hhu/ba/yoshikoWrapper/core/YoshikoLoader.java
index 1eec501..f7d349d 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/core/YoshikoLoader.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/core/YoshikoLoader.java
@@ -61,7 +61,6 @@ public class YoshikoLoader {
 			//This might happen as Java doesn't unload native libs
 			//One such case might be reloading the Cytoscape app on-the-fly
 			logger.error(e.getMessage());
-			return;
 		}
 		LibraryInterface.setVerbosity(3);
 		//update cfg
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
index 1ce809d..2bb3033 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ClusterViewList.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/ClusterViewList.java
@@ -74,4 +74,16 @@ public class ClusterViewList extends JPanel implements Scrollable {
 		return ret;
 	}
 
+	public void toggleSingleVisibility(boolean showSingles) {
+		for (ClusterView cv : getClusterViews()) {
+			if (cv.getCluster().getSize() > 1 || showSingles) {
+				cv.setVisible(true);
+			}
+			else {
+				cv.setVisible(false);
+			}
+		}
+
+	}
+
 }
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/LanguageSwitcherPanel.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/LanguageSwitcherPanel.java
similarity index 71%
rename from src/main/java/de/hhu/ba/yoshikoWrapper/swing/LanguageSwitcherPanel.java
rename to src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/LanguageSwitcherPanel.java
index 8848647..d9fa246 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/LanguageSwitcherPanel.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/LanguageSwitcherPanel.java
@@ -19,26 +19,21 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  * SOFTWARE.
  ******************************************************************************/
-package de.hhu.ba.yoshikoWrapper.swing;
+package de.hhu.ba.yoshikoWrapper.swing.components;
 
 
-import javax.swing.BoxLayout;
+import javax.swing.JPanel;
 
-import org.cytoscape.util.swing.BasicCollapsiblePanel;
 
-import de.hhu.ba.yoshikoWrapper.core.LocalizationManager;
-import de.hhu.ba.yoshikoWrapper.swing.components.LanguageSwitcher;
+import de.hhu.ba.yoshikoWrapper.swing.SwingUtil;
 
 @SuppressWarnings("serial")
-public class LanguageSwitcherPanel extends BasicCollapsiblePanel{
+public class LanguageSwitcherPanel extends JPanel{
 
+	final private LanguageSwitcher switcher;
 
 	public LanguageSwitcherPanel() {
-		super(LocalizationManager.get("switchLanguage"));
-		final LanguageSwitcher switcher;
-		//final BasicCollapsiblePanel ret = new BasicCollapsiblePanel();
-		//getContentPane().setLayout(new BoxLayout(getContentPane(),BoxLayout.X_AXIS));
-		//SWING COMPONENTS INIT
+
 		switcher = new LanguageSwitcher();
 
 		SwingUtil.addAll(this,
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/MainPanel.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/MainPanel.java
index b97cc6c..0b60b3c 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/MainPanel.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/components/MainPanel.java
@@ -61,7 +61,6 @@ import de.hhu.ba.yoshikoWrapper.core.YoshikoLoader;
 import de.hhu.ba.yoshikoWrapper.cytoUtil.GraphAnalyzer;
 import de.hhu.ba.yoshikoWrapper.swing.AboutDialogFactory;
 import de.hhu.ba.yoshikoWrapper.swing.GraphicsLoader;
-import de.hhu.ba.yoshikoWrapper.swing.LanguageSwitcherPanel;
 import de.hhu.ba.yoshikoWrapper.swing.LibraryPanelFactory;
 import de.hhu.ba.yoshikoWrapper.swing.SwingUtil;
 import de.hhu.ba.yoshikoWrapper.tasks.AlgorithmTask;
@@ -74,18 +73,23 @@ public class MainPanel extends JPanel implements CytoPanelComponent {
 
 	//SWING COMPONENTS
 
-
 	private final YoshikoHeader header;
 
 	private final JButton about;
 
 	private final JCheckBox showAdvancedOptions;
+
 	private final ArrayList<JComponent> advancedOptions;
 
 	private final JScrollPane scrollPane;
 	private final JPanel scrollableContent;
-	//Those two work with factories whysoever
-	private final BasicCollapsiblePanel langPanel;
+
+	/**
+	 * Panel for selecting the application language
+	 */
+	private final LanguageSwitcherPanel langPanel;
+	private final BasicCollapsiblePanel langWrapper;
+
 	private final BasicCollapsiblePanel libraryPanel;
 
 	//Those don't work really as collapsible panels and cause glitches which forces the workaround of wrapping them
@@ -128,6 +132,8 @@ public class MainPanel extends JPanel implements CytoPanelComponent {
 		scrollPane.setBorder(BorderFactory.createEmptyBorder());
 
 		langPanel = new LanguageSwitcherPanel();
+		langWrapper = new BasicCollapsiblePanel(LocalizationManager.get("switchLanguage"));
+		langWrapper.add(langPanel);
 
 		libraryPanel = LibraryPanelFactory.createLibraryPanel();
 		//If no library is loaded yet the obvious panel should be showing up
@@ -151,15 +157,16 @@ public class MainPanel extends JPanel implements CytoPanelComponent {
 		runButton = new JButton(LocalizationManager.get("run"));
 		runButton.addActionListener(buttonListener);
 
-		//Add components to main panel
+		//Add components to the scrollable part of the main panel
 		SwingUtil.addAll(scrollableContent,
-				langPanel,
+				langWrapper,
 				libraryPanel,
 				ecPanelWrapper,
 				reductionWrapper,
 				opWrapper
 		);
 
+		//Add the 'fixed' components to the main panel
 		SwingUtil.addAll(this,
 				header,
 				about,
@@ -207,7 +214,7 @@ public class MainPanel extends JPanel implements CytoPanelComponent {
 		);
 
 		scrollLayout.setHorizontalGroup(scrollLayout.createParallelGroup(Alignment.LEADING,true)
-				.addComponent(langPanel,DEFAULT_SIZE, DEFAULT_SIZE,DEFAULT_SIZE)
+				.addComponent(langWrapper,DEFAULT_SIZE, DEFAULT_SIZE,DEFAULT_SIZE)
 				.addComponent(libraryPanel,DEFAULT_SIZE, DEFAULT_SIZE,DEFAULT_SIZE)
 				.addComponent(ecPanelWrapper,DEFAULT_SIZE, DEFAULT_SIZE,DEFAULT_SIZE)
 				.addComponent(reductionWrapper,DEFAULT_SIZE, DEFAULT_SIZE,DEFAULT_SIZE)
@@ -226,7 +233,7 @@ public class MainPanel extends JPanel implements CytoPanelComponent {
 		);
 
 		scrollLayout.setVerticalGroup(scrollLayout.createSequentialGroup()
-				.addComponent(langPanel,DEFAULT_SIZE,DEFAULT_SIZE,PREFERRED_SIZE)
+				.addComponent(langWrapper,DEFAULT_SIZE,DEFAULT_SIZE,PREFERRED_SIZE)
 				.addComponent(libraryPanel,DEFAULT_SIZE,DEFAULT_SIZE,PREFERRED_SIZE)
 				.addComponent(ecPanelWrapper,DEFAULT_SIZE,DEFAULT_SIZE,PREFERRED_SIZE)
 				.addComponent(reductionWrapper,DEFAULT_SIZE,DEFAULT_SIZE,PREFERRED_SIZE)
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 ea88fc6..91a9c86 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
@@ -27,24 +27,32 @@ import static javax.swing.GroupLayout.PREFERRED_SIZE;
 
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
 import java.util.ArrayList;
 
 import javax.swing.GroupLayout;
 import javax.swing.GroupLayout.Alignment;
 import javax.swing.GroupLayout.Group;
 import javax.swing.JButton;
+import javax.swing.JCheckBox;
 import javax.swing.JLabel;
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.ScrollPaneConstants;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
 
 import org.cytoscape.work.TaskIterator;
 
+import com.sun.media.jfxmedia.logging.Logger;
+
 import de.hhu.ba.yoshikoWrapper.core.CyCore;
 import de.hhu.ba.yoshikoWrapper.core.LocalizationManager;
 import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoCluster;
 import de.hhu.ba.yoshikoWrapper.graphModel.YoshikoSolution;
+import de.hhu.ba.yoshikoWrapper.logging.YoshikoLogger;
 import de.hhu.ba.yoshikoWrapper.swing.SwingUtil;
 import de.hhu.ba.yoshikoWrapper.tasks.CreateClusterViews;
 import de.hhu.ba.yoshikoWrapper.tasks.CreateMetaGraphTask;
@@ -56,10 +64,10 @@ import de.hhu.ba.yoshikoWrapper.tasks.CreateMetaGraphTask;
 public class SolutionTab extends JPanel {
 
 	//SWING COMPONENTS
-
+	private final JLabel clusterCount;
+	private final JCheckBox hideSingles;
 	private final JScrollPane scrollPane;
 	private final ClusterViewList clusterViewList;
-	private final JLabel clusterCount;
 	private final JButton createClusterView;
 	private final JButton createMetaGraph;
 
@@ -83,6 +91,28 @@ public class SolutionTab extends JPanel {
 		//Save abstract solution object for reference
 		this.solution = s;
 
+		hideSingles = new JCheckBox(LocalizationManager.get("hideSingles"));
+		//We check this option as default //TODO: We might save that to config?
+		hideSingles.setSelected(true);
+
+		hideSingles.addItemListener(new ItemListener(){
+
+			@Override
+			public void itemStateChanged(ItemEvent e) {
+				try {
+					if(e.getStateChange() == ItemEvent.SELECTED) {
+						clusterViewList.toggleSingleVisibility(false);
+					}
+					else if (e.getStateChange() == ItemEvent.DESELECTED) {
+						clusterViewList.toggleSingleVisibility(true);
+					}
+				}
+				catch(Exception ex) { //TODO: Specify which type of exceptions can actually occur and process accordingly
+					ex.printStackTrace();
+				}
+			}
+		});
+
 		//Declaration of Swing Components
 		clusterViewList = new ClusterViewList();
 
@@ -164,11 +194,14 @@ public class SolutionTab extends JPanel {
 
 		clusterViewList.setLayout(scrollLayout);
 
+		//Define main layout for solution tab
+
 		layout = new GroupLayout(this);
 
 		layout.setHorizontalGroup(layout.createParallelGroup(Alignment.CENTER,true)
 				.addGap(8)
 				.addComponent(clusterCount,DEFAULT_SIZE,DEFAULT_SIZE,DEFAULT_SIZE)
+				.addComponent(hideSingles,DEFAULT_SIZE,DEFAULT_SIZE,DEFAULT_SIZE)
 				.addGap(8)
 				.addComponent(scrollPane,DEFAULT_SIZE,DEFAULT_SIZE,Short.MAX_VALUE)
 				.addComponent(createClusterView,DEFAULT_SIZE,DEFAULT_SIZE,DEFAULT_SIZE)
@@ -177,6 +210,7 @@ public class SolutionTab extends JPanel {
 		layout.setVerticalGroup(layout.createSequentialGroup()
 				.addGap(8)
 				.addComponent(clusterCount,DEFAULT_SIZE,DEFAULT_SIZE,DEFAULT_SIZE)
+				.addComponent(hideSingles,DEFAULT_SIZE,DEFAULT_SIZE,DEFAULT_SIZE)
 				.addGap(8)
 				.addComponent(scrollPane,DEFAULT_SIZE,DEFAULT_SIZE,DEFAULT_SIZE)
 				.addComponent(createClusterView,DEFAULT_SIZE,DEFAULT_SIZE,DEFAULT_SIZE)
diff --git a/src/main/resources/YoshikoStrings.properties b/src/main/resources/YoshikoStrings.properties
index 6230ba1..085bc84 100644
--- a/src/main/resources/YoshikoStrings.properties
+++ b/src/main/resources/YoshikoStrings.properties
@@ -45,6 +45,7 @@ exportSelectedClusters = Export selected clusters
 firstStart = Thanks for using the Yoshiko Clustering Tool!\nIt appears, that this is your first time using this tool.\nIf you want an in-depth explanation of the algorithm please refer to: [INSERT COOL LINK HERE]
 gap = Gap
 getYoshiko = Get Yoshiko Library
+hideSingles = Hide single-node clusters
 icTooltip = This value is used to determine what the algorithm pays when inserting an edge.\nExisting mappings overwrite this value.\nA higher value means that the algorithm is less likely to insert edges in order to generate a cluster.
 incompleteResult = This run yielded no usable result!
 instance = Instance
-- 
GitLab