Author: kono
Date: 2011-05-24 16:54:20 -0700 (Tue, 24 May 2011)
New Revision: 25520
Modified:
core3/vizmap-api/trunk/src/test/java/org/cytoscape/view/vizmap/AbstractVisualStyleTest.java
core3/vizmap-impl/trunk/impl/src/main/java/org/cytoscape/view/vizmap/internal/VisualStyleImpl.java
core3/vizmap-impl/trunk/impl/src/test/java/org/cytoscape/view/vizmap/VisualStyleTest.java
Log:
Visual Style bugs related to default values had been updated. Unit tests had
been updated to detect this type of bug.
Modified:
core3/vizmap-api/trunk/src/test/java/org/cytoscape/view/vizmap/AbstractVisualStyleTest.java
===================================================================
---
core3/vizmap-api/trunk/src/test/java/org/cytoscape/view/vizmap/AbstractVisualStyleTest.java
2011-05-24 23:52:55 UTC (rev 25519)
+++
core3/vizmap-api/trunk/src/test/java/org/cytoscape/view/vizmap/AbstractVisualStyleTest.java
2011-05-24 23:54:20 UTC (rev 25520)
@@ -29,6 +29,12 @@
protected static final String attrName = "Sample attr 1";
+
+ protected static final Color RED1 = new Color(200, 0, 0);
+ protected static final Color GREEN1 = new Color(0, 200, 0);
+ protected static final Color RED2 = new Color(100, 0, 0);
+ protected static final Color GREEN2 = new Color(0, 100, 0);
+
protected VisualStyle style;
protected String originalTitle;
@@ -58,12 +64,12 @@
colorMapping2 = new DiscreteMapping<String, Paint>(attrName,
type,
MinimalVisualLexicon.NODE_FILL_COLOR);
- colorMapping1.putMapValue("red", Color.RED);
- colorMapping1.putMapValue("green", Color.GREEN);
+ colorMapping1.putMapValue("red", RED2);
+ colorMapping1.putMapValue("green", GREEN2);
colorMapping1.putMapValue("blue", Color.BLUE);
- colorMapping2.putMapValue("red", Color.RED);
- colorMapping2.putMapValue("green", Color.GREEN);
+ colorMapping2.putMapValue("red", RED1);
+ colorMapping2.putMapValue("green", GREEN1);
colorMapping2.putMapValue("blue", Color.BLUE);
CyProperty<Properties> cyProperties = mock(CyProperty.class);
@@ -116,26 +122,38 @@
style.setDefaultValue(MinimalVisualLexicon.NODE_FILL_COLOR,
Color.PINK);
final Paint defaultNodeColor =
MinimalVisualLexicon.NODE_FILL_COLOR.getDefault();
+ final Paint defaultNodePaint =
MinimalVisualLexicon.NODE_PAINT.getDefault();
final View<CyNode> nodeView1 = networkView.getNodeView(node1);
final View<CyNode> nodeView2 = networkView.getNodeView(node2);
final View<CyNode> nodeView3 = networkView.getNodeView(node3);
+
+ // Before apply call, all node views should have same color
(property default).
+ assertEquals(defaultNodeColor,
nodeView1.getVisualProperty(MinimalVisualLexicon.NODE_FILL_COLOR));
assertEquals(defaultNodeColor,
nodeView2.getVisualProperty(MinimalVisualLexicon.NODE_FILL_COLOR));
+ assertEquals(defaultNodeColor,
nodeView3.getVisualProperty(MinimalVisualLexicon.NODE_FILL_COLOR));
+ assertEquals(defaultNodePaint,
nodeView1.getVisualProperty(MinimalVisualLexicon.NODE_PAINT));
+ assertEquals(defaultNodePaint,
nodeView2.getVisualProperty(MinimalVisualLexicon.NODE_PAINT));
+ assertEquals(defaultNodePaint,
nodeView3.getVisualProperty(MinimalVisualLexicon.NODE_PAINT));
+ // Two existing mappings.
assertEquals(2, style.getAllVisualMappingFunctions().size());
+
+ // Apply mappings.
style.apply(networkView);
+
+ // Check defaults
assertEquals(Color.PINK,
style.getDefaultValue(MinimalVisualLexicon.NODE_FILL_COLOR));
+ assertEquals(Color.BLACK,
style.getDefaultValue(MinimalVisualLexicon.NODE_PAINT));
+ // Check results.
+ assertEquals(RED1,
nodeView1.getVisualProperty(MinimalVisualLexicon.NODE_FILL_COLOR));
+ assertEquals(GREEN1,
nodeView2.getVisualProperty(MinimalVisualLexicon.NODE_FILL_COLOR));
+ assertEquals(RED2,
nodeView1.getVisualProperty(MinimalVisualLexicon.NODE_PAINT));
+ assertEquals(GREEN2,
nodeView2.getVisualProperty(MinimalVisualLexicon.NODE_PAINT));
- Paint prop1 =
nodeView1.getVisualProperty(MinimalVisualLexicon.NODE_FILL_COLOR);
-// assertEquals(Color.RED,
nodeView1.getVisualProperty(MinimalVisualLexicon.NODE_FILL_COLOR));
-//
-// assertEquals(Color.PINK,
networkView.getNodeView(node3).getVisualProperty(MinimalVisualLexicon.NODE_FILL_COLOR));
-// assertEquals(Color.GREEN,
networkView.getNodeView(node2).getVisualProperty(MinimalVisualLexicon.NODE_FILL_COLOR));
-//
-// assertEquals(Color.RED,
networkView.getNodeView(node1).getVisualProperty(MinimalVisualLexicon.NODE_PAINT));
-
- //assertEquals(Color.BLACK, networkView.getNodeView(node3));
-
+ // Check default values. Leaf node will be applied.
+ assertEquals(Color.BLACK,
nodeView3.getVisualProperty(MinimalVisualLexicon.NODE_PAINT));
+ assertEquals(Color.PINK,
nodeView3.getVisualProperty(MinimalVisualLexicon.NODE_FILL_COLOR));
}
}
Modified:
core3/vizmap-impl/trunk/impl/src/main/java/org/cytoscape/view/vizmap/internal/VisualStyleImpl.java
===================================================================
---
core3/vizmap-impl/trunk/impl/src/main/java/org/cytoscape/view/vizmap/internal/VisualStyleImpl.java
2011-05-24 23:52:55 UTC (rev 25519)
+++
core3/vizmap-impl/trunk/impl/src/main/java/org/cytoscape/view/vizmap/internal/VisualStyleImpl.java
2011-05-24 23:54:20 UTC (rev 25520)
@@ -38,6 +38,7 @@
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import org.cytoscape.model.CyEdge;
import org.cytoscape.model.CyNetwork;
@@ -45,6 +46,8 @@
import org.cytoscape.model.CyTableEntry;
import org.cytoscape.view.model.CyNetworkView;
import org.cytoscape.view.model.View;
+import org.cytoscape.view.model.VisualLexicon;
+import org.cytoscape.view.model.VisualLexiconNode;
import org.cytoscape.view.model.VisualProperty;
import org.cytoscape.view.model.Visualizable;
import org.cytoscape.view.vizmap.VisualMappingFunction;
@@ -208,31 +211,38 @@
final Collection<VisualProperty<?>> visualProperties) {
for (VisualProperty<?> vp : visualProperties)
- applyToView(views, vp);
+ applyToView(views, vp);
}
private void applyToView(final Collection<? extends View<?>> views,
final VisualProperty<?> vp) {
logger.info("###### Apply called for " + vp.getDisplayName());
-
+
final VisualMappingFunction<?, ?> mapping =
getVisualMappingFunction(vp);
if (mapping != null) {
// Mapping is available for this VP. Apply it.
- logger.debug("###### Visual Mapping found for " +
vp.getDisplayName() + ": " + mapping.toString());
+ logger.debug("Visual Mapping found for " +
vp.getDisplayName() + ": " + mapping.toString());
+
+ // Default of this style
final Object styleDefaultValue = getDefaultValue(vp);
+ // Default of this Visual Property
+ final Object vpDefault = vp.getDefault();
+
for (View<?> view : views) {
mapping.apply((View<? extends CyTableEntry>)
view);
-
- // FIXME: this condition is not enough in some
cases.
- if (view.getVisualProperty(vp) ==
vp.getDefault())
+
+ if (view.getVisualProperty(vp) == vpDefault) {
view.setVisualProperty(vp,
styleDefaultValue);
+ }
}
} else if (!vp.shouldIgnoreDefault()) {
// Ignore defaults flag is OFF. Apply defaults.
applyStyleDefaults((Collection<View<?>>) views, vp);
} else if (vp.getDefault() instanceof Visualizable == false) {
Object defVal = getDefaultValue(vp);
+
+ // Visual Style does not have default value
if (defVal == null) {
this.perVSDefaults.put(vp, vp.getDefault());
defVal = getDefaultValue(vp);
@@ -244,6 +254,8 @@
// logger.debug(vp.getDisplayName() + ": DEF
Val = " + defVal);
if (defVal.equals(val) == false)
view.setVisualProperty(vp, val);
+
+ logger.debug("!! Applied 2: " +
view.getVisualProperty(vp));
}
}
}
Modified:
core3/vizmap-impl/trunk/impl/src/test/java/org/cytoscape/view/vizmap/VisualStyleTest.java
===================================================================
---
core3/vizmap-impl/trunk/impl/src/test/java/org/cytoscape/view/vizmap/VisualStyleTest.java
2011-05-24 23:52:55 UTC (rev 25519)
+++
core3/vizmap-impl/trunk/impl/src/test/java/org/cytoscape/view/vizmap/VisualStyleTest.java
2011-05-24 23:54:20 UTC (rev 25520)
@@ -3,7 +3,10 @@
import static org.mockito.Mockito.*;
import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import org.cytoscape.view.model.VisualLexicon;
import org.cytoscape.view.model.VisualProperty;
import org.cytoscape.view.presentation.property.MinimalVisualLexicon;
import org.cytoscape.view.presentation.property.NullVisualProperty;
@@ -21,14 +24,19 @@
// Create root node.
final VisualLexiconManager lexManager =
mock(VisualLexiconManager.class);
+
// Create root node.
final NullVisualProperty minimalRoot = new
NullVisualProperty("MINIMAL_ROOT", "Minimal Root Visual Property");
- final MinimalVisualLexicon minimalLex = new
MinimalVisualLexicon(minimalRoot);
+ final MinimalVisualLexicon minimalLex = new
MinimalVisualLexicon(minimalRoot);
+ final Set<VisualLexicon> lexSet = new HashSet<VisualLexicon>();
+ lexSet.add(minimalLex);
final Collection<VisualProperty<?>> nodeVP =
minimalLex.getAllDescendants(MinimalVisualLexicon.NODE);
final Collection<VisualProperty<?>> edgeVP =
minimalLex.getAllDescendants(MinimalVisualLexicon.EDGE);
when(lexManager.getNodeVisualProperties()).thenReturn(nodeVP);
when(lexManager.getEdgeVisualProperties()).thenReturn(edgeVP);
+ when(lexManager.getAllVisualLexicon()).thenReturn(lexSet);
+
final VisualStyleFactoryImpl visualStyleFactory = new
VisualStyleFactoryImpl(lexManager);
originalTitle = "Style 1";
newTitle = "Style 2";
--
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.