You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by tv...@apache.org on 2009/08/15 08:37:01 UTC
svn commit: r804439 - in /incubator/pivot/trunk:
core/src/org/apache/pivot/collections/Sequence.java
wtk/src/org/apache/pivot/wtk/TreeView.java
Author: tvolkert
Date: Sat Aug 15 06:37:01 2009
New Revision: 804439
URL: http://svn.apache.org/viewvc?rev=804439&view=rev
Log:
PIVOT-198 :: Change TreeView to use ImmutablePath class
Modified:
incubator/pivot/trunk/core/src/org/apache/pivot/collections/Sequence.java
incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TreeView.java
Modified: incubator/pivot/trunk/core/src/org/apache/pivot/collections/Sequence.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/core/src/org/apache/pivot/collections/Sequence.java?rev=804439&r1=804438&r2=804439&view=diff
==============================================================================
--- incubator/pivot/trunk/core/src/org/apache/pivot/collections/Sequence.java (original)
+++ incubator/pivot/trunk/core/src/org/apache/pivot/collections/Sequence.java Sat Aug 15 06:37:01 2009
@@ -104,6 +104,10 @@
return new ImmutableIterator<Integer>(elements.iterator());
}
+ public Integer[] toArray() {
+ return elements.toArray(Integer[].class);
+ }
+
public static Path forDepth(int depth) {
return new Path(new ArrayList<Integer>(depth));
}
Modified: incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TreeView.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TreeView.java?rev=804439&r1=804438&r2=804439&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TreeView.java (original)
+++ incubator/pivot/trunk/wtk/src/org/apache/pivot/wtk/TreeView.java Sat Aug 15 06:37:01 2009
@@ -22,7 +22,9 @@
import org.apache.pivot.collections.List;
import org.apache.pivot.collections.ListListener;
import org.apache.pivot.collections.Sequence;
+import org.apache.pivot.collections.Sequence.Tree.ImmutablePath;
import org.apache.pivot.collections.Sequence.Tree.Path;
+import org.apache.pivot.collections.immutable.ImmutableList;
import org.apache.pivot.util.Filter;
import org.apache.pivot.util.ListenerList;
import org.apache.pivot.wtk.content.TreeViewNodeRenderer;
@@ -392,7 +394,7 @@
* This must be done to release references from the tree data to our
* internal BranchHandler data structures. Failure to do so would mean
* that our BranchHandler objects would remain in scope as long as the
- * tree data remained in scope, even if we were no longer using the
+ * tree data remained in scope, even if we were no longer using the
* BranchHandler objects.
*/
@SuppressWarnings("unchecked")
@@ -579,7 +581,9 @@
break;
}
- affectedPath.update(depth, affectedPath.get(depth) + 1);
+ Integer[] elements = affectedPath.toArray();
+ elements[depth]++;
+ paths.update(i, new ImmutablePath(elements));
}
}
@@ -637,7 +641,9 @@
break;
}
- affectedPath.update(depth, affectedPath.get(depth) - count);
+ Integer[] elements = affectedPath.toArray();
+ elements[depth] -= count;
+ paths.update(i, new ImmutablePath(elements));
}
}
@@ -882,7 +888,6 @@
if (previousNodeRenderer != nodeRenderer) {
this.nodeRenderer = nodeRenderer;
-
treeViewListeners.nodeRendererChanged(this, previousNodeRenderer);
}
}
@@ -978,16 +983,7 @@
*
*/
public Sequence<Path> getSelectedPaths() {
- int count = selectedPaths.getLength();
-
- Sequence<Path> selectedPaths = new ArrayList<Path>(count);
-
- // Deep copy the selected paths into a new list
- for (int i = 0; i < count; i++) {
- selectedPaths.add(new Path(this.selectedPaths.get(i)));
- }
-
- return selectedPaths;
+ return new ImmutableList<Path>(selectedPaths);
}
/**
@@ -1024,15 +1020,14 @@
monitorBranch(new Path(path, path.getLength() - 1));
// Update the selection
- this.selectedPaths.add(new Path(path));
+ this.selectedPaths.add(new ImmutablePath(path));
}
// Notify listeners
treeViewSelectionListeners.selectedPathsChanged(this, previousSelectedPaths);
}
- // TODO return getSelectedPaths() when we start using immutable paths
- return null;
+ return getSelectedPaths();
}
/**
@@ -1043,13 +1038,7 @@
* The first selected path, or <tt>null</tt> if nothing is selected.
*/
public Path getFirstSelectedPath() {
- Path selectedPath = null;
-
- if (selectedPaths.getLength() > 0) {
- selectedPath = new Path(selectedPaths.get(0));
- }
-
- return selectedPath;
+ return (selectedPaths.getLength() > 0 ? selectedPaths.get(0) : null);
}
/**
@@ -1060,13 +1049,8 @@
* The last selected path, or <tt>null</tt> if nothing is selected.
*/
public Path getLastSelectedPath() {
- Path selectedPath = null;
-
- if (selectedPaths.getLength() > 0) {
- selectedPath = new Path(selectedPaths.get(selectedPaths.getLength() - 1));
- }
-
- return selectedPath;
+ return (selectedPaths.getLength() > 0
+ ? selectedPaths.get(selectedPaths.getLength() - 1) : null);
}
/**
@@ -1083,13 +1067,7 @@
throw new IllegalStateException("Tree view is not in single-select mode.");
}
- Path selectedPath = null;
-
- if (selectedPaths.getLength() > 0) {
- selectedPath = new Path(selectedPaths.get(0));
- }
-
- return selectedPath;
+ return (selectedPaths.getLength() > 0 ? selectedPaths.get(0) : null);
}
/**
@@ -1100,10 +1078,7 @@
throw new IllegalArgumentException("path is null.");
}
- Sequence<Path> selectedPaths = new ArrayList<Path>(1);
- selectedPaths.add(new Path(path));
-
- setSelectedPaths(selectedPaths);
+ setSelectedPaths(new ArrayList<Path>(path));
}
/**
@@ -1153,7 +1128,7 @@
monitorBranch(new Path(path, path.getLength() - 1));
// Update the selection
- selectedPaths.add(new Path(path));
+ selectedPaths.add(new ImmutablePath(path));
// Notify listeners
treeViewSelectionListeners.selectedPathAdded(this, path);
@@ -1494,7 +1469,7 @@
monitorBranch(new Path(path, path.getLength() - 1));
// Update the checked paths
- checkedPaths.add(new Path(path));
+ checkedPaths.add(new ImmutablePath(path));
} else {
// Update the checked paths
checkedPaths.remove(index, 1);
@@ -1536,16 +1511,7 @@
* non-<tt>null</tt>.
*/
public Sequence<Path> getCheckedPaths() {
- int count = checkedPaths.getLength();
-
- Sequence<Path> checkedPaths = new ArrayList<Path>(count);
-
- // Deep copy the checked paths into a new list
- for (int i = 0; i < count; i++) {
- checkedPaths.add(new Path(this.checkedPaths.get(i)));
- }
-
- return checkedPaths;
+ return new ImmutableList<Path>(checkedPaths);
}
/**
@@ -1574,7 +1540,7 @@
monitorBranch(path);
// Update the expanded paths
- expandedPaths.add(new Path(path));
+ expandedPaths.add(new ImmutablePath(path));
// Notify listeners
treeViewBranchListeners.branchExpanded(this, path);