Author: abeld
Date: 2009-04-15 13:00:38 -0700 (Wed, 15 Apr 2009)
New Revision: 16586
Removed:
core3/viewmodel-impl/branches/edit-views/src/main/java/org/cytoscape/view/model/internal/ColumnOrientedViewColumn.java
Modified:
core3/viewmodel-impl/branches/edit-views/src/main/java/org/cytoscape/view/model/internal/ColumnOrientedNetworkViewImpl.java
core3/viewmodel-impl/branches/edit-views/src/main/java/org/cytoscape/view/model/internal/ColumnOrientedViewImpl.java
Log:
edit-views branch of viewmodel-impl: update implementation to compile
with edit-views branch of viewmodel-api. This means going back to a
row-oriented implementation. (Basically merging from row-oriented
version of viewmodel-impl.) File names are thus misleading, but I
won't change them so that diffs remain usable.
Modified:
core3/viewmodel-impl/branches/edit-views/src/main/java/org/cytoscape/view/model/internal/ColumnOrientedNetworkViewImpl.java
===================================================================
---
core3/viewmodel-impl/branches/edit-views/src/main/java/org/cytoscape/view/model/internal/ColumnOrientedNetworkViewImpl.java
2009-04-15 19:12:58 UTC (rev 16585)
+++
core3/viewmodel-impl/branches/edit-views/src/main/java/org/cytoscape/view/model/internal/ColumnOrientedNetworkViewImpl.java
2009-04-15 20:00:38 UTC (rev 16586)
@@ -78,7 +78,6 @@
private HashMap<CyEdge, ColumnOrientedViewImpl<CyEdge>> edgeViews;
private HashMap<String, Set<View<? extends GraphObject>>> subsets;
private ColumnOrientedViewImpl<CyNetwork> viewCyNetwork;
- private HashMap<VisualProperty<?>, ColumnOrientedViewColumn<?>> columns;
/**
* Creates a new ColumnOrientedNetworkViewImpl object.
@@ -98,17 +97,16 @@
nodeViews = new HashMap<CyNode,
ColumnOrientedViewImpl<CyNode>>();
edgeViews = new HashMap<CyEdge,
ColumnOrientedViewImpl<CyEdge>>();
subsets = new HashMap<String, Set<View<? extends
GraphObject>>>();
- columns = new HashMap<VisualProperty<?>,
ColumnOrientedViewColumn<?>>();
for (CyNode node : network.getNodeList()) {
- nodeViews.put(node, new
ColumnOrientedViewImpl<CyNode>(node, this));
+ nodeViews.put(node, new
ColumnOrientedViewImpl<CyNode>(node));
}
for (CyEdge edge : network.getEdgeList()) {
- edgeViews.put(edge, new
ColumnOrientedViewImpl<CyEdge>(edge, this));
+ edgeViews.put(edge, new
ColumnOrientedViewImpl<CyEdge>(edge));
}
- viewCyNetwork = new ColumnOrientedViewImpl<CyNetwork>(network,
this);
+ viewCyNetwork = new ColumnOrientedViewImpl<CyNetwork>(network);
}
/**
@@ -179,7 +177,7 @@
return;
final CyEdge edge = e.getEdge();
- edgeViews.put(edge, new ColumnOrientedViewImpl<CyEdge>(edge,
this)); // FIXME:
+ edgeViews.put(edge, new ColumnOrientedViewImpl<CyEdge>(edge));
// FIXME:
// View
// creation
// here
@@ -206,7 +204,7 @@
return;
final CyNode node = e.getNode();
- nodeViews.put(node, new ColumnOrientedViewImpl<CyNode>(node,
this));
+ nodeViews.put(node, new ColumnOrientedViewImpl<CyNode>(node));
}
/**
@@ -237,18 +235,6 @@
edgeViews.remove(e.getNode());
}
- public <T> ColumnOrientedViewColumn<T> getColumn(final VisualProperty<?
extends T> vp) {
- if (vp == null)
- throw new NullPointerException("VisualProperty must not
be null");
- if (columns.containsKey(vp)) {
- return (ColumnOrientedViewColumn<T>) columns.get(vp);
- } else { // create column
- ColumnOrientedViewColumn<T> column = new
ColumnOrientedViewColumn<T>((VisualProperty<T>) vp);
- columns.put(vp, column);
- return column;
- }
- }
-
/**
* DOCUMENT ME!
*
Deleted:
core3/viewmodel-impl/branches/edit-views/src/main/java/org/cytoscape/view/model/internal/ColumnOrientedViewColumn.java
===================================================================
---
core3/viewmodel-impl/branches/edit-views/src/main/java/org/cytoscape/view/model/internal/ColumnOrientedViewColumn.java
2009-04-15 19:12:58 UTC (rev 16585)
+++
core3/viewmodel-impl/branches/edit-views/src/main/java/org/cytoscape/view/model/internal/ColumnOrientedViewColumn.java
2009-04-15 20:00:38 UTC (rev 16586)
@@ -1,163 +0,0 @@
-package org.cytoscape.view.model.internal;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.cytoscape.view.model.View;
-import org.cytoscape.view.model.ViewColumn;
-import org.cytoscape.view.model.VisualProperty;
-
-/**
- * A column in the viewmodel table
- *
- * TODO: current check lock value every time value is accessed. Might be more
- * efficient to optimize for access speed by swapping locked value and computed
- * value whenever lock is set or cleared.
- *
- * @param <T>
- * the data type of the VisualProperty this belongs to
- */
-public class ColumnOrientedViewColumn<T> implements ViewColumn<T> {
- private static final String VIEW_IS_NULL = "View is null";
-
- private final HashMap<View<?>, T> values;
- private final HashMap<View<?>, T> lockedValues;
- // note: this surely could be done more efficiently...:
- private final HashMap<View<?>, Boolean> bypassLocks;
- private final VisualProperty<T> vp;
- /**
- * The per-VisualStyle default value for the VisualProperty that this
Column
- * represents
- */
- private T defaultValue;
-
- /**
- * Create for given VP
- *
- * @param vp
- * the VisualProperty
- */
- public ColumnOrientedViewColumn(final VisualProperty<T> vp) {
- this.vp = vp;
- this.values = new HashMap<View<?>, T>();
- this.lockedValues = new HashMap<View<?>, T>();
- this.bypassLocks = new HashMap<View<?>, Boolean>();
- this.defaultValue = vp.getDefault();
- }
-
- public Class<T> getDataType() {
- return vp.getType();
- }
-
- public T getValue(View<?> view) {
- if (view == null)
- throw new NullPointerException(VIEW_IS_NULL);
-
- final Boolean b = bypassLocks.get(view);
- if ((b != null) && b.booleanValue()) {
- return lockedValues.get(view);
- } else if (values.containsKey(view)) {
- return values.get(view);
- } else {
- return defaultValue;
- }
- }
-
- /**
- *
- * Sets the computed value for the given view. Note that using this
method
- * for setting many values will be horribly inefficient. Use setValues()
- * instead.
- */
- public <V extends T> void setValue(View<?> view, V value) {
- internal_setValue(view, value);
- // FIXME: fire event!
- }
-
- /**
- * Bulk method for setting many values at once. This fires only a
single event and is thus much more efficient.
- */
- public void setValues(Map<? extends View<?>, T> values, List<? extends
View<?>> toClear) {
- for (Map.Entry<? extends View<?>, T> entry : values.entrySet()){
- internal_setValue(entry.getKey(), entry.getValue());
- }
- if ( toClear != null ) {
- for (View<?>v: toClear){
- internal_clearValue(v);
- }
- }
- // FIXME: fire event!
- }
-
- /** An internal method, to avoid duplicating this code in setValue()
and setValues(). This method does not fire events!
- * (I hope the compiler optimizes this away...)
- */
- private void internal_setValue(View<?> view, T value){
- if (view == null)
- throw new NullPointerException(VIEW_IS_NULL);
-
- values.put(view, value);
- }
-
- public void clearValue(View<?> view) {
- internal_clearValue(view);
- // FIXME: fire event!
- }
-
- private void internal_clearValue(View<?> view) {
- if (view == null)
- throw new NullPointerException(VIEW_IS_NULL);
-
- values.remove(view);
- }
-
- /**
- * Used by VisualStyle.apply to set the per-VisualStyle default value
- *
- * @param value
- * the per-VisualStyle default value
- */
- public void setDefaultValue(T value) {
- defaultValue = value;
- }
-
- public void setLockedValue(final View<?> view, final T value) {
- if (view == null)
- throw new NullPointerException(VIEW_IS_NULL);
- lockedValues.put(view, value);
- bypassLocks.put(view, Boolean.TRUE);
- }
-
- /**
- * @param vp
- * the VisualProperty
- * @return true if current VisualProperty value is locked
- */
- public boolean isValueLocked(final View<?> view) {
- if (view == null)
- throw new NullPointerException(VIEW_IS_NULL);
-
- final Boolean value = bypassLocks.get(view);
-
- if (value == null) {
- return false;
- } else {
- return value.booleanValue();
- }
- }
-
- /**
- * Clear value lock for given VisualProperty.
- *
- * @param vp
- * the VisualProperty
- */
- public void clearValueLock(final View<?> view) {
- if (view == null)
- throw new NullPointerException(VIEW_IS_NULL);
- lockedValues.remove(view);
- bypassLocks.put(view, Boolean.FALSE);
- }
-
-}
Modified:
core3/viewmodel-impl/branches/edit-views/src/main/java/org/cytoscape/view/model/internal/ColumnOrientedViewImpl.java
===================================================================
---
core3/viewmodel-impl/branches/edit-views/src/main/java/org/cytoscape/view/model/internal/ColumnOrientedViewImpl.java
2009-04-15 19:12:58 UTC (rev 16585)
+++
core3/viewmodel-impl/branches/edit-views/src/main/java/org/cytoscape/view/model/internal/ColumnOrientedViewImpl.java
2009-04-15 20:00:38 UTC (rev 16586)
@@ -41,6 +41,7 @@
import java.util.List;
import java.util.ArrayList;
+import java.util.HashMap;
/**
@@ -52,9 +53,14 @@
* @param <S> the base (model-level) object for which this is a View. For
example, CyNode or CyEdge
*/
public class ColumnOrientedViewImpl<S> implements View<S> {
+ private static final String VP_IS_NULL = "VisualProperty is null";
+
private final S source;
+ private final HashMap<VisualProperty<?>, Object> vpValues;
+
+ // note: this surely could be done more efficiently...:
+ private final HashMap<VisualProperty<?>, Boolean> bypassLocks;
private final long suid;
- private final ColumnOrientedNetworkViewImpl networkView;
private final List<ViewChangeListener> listeners;
/**
@@ -62,11 +68,12 @@
*
* @param source DOCUMENT ME!
*/
- public ColumnOrientedViewImpl(final S source, final
ColumnOrientedNetworkViewImpl networkView) {
+ public ColumnOrientedViewImpl(final S source) {
suid = SUIDFactory.getNextSUID();
this.source = source;
- this.networkView = networkView;
listeners = new ArrayList<ViewChangeListener>();
+ vpValues = new HashMap<VisualProperty<?>, Object>();
+ bypassLocks = new HashMap<VisualProperty<?>, Boolean>();
}
/**
@@ -79,7 +86,13 @@
* @param o DOCUMENT ME!
*/
public <P, V extends P> void setVisualProperty(final VisualProperty<?
extends P> vp, final V value) {
- networkView.getColumn(vp).setValue(this, value);
+ if (vp == null)
+ throw new NullPointerException(VP_IS_NULL);
+
+ final Boolean b = bypassLocks.get(vp);
+
+ if ((b == null) || !b.booleanValue())
+ vpValues.put(vp, value);
for ( ViewChangeListener vcl : listeners )
vcl.visualPropertySet(vp,value);
}
@@ -94,7 +107,14 @@
* @return DOCUMENT ME!
*/
public <T> T getVisualProperty(final VisualProperty<T> vp) {
- return networkView.getColumn(vp).getValue(this);
+ if (vp == null)
+ throw new NullPointerException(VP_IS_NULL);
+
+ if (vpValues.containsKey(vp))
+ return (T) vpValues.get(vp);
+ else
+
+ return vp.getDefault();
}
/**
@@ -129,7 +149,11 @@
* @param value the value to set
*/
public <P, V extends P> void setLockedValue(final VisualProperty<?
extends P> vp, final V value){
- networkView.getColumn(vp).setLockedValue(this, value);
+ if (vp == null)
+ throw new NullPointerException(VP_IS_NULL);
+
+ setVisualProperty(vp, value);
+ bypassLocks.put(vp, Boolean.TRUE);
}
/**
@@ -137,7 +161,16 @@
* @return true if current VisualProperty value is locked
*/
public boolean isValueLocked(final VisualProperty<?> vp){
- return networkView.getColumn(vp).isValueLocked(this);
+ if (vp == null)
+ throw new NullPointerException(VP_IS_NULL);
+
+ final Boolean value = bypassLocks.get(vp);
+
+ if (value == null) {
+ return false;
+ } else {
+ return value.booleanValue();
+ }
}
/**
@@ -146,7 +179,10 @@
* @param vp the VisualProperty
*/
public void clearValueLock(final VisualProperty<?> vp){
- networkView.getColumn(vp).clearValueLock(this);
+ if (vp == null)
+ throw new NullPointerException(VP_IS_NULL);
+
+ bypassLocks.put(vp, Boolean.FALSE);
}
public void addViewChangeListener(ViewChangeListener vcl) {
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---