[Bprocessor-commit] gui/src/net/sourceforge/bprocessor/gui/treeview GenericTreeView.java, 1.55, 1.5
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2006-10-13 15:49:39
|
Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/treeview In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv8944/src/net/sourceforge/bprocessor/gui/treeview Modified Files: GenericTreeView.java SpaceTreeView.java Log Message: Fixed the tree so that it yet again uses the new update functionallity... ALL INSERTION AND DELETION IN THE TREE IS HANDLED BY THE update(Object o) METHODS NOT THE CONSTRUCTORS Index: GenericTreeView.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/treeview/GenericTreeView.java,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** GenericTreeView.java 9 Oct 2006 12:42:29 -0000 1.55 --- GenericTreeView.java 13 Oct 2006 15:49:37 -0000 1.56 *************** *** 491,496 **** public void update(Object o) { if (o instanceof Entity || o instanceof Attribute) { ! userObject = o; ! model.nodeChanged(this); } } --- 491,498 ---- public void update(Object o) { if (o instanceof Entity || o instanceof Attribute) { ! if (userObject != o) { ! userObject = o; ! model.nodeChanged(this); ! } } } *************** *** 997,1002 **** public ProjectNode(Project p) { super(p); ! update(p); ! add(new GeometryContainer("Geometry", Project.getInstance().world())); } --- 999,1003 ---- public ProjectNode(Project p) { super(p); ! add(new GeometryContainer("Geometry", p.world())); } *************** *** 1007,1011 **** public void update(Object o) { if (o instanceof Project) { ! super.update(((Project)o).getSpaces()); } else { log.warn("Were a " + o + " not a Project"); --- 1008,1016 ---- public void update(Object o) { if (o instanceof Project) { ! Collection c = new LinkedList(); ! Project proj = (Project)o; ! c.add(proj.world()); ! c.addAll(proj.getSpaces()); ! super.update(c); } else { log.warn("Were a " + o + " not a Project"); *************** *** 1023,1027 **** while (iter.hasNext()) { Space s = (Space)iter.next(); ! this.add(new SpaceNode(s)); ins[i] = this.getChildCount() - 1; i++; --- 1028,1036 ---- while (iter.hasNext()) { Space s = (Space)iter.next(); ! if (s.getLevel() == Space.PROJECT_LEVEL) { ! this.add(new GeometryContainer("Geometry", ((Project)userObject).world())); ! } else { ! this.add(new SpaceNode(s)); ! } ins[i] = this.getChildCount() - 1; i++; Index: SpaceTreeView.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/treeview/SpaceTreeView.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** SpaceTreeView.java 9 Oct 2006 12:42:29 -0000 1.17 --- SpaceTreeView.java 13 Oct 2006 15:49:37 -0000 1.18 *************** *** 8,17 **** package net.sourceforge.bprocessor.gui.treeview; - import java.util.ArrayList; - import java.util.Enumeration; - - import javax.swing.tree.DefaultMutableTreeNode; - import javax.swing.tree.TreePath; - import net.sourceforge.bprocessor.model.Project; --- 8,11 ---- *************** *** 31,34 **** --- 25,34 ---- public SpaceTreeView() { super(); + root.removeAllChildren(); + root.add(new ProjectNode(Project.getInstance())); + root.add(new ConstraintContainer("Constraints", Project.getInstance().getConstraints())); + root.add(new ParameterBlockNode("Globals", Project.getInstance().getGlobals())); + root.add(new ConstructorContainer("Constructors", Project.getInstance().getConstructors())); + model.nodeStructureChanged(root); } *************** *** 37,115 **** */ public void update() { ! if (root.getChildCount() == 5) { ((GenericNode)root.getChildAt(0)).update(Project.getInstance()); ((GenericNode)root.getChildAt(1)).update(Project.getInstance().getConstraints()); ((GenericNode)root.getChildAt(2)).update(Project.getInstance().getGlobals()); ! ((GenericNode)root.getChildAt(3)).update(Project.getInstance().world()); ! ((GenericNode)root.getChildAt(4)).update(Project.getInstance().getConstructors()); ! } else { ! Enumeration e = getExpandedDescendants(new TreePath(root)); ! Object[] paths = findPaths(e); ! root.removeAllChildren(); ! root.add(new ProjectNode(Project.getInstance())); ! root.add(new ConstraintContainer("Constraints", Project.getInstance().getConstraints())); ! root.add(new ParameterBlockNode("Globals", Project.getInstance().getGlobals())); ! root.add(new ConstructorContainer("Constructors", Project.getInstance().getConstructors())); ! 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); ! } ! } } } --- 37,45 ---- */ public void update() { ! if (root.getChildCount() == 4) { ((GenericNode)root.getChildAt(0)).update(Project.getInstance()); ((GenericNode)root.getChildAt(1)).update(Project.getInstance().getConstraints()); ((GenericNode)root.getChildAt(2)).update(Project.getInstance().getGlobals()); ! ((GenericNode)root.getChildAt(3)).update(Project.getInstance().getConstructors()); } } |