From 766f50eff7664c3d732a07edef062d4db7b4cb5f Mon Sep 17 00:00:00 2001
From: Philipp Spohr <spohr.philipp@web.de>
Date: Fri, 18 Aug 2017 15:16:50 +0200
Subject: [PATCH] swing is such a wonderful intuitive library /s

---
 .../ba/yoshikoWrapper/core/AlgorithmTask.java | 30 +++++++++----
 .../core/LocalizationManager.java             | 16 ++++---
 .../ba/yoshikoWrapper/gui/ClusterView.java    | 42 +++++++++++++++++++
 .../yoshikoWrapper/gui/LanguageSwitcher.java  |  3 ++
 .../ba/yoshikoWrapper/gui/SolutionTab.java    | 19 +++++++++
 .../ba/yoshikoWrapper/gui/SolutionsPanel.java | 24 +++++------
 src/main/resources/YoshikoStrings.properties  |  4 +-
 .../resources/YoshikoStrings_de_DE.properties |  4 +-
 8 files changed, 113 insertions(+), 29 deletions(-)
 create mode 100644 src/main/java/de/hhu/ba/yoshikoWrapper/gui/ClusterView.java

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 f63d937..5502f29 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/core/AlgorithmTask.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/core/AlgorithmTask.java
@@ -8,6 +8,8 @@ import org.cytoscape.work.AbstractTask;
 import org.cytoscape.work.TaskMonitor;
 import org.slf4j.Logger;
 
+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.logging.YoshikoLogger;
 import de.hhu.ba.yoshikoWrapper.swig.LibraryInterface;
