[Bprocessor-commit] gui/src/net/sourceforge/bprocessor/gui/treeview SpaceTreeView.java,1.6,1.7
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2006-04-12 15:10:16
|
Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/treeview In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2741/src/net/sourceforge/bprocessor/gui/treeview Modified Files: SpaceTreeView.java Log Message: Keeps the tree in the databaseview in the same way always Index: SpaceTreeView.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/treeview/SpaceTreeView.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** SpaceTreeView.java 5 Apr 2006 09:35:50 -0000 1.6 --- SpaceTreeView.java 12 Apr 2006 15:10:09 -0000 1.7 *************** *** 8,12 **** --- 8,17 ---- package net.sourceforge.bprocessor.gui.treeview; + import java.util.ArrayList; import java.util.Collection; + import java.util.Enumeration; + + import javax.swing.tree.DefaultMutableTreeNode; + import javax.swing.tree.TreePath; import net.sourceforge.bprocessor.model.Project; *************** *** 33,40 **** */ public void update() { - root.removeAllChildren(); Collection construction = Project.getInstance().getConstructionSpaces(); Collection functional = Project.getInstance().getFunctionalSpaces(); Collection constraints = Project.getInstance().getConstraints(); root.add(new SpaceContainer("Functional", functional)); root.add(new SpaceContainer("Construction", construction)); --- 38,47 ---- */ public void update() { Collection construction = Project.getInstance().getConstructionSpaces(); Collection functional = Project.getInstance().getFunctionalSpaces(); Collection constraints = Project.getInstance().getConstraints(); + Enumeration e = getExpandedDescendants(new TreePath(root)); + Object[] paths = findPaths(e); + root.removeAllChildren(); root.add(new SpaceContainer("Functional", functional)); root.add(new SpaceContainer("Construction", construction)); *************** *** 42,45 **** --- 49,112 ---- root.add(new GeometryContainer("Geometry", Project.getInstance().world())); model.nodeStructureChanged(root); + openPaths(paths); + } + + /** + * Find the paths + * @param e and enumerator of open nodes + * @return And array of arrays of objects + */ + private Object[] findPaths(Enumeration e) { + if (e != null) { + ArrayList res = new ArrayList(); + while (e.hasMoreElements()) { + Object o = e.nextElement(); + if (o instanceof TreePath) { + TreePath tp = (TreePath)o; + Object[] os = tp.getPath(); + Object[] temp = new Object[os.length]; + for (int i = 0; i < os.length; i++) { + temp[i] = ((DefaultMutableTreeNode)os[i]).getUserObject(); + } + res.add(temp); + } + } + return res.toArray(); + } + return null; + } + + /** + * Open the paths of the given objects + * @param paths The open paths + */ + public void openPaths(Object[] paths) { + if (paths != null) { + for (int i = 0; i < paths.length; i++) { + Object[] route = (Object[])paths[i]; + if (route.length > 1) { + openPath(root, 1, route); + } + } + } + } + + /** + * Open one path in the tree + * @param depth The depth reached in this call (< route.length) + * @param node The node to check in + * @param route The path to open + */ + private void openPath(DefaultMutableTreeNode node, int depth, Object[] route) { + Enumeration e = node.children(); + while (e.hasMoreElements()) { + DefaultMutableTreeNode current = (DefaultMutableTreeNode)e.nextElement(); + if (current.getUserObject() == route[depth]) { + expandPath(new TreePath(current.getPath())); + if (depth + 1 < route.length) { + openPath(current, depth + 1, route); + } + } + } } } |