Author: mes
Date: 2011-07-05 17:47:54 -0700 (Tue, 05 Jul 2011)
New Revision: 26053
Added:
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/internal/
Removed:
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMappingFactory.java
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMappingImpl.java
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingFactory.java
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingImpl.java
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/PassthroughMappingFactory.java
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/PassthroughMappingImpl.java
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/interpolators/
core3/vizmap-api/trunk/src/test/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingTest.java
Log:
moved impl code into impl
Deleted:
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMappingFactory.java
===================================================================
---
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMappingFactory.java
2011-07-06 00:32:08 UTC (rev 26052)
+++
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMappingFactory.java
2011-07-06 00:47:54 UTC (rev 26053)
@@ -1,35 +0,0 @@
-package org.cytoscape.view.vizmap.mappings;
-
-import org.cytoscape.view.model.VisualProperty;
-import org.cytoscape.view.vizmap.VisualMappingFunction;
-import org.cytoscape.view.vizmap.VisualMappingFunctionFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class ContinuousMappingFactory implements VisualMappingFunctionFactory {
-
- private static final Logger logger =
LoggerFactory.getLogger(ContinuousMappingFactory.class);
-
- @Override
- public <K, V> VisualMappingFunction<K, V>
createVisualMappingFunction(final String attributeName,
- Class<K> attrValueType, VisualProperty<V> vp) {
-
- logger.debug("Trying to create Continuous mapping. Data Type
is " + attrValueType);
-
- // Validate attribute type: Continuous Mapping is compatible
with Numbers only.
- if(Number.class.isAssignableFrom(attrValueType) == false)
- throw new IllegalArgumentException("ContinuousMapping
can be used for numerical attributes only.");
-
- return new ContinuousMappingImpl<K, V>(attributeName,
attrValueType, vp);
- }
-
- @Override public String toString() {
- return ContinuousMapping.CONTINUOUS;
- }
-
- @Override
- public Class<?> getMappingFunctionType() {
- return ContinuousMapping.class;
- }
-
-}
Deleted:
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMappingImpl.java
===================================================================
---
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMappingImpl.java
2011-07-06 00:32:08 UTC (rev 26052)
+++
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/ContinuousMappingImpl.java
2011-07-06 00:47:54 UTC (rev 26053)
@@ -1,287 +0,0 @@
-/*
- File: ContinuousMappingImpl.java
-
- Copyright (c) 2006, 2010, The Cytoscape Consortium (www.cytoscape.org)
-
- 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
- any later version.
-
- This library is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
- MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
- documentation provided hereunder is on an "as is" basis, and the
- Institute for Systems Biology and the Whitehead Institute
- have no obligations to provide maintenance, support,
- updates, enhancements or modifications. In no event shall the
- Institute for Systems Biology and the Whitehead Institute
- be liable to any party for direct, indirect, special,
- incidental or consequential damages, including lost profits, arising
- out of the use of this software and its documentation, even if the
- Institute for Systems Biology and the Whitehead Institute
- have been advised of the possibility of such damage. See
- the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with this library; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
-*/
-package org.cytoscape.view.vizmap.mappings;
-
-
-import java.awt.Color;
-import java.awt.Paint;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.cytoscape.model.CyRow;
-import org.cytoscape.model.CyTableEntry;
-import org.cytoscape.view.model.View;
-import org.cytoscape.view.model.VisualProperty;
-import org.cytoscape.view.vizmap.mappings.interpolators.FlatInterpolator;
-import org.cytoscape.view.vizmap.mappings.interpolators.Interpolator;
-import
org.cytoscape.view.vizmap.mappings.interpolators.LinearNumberToColorInterpolator;
-import
org.cytoscape.view.vizmap.mappings.interpolators.LinearNumberToNumberInterpolator;
-
-
-/**
- * Implements an interpolation table mapping data to values of a particular
- * class. The data value is extracted from a bundle of attributes by using a
- * specified data attribute name.
- *
- * @param <V>
- * Type of object Visual Property holds
- *
- * For refactoring changes in this class, please refer to:
- * cytoscape.visual.mappings.continuous.README.txt.
- *
- */
-public class ContinuousMappingImpl<K, V> extends
AbstractVisualMappingFunction<K, V> implements ContinuousMapping<K, V> {
-
- // used to interpolate between boundaries
- private Interpolator<K, V> interpolator;
-
- // Contains List of Data Points
- private List<ContinuousMappingPoint<K, V>> points;
-
- ContinuousMappingImpl(final String attrName, final Class<K> attrType,
final VisualProperty<V> vp) {
- super(attrName, attrType, vp);
-
- // Validate type. K is always a number.
- if(Number.class.isAssignableFrom(attrType) == false)
- throw new IllegalArgumentException("Attribute type
should be Number.");
-
- this.points = new ArrayList<ContinuousMappingPoint<K, V>>();
-
- // TODO FIXME use factory here.
- // Create Interpolator
- if (vp.getRange().getType() == Color.class ||
vp.getRange().getType() == Paint.class)
- interpolator = (Interpolator<K, V>) new
LinearNumberToColorInterpolator();
- else if (Number.class.isAssignableFrom(vp.getRange().getType()))
- interpolator = (Interpolator<K, V>) new
LinearNumberToNumberInterpolator();
- else
- interpolator = (Interpolator<K, V>) new
FlatInterpolator();
- }
-
-
- /* (non-Javadoc)
- * @see org.cytoscape.view.vizmap.mappings.ContinuousMapping#toString()
- */
- @Override
- public String toString() {
- return 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 View<? extends CyTableEntry> view) {
- if (view == null)
- return;
-
- if(this.points.size() == 0)
- return;
-
- doMap(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 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 void doMap(final View<? extends CyTableEntry> view) {
-
- final CyRow row = view.getModel().getCyRow();
-
- if (row.isSet(attrName)) {
- // skip Views where source attribute is not defined;
- // ViewColumn will automatically substitute the per-VS
or global
- // default, as appropriate
-
- // In all cases, attribute value should be a number for
continuous
- // mapping.
- final K attrValue = view.getModel().getCyRow()
- .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);
- }
-
- }
-
- private V getRangeValue(K domainValue) {
- ContinuousMappingPoint<K, V> firstPoint = points.get(0);
- K minDomain = firstPoint.getValue();
-
- // if given domain value is smaller than any in our list,
- // return the range value for the smallest domain value we have.
- int firstCmp = compareValues(domainValue, minDomain);
-
- if (firstCmp <= 0) {
- BoundaryRangeValues<V> bv = firstPoint.getRange();
-
- if (firstCmp < 0)
- return bv.lesserValue;
- else
-
- return bv.equalValue;
- }
-
- // if given domain value is larger than any in our Vector,
- // return the range value for the largest domain value we have.
- ContinuousMappingPoint<K, V> lastPoint =
points.get(points.size() - 1);
- K maxDomain = lastPoint.getValue();
-
- if (compareValues(domainValue, maxDomain) > 0) {
- BoundaryRangeValues<V> bv = lastPoint.getRange();
-
- return bv.greaterValue;
- }
-
- // OK, it's somewhere in the middle, so find the boundaries and
- // pass to our interpolator function. First check for a null
- // interpolator function
- if (this.interpolator == null)
- return null;
-
- // Note that the list of Points is sorted.
- // Also, the case of the inValue equalling the smallest key was
- // checked above.
- ContinuousMappingPoint<K, V> currentPoint;
- int index = 0;
-
- for (index = 0; index < points.size(); index++) {
- currentPoint = points.get(index);
-
- K currentValue = currentPoint.getValue();
- int cmpValue = compareValues(domainValue, currentValue);
-
- if (cmpValue == 0) {
- BoundaryRangeValues<V> bv =
currentPoint.getRange();
-
- return bv.equalValue;
- } else if (cmpValue < 0)
- break;
- }
-
- return getRangeValue(index, domainValue);
- }
-
- /**
- * This is tricky. The desired domain value is greater than lowerDomain
and
- * less than upperDomain. Therefore, we want the "greater" field of the
- * lower boundary value (because the desired domain value is greater)
and
- * the "lesser" field of the upper boundary value (semantic
difficulties).
- */
- private V getRangeValue(int index, K domainValue) {
- // Get Lower Domain and Range
- ContinuousMappingPoint<K, V> lowerBound = points.get(index - 1);
- K lowerDomain = lowerBound.getValue();
- BoundaryRangeValues<V> lv = lowerBound.getRange();
- V lowerRange = lv.greaterValue;
-
- // Get Upper Domain and Range
- ContinuousMappingPoint<K, V> upperBound = points.get(index);
- K upperDomain = upperBound.getValue();
- BoundaryRangeValues<V> gv = upperBound.getRange();
- V upperRange = gv.lesserValue;
-
- V value = interpolator.getRangeValue(lowerDomain, lowerRange,
upperDomain, upperRange, domainValue);
-
- return value;
- }
-
- /**
- * Helper function to compare Number objects. This is needed because
Java
- * 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();
- double d2 = n2.doubleValue();
-
- if (d1 < d2)
- return -1;
- else if (d1 > d2)
- return 1;
- else
- return 0;
- }
-}
Deleted:
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingFactory.java
===================================================================
---
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingFactory.java
2011-07-06 00:32:08 UTC (rev 26052)
+++
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingFactory.java
2011-07-06 00:47:54 UTC (rev 26053)
@@ -1,26 +0,0 @@
-package org.cytoscape.view.vizmap.mappings;
-
-import org.cytoscape.view.model.VisualProperty;
-import org.cytoscape.view.vizmap.VisualMappingFunction;
-import org.cytoscape.view.vizmap.VisualMappingFunctionFactory;
-
-public class DiscreteMappingFactory implements
- VisualMappingFunctionFactory {
-
- @Override
- public <K, V> VisualMappingFunction<K, V>
createVisualMappingFunction(final String attributeName,
- Class<K> attrValueType, final VisualProperty<V> vp) {
-
- return new DiscreteMappingImpl<K, V>(attributeName,
attrValueType, vp);
- }
-
- @Override public String toString() {
- return DiscreteMapping.DISCRETE;
- }
-
- @Override
- public Class<?> getMappingFunctionType() {
- return DiscreteMapping.class;
- }
-
-}
Deleted:
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingImpl.java
===================================================================
---
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingImpl.java
2011-07-06 00:32:08 UTC (rev 26052)
+++
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingImpl.java
2011-07-06 00:47:54 UTC (rev 26053)
@@ -1,168 +0,0 @@
-/*
- File: DiscreteMappingImpl.java
-
- Copyright (c) 2006, 2010, The Cytoscape Consortium (www.cytoscape.org)
-
- 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
- any later version.
-
- This library is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
- MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
- documentation provided hereunder is on an "as is" basis, and the
- Institute for Systems Biology and the Whitehead Institute
- have no obligations to provide maintenance, support,
- updates, enhancements or modifications. In no event shall the
- Institute for Systems Biology and the Whitehead Institute
- be liable to any party for direct, indirect, special,
- incidental or consequential damages, including lost profits, arising
- out of the use of this software and its documentation, even if the
- Institute for Systems Biology and the Whitehead Institute
- have been advised of the possibility of such damage. See
- the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with this library; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-package org.cytoscape.view.vizmap.mappings;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.cytoscape.model.CyColumn;
-import org.cytoscape.model.CyRow;
-import org.cytoscape.model.CyTableEntry;
-import org.cytoscape.view.model.View;
-import org.cytoscape.view.model.VisualProperty;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Implements a lookup table mapping data to values of a particular class. The
- * data value is extracted from a bundle of attributes by using a specified
data
- * attribute name.
- */
-public class DiscreteMappingImpl<K, V> extends
AbstractVisualMappingFunction<K, V> implements DiscreteMapping<K, V> {
-
- private static final Logger logger =
LoggerFactory.getLogger(DiscreteMapping.class);
-
- // contains the actual map elements (sorted)
- private final Map<K, V> attribute2visualMap;
-
- /**
- * Constructor.
- *
- * @param defObj
- * Default Object.
- */
- public DiscreteMappingImpl(final String attrName, final Class<K>
attrType, final VisualProperty<V> vp) {
- super(attrName, attrType, vp);
- attribute2visualMap = new HashMap<K, V>();
- }
-
- /* (non-Javadoc)
- * @see org.cytoscape.view.vizmap.mappings.DiscreteMapping#toString()
- */
- @Override
- public String toString() {
- return DISCRETE;
- }
-
- /* (non-Javadoc)
- * @see
org.cytoscape.view.vizmap.mappings.DiscreteMapping#apply(org.cytoscape.view.model.View)
- */
- @Override
- public void apply(View<? extends CyTableEntry> view) {
- if (view == null)
- return; // empty view, nothing to do
-
- applyDiscreteMapping(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 View<? extends CyTableEntry>
view) {
- final CyRow row = view.getModel().getCyRow();
- V value = null;
-
- 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);
- }
- }
-
- // 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;
- }
-}
Deleted:
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/PassthroughMappingFactory.java
===================================================================
---
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/PassthroughMappingFactory.java
2011-07-06 00:32:08 UTC (rev 26052)
+++
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/PassthroughMappingFactory.java
2011-07-06 00:47:54 UTC (rev 26053)
@@ -1,24 +0,0 @@
-package org.cytoscape.view.vizmap.mappings;
-
-import org.cytoscape.view.model.VisualProperty;
-import org.cytoscape.view.vizmap.VisualMappingFunction;
-import org.cytoscape.view.vizmap.VisualMappingFunctionFactory;
-
-public class PassthroughMappingFactory implements VisualMappingFunctionFactory{
-
- @Override
- public <K, V> VisualMappingFunction<K, V>
createVisualMappingFunction(final String attributeName,
- Class<K> attrValueType, VisualProperty<V> vp) {
- return new PassthroughMappingImpl<K, V>(attributeName,
attrValueType, vp);
- }
-
- @Override public String toString() {
- return PassthroughMapping.PASSTHROUGH;
- }
-
- @Override
- public Class<?> getMappingFunctionType() {
- return PassthroughMapping.class;
- }
-
-}
Deleted:
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/PassthroughMappingImpl.java
===================================================================
---
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/PassthroughMappingImpl.java
2011-07-06 00:32:08 UTC (rev 26052)
+++
core3/vizmap-api/trunk/src/main/java/org/cytoscape/view/vizmap/mappings/PassthroughMappingImpl.java
2011-07-06 00:47:54 UTC (rev 26053)
@@ -1,116 +0,0 @@
-/*
- Copyright (c) 2006, 2007, 2010, The Cytoscape Consortium (www.cytoscape.org)
-
- 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
- any later version.
-
- This library is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
- MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
- documentation provided hereunder is on an "as is" basis, and the
- Institute for Systems Biology and the Whitehead Institute
- have no obligations to provide maintenance, support,
- updates, enhancements or modifications. In no event shall the
- Institute for Systems Biology and the Whitehead Institute
- be liable to any party for direct, indirect, special,
- incidental or consequential damages, including lost profits, arising
- out of the use of this software and its documentation, even if the
- Institute for Systems Biology and the Whitehead Institute
- have been advised of the possibility of such damage. See
- the GNU Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with this library; if not, write to the Free Software Foundation,
- Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
- */
-
-package org.cytoscape.view.vizmap.mappings;
-
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import org.cytoscape.model.CyColumn;
-import org.cytoscape.model.CyRow;
-import org.cytoscape.model.CyTableEntry;
-import org.cytoscape.view.model.View;
-import org.cytoscape.view.model.VisualProperty;
-
-/**
- */
-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?
- */
- public PassthroughMappingImpl(final String attrName, final Class<K>
attrType,
- final VisualProperty<V> vp) {
- super(attrName, attrType, vp);
- }
-
- /* (non-Javadoc)
- * @see org.cytoscape.view.vizmap.mappings.PassthroughMapping#toString()
- */
- @Override
- public String toString() {
- return PASSTHROUGH;
- }
-
- /* (non-Javadoc)
- * @see
org.cytoscape.view.vizmap.mappings.PassthroughMapping#apply(org.cytoscape.view.model.View)
- */
- @Override
- public void apply(final View<? extends CyTableEntry> view) {
- if (view == null)
- return; // empty list, nothing to do
-
- final CyRow row = view.getModel().getCyRow();
-
- 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;
-
- if (attrClass.isAssignableFrom(List.class)) {
- List<?> list = row.getList(attrName,
column.getListElementType());
- StringBuffer sb = new StringBuffer();
-
- if (list != null && !list.isEmpty()) {
- for (Object item : list)
- sb.append(item.toString() +
"\n");
-
- sb.deleteCharAt(sb.length() - 1);
- }
-
- value = (K) sb.toString();
- } else {
- value = row.get(attrName, attrType);
- }
-
- final V converted = convertToValue(value);
-
- view.setVisualProperty(vp, converted);
- } else {
- // remove value, so that default value will be used:
- view.setVisualProperty(vp, null);
- }
- }
-
- // TODO: make this converter pluggable
- private V convertToValue(final K key) {
- try {
- return (V) key;
- } catch (Exception e) {
- return null;
- }
-
- }
-}
Deleted:
core3/vizmap-api/trunk/src/test/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingTest.java
===================================================================
---
core3/vizmap-api/trunk/src/test/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingTest.java
2011-07-06 00:32:08 UTC (rev 26052)
+++
core3/vizmap-api/trunk/src/test/java/org/cytoscape/view/vizmap/mappings/DiscreteMappingTest.java
2011-07-06 00:47:54 UTC (rev 26053)
@@ -1,60 +0,0 @@
-package org.cytoscape.view.vizmap.mappings;
-
-import static org.junit.Assert.*;
-import static org.junit.Assert.assertEquals;
-
-import java.awt.Color;
-import java.awt.Paint;
-
-import org.cytoscape.view.presentation.property.MinimalVisualLexicon;
-import org.cytoscape.view.vizmap.mappings.DiscreteMapping;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-public class DiscreteMappingTest {
-
- @Before
- public void setUp() throws Exception {
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
- @Test
- public void testDiscreteMapping() {
- final String attrName = "sample attr 1";
- final DiscreteMapping<String, Paint> mapping =
createDiscreteMapping(attrName);
-
- assertEquals(attrName, mapping.getMappingAttributeName());
- assertEquals(String.class, mapping.getMappingAttributeType());
- assertEquals(MinimalVisualLexicon.NODE_FILL_COLOR,
mapping.getVisualProperty());
-
- mapping.putMapValue("r", Color.RED);
- mapping.putMapValue("g", Color.GREEN);
- mapping.putMapValue("b", Color.BLUE);
-
- assertEquals(Color.RED, mapping.getMapValue("r"));
- assertEquals(Color.GREEN, mapping.getMapValue("g"));
- assertEquals(Color.BLUE, mapping.getMapValue("b"));
- assertEquals(null, mapping.getMapValue("p"));
-
- mapping.putMapValue("g", Color.GRAY);
- assertEquals(Color.GRAY, mapping.getMapValue("g"));
- mapping.putMapValue("g", null);
- assertNull(mapping.getMapValue("g"));
- }
-
-
- private DiscreteMapping<String, Paint> createDiscreteMapping(final
String attrName) {
-
- final Class<String> type = String.class;
-
- final DiscreteMapping<String, Paint> mapping = new
DiscreteMappingImpl<String, Paint>(attrName, type,
- MinimalVisualLexicon.NODE_FILL_COLOR);
-
- return mapping;
- }
-
-}
--
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.