From e4462426011cb9341b40d652492a67729a4b98ce Mon Sep 17 00:00:00 2001
From: Philipp Spohr <spohr.philipp@web.de>
Date: Tue, 12 Dec 2017 15:58:00 +0100
Subject: [PATCH] Some JavaDoc additions / CyRest, some cleanup

---
 .../core/LocalizationManager.java             |  3 +-
 .../core/NetworkParsingException.java         |  5 +++
 .../ba/yoshikoWrapper/core/ParameterSet.java  | 39 ++++++++++++++++++-
 .../graphModel/YoshikoResult.java             |  2 -
 .../graphModel/YoshikoSolution.java           | 12 ++++++
 .../ba/yoshikoWrapper/swing/FormatHelper.java | 15 +++++++
 .../yoshikoWrapper/swing/GraphicsLoader.java  |  3 ++
 .../ba/yoshikoWrapper/swing/SwingUtil.java    |  6 +++
 .../yoshikoWrapper/tasks/AlgorithmTask.java   | 12 ++++++
 .../tasks/GetSolutionsTask.java               |  1 -
 10 files changed, 91 insertions(+), 7 deletions(-)

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 7f55098..6a50738 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/core/LocalizationManager.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/core/LocalizationManager.java
@@ -53,7 +53,6 @@ public class LocalizationManager {
         locales.put("deDE", german);
         locales.put("hrHR", serbocroatianLatin);
         locales.put("elEL", modernGreek);
-
     }
 
 
@@ -104,7 +103,7 @@ public class LocalizationManager {
 	}
 
 	public static void switchLanguage(String key) {
-		System.out.println("DEBUG: SWITCHING TO: "+key);
+		//System.out.println("DEBUG: SWITCHING TO: "+key);
 		currentLocale = locales.get(key);
 		updateBundle();
 	}
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/core/NetworkParsingException.java b/src/main/java/de/hhu/ba/yoshikoWrapper/core/NetworkParsingException.java
index 65b9c43..c556b9d 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/core/NetworkParsingException.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/core/NetworkParsingException.java
@@ -1,5 +1,10 @@
 package de.hhu.ba.yoshikoWrapper.core;
 
