Author: ruschein
Date: 2010-08-12 13:55:17 -0700 (Thu, 12 Aug 2010)
New Revision: 21351
Modified:
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/proxysettings/ProxySettingsTask.java
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/tests/tunables/TunablesTestTask.java
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/internal/algorithms/GridNodeLayout.java
core3/work-api/trunk/src/main/java/org/cytoscape/work/TunableValidator.java
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/GuiTunableInterceptor.java
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/utils/XorPanel.java
Log:
Refactored TunableValidator.
Modified:
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/proxysettings/ProxySettingsTask.java
===================================================================
---
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/proxysettings/ProxySettingsTask.java
2010-08-12 20:30:26 UTC (rev 21350)
+++
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/proxysettings/ProxySettingsTask.java
2010-08-12 20:55:17 UTC (rev 21351)
@@ -52,7 +52,7 @@
this.streamUtil = streamUtil;
}
- public void validate() throws Exception {
+ public boolean tunablesAreValid(final Appendable errMsg) throws
Exception {
storeProxySettings();
FutureTask<Exception> executor = new FutureTask<Exception>(new
TestProxySettings(streamUtil));
@@ -69,8 +69,11 @@
revertProxySettings();
- if (result != null)
- throw new Exception("Cytoscape was unable to connect to
the internet because:\n\n" + result.getMessage());
+ if (result == null)
+ return true;
+
+ errMsg.append("Cytoscape was unable to connect to the internet
because:\n\n" + result.getMessage());
+ return false;
}
public void run(TaskMonitor taskMonitor) {
Modified:
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/tests/tunables/TunablesTestTask.java
===================================================================
---
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/tests/tunables/TunablesTestTask.java
2010-08-12 20:30:26 UTC (rev 21350)
+++
core3/core-task-impl/trunk/src/main/java/org/cytoscape/task/internal/tests/tunables/TunablesTestTask.java
2010-08-12 20:55:17 UTC (rev 21351)
@@ -37,6 +37,7 @@
import org.cytoscape.work.Task;
import org.cytoscape.work.TaskMonitor;
import org.cytoscape.work.Tunable;
+import org.cytoscape.work.TunableValidator;
import org.cytoscape.work.util.BoundedDouble;
import org.cytoscape.work.util.BoundedFloat;
import org.cytoscape.work.util.BoundedInteger;
@@ -45,7 +46,7 @@
import org.cytoscape.work.util.ListSingleSelection;
-public class TunablesTestTask extends AbstractTask {
+public class TunablesTestTask extends AbstractTask implements TunableValidator
{
@Tunable(description="String")
public String s;
@@ -85,6 +86,9 @@
@Tunable(description="Boolean")
public Boolean b2;
+ @Tunable(description="Must be \"valid\"")
+ public String vt;
+
private int getterSetterInt;
public TunablesTestTask() {
@@ -114,6 +118,7 @@
System.err.println("boolean="+b);
System.err.println("Boolean="+b2);
System.err.println("getterSetterInt="+getterSetterInt);
+ System.err.println("Validated tunable="+vt);
}
@Tunable(description="Getter/setter int")
@@ -121,4 +126,15 @@
@Tunable(description="Getter/setter int")
public void setInt(final Integer newValue) { getterSetterInt =
newValue; }
+
+ public boolean tunablesAreValid(final Appendable errMsg) {
+ if (vt.equals("valid"))
+ return true;
+
+ try {
+ errMsg.append("Bad input: \"valid\" expected!");
+ } finally {
+ return false;
+ }
+ }
}
Modified:
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/internal/algorithms/GridNodeLayout.java
===================================================================
---
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/internal/algorithms/GridNodeLayout.java
2010-08-12 20:30:26 UTC (rev 21350)
+++
core3/layout-api/trunk/src/main/java/org/cytoscape/view/layout/internal/algorithms/GridNodeLayout.java
2010-08-12 20:55:17 UTC (rev 21351)
@@ -1,15 +1,8 @@
/*
File: GridNodeLayout.java
- Copyright (c) 2006, The Cytoscape Consortium (www.cytoscape.org)
+ Copyright (c) 2006, 2010, The Cytoscape Consortium (www.cytoscape.org)
- The Cytoscape Consortium is:
- - Institute for Systems Biology
- - University of California San Diego
- - Memorial Sloan-Kettering Cancer Center
- - Pasteur Institute
- - Agilent Technologies
-
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2.1 of the License, or
@@ -36,6 +29,7 @@
*/
package org.cytoscape.view.layout.internal.algorithms;
+
import java.util.List;
import org.cytoscape.model.CyEdge;
@@ -54,67 +48,32 @@
* The GridNodeLayout provides a very simple layout, suitable as
* the default layout for Cytoscape data readers.
*/
-public class GridNodeLayout extends AbstractLayout implements TunableValidator{
-
-// private ModuleProperties layoutProperties;
-
+public class GridNodeLayout extends AbstractLayout implements TunableValidator
{
@Tunable(description="Vertical spacing between nodes")
- public double nodeVerticalSpacing = 40.0;
+ public double nodeVerticalSpacing = 40.0;
@Tunable(description="Horizontal spacing between nodes")
- public double nodeHorizontalSpacing = 80.0;
+ public double nodeHorizontalSpacing = 80.0;
-
+
/**
* Creates a new GridNodeLayout object.
*/
public GridNodeLayout(UndoSupport un) {
super(un);
-// initProps();
}
-
- public void validate() throws java.io.IOException{
- if(nodeVerticalSpacing == 30.0 )throw new
java.io.IOException("This is a test : I don't want 30.0 for nodeVerticalSpacing
value\nProvide something else!!!!");
- }
-/*
+ public boolean tunablesAreValid(final Appendable errMsg) {
+ if (nodeVerticalSpacing != 30.0 )
+ return true;
- private void initProps() {
- layoutProperties =
TunableFactory.getModuleProperties(getName(),"layout");
-
layoutProperties.add(TunableFactory.getTunable("nodeHorizontalSpacing",
"Horizontal spacing between nodes", Tunable.DOUBLE, new Double(80.0)));
- layoutProperties.add(TunableFactory.getTunable("nodeVerticalSpacing",
"Vertical spacing between nodes", Tunable.DOUBLE, new Double(80.0)));
+ try {
+ errMsg.append("This is a test : I don't want 30.0 for
nodeVerticalSpacing value\nProvide something else!!!!");
+ } finally {
+ return false;
+ }
}
- public void updateSettings() {
- updateSettings(false);
- }
-
- public void updateSettings(boolean force) {
- layoutProperties.updateValues();
-
- Tunable t = layoutProperties.get("nodeHorizontalSpacing");
-
- if ((t != null) && (t.valueChanged() || force))
- nodeHorizontalSpacing = ((Double) t.getValue()).doubleValue();
-
- t = layoutProperties.get("nodeVerticalSpacing");
-
- if ((t != null) && (t.valueChanged() || force))
- nodeVerticalSpacing = ((Double) t.getValue()).doubleValue();
- }
-
- public void revertSettings() {
- layoutProperties.revertProperties();
- }
-
- public JPanel getSettingsPanel() {
- JPanel panel = new JPanel(new GridLayout(0, 1));
- panel.add(layoutProperties.getTunablePanel());
-
- return panel;
- }
-*/
-
/**
* DOCUMENT ME!
*
@@ -136,13 +95,12 @@
/**
* We do support selected only
*
- * @return true
+ * @return true
*/
public boolean supportsSelectedOnly() {
return true;
}
-
/**
* DOCUMENT ME!
*/
@@ -199,7 +157,7 @@
edgeList =
network.getAdjacentEdgeList(nView.getModel(),CyEdge.Type.ANY);
// TODO
// for (CyEdge edge: edgeList) {
-// networkView.getCyEdgeView(edge).clearBends();
+// networkView.getCyEdgeView(edge).clearBends();
// }
if (isLocked(nView)) {
@@ -235,5 +193,5 @@
//xColumn.setValues(xMap,null);
//yColumn.setValues(yMap,null);
}
-
+
}
Modified:
core3/work-api/trunk/src/main/java/org/cytoscape/work/TunableValidator.java
===================================================================
--- core3/work-api/trunk/src/main/java/org/cytoscape/work/TunableValidator.java
2010-08-12 20:30:26 UTC (rev 21350)
+++ core3/work-api/trunk/src/main/java/org/cytoscape/work/TunableValidator.java
2010-08-12 20:55:17 UTC (rev 21351)
@@ -2,10 +2,10 @@
/**
- * If implemented, this interface is used to apply a test to the modified
values of the class.
+ * If implemented, this interface is used to apply a test to the modified
values of a Tunable.
*
* <p><pre>
- * <b>example</b> :
+ * <b>Example</b>:
*
* If using this Test class :
* <code>
@@ -32,12 +32,12 @@
* @author Pasteur
*
*/
-public interface TunableValidator{
-
+public interface TunableValidator {
/**
- * Executes the validation test on the annotated <code>Tunables</code>
present in the class whose Objects have been modified.
+ * Executes the validation test on the annotated <code>Tunables</code>.
*
- * @return The message that will be displayed if the test failed, or
<i>null</i> if the test succeeded.
+ * @param errMsg if the validation failed an explanatory message can
be found here and accessed via <code>errMsg.toString()</code>
+ * @return true if the test succeeded and false otherwise
*/
- void validate() throws Exception;
+ boolean tunablesAreValid(final Appendable errMsg) throws Exception;
}
Modified:
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/GuiTunableInterceptor.java
===================================================================
---
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/GuiTunableInterceptor.java
2010-08-12 20:30:26 UTC (rev 21350)
+++
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/GuiTunableInterceptor.java
2010-08-12 20:55:17 UTC (rev 21351)
@@ -48,7 +48,7 @@
private Map<List<GUIHandler>,JPanel> panelMap;
private List<GUIHandler> handlers;
private boolean newValuesSet;
- private Object[] objs;
+ private Object[] objectsWithTunables;
/**
* Creates an Interceptor that will use the <code>GUIHandlers</code>
created in a <code>HandlerFactory</code> from intercepted <code>Tunables</code>.
@@ -103,12 +103,12 @@
* @return if new values has been successfully set
*/
public boolean createUI(Object... proxyObjs) {
- this.objs = convertSpringProxyObjs(proxyObjs);
+ this.objectsWithTunables = convertSpringProxyObjs(proxyObjs);
handlers = new ArrayList<GUIHandler>();
- for (Object o : objs) {
- if (!handlerMap.containsKey(o))
+ for (final Object objectWithTunables : objectsWithTunables) {
+ if (!handlerMap.containsKey(objectWithTunables))
throw new IllegalArgumentException("No Tunables
exist for Object yet!");
- handlers.addAll(handlerMap.get(o).values());
+
handlers.addAll(handlerMap.get(objectWithTunables).values());
}
if (handlers.isEmpty()) {
@@ -272,7 +272,8 @@
/**
* Displays the JPanels of each <code>GUIHandler</code> in a
<code>JOptionPane</code>
*
- * Set the new <i>"value"</i> to <code>Tunable</code> object if the
user clicked on <i>OK</i>, and if the validate method from
<code>TunableValidator</code> interface succeeded
+ * Set the new <i>"value"</i> to <code>Tunable</code> object if the
user clicked on
+ * <i>OK</i>, and if the validate method from
<code>TunableValidator</code> interface succeeded.
*/
private void displayOptionPanel() {
Object[] buttons = {"OK", "Cancel"};
@@ -292,7 +293,6 @@
newValuesSet = false;
}
-
/**
* Check if the conditions set in validate method from
<code>TunableValidator</code> are met
*
@@ -301,21 +301,25 @@
* @return success(true) or failure(false) for the validation
*/
private boolean validateTunableInput() {
- for (Object o : objs) {
- Object[] interfaces = o.getClass().getInterfaces();
- for (Object inter : interfaces) {
- if(inter.equals(TunableValidator.class)) {
- try {
-
((TunableValidator)o).validate();
- } catch (Exception e) {
-
JOptionPane.showMessageDialog(new JFrame(), e.toString(), "TunableValidator
problem", JOptionPane.ERROR_MESSAGE);
- e.printStackTrace();
-
if(parentPanel==null)displayOptionPanel();
- return false;
- }
+ for (final Object objectWithTunables : objectsWithTunables) {
+ if (!(objectWithTunables instanceof TunableValidator))
+ continue;
+
+ final Appendable errMsg = new StringBuilder();
+ try {
+ if
(!((TunableValidator)objectWithTunables).tunablesAreValid(errMsg)) {
+ JOptionPane.showMessageDialog(new
JFrame(), errMsg.toString(),
+ "Input
Validation Problem",
+
JOptionPane.ERROR_MESSAGE);
+ if (parentPanel == null)
+ displayOptionPanel();
+ return false;
}
+ } catch (Exception e) {
+ e.printStackTrace();
}
}
+
parentPanel = null;
newValuesSet = true;
return true;
Modified:
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/utils/XorPanel.java
===================================================================
---
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/utils/XorPanel.java
2010-08-12 20:30:26 UTC (rev 21350)
+++
core3/work-swing-impl/trunk/src/main/java/org/cytoscape/work/internal/tunables/utils/XorPanel.java
2010-08-12 20:55:17 UTC (rev 21351)
@@ -68,7 +68,7 @@
}
}
- class GUIHandlerSwitchListener implements GUIHandler {
+ class GUIHandlerSwitchListener implements GUIHandler {
public Tunable getTunable() {return null;}
public Field getField() {return null;}
public Object getObject() {return null;}
@@ -94,6 +94,7 @@
@Override public String getDescription() { return null; }
@Override public Object getValue() { return null; }
@Override public void setValue(final Object newValue) { }
+ @Override public String getQualifiedName() { return null; }
public String getName() { return null; }
public JPanel getJPanel() { return null; }
public void handle() {}
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.