Author: abeld
Date: 2009-03-12 01:55:08 -0700 (Thu, 12 Mar 2009)
New Revision: 16215
Modified:
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/viewmodel-impl-columns/src/main/java/org/cytoscape/view/model/internal/ColumnOrientedViewColumn.java
Log:
refactored-viewmodel: fix 'computed values is not restored after lock is
removed' bug in column-oriented implementation.
Store locked and computed values (set by setLockedValue() and
setValue() respectively) seperatelly, so that computed value can be
allways restored. This fixes handling the following case:
If somebody does the following:
1) set locked value
2) apply a visual style
3) remove the lock from the value
then the value should revert to the value it would have gotten in step
2) if it hasn't been locked.
Modified:
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/viewmodel-impl-columns/src/main/java/org/cytoscape/view/model/internal/ColumnOrientedViewColumn.java
===================================================================
---
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/viewmodel-impl-columns/src/main/java/org/cytoscape/view/model/internal/ColumnOrientedViewColumn.java
2009-03-12 08:07:58 UTC (rev 16214)
+++
cytoscape3/branches/abeld-gsoc/dev/refactored-viewmodel/viewmodel-impl-columns/src/main/java/org/cytoscape/view/model/internal/ColumnOrientedViewColumn.java
2009-03-12 08:55:08 UTC (rev 16215)
@@ -8,74 +8,97 @@
/**
* A column in the viewmodel table
- * @param <T> the data type of the VisualProperty this belongs to
+ *
+ * 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;
/**
+ * The per-VisualStyle default value for the VisualProperty that this
Column
+ * represents
+ */
+ private T defaultValue;
+
+ /**
* Create for given VP
- * @param vp the VisualProperty
+ *
+ * @param vp
+ * the VisualProperty
*/
public ColumnOrientedViewColumn(final VisualProperty<T> vp) {
this.vp = vp;
this.values = new HashMap<View<?>, T>();
- this.bypassLocks= new HashMap<View<?>, Boolean>();
+ this.lockedValues = new HashMap<View<?>, T>();
+ this.bypassLocks = new HashMap<View<?>, Boolean>();
this.defaultValue = vp.getDefault();
}
- public Class<T> getDataType(){
+
+ public Class<T> getDataType() {
return vp.getType();
}
- public T getValue(View<?> view){
+
+ public T getValue(View<?> view) {
if (view == null)
throw new NullPointerException(VIEW_IS_NULL);
- if (values.containsKey(view)){
+ 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;
}
}
- public void setValue(View<?> view, T value){
+
+ public void setValue(View<?> view, T value) {
if (view == null)
throw new NullPointerException(VIEW_IS_NULL);
- final Boolean b = bypassLocks.get(view);
+ values.put(view, value);
+ }
- if ((b == null) || !b.booleanValue())
- values.put(view, value);
- }
- public void clearValue(View<?> view){
+ public void 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
+ *
+ * @param value
+ * the per-VisualStyle default value
*/
- public void setDefaultValue(T value){
+ public void setDefaultValue(T value) {
defaultValue = value;
}
-
- public void setLockedValue(final View<?> view, final T value){
+
+ public void setLockedValue(final View<?> view, final T value) {
if (view == null)
throw new NullPointerException(VIEW_IS_NULL);
- setValue(view, value);
+ lockedValues.put(view, value);
bypassLocks.put(view, Boolean.TRUE);
}
+
/**
- * @param vp the VisualProperty
+ * @param vp
+ * the VisualProperty
* @return true if current VisualProperty value is locked
*/
- public boolean isValueLocked(final View<?> view){
+ public boolean isValueLocked(final View<?> view) {
if (view == null)
throw new NullPointerException(VIEW_IS_NULL);
@@ -87,15 +110,17 @@
return value.booleanValue();
}
}
+
/**
* Clear value lock for given VisualProperty.
*
- * @param vp the VisualProperty
+ * @param vp
+ * the VisualProperty
*/
- public void clearValueLock(final View<?> view){
+ public void clearValueLock(final View<?> view) {
if (view == null)
throw new NullPointerException(VIEW_IS_NULL);
-
+ lockedValues.remove(view);
bypassLocks.put(view, Boolean.FALSE);
}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---