[Bprocessor-commit] gui/src/net/sourceforge/bprocessor/gui/treeview GenericTreeView.java, 1.61, 1.6
Status: Pre-Alpha
Brought to you by:
henryml
|
From: rimestad <rim...@us...> - 2006-11-15 10:31:11
|
Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/treeview In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv5850/src/net/sourceforge/bprocessor/gui/treeview Modified Files: GenericTreeView.java Log Message: made some fixes to the tree view Index: GenericTreeView.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/treeview/GenericTreeView.java,v retrieving revision 1.61 retrieving revision 1.62 diff -C2 -d -r1.61 -r1.62 *** GenericTreeView.java 7 Nov 2006 10:51:28 -0000 1.61 --- GenericTreeView.java 15 Nov 2006 10:30:58 -0000 1.62 *************** *** 16,22 **** --- 16,24 ---- import java.util.Comparator; import java.util.Enumeration; + import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; + import java.util.Map; import java.util.Set; *************** *** 40,44 **** import net.sourceforge.bprocessor.model.Attribute; import net.sourceforge.bprocessor.model.Camera; - import net.sourceforge.bprocessor.model.Constraint; import net.sourceforge.bprocessor.model.Constructor; import net.sourceforge.bprocessor.model.Edge; --- 42,45 ---- *************** *** 130,133 **** --- 131,137 ---- private boolean isChanged; + /** The object udpated on a update call */ + private Object updated = null; + /** * Renderer *************** *** 203,207 **** this.addTreeSelectionListener(new SelectionListener()); this.addMouseListener(new GenericMouseAdapter()); - //this.addKeyListener(new GenericKeyListener()); model = (DefaultTreeModel) getModel(); root = (DefaultMutableTreeNode) model.getRoot(); --- 207,210 ---- *************** *** 210,214 **** isChanged = false; setCellRenderer(new Renderer()); ! changed(); } --- 213,217 ---- isChanged = false; setCellRenderer(new Renderer()); ! //changed(); } *************** *** 312,315 **** --- 315,321 ---- if (o != null) { this.userObject = o; + if (o == updated) { + model.nodeChanged(this); + } } else { log.warn("Tried to update with null on " + this); *************** *** 330,344 **** */ public class ContainerNode extends GenericNode { ! /** ! * ! */ private static final long serialVersionUID = 1L; ! /** * Constructor for ContainerNode ! * @param object User object */ ! public ContainerNode(Object object) { ! super(object); } --- 336,352 ---- */ public class ContainerNode extends GenericNode { ! /** */ private static final long serialVersionUID = 1L; ! /** The content for the container for the node */ ! protected Object content; ! /** * Constructor for ContainerNode ! * @param object User collection to put in ! * @param label The label for the container node */ ! public ContainerNode(Object label, Object object) { ! super(label); ! this.content = object; } *************** *** 347,354 **** */ public String toString() { ! if (SHOW_COUNTERS) { ! return (this.getUserObject().toString() + " #" + this.getChildCount()); } else { ! return this.getUserObject().toString(); } } --- 355,362 ---- */ public String toString() { ! if (userObject instanceof Entity) { ! return ((Entity)userObject).getName(); } else { ! return userObject.toString(); } } *************** *** 399,411 **** public void update(Object o) { if (o instanceof Collection) { ! Set elem = new HashSet((Collection)o); Set children = new HashSet(); Enumeration e = this.children(); while (e.hasMoreElements()) { GenericNode sn = (GenericNode)e.nextElement(); ! if (elem.contains(sn.getUserObject())) { //If the node is allready there then just update it ! sn.update(sn.getUserObject()); ! elem.remove(sn.getUserObject()); } else { children.add(sn); --- 407,428 ---- public void update(Object o) { if (o instanceof Collection) { ! content = (Collection) o; ! //to make sure undo and redo keep nodes ! Map elem = new HashMap(); ! Iterator iter = ((Collection)o).iterator(); ! while (iter.hasNext()) { ! Entity e = (Entity)iter.next(); ! elem.put(e.getId(), e); ! } ! //Set elem = new HashSet((Collection)o); Set children = new HashSet(); Enumeration e = this.children(); while (e.hasMoreElements()) { GenericNode sn = (GenericNode)e.nextElement(); ! Long id = ((Entity)sn.getUserObject()).getId(); ! if (elem.containsKey(id)) { //If the node is allready there then just update it ! sn.update(elem.get(id)); ! elem.remove(id); } else { children.add(sn); *************** *** 413,417 **** } if (elem.size() > 0) { ! this.insertChildren(elem); } if (children.size() > 0) { --- 430,434 ---- } if (elem.size() > 0) { ! this.insertChildren(elem.values()); } if (children.size() > 0) { *************** *** 419,423 **** } } else { ! log.warn("Were called with " + o + " and not a list"); } } --- 436,440 ---- } } else { ! log.warn(userObject + " were called with " + o + " and not a list"); } } *************** *** 428,434 **** */ public void insertChildren(Collection elem) { ! int[] ins = new int[elem.size()]; int i = 0; ! Iterator iter = elem.iterator(); while (iter.hasNext()) { this.add(new EntityNode(iter.next())); --- 445,460 ---- */ public void insertChildren(Collection elem) { ! final Comparator num = ! new Comparator() { ! public int compare(Object s1, Object s2) { ! return ((Entity) s1).getId().compareTo(((Entity) s2).getId()); ! } ! }; ! LinkedList sort = new LinkedList(elem); ! Collections.sort(sort, num); ! //insert ! int[] ins = new int[sort.size()]; int i = 0; ! Iterator iter = sort.iterator(); while (iter.hasNext()) { this.add(new EntityNode(iter.next())); *************** *** 483,500 **** return pm; } - - - /** - * Update the node with the given object - * @param o The object - */ - public void update(Object o) { - if (o instanceof Entity || o instanceof Attribute) { - if (userObject != o) { - userObject = o; - model.nodeChanged(this); - } - } - } } --- 509,512 ---- *************** *** 522,525 **** --- 534,541 ---- add(new ElementContainer("Elements", space.getElements())); add(new GeometryContainer("Geometry", space)); + if (space.isContainer()) { + ContainerNode cn = new ConstructorContainer("Constructors", space.getConstructors()); + add(cn); + } if (space.getModellor() != null) { add(new ModellorNode(space.getModellor())); *************** *** 534,552 **** if (o instanceof Space) { Space s = (Space)o; ((GenericNode)getChildAt(0)).update(s.getEnvelope()); ((GenericNode)getChildAt(1)).update(s.getElements()); ((GenericNode)getChildAt(2)).update(s); if (s.getModellor() != null) { ! if (getChildCount() == 4) { ! ((GenericNode)getChildAt(3)).update(s.getModellor()); } else { add(new ModellorNode(s.getModellor())); ! model.nodesWereInserted(this, new int[]{3}); } } else { ! if (getChildCount() == 4) { ! TreeNode node = getChildAt(3); ! remove(3); ! model.nodesWereRemoved(this, new int[]{3}, new Object[]{node}); } } --- 550,575 ---- if (o instanceof Space) { Space s = (Space)o; + current = s; + if (updated == current) { + model.nodeChanged(this); + } ((GenericNode)getChildAt(0)).update(s.getEnvelope()); ((GenericNode)getChildAt(1)).update(s.getElements()); ((GenericNode)getChildAt(2)).update(s); + if (s.isContainer()) { + ((GenericNode)getChildAt(3)).update(s.getConstructors()); + } if (s.getModellor() != null) { ! if (getChildCount() == 5) { ! ((GenericNode)getChildAt(4)).update(s.getModellor()); } else { add(new ModellorNode(s.getModellor())); ! model.nodesWereInserted(this, new int[]{4}); } } else { ! if (getChildCount() == 5) { ! TreeNode node = getChildAt(4); ! remove(4); ! model.nodesWereRemoved(this, new int[]{4}, new Object[]{node}); } } *************** *** 621,626 **** */ public void update(Object o) { if (o instanceof Surface) { - userObject = (Surface)o; ((GenericNode)getChildAt(0)).update(((Surface)o).getEdges()); } --- 644,649 ---- */ public void update(Object o) { + super.update(o); if (o instanceof Surface) { ((GenericNode)getChildAt(0)).update(((Surface)o).getEdges()); } *************** *** 687,692 **** public void update(Object o) { if (o instanceof Edge) { Edge e = (Edge)o; - userObject = e; ((EntityNode)this.getChildAt(0)).update(e.getFrom()); ((EntityNode)this.getChildAt(1)).update(e.getTo()); --- 710,715 ---- public void update(Object o) { if (o instanceof Edge) { + super.update(o); Edge e = (Edge)o; ((EntityNode)this.getChildAt(0)).update(e.getFrom()); ((EntityNode)this.getChildAt(1)).update(e.getTo()); *************** *** 746,752 **** */ public class SurfaceContainer extends ContainerNode { ! /** ! * ! */ private static final long serialVersionUID = 1L; --- 769,773 ---- */ public class SurfaceContainer extends ContainerNode { ! /** */ private static final long serialVersionUID = 1L; *************** *** 757,774 **** */ public SurfaceContainer(String name, Collection surfaces) { ! super(name); ! final Comparator num = ! new Comparator() { ! public int compare(Object s1, Object s2) { ! return ((Surface) s1).getId().compareTo(((Surface) s2).getId()); ! } ! }; ! LinkedList sort = new LinkedList(surfaces); ! Collections.sort(sort, num); ! Iterator iter = sort.iterator(); ! while (iter.hasNext()) { ! Surface current = (Surface) iter.next(); ! add(new SurfaceNode(current)); ! } } --- 778,783 ---- */ public SurfaceContainer(String name, Collection surfaces) { ! super(name, surfaces); ! insertChildren(surfaces); } *************** *** 778,784 **** */ public void insertChildren(Collection elem) { ! int[] ins = new int[elem.size()]; int i = 0; ! Iterator iter = elem.iterator(); while (iter.hasNext()) { Surface s = (Surface)iter.next(); --- 787,802 ---- */ public void insertChildren(Collection elem) { ! final Comparator num = ! new Comparator() { ! public int compare(Object s1, Object s2) { ! return ((Surface) s1).getId().compareTo(((Surface) s2).getId()); ! } ! }; ! LinkedList sort = new LinkedList(elem); ! Collections.sort(sort, num); ! //insert ! int[] ins = new int[sort.size()]; int i = 0; ! Iterator iter = sort.iterator(); while (iter.hasNext()) { Surface s = (Surface)iter.next(); *************** *** 815,824 **** */ public ElementContainer(String name, Collection elements) { ! super(name); ! Iterator iter = elements.iterator(); ! while (iter.hasNext()) { ! Space current = (Space) iter.next(); ! add(new SpaceNode(current)); ! } } --- 833,838 ---- */ public ElementContainer(String name, Collection elements) { ! super(name, elements); ! insertChildren(elements); } *************** *** 828,834 **** */ public void insertChildren(Collection elem) { ! int[] ins = new int[elem.size()]; int i = 0; ! Iterator iter = elem.iterator(); while (iter.hasNext()) { Space s = (Space)iter.next(); --- 842,857 ---- */ public void insertChildren(Collection elem) { ! final Comparator num = ! new Comparator() { ! public int compare(Object s1, Object s2) { ! return ((Space) s1).getId().compareTo(((Space) s2).getId()); ! } ! }; ! LinkedList sort = new LinkedList(elem); ! Collections.sort(sort, num); ! ! int[] ins = new int[sort.size()]; int i = 0; ! Iterator iter = sort.iterator(); while (iter.hasNext()) { Space s = (Space)iter.next(); *************** *** 863,867 **** */ public GeometryContainer(String name, Space space) { ! super(name); add(new SurfaceContainer("Surfaces", space.getSurfaces())); add(new EdgeContainer("Edges", space.getEdges())); --- 886,890 ---- */ public GeometryContainer(String name, Space space) { ! super(name, null); add(new SurfaceContainer("Surfaces", space.getSurfaces())); add(new EdgeContainer("Edges", space.getEdges())); *************** *** 876,879 **** --- 899,906 ---- if (o instanceof Space) { Space s = (Space)o; + if (s == updated) { + userObject = s; + model.nodeChanged(this); + } ((SurfaceContainer)this.getChildAt(0)).update(s.getSurfaces()); ((EdgeContainer)this.getChildAt(1)).update(s.getEdges()); *************** *** 901,910 **** */ public ConstructorContainer(String name, Collection constructors) { ! super(name); ! Iterator iter = constructors.iterator(); ! while (iter.hasNext()) { ! Constructor current = (Constructor) iter.next(); ! add(new ConstructorNode(current)); ! } } --- 928,933 ---- */ public ConstructorContainer(String name, Collection constructors) { ! super(name, constructors); ! insertChildren(constructors); } *************** *** 922,928 **** */ public void insertChildren(Collection elem) { ! int[] ins = new int[elem.size()]; int i = 0; ! Iterator iter = elem.iterator(); while (iter.hasNext()) { Constructor s = (Constructor)iter.next(); --- 945,959 ---- */ public void insertChildren(Collection elem) { ! final Comparator num = ! new Comparator() { ! public int compare(Object s1, Object s2) { ! return ((Constructor) s1).getId().compareTo(((Constructor) s2).getId()); ! } ! }; ! LinkedList sort = new LinkedList(elem); ! Collections.sort(sort, num); ! int[] ins = new int[sort.size()]; int i = 0; ! Iterator iter = sort.iterator(); while (iter.hasNext()) { Constructor s = (Constructor)iter.next(); *************** *** 948,957 **** */ public EdgeContainer(String name, Collection edges) { ! super(name); ! Iterator iter = edges.iterator(); ! while (iter.hasNext()) { ! Edge current = (Edge) iter.next(); ! add(new EdgeNode(current)); ! } } --- 979,984 ---- */ public EdgeContainer(String name, Collection edges) { ! super(name, edges); ! insertChildren(edges); } *************** *** 961,967 **** */ public void insertChildren(Collection elem) { ! int[] ins = new int[elem.size()]; int i = 0; ! Iterator iter = elem.iterator(); while (iter.hasNext()) { Edge s = (Edge)iter.next(); --- 988,1002 ---- */ public void insertChildren(Collection elem) { ! final Comparator num = ! new Comparator() { ! public int compare(Object s1, Object s2) { ! return ((Edge) s1).getId().compareTo(((Edge) s2).getId()); ! } ! }; ! LinkedList sort = new LinkedList(elem); ! Collections.sort(sort, num); ! int[] ins = new int[sort.size()]; int i = 0; ! Iterator iter = sort.iterator(); while (iter.hasNext()) { Edge s = (Edge)iter.next(); *************** *** 994,998 **** */ public ProjectNode(Project p) { ! super(p); } --- 1029,1034 ---- */ public ProjectNode(Project p) { ! super(p, p.getSpaces()); ! insertChildren(p.getSpaces()); } *************** *** 1004,1007 **** --- 1040,1047 ---- if (o instanceof Project) { Project proj = (Project)o; + if (proj == updated) { + userObject = proj; + model.nodeChanged(this); + } super.update(proj.getSpaces()); } else { *************** *** 1015,1021 **** */ public void insertChildren(Collection elem) { ! int[] ins = new int[elem.size()]; int i = 0; ! Iterator iter = elem.iterator(); while (iter.hasNext()) { Space s = (Space)iter.next(); --- 1055,1070 ---- */ public void insertChildren(Collection elem) { ! final Comparator num = ! new Comparator() { ! public int compare(Object s1, Object s2) { ! return ((Space) s1).getId().compareTo(((Space) s2).getId()); ! } ! }; ! LinkedList sort = new LinkedList(elem); ! Collections.sort(sort, num); ! ! int[] ins = new int[sort.size()]; int i = 0; ! Iterator iter = sort.iterator(); while (iter.hasNext()) { Space s = (Space)iter.next(); *************** *** 1040,1044 **** */ public CameraNode(Camera c) { ! super(c); update(c); } --- 1089,1093 ---- */ public CameraNode(Camera c) { ! super(c, c.getClipplanes()); update(c); } *************** *** 1050,1053 **** --- 1099,1106 ---- public void update(Object o) { if (o instanceof Camera) { + userObject = o; + if (o == updated) { + model.nodeChanged(this); + } super.update(((Camera)o).getClipplanes()); } else { *************** *** 1070,1079 **** */ public VertexContainer(String name, Collection vertices) { ! super(name); ! Iterator iter = vertices.iterator(); ! while (iter.hasNext()) { ! Vertex current = (Vertex) iter.next(); ! add(new VertexNode(current)); ! } } --- 1123,1128 ---- */ public VertexContainer(String name, Collection vertices) { ! super(name, vertices); ! insertChildren(vertices); } *************** *** 1092,1098 **** */ public void insertChildren(Collection elem) { ! int[] ins = new int[elem.size()]; int i = 0; ! Iterator iter = elem.iterator(); while (iter.hasNext()) { Vertex s = (Vertex)iter.next(); --- 1141,1156 ---- */ public void insertChildren(Collection elem) { ! final Comparator num = ! new Comparator() { ! public int compare(Object s1, Object s2) { ! return ((Vertex) s1).getId().compareTo(((Vertex) s2).getId()); ! } ! }; ! LinkedList sort = new LinkedList(elem); ! Collections.sort(sort, num); ! ! int[] ins = new int[sort.size()]; int i = 0; ! Iterator iter = sort.iterator(); while (iter.hasNext()) { Vertex s = (Vertex)iter.next(); *************** *** 1112,1118 **** private static final long serialVersionUID = 1L; - /** name */ - private String name; - /** * Constructor --- 1170,1173 ---- *************** *** 1121,1152 **** */ public ParameterBlockNode(String name, ParameterBlock object) { ! super(object); ! this.name = name; ! Iterator iter = object.getAttributes().iterator(); ! while (iter.hasNext()) { ! Attribute current = (Attribute) iter.next(); ! add(new EntityNode(current)); ! } } ! /** ! * Update the node with the given object ! * @param o The object */ public void update(Object o) { if (o instanceof ParameterBlock) { ! super.update(((ParameterBlock)o).getAttributes()); } } /** - * Name - * @return String - */ - public String toString() { - return name; - } - - /** * Context menu for ParameterBlockNode * @return the menu --- 1176,1193 ---- */ public ParameterBlockNode(String name, ParameterBlock object) { ! super(name, object); ! insertChildren(object.getAttributes()); } ! /** ! * @param o the object to update with */ public void update(Object o) { if (o instanceof ParameterBlock) { ! update(((ParameterBlock)o).getAttributes()); } } /** * Context menu for ParameterBlockNode * @return the menu *************** *** 1200,1209 **** */ public ConstraintContainer(String name, Collection constraints) { ! super(name); ! Iterator iter = constraints.iterator(); ! while (iter.hasNext()) { ! Constraint current = (Constraint) iter.next(); ! add(new EntityNode(current)); ! } } } --- 1241,1246 ---- */ public ConstraintContainer(String name, Collection constraints) { ! super(name, constraints); ! update(constraints); } } *************** *** 1300,1305 **** */ public void update(Object object) { ! changed(); } - } --- 1337,1344 ---- */ public void update(Object object) { ! updated = object; ! update(); ! updated = null; ! //changed(); } } |