@@ -88,29 +90,41 @@ public class AlgorithmTask extends AbstractTask {
 		SWIGTYPE_p_ysk__ClusterEditingSolutions solutions = LibraryInterface.processLibraryInput(input);
 		taskMonitor.setProgress(0.9);
 
+		this.solutionsPanel.reset();
+
 		
 		long numberOfSolutions = LibraryInterface.ClusterEditingSolutions_getNumberOfSolutions(solutions);
-		this.solutionsPanel.erase();
-		this.solutionsPanel.generateSolTabs(numberOfSolutions);
-		System.out.println("Found: "+numberOfSolutions+" solutions!");
+		taskMonitor.setStatusMessage("Found: "+numberOfSolutions+" solutions!");
+		
 		double modificationCost = LibraryInterface.ClusterEditingSolutions_getTotalCost(solutions);
-		System.out.println("Paid a total modification cost of: "+modificationCost);
+		taskMonitor.setStatusMessage("Paid a total modification cost of: "+modificationCost);
+		
 		for (long i=0;i<numberOfSolutions;i++) {
-			System.out.println("Processing solution "+(i+1)+" of "+numberOfSolutions);
+			
+			taskMonitor.setStatusMessage("Processing solution "+(i+1)+" of "+numberOfSolutions);
+		
+			SolutionTab tab = this.solutionsPanel.addSolutionTab(i);
 			String columnName = "YOSHIKO_SOLUTION_"+(i+1);
+			
 			net.getDefaultNodeTable().deleteColumn(columnName);
 			net.getDefaultNodeTable().createColumn(columnName, String.class, false);
+			
 			long numberOfClusters = LibraryInterface.ClusterEditingSolutions_getNumberOfClusters(solutions, i);
+			
 			for (long k=0;k<numberOfClusters;k++) {
-				System.out.println("Processing cluster "+(k+1)+" of "+numberOfClusters);
+				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(solutions, i, k);
 				long sizeOfCluster = LibraryInterface.IntVector_size(cluster);
+				cV.setClusterSize(sizeOfCluster);
 				for (int l=0;l<sizeOfCluster;l++) { //Unsafe mismatch int long
-					System.out.println("Processing entry "+(l+1)+ " of "+sizeOfCluster);
+					taskMonitor.setStatusMessage("Processing entry "+(l+1)+ " of "+sizeOfCluster);
 					int nodeID = LibraryInterface.IntVector_get(cluster, l);
 					CyNode node = nodeMap.indexOf(nodeID); //<<< Another int/long conversion
+					cV.addNode(node);
 					if (node == null) {
-						System.out.println("FATAL ERROR: Node was not previously mapped!");
+						logger.error("FATAL ERROR: Node was not previously mapped!");
 						return;
 					}
 					net.getRow(node).set(columnName, ""+(k+1));
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/core/LocalizationManager.java b/src/main/java/de/hhu/ba/yoshikoWrapper/core/LocalizationManager.java
index fae2f29..ec76cf4 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/core/LocalizationManager.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/core/LocalizationManager.java
@@ -22,7 +22,7 @@ public class LocalizationManager {
 	
 	static private ResourceBundle currentBundle;
 	
-	static private Locale currentLanguage = usEnglish;
+	static private Locale currentLocale = usEnglish;
 
 	static public Collection<Locale> getLocales(){
 		return locales.values();
@@ -30,27 +30,31 @@ public class LocalizationManager {
 	
 	static public String get(String key) {
 		if (currentBundle == null) {
-			currentBundle = ResourceBundle.getBundle("YoshikoStrings",currentLanguage);
+			currentBundle = ResourceBundle.getBundle("YoshikoStrings",currentLocale);
 		}
 		return currentBundle.getString(key);
 	}
 	
 	static public void switchLanguage(Locale lcl) {
-		currentLanguage = lcl;
+		currentLocale = lcl;
 		updateBundle();
 	}
 
 	public static void switchLanguage(String key) {
 		System.out.println("DEBUG: SWITCHING TO: "+key);
-		currentLanguage = locales.get(key);
+		currentLocale = locales.get(key);
 		updateBundle();
 	}
 	
 	private static void updateBundle() {
-		currentBundle = ResourceBundle.getBundle("YoshikoStrings",currentLanguage);
+		currentBundle = ResourceBundle.getBundle("YoshikoStrings",currentLocale);
 		CyCore.cm.getProperties().setProperty(
 				"locale",
-				currentLanguage.getLanguage()+currentLanguage.getCountry()
+				currentLocale.getLanguage()+currentLocale.getCountry()
 				);
 	}
+
+	public static Locale getCurrentLocale() {
+		return currentLocale;
+	}
 }
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ClusterView.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ClusterView.java
new file mode 100644
index 0000000..da5040e
--- /dev/null
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/ClusterView.java
@@ -0,0 +1,42 @@
+package de.hhu.ba.yoshikoWrapper.gui;
+
+import javax.swing.BoxLayout;
+import javax.swing.JLabel;
+import javax.swing.JList;
+
+import org.cytoscape.model.CyNode;
+
+import de.hhu.ba.yoshikoWrapper.core.LocalizationManager;
+
+@SuppressWarnings("serial")
+public class ClusterView extends ComfortPanel {
+	
+	private final JLabel title;
+	private final JLabel clusterSize;
+	
+	private JList<String> nodeList;
+	
+	public ClusterView() {
+		this.setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
+		
+		this.title = new JLabel();
+		this.clusterSize = new JLabel();
+		this.nodeList = new JList<String>();
+		
+		this.addAll(title,clusterSize,nodeList);
+	}
+	
+	public void setTitle(long x) {
+		this.title.setText(LocalizationManager.get("cluster")+" "+x);
+	}
+
+	public void setClusterSize(long x) {
+		this.clusterSize.setText(LocalizationManager.get("clusterSize")+" "+x);
+	}
+
+	public void addNode(CyNode node) {
+		this.nodeList.add(new JLabel(node.toString()));
+		revalidate();
+		repaint();
+	}
+}
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/LanguageSwitcher.java b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/LanguageSwitcher.java
index b017bae..3bed26b 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/LanguageSwitcher.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/LanguageSwitcher.java
@@ -15,6 +15,9 @@ public class LanguageSwitcher extends JComboBox<Locale>{
 	public LanguageSwitcher() {
 		for (Locale l: LocalizationManager.getLocales() ) {
 			this.addItem(l);
+			if (LocalizationManager.getCurrentLocale() == l) {
+				this.setSelectedItem(l);
+			}
 		}
 		this.addActionListener(new ActionListener() {
 
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 2a41d72..300a4f2 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/SolutionTab.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/SolutionTab.java
@@ -1,7 +1,26 @@
 package de.hhu.ba.yoshikoWrapper.gui;
 
+import javax.swing.JLabel;
+import javax.swing.JScrollPane;
 
 @SuppressWarnings("serial")
 public class SolutionTab extends ComfortPanel {
+	
+	private final JScrollPane scrollPane;
+	private final JLabel testLabel;
+	
+	public SolutionTab() {
+		//init swing components
+		scrollPane = new JScrollPane();
+		testLabel = new JLabel("test");
+		this.addAll(scrollPane,testLabel);
+	}
+	
+
+	public ClusterView addCluster(long k) {
+		ClusterView clusterView = new ClusterView();
+		scrollPane.add(clusterView);
+		return clusterView;
+	}
 
 }
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 425ed42..a7ae442 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/gui/SolutionsPanel.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/gui/SolutionsPanel.java
@@ -19,20 +19,18 @@ public class SolutionsPanel extends ComfortPanel implements CytoPanelComponent{
 		solutionTabs = new JTabbedPane();
 		this.add(solutionTabs);
 	}
-
-	public void generateSolTabs(long numberOfSolutions) {
-		for (long i=0;i<numberOfSolutions;i++) {
-			solutionTabs.add(
-					LocalizationManager.get("solution")+" "+(i+1),
-					new SolutionTab()
-			);
-		}
+	
+	public SolutionTab addSolutionTab(long i) {
+		SolutionTab tab = new SolutionTab();
+		solutionTabs.add(
+				LocalizationManager.get("solution")+" "+(i+1),
+				tab
+		);
+		return tab;
 	}
-	/**
-	 * Helper pseudo-destructor as the object itself can't be reassigned due to Cytoscapes registry
-	 */
-	public void erase() {
-		this.removeAll();
+
+	public void reset() {
+		solutionTabs.removeAll();
 	}
 	
 	@Override
diff --git a/src/main/resources/YoshikoStrings.properties b/src/main/resources/YoshikoStrings.properties
index 44fedf8..3f25f42 100644
--- a/src/main/resources/YoshikoStrings.properties
+++ b/src/main/resources/YoshikoStrings.properties
@@ -5,4 +5,6 @@ yoshTask = Performing Yoshiko Algorithm
 solution = Solution
 restartNeeded = Changes only take effect after restart!
 noLibTitle = Library not loaded!
-noLibMessage = There is no Yoshiko Library currently loaded! You might have to specify its location.
\ No newline at end of file
+noLibMessage = There is no Yoshiko Library currently loaded! You might have to specify its location.
+cluster = Cluster
+clusterSize = Cluster Size:
\ No newline at end of file
diff --git a/src/main/resources/YoshikoStrings_de_DE.properties b/src/main/resources/YoshikoStrings_de_DE.properties
index 079652e..57706bb 100644
--- a/src/main/resources/YoshikoStrings_de_DE.properties
+++ b/src/main/resources/YoshikoStrings_de_DE.properties
@@ -1,2 +1,4 @@
 resultsPanelTitle = Yoshiko Ergebnisse
-resolveLibPath = Yoshiko Library suchen
\ No newline at end of file
+resolveLibPath = Yoshiko Library suchen
+clusterSize = Cluster Gr��e:
+solution = L�sung
\ No newline at end of file
-- 
GitLab