Author: abeld
Date: 2009-03-12 02:34:46 -0700 (Thu, 12 Mar 2009)
New Revision: 16216
Modified:
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/ContinuousMapping.java
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/DiscreteMapping.java
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/PassthroughMappingCalculator.java
Log:
refactored-viewmodel: fix default-mappings-columns (column-oriented
implementation of default MappingCalculators) to use column-oriented vizmap api
Modified:
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/ContinuousMapping.java
===================================================================
---
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/ContinuousMapping.java
2009-03-12 08:55:08 UTC (rev 16215)
+++
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/ContinuousMapping.java
2009-03-12 09:34:46 UTC (rev 16216)
@@ -46,6 +46,7 @@
import org.cytoscape.model.GraphObject;
import org.cytoscape.vizmap.MappingCalculator;
import org.cytoscape.view.model.View;
+import org.cytoscape.view.model.ViewColumn;
import org.cytoscape.view.model.VisualProperty;
import org.cytoscape.vizmap.mappings.ContinuousMappingPoint;
import org.cytoscape.vizmap.mappings.interpolators.Interpolator;
@@ -148,21 +149,19 @@
this.attrName = attrName;
}
- public <V extends GraphObject> void apply(View<V> v, Object
defaultValue) {
- CyRow row = v.getSource().attrs();
+ public <T, V extends GraphObject> void apply(ViewColumn<T> column,
List<? extends View<V>> views){
+ if (views.size() < 1)
+ return; // empty list, nothing to do
+ CyRow row = views.get(0).getSource().attrs(); // to check
types, have to peek at first view instance
// check types:
Class<?> attrType =
row.getDataTable().getColumnTypeMap().get(attrName);
Class<?> vpType = vp.getType();
- if (vpType.isAssignableFrom(rangeClass) &&
- Number.class.isAssignableFrom(attrType)){
- // should check here?
- // if (keyClass.isAssignableFrom(attrType))
- doMap(v, row, defaultValue, (Class<Number>)attrType,
vpType);
+ if (vpType.isAssignableFrom(rangeClass) &&
Number.class.isAssignableFrom(attrType)){
+ doMap(views, column, (Class<Number>)attrType); // due
to check in previous line, this is a safe cast
} else {
throw new IllegalArgumentException("Mapping
"+toString()+" can't map from attribute type "+attrType+" to VisualProperty
"+vp+" of type "+vp.getType());
}
}
-
/**
* Read attribute from row, map it and apply it.
*
@@ -170,18 +169,24 @@
*
* Putting this in a separate method makes it possible to make it
type-parametric.
*
- * @param <T> the type-parameter of the VisualProperty vp
+ * @param <T> the type-parameter of the ViewColumn column
* @param <K> the type-parameter of the domain of the mapping (the
object read as an attribute value has to be is-a K)
* @param <V> the type-parameter of the View
*/
- private <T,K extends Number, V extends GraphObject> void doMap(final
View<V> v, CyRow row, Object defaultValue, Class<K> attrType, Class<T>vpType){
- if (row.contains(attrName, attrType) ){
- final K attrValue = (K)
v.getSource().attrs().get(attrName, attrType);
- final T value = (T) getRangeValue(attrValue); // FIXME:
make getRangeValue type-parametric, so this shouldn't be needed
- v.setVisualProperty((VisualProperty<T>)vp, value);
- } else { // apply per-VS or global default where attribute is
not found
- v.setVisualProperty((VisualProperty<T>)vp,
(T)defaultValue);
- }
+ private <T,K extends Number, V extends GraphObject> void doMap(final
List<? extends View<V>> views, ViewColumn<T> column, Class<K> attrType){
+ for (View<V> v: views){
+ CyRow row = v.getSource().attrs();
+ if (row.contains(attrName, attrType) ){
+ // skip Views where source attribute is not
defined;
+ // ViewColumn will automatically substitute the
per-VS or global default, as appropriate
+
+ final K attrValue = (K)
v.getSource().attrs().get(attrName, attrType);
+ final T value = (T) getRangeValue(attrValue);
// FIXME: make getRangeValue type-parametric, so this shouldn't be needed (??)
+ column.setValue(v, value);
+ } else { // remove value so that default value will be
used:
+ column.clearValue(v);
+ }
+ }
}
private Object getRangeValue(Number domainValue) {
ContinuousMappingPoint firstPoint = points.get(0);
Modified:
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/DiscreteMapping.java
===================================================================
---
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/DiscreteMapping.java
2009-03-12 08:55:08 UTC (rev 16215)
+++
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/DiscreteMapping.java
2009-03-12 09:34:46 UTC (rev 16216)
@@ -45,9 +45,11 @@
import org.cytoscape.model.CyRow;
import org.cytoscape.model.GraphObject;
import org.cytoscape.view.model.View;
+import org.cytoscape.view.model.ViewColumn;
import org.cytoscape.view.model.VisualProperty;
import org.cytoscape.vizmap.MappingCalculator;
+import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
@@ -105,20 +107,21 @@
return vp;
}
- public <V extends GraphObject> void apply(View<V> v, Object
defaultValue){
- CyRow row = v.getSource().attrs();
+ public <T, V extends GraphObject> void apply(ViewColumn<T> column,
List<? extends View<V>> views){
+ if (views.size() < 1)
+ return; // empty list, nothing to do
+ CyRow row = views.get(0).getSource().attrs(); // to check
types, have to peek at first view instance
// check types:
Class<?> attrType =
row.getDataTable().getColumnTypeMap().get(attrName);
Class<?> vpType = vp.getType();
if (vpType.isAssignableFrom(rangeClass)){
- // should check here?
+ // FIXME: should check here? or does that not matter?
// if (keyClass.isAssignableFrom(attrType))
- doMap(v, row, defaultValue, attrType, vpType);
+ doMap(views, column, attrType);
} else {
throw new IllegalArgumentException("Mapping
"+toString()+" can't map from attribute type "+attrType+" to VisualProperty
"+vp+" of type "+vp.getType());
}
}
-
/**
* Read attribute from row, map it and apply it.
*
@@ -126,22 +129,28 @@
*
* Putting this in a separate method makes it possible to make it
type-parametric.
*
- * @param <T> the type-parameter of the VisualProperty vp
+ * @param <T> 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 <T,K, V extends GraphObject> void doMap(final View<V> v, CyRow
row, Object defaultValue, Class<K> attrType, Class<T>vpType){
- if (row.contains(attrName, attrType) ){
- final K key = (K) v.getSource().attrs().get(attrName,
attrType);
- if (treeMap.containsKey(key)){
- final T value = (T) treeMap.get(key);
- v.setVisualProperty((VisualProperty<T>)vp,
value);
- } else { // use per-mapping default
- v.setVisualProperty((VisualProperty<T>)vp,
(T)defaultObj);
+ private <T,K, V extends GraphObject> void doMap(final List<? extends
View<V>> views, ViewColumn<T> column, Class<K> attrType){
+ for (View<V> v: views){
+ CyRow row = v.getSource().attrs();
+ if (row.contains(attrName, attrType) ){
+ // skip Views where source attribute is not
defined;
+ // ViewColumn will automatically substitute the
per-VS or global default, as appropriate
+
+ final K key = (K)
v.getSource().attrs().get(attrName, attrType);
+ if (treeMap.containsKey(key)){
+ final T value = (T) treeMap.get(key);
+ column.setValue(v, value);
+ } else { // remove value so that default value
will be used:
+ column.clearValue(v);
+ }
+ } else { // remove value so that default value will be
used:
+ column.clearValue(v);
}
- } else { // apply per-VS or global default where attribute is
not found
- v.setVisualProperty((VisualProperty<T>)vp,
(T)defaultValue);
- }
+ }
}
/**
Modified:
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/PassthroughMappingCalculator.java
===================================================================
---
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/PassthroughMappingCalculator.java
2009-03-12 08:55:08 UTC (rev 16215)
+++
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/default-mappings-columns/src/main/java/org/cytoscape/vizmap/mappings/PassthroughMappingCalculator.java
2009-03-12 09:34:46 UTC (rev 16216)
@@ -42,6 +42,7 @@
import org.cytoscape.vizmap.*;
+import java.util.List;
/**
*/
@@ -54,7 +55,7 @@
* currently we force that to be the same as the VisualProperty;
* FIXME: allow different once? but how to coerce?
*/
- public PassthroughMappingCalculator(final String attributeName, final
VisualProperty<?> vp) {
+ public <T> PassthroughMappingCalculator(final String attributeName,
final VisualProperty<T> vp) {
this.attributeName = attributeName;
this.vp = vp;
}
@@ -100,43 +101,43 @@
*
* @param v DOCUMENT ME!
*/
- public <V extends GraphObject> void apply(final View<V> v, Object
defaultValue) {
- CyRow row = v.getSource().attrs();
+ public <T, V extends GraphObject> void apply(ViewColumn<T> column,
List<? extends View<V>> views){
+ if (views.size() < 1)
+ return; // empty list, nothing to do
+ CyRow row = views.get(0).getSource().attrs();
Class<?> attrType =
row.getDataTable().getColumnTypeMap().get(attributeName);
// since attributes can only store certain types of Objects, it
is enough to test for these:
Class<?> vpType = vp.getType();
+ // FIXME: also check that column's vp is internally-stored vp!
if (vpType.isAssignableFrom(attrType)){
// can simply copy object without any conversion
- doCopy(v, row, defaultValue, attrType, vpType);
+ for (View<V> v: views){
+ row = v.getSource().attrs();
+ if (row.contains(attributeName, attrType) ){
+ // skip Views where source attribute is
not defined; ViewColumn will automatically substitute the per-VS or global
default, as appropriate
+ final T value = (T)
row.get(attributeName, attrType);
+ column.setValue(v, value);
+ } else { // remove value so that default value
will be used:
+ column.clearValue(v);
+ }
+ }
} else if (String.class.isAssignableFrom(vpType)){
// can convert any object to string, so no need to
check attribute type
- // also, since we have to convert the Object here,
can't use doCopy()
- if (row.contains(attributeName, attrType) ){
- final Object value =
v.getSource().attrs().get(attributeName, attrType);
- v.setVisualProperty((VisualProperty<String>)vp,
value.toString());
- } else { // apply per-VS or global default where
attribute is not found:
- v.setVisualProperty((VisualProperty<String>)vp,
defaultValue.toString());
+ // also, since we have to convert the Object here,
can't use checkAndDoCopy()
+ ViewColumn<String> c = (ViewColumn<String>) column; //
have to cast here, even though previous check ensures that T is
java.util.String
+ for (View<V> v: views){
+ row = v.getSource().attrs();
+ if (row.contains(attributeName, attrType) ){
+ // skip Views where source attribute is
not defined; ViewColumn will automatically substitute the per-VS or global
default, as appropriate
+ final Object value = (Object)
row.get(attributeName, attrType);
+ c.setValue(v, value.toString());
+ } else { // remove value so that default value
will be used:
+ c.clearValue(v);
+ }
}
} else {
throw new IllegalArgumentException("Mapping
"+toString()+" can't map from attribute type "+attrType+" to VisualProperty
"+vp+" of type "+vp.getType());
}
// FIXME: handle List & Map
}
- /**
- * Copy, without any conversion apart from possible upcast from
attrType to vpType.
- *
- * vpType is guaranteed to be a superclass (or the same as) attrType
- *
- * Putting this in a separate method makes it possible to make it
parametric.
- *
- * @param <T> the type-parameter of the VisualProperty vp
- */
- private <T, V extends GraphObject> void doCopy(final View<V> v, CyRow
row, Object defaultValue, Class<?> attrType, Class<T>vpType){
- if (row.contains(attributeName, attrType) ){
- final T value = (T)
v.getSource().attrs().get(attributeName, attrType);
- v.setVisualProperty((VisualProperty<T>)vp, value);
- } else { // apply per-VS or global default where attribute is
not found
- v.setVisualProperty((VisualProperty<T>)vp,
(T)defaultValue);
- }
- }
}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---