+/**
+ * Simple Exception that should be thrown when the CyNetwork combined with the given parameters can not be parsed in a meaningful WCE instance
+ * @author Philipp Spohr, Dec 12, 2017
+ *
+ */
 @SuppressWarnings("serial")
 public class NetworkParsingException extends Exception {
 
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/core/ParameterSet.java b/src/main/java/de/hhu/ba/yoshikoWrapper/core/ParameterSet.java
index 79d7daa..08ac18a 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/core/ParameterSet.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/core/ParameterSet.java
@@ -1,10 +1,14 @@
 package de.hhu.ba.yoshikoWrapper.core;
 
 
+import java.io.IOException;
+
 import org.cytoscape.model.CyColumn;
 import org.cytoscape.work.Tunable;
+import org.cytoscape.work.TunableValidator;
 
-public class ParameterSet {
+public class ParameterSet implements TunableValidator
+{
 
 	@Tunable(description="Time Limit for the ILP mode", context="nogui")
 	public int timeLimit = -1;
@@ -21,7 +25,7 @@ public class ParameterSet {
 	@Tunable(description="The default deletion cost that is to be used for edges without an associated weight",context="nogui")
 	public double defaultDeletionCost = 1;
 
-	@Tunable(description="A bitmask representing which reduction rules should be used",context="nogui") //TODO: Filter bad bitmasks
+	@Tunable(description="A bitmask representing which reduction rules should be used",context="nogui")
 	public String reductionRulesBitMask = "000000";
 	@Tunable(description="A value controlling the resolution of the SNR reduction rule. Higher values mean a longer running time but possibly better reduction.",context="nogui")
 	public double snrMultFactor = 1.0;
@@ -44,4 +48,35 @@ public class ParameterSet {
 	/**Describes whether auto configuration of the reduction rules is to be used. Overrides the bit mask.**/
 	public boolean suggestReduction = true;
 
+	@Override
+	public ValidationState getValidationState(Appendable errMsg) {
+		if (!checkBitmask(reductionRulesBitMask)) {
+			try {
+				errMsg.append("The Bitmask provided is invalid! Needs to be six bit binary (example: 011001)");
+			} catch (IOException e) {
+				// TODO Auto-generated catch block
+				e.printStackTrace();
+			}
+			return ValidationState.INVALID;
+		}
+		return ValidationState.OK;
+	}
+
+	/**
+	 * Helper function that verifies a String and checks if it represents a 6-bit bitmask
+	 * @param mask
+	 * @return
+	 */
+	private boolean checkBitmask(String mask) {
+		if (mask.length() != 6) {
+			return false;
+		}
+		for (byte c : mask.getBytes()) {
+			if (((char)c)!='0'&&((char)c)!='0') {
+				return false;
+			}
+		}
+		return true;
+	}
+
 }
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoResult.java b/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoResult.java
index 0a4ea3b..d6af2cf 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoResult.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoResult.java
@@ -21,7 +21,6 @@
  ******************************************************************************/
 package de.hhu.ba.yoshikoWrapper.graphModel;
 
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
 
@@ -67,7 +66,6 @@ public class YoshikoResult{
 		return flags;
 	}
 
-
 	public void addSolution(YoshikoSolution solution) {
 		solutions.put(solution.getId(),solution);
 	}
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoSolution.java b/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoSolution.java
index 1a20245..e862745 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoSolution.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/graphModel/YoshikoSolution.java
@@ -34,11 +34,23 @@ import org.slf4j.Logger;
 import de.hhu.ba.yoshikoWrapper.core.CyCore;
 import de.hhu.ba.yoshikoWrapper.logging.YoshikoLogger;
 
+/**
+ * Represents a solution found by the Yoshiko algorithm.
+ * @author Philipp Spohr, Dec 12, 2017
+ *
+ */
 public class YoshikoSolution {
 
+	/**A reference to the result (and thus the Yoshiko run) to which this solution belongs
+	 * TODO: I hate this codestyle wise maybe replace in the long run
+	 */
 	private final YoshikoResult result;
 
+	/**
+	 * The CyNetwork representing the meta-graph for this solution if such a graph exists.
+	 */
 	private CyNetwork metaGraph;
+
 	private HashMap<YoshikoCluster, CyNode> metaGraphMap;
 
 
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/FormatHelper.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/FormatHelper.java
index 284757e..2a7fbff 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/FormatHelper.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/FormatHelper.java
@@ -26,12 +26,27 @@ import java.text.NumberFormat;
 
 import javax.swing.text.NumberFormatter;
 
+/**
+ * Serves as a Factory for various formatters that might be helpful for restricted input fields.
+ * @author Philipp Spohr, Dec 12, 2017
+ *
+ */
 public class FormatHelper {
 
+	/**Returns a basic integer input formatter accepting only positive integers
+	 * Equivalent to getIntegerFormatter(0,Integer.MAX_VALUE)
+	 * @return The NumberFormatter object
+	 */
 	public static NumberFormatter getIntegerFormatter() {
 		return getIntegerFormatter(0, Integer.MAX_VALUE);
 	}
 
+	/**
+	 * Returns a basic integer input formatter accepting only integers in the given range
+	 * @param minValue The smallest, accepted integer
+	 * @param maxValue The largest, accepted integer
+	 * @return A NumberFormatter object accepting only integers in the given range
+	 */
 	public static NumberFormatter getIntegerFormatter(int minValue, int maxValue) {
 		NumberFormat format = NumberFormat.getInstance();
 	    NumberFormatter formatter = new NumberFormatter(format);
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/GraphicsLoader.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/GraphicsLoader.java
index ee1ae4b..27a5272 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/GraphicsLoader.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/GraphicsLoader.java
@@ -43,6 +43,9 @@ public class GraphicsLoader {
 	private static BufferedImage infoIcon;
 	private static BufferedImage infoIcon_highlighted;
 
+	/**
+	 * The fixed Yoshiko styled color, for quick reference
+	 */
 	public final static Color yoshikoGreen = new Color(0,128,0);
 
 	private final static ClassLoader classLoader = GraphicsLoader.class.getClassLoader();
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/SwingUtil.java b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/SwingUtil.java
index b190b5a..003518e 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/swing/SwingUtil.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/swing/SwingUtil.java
@@ -26,7 +26,13 @@ import java.text.DecimalFormat;
 
 import javax.swing.JComponent;
 
+/**
+ * Contains some basic convenience functions for working with Swing that have no other place (as of now)
+ * @author Philipp Spohr, Dec 12, 2017
+ *
+ */
 public class SwingUtil {
+
 	public static void addAll(Container container, JComponent ... components) {
 		for (JComponent c: components) {
 			container.add(c);
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/AlgorithmTask.java b/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/AlgorithmTask.java
index 8f7299e..d764f9e 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/AlgorithmTask.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/AlgorithmTask.java
@@ -24,6 +24,8 @@ package de.hhu.ba.yoshikoWrapper.tasks;
 import java.awt.Window;
 import java.util.Properties;
 
+import javax.swing.SwingUtilities;
+
 import org.cytoscape.application.swing.CytoPanel;
 import org.cytoscape.application.swing.CytoPanelComponent;
 import org.cytoscape.application.swing.CytoPanelName;
@@ -243,6 +245,16 @@ public class AlgorithmTask extends AbstractTask implements ObservableTask {
 		eastPanel.setSelectedIndex(eastPanel.indexOfComponent(resultPanel));
 		//Show (might be invisible)
 		eastPanel.setState(CytoPanelState.DOCK);
+		//Blackest magic, attempts to scale the result panel to a good size
+		SwingUtilities.invokeLater(
+				new Runnable() {
+					@Override
+					public void run() {
+						eastPanel.getThisComponent().setMinimumSize(eastPanel.getThisComponent().getPreferredSize());
+						eastPanel.getThisComponent().revalidate();
+					}
+				}
+			);
 		//eastPanel.getThisComponent().revalidate();
 
 	}
diff --git a/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/GetSolutionsTask.java b/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/GetSolutionsTask.java
index cac56b2..b36ef96 100644
--- a/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/GetSolutionsTask.java
+++ b/src/main/java/de/hhu/ba/yoshikoWrapper/tasks/GetSolutionsTask.java
@@ -29,7 +29,6 @@ public class GetSolutionsTask implements ObservableTask {
 	@Override
 	public void cancel() {
 		// TODO Auto-generated method stub
-
 	}
 
 	@SuppressWarnings("unchecked")
-- 
GitLab