Author: clopes
Date: 2012-05-25 13:59:46 -0700 (Fri, 25 May 2012)
New Revision: 29363
Modified:
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/AbstractApplyHandler.java
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/ContinuousMappingImpl.java
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/DiscreteMappingImpl.java
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/PassthroughMappingImpl.java
core3/samples/trunk/sample28/
Log:
Fixed a bug that could prevent a mapped visual property value from being
applied when removing a bypass (if the default value of the visual property was
the same as the mapped value, it would be replaced by the style's default
value).
Fixed a couple of ClassCastExceptions that could make the whole VizMapper panel
unstable.
The mapping functions no longer set null visual property values, because that
could set the wrong default value--the visual property's default could replace
the style's default.
Modified:
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/AbstractApplyHandler.java
===================================================================
---
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/AbstractApplyHandler.java
2012-05-25 20:44:25 UTC (rev 29362)
+++
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/AbstractApplyHandler.java
2012-05-25 20:59:46 UTC (rev 29363)
@@ -32,7 +32,7 @@
final VisualMappingFunction<?, ?> mapping =
style.getVisualMappingFunction(vp);
if (mapping != null)
- applyMappedValue(row, view, vp, mapping);
+ mapping.apply(row, view);
else
applyDefaultToView(view, vp);
}
@@ -40,19 +40,6 @@
override(view);
}
- // private void applyDefaultValue(final View<T> view, final
- // VisualProperty<?> vp) {
- // Object defaultValue = style.getDefaultValue(vp);
- //
- // if (defaultValue == null) {
- // ((VisualStyleImpl) style).getStyleDefaults().put(vp,
vp.getDefault());
- // defaultValue = style.getDefaultValue(vp);
- // }
- //
- // if (!vp.shouldIgnoreDefault())
- // view.setVisualProperty(vp, defaultValue);
- // }
-
private void applyDefaultToView(final View<T> view, final
VisualProperty<?> vp) {
final Set<VisualLexicon> lexSet =
lexManager.getAllVisualLexicon();
if(lexSet.size() != 0)
@@ -96,19 +83,4 @@
}
}
}
-
- private void applyMappedValue(final CyRow row, final View<T> view,
final VisualProperty<?> vp,
- final VisualMappingFunction<?, ?> mapping) {
- // Default of this style
- final Object styleDefaultValue = style.getDefaultValue(vp);
- // Default of this Visual Property
- final Object vpDefault = vp.getDefault();
-
- mapping.apply(row, view);
-
- if (view.getVisualProperty(vp) == vpDefault)
- view.setVisualProperty(vp, styleDefaultValue);
-
- }
-
}
Modified:
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/ContinuousMappingImpl.java
===================================================================
---
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/ContinuousMappingImpl.java
2012-05-25 20:44:25 UTC (rev 29362)
+++
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/ContinuousMappingImpl.java
2012-05-25 20:59:46 UTC (rev 29363)
@@ -74,7 +74,7 @@
super(attrName, attrType, table, vp);
// Validate type. K is always a number.
- if(Number.class.isAssignableFrom(attrType) == false)
+ if (Number.class.isAssignableFrom(attrType) == false)
throw new IllegalArgumentException("Attribute type
should be Number.");
this.points = new ArrayList<ContinuousMappingPoint<K, V>>();
@@ -89,70 +89,40 @@
interpolator = (Interpolator<K, V>) new
FlatInterpolator();
}
-
- /* (non-Javadoc)
- * @see org.cytoscape.view.vizmap.mappings.ContinuousMapping#toString()
- */
@Override
public String toString() {
return ContinuousMapping.CONTINUOUS;
}
- /* (non-Javadoc)
- * @see
org.cytoscape.view.vizmap.mappings.ContinuousMapping#getAllPoints()
- */
@Override
public List<ContinuousMappingPoint<K, V>> getAllPoints() {
return points;
}
- /* (non-Javadoc)
- * @see
org.cytoscape.view.vizmap.mappings.ContinuousMapping#addPoint(K,
org.cytoscape.view.vizmap.mappings.BoundaryRangeValues)
- */
@Override
public void addPoint(K value, BoundaryRangeValues<V> brv) {
points.add(new ContinuousMappingPoint<K, V>(value, brv));
}
- /* (non-Javadoc)
- * @see
org.cytoscape.view.vizmap.mappings.ContinuousMapping#removePoint(int)
- */
@Override
public void removePoint(int index) {
points.remove(index);
}
- /* (non-Javadoc)
- * @see
org.cytoscape.view.vizmap.mappings.ContinuousMapping#getPointCount()
- */
@Override
public int getPointCount() {
return points.size();
}
- /* (non-Javadoc)
- * @see
org.cytoscape.view.vizmap.mappings.ContinuousMapping#getPoint(int)
- */
@Override
public ContinuousMappingPoint<K, V> getPoint(int index) {
return points.get(index);
}
- /* (non-Javadoc)
- * @see
org.cytoscape.view.vizmap.mappings.ContinuousMapping#apply(org.cytoscape.view.model.View)
- */
@Override
public void apply(final CyRow row, final View<? extends CyIdentifiable>
view) {
- if (row == null)
- return;
-
- if (view == null)
- return;
-
- if(this.points.size() == 0)
- return;
-
- doMap(row,view);
+ if (row != null && view != null && !this.points.isEmpty())
+ doMap(row,view);
}
/**
@@ -172,7 +142,6 @@
* the type-parameter of the View
*/
private void doMap(final CyRow row, final View<? extends
CyIdentifiable> view) {
-
if (row.isSet(attrName)) {
// skip Views where source attribute is not defined;
// ViewColumn will automatically substitute the per-VS
or global
@@ -183,8 +152,6 @@
final K attrValue = row.get(attrName, attrType);
final V value = getRangeValue(attrValue);
view.setVisualProperty(vp, value);
- } else { // remove value so that default value will be used:
- view.setVisualProperty(vp, null);
}
}
@@ -202,7 +169,6 @@
if (firstCmp < 0)
return bv.lesserValue;
else
-
return bv.equalValue;
}
@@ -275,7 +241,6 @@
* doesn't allow comparing, for example, Integer objects to Double
objects.
*/
private int compareValues(K probe, K target) {
-
final Number n1 = (Number) probe;
final Number n2 = (Number) target;
double d1 = n1.doubleValue();
Modified:
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/DiscreteMappingImpl.java
===================================================================
---
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/DiscreteMappingImpl.java
2012-05-25 20:44:25 UTC (rev 29362)
+++
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/DiscreteMappingImpl.java
2012-05-25 20:59:46 UTC (rev 29363)
@@ -67,111 +67,69 @@
attribute2visualMap = new HashMap<K, V>();
}
- /* (non-Javadoc)
- * @see org.cytoscape.view.vizmap.mappings.DiscreteMapping#toString()
- */
@Override
public String toString() {
return DiscreteMapping.DISCRETE;
}
- /* (non-Javadoc)
- * @see
org.cytoscape.view.vizmap.mappings.DiscreteMapping#apply(org.cytoscape.view.model.View)
- */
@Override
public void apply(CyRow row, View<? extends CyIdentifiable> view) {
- if ( row == null )
- return;
-
- if (view == null)
- return; // empty view, nothing to do
-
- applyDiscreteMapping(row,view);
- }
-
- /**
- * Read attribute from row, map it and apply it.
- *
- * types are guaranteed to be correct (? FIXME: check this)
- *
- * Putting this in a separate method makes it possible to make it
- * type-parametric.
- *
- * @param <V>
- * the type-parameter of the ViewColumn column
- * @param <K>
- * the type-parameter of the key stored in the mapping (the
- * object read as an attribute value has to be is-a K)
- * @param <V>
- * the type-parameter of the View
- */
- private void applyDiscreteMapping(final CyRow row, final View<? extends
CyIdentifiable> view) {
-
- V value = null;
-
- if(attrName.equals(CyIdentifiable.SUID)) {
- // Special case: SUID
- Object key = Long.valueOf(view.getModel().getSUID());
- if (key != null)
- value = attribute2visualMap.get(key);
- } else if (row.isSet(attrName)) {
- // skip Views where source attribute is not defined;
- // ViewColumn will automatically substitute the per-VS
or global
- // default, as appropriate
- final CyColumn column =
row.getTable().getColumn(attrName);
- final Class<?> attrClass = column.getType();
-
- if (attrClass.isAssignableFrom(List.class)) {
- List<?> list = row.getList(attrName,
column.getListElementType());
-
- if (list != null) {
- for (Object item : list) {
- // TODO: should we convert
other types to String?
- String key = item.toString();
- value =
attribute2visualMap.get(key);
- if (value != null)
- break;
- }
- }
- } else {
- Object key = row.get(attrName, attrType);
-
+ if (row != null && view != null) {
+ V value = null;
+
+ if (attrName.equals(CyIdentifiable.SUID)) {
+ // Special case: SUID
+ Object key =
Long.valueOf(view.getModel().getSUID());
+
if (key != null)
value = attribute2visualMap.get(key);
+ } else if (row.isSet(attrName)) {
+ // skip Views where source attribute is not
defined;
+ // ViewColumn will automatically substitute the
per-VS or global default, as appropriate
+ final CyColumn column =
row.getTable().getColumn(attrName);
+ final Class<?> attrClass = column.getType();
+
+ if (attrClass.isAssignableFrom(List.class)) {
+ List<?> list = row.getList(attrName,
column.getListElementType());
+
+ if (list != null) {
+ for (Object item : list) {
+ // TODO: should we
convert other types to String?
+ String key =
item.toString();
+ value =
attribute2visualMap.get(key);
+
+ if (value != null)
+ break;
+ }
+ }
+ } else {
+ Object key = row.get(attrName,
attrType);
+
+ if (key != null)
+ value =
attribute2visualMap.get(key);
+ }
}
+
+ if (value != null)
+ view.setVisualProperty(vp, value);
}
-
- // set a new value or null to use the default one:
- view.setVisualProperty(vp, value);
}
- /* (non-Javadoc)
- * @see
org.cytoscape.view.vizmap.mappings.DiscreteMapping#getMapValue(K)
- */
@Override
public V getMapValue(K key) {
return attribute2visualMap.get(key);
}
- /* (non-Javadoc)
- * @see
org.cytoscape.view.vizmap.mappings.DiscreteMapping#putMapValue(K, T)
- */
@Override
public <T extends V> void putMapValue(final K key, final T value) {
attribute2visualMap.put(key, value);
}
- /* (non-Javadoc)
- * @see
org.cytoscape.view.vizmap.mappings.DiscreteMapping#putAll(java.util.Map)
- */
@Override
public <T extends V> void putAll(Map<K, T> map) {
attribute2visualMap.putAll(map);
}
- /* (non-Javadoc)
- * @see org.cytoscape.view.vizmap.mappings.DiscreteMapping#getAll()
- */
@Override
public Map<K, V> getAll() {
return attribute2visualMap;
Modified:
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/PassthroughMappingImpl.java
===================================================================
---
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/PassthroughMappingImpl.java
2012-05-25 20:44:25 UTC (rev 29362)
+++
core3/impl/trunk/vizmap-impl/impl/src/main/java/org/cytoscape/view/vizmap/internal/mappings/PassthroughMappingImpl.java
2012-05-25 20:59:46 UTC (rev 29363)
@@ -41,48 +41,40 @@
/**
*/
-public class PassthroughMappingImpl<K, V> extends
- AbstractVisualMappingFunction<K, V> implements
PassthroughMapping<K, V> {
+public class PassthroughMappingImpl<K, V> extends
AbstractVisualMappingFunction<K, V> implements
+ PassthroughMapping<K, V> {
/**
* dataType is the type of the _attribute_ !! currently we force that
to be
- * the same as the VisualProperty; FIXME: allow different once? but how
to
- * coerce?
+ * the same as the VisualProperty; FIXME: allow different once? but how
to coerce?
*/
public PassthroughMappingImpl(final String attrName, final Class<K>
attrType, final CyTable table,
final VisualProperty<V> vp) {
super(attrName, attrType, table, vp);
}
- /* (non-Javadoc)
- * @see org.cytoscape.view.vizmap.mappings.PassthroughMapping#toString()
- */
@Override
public String toString() {
return PassthroughMapping.PASSTHROUGH;
}
- /* (non-Javadoc)
- * @see
org.cytoscape.view.vizmap.mappings.PassthroughMapping#apply(org.cytoscape.view.model.View)
- */
@Override
public void apply(final CyRow row, final View<? extends CyIdentifiable>
view) {
- if ( row == null )
+ if (row == null || view == null)
return;
- if (view == null)
- return; // empty list, nothing to do
-
- if(attrName.equals(CyIdentifiable.SUID)) {
+ V value = null;
+
+ if (attrName.equals(CyIdentifiable.SUID)) {
// Special case: SUID
- view.setVisualProperty(vp,
(V)Long.valueOf(view.getModel().getSUID()));
+ value = (V) view.getModel().getSUID();
} else if (row.isSet(attrName)) {
// skip Views where source attribute is not defined;
// ViewColumn will automatically substitute the per-VS
or
// global default, as appropriate
final CyColumn column =
row.getTable().getColumn(attrName);
final Class<?> attrClass = column.getType();
- K value = null;
+ K tempValue = null;
if (attrClass.isAssignableFrom(List.class)) {
List<?> list = row.getList(attrName,
column.getListElementType());
@@ -95,18 +87,16 @@
sb.deleteCharAt(sb.length() - 1);
}
- value = (K) sb.toString();
+ tempValue = (K) sb.toString();
} else {
- value = row.get(attrName, (Class<? extends K>)
attrClass);
+ tempValue = row.get(attrName, (Class<? extends
K>) attrClass);
}
- final V converted = convertToValue(value);
-
- view.setVisualProperty(vp, converted);
- } else {
- // remove value, so that default value will be used:
- view.setVisualProperty(vp, null);
+ value = convertToValue(tempValue);
}
+
+ if (value != null)
+ view.setVisualProperty(vp, value);
}
// TODO: make this converter pluggable
@@ -116,6 +106,5 @@
} catch (Exception e) {
return null;
}
-
}
}
Property changes on: core3/samples/trunk/sample28
___________________________________________________________________
Added: svn:ignore
+ .settings
.project
--
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.