Thread: [Bprocessor-commit] gui/src/net/sourceforge/bprocessor/gui/treeview GenericTreeView.java, 1.117, 1.
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2007-11-06 08:06:10
|
Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/treeview In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv14714/src/net/sourceforge/bprocessor/gui/treeview Modified Files: GenericTreeView.java SpaceTreeView.java Log Message: Index: GenericTreeView.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/treeview/GenericTreeView.java,v retrieving revision 1.117 retrieving revision 1.118 diff -C2 -d -r1.117 -r1.118 *** GenericTreeView.java 31 Oct 2007 11:33:27 -0000 1.117 --- GenericTreeView.java 6 Nov 2007 08:06:12 -0000 1.118 *************** *** 44,47 **** --- 44,48 ---- import net.sourceforge.bprocessor.model.Attribute; import net.sourceforge.bprocessor.model.Camera; + import net.sourceforge.bprocessor.model.Command; import net.sourceforge.bprocessor.model.Constructor; import net.sourceforge.bprocessor.model.CoordinateSystem; *************** *** 49,52 **** --- 50,54 ---- import net.sourceforge.bprocessor.model.Entity; import net.sourceforge.bprocessor.model.Geometric; + import net.sourceforge.bprocessor.model.Material; import net.sourceforge.bprocessor.model.Observer; import net.sourceforge.bprocessor.model.ParameterBlock; *************** *** 61,64 **** --- 63,67 ---- import net.sourceforge.bprocessor.gui.GUI; import net.sourceforge.bprocessor.gui.PopupMenu; + import net.sourceforge.bprocessor.gui.actions.GeometricMenuAction; import net.sourceforge.bprocessor.gui.attrview.AttributeView; *************** *** 512,535 **** public void update(Object object) { if (object instanceof Collection) { ! content = (Collection) object; ! Set<Entity> elements = new HashSet<Entity>(); ! elements.addAll(content); ! Set<GenericNode> children = new HashSet<GenericNode>(); ! Enumeration enumeration = this.children(); ! while (enumeration.hasMoreElements()) { ! GenericNode node = (GenericNode)enumeration.nextElement(); ! Entity entity = (Entity)node.getUserObject(); ! if (elements.contains(entity)) { ! node.update(entity); ! elements.remove(entity); ! } else { ! children.add(node); } - } - if (elements.size() > 0) { - this.insertChildren(elements); - } - if (children.size() > 0) { - this.removeChildren(children); } } else { --- 515,557 ---- public void update(Object object) { if (object instanceof Collection) { ! if (sort) { ! content = (Collection) object; ! Set<Entity> elements = new HashSet<Entity>(); ! elements.addAll(content); ! Set<GenericNode> children = new HashSet<GenericNode>(); ! Enumeration enumeration = this.children(); ! while (enumeration.hasMoreElements()) { ! GenericNode node = (GenericNode)enumeration.nextElement(); ! Entity entity = (Entity)node.getUserObject(); ! if (elements.contains(entity)) { ! node.update(entity); ! elements.remove(entity); ! } else { ! children.add(node); ! } ! } ! if (elements.size() > 0) { ! this.insertChildren(elements); ! } ! if (children.size() > 0) { ! this.removeChildren(children); ! } ! } else { ! boolean insert = false; ! Collection c = (Collection) object; ! HashSet set = new HashSet(c); ! Enumeration children = this.children(); ! while (children.hasMoreElements()) { ! GenericNode node = (GenericNode)children.nextElement(); ! if (!set.contains(node.getUserObject())) { ! this.removeAllChildren(); ! insert = true; ! break; ! } ! } ! if (insert) { ! this.insertChildren(c); ! model.nodeStructureChanged(this); } } } else { *************** *** 550,553 **** --- 572,580 ---- int i = 0; for (Entity current : sorted) { + if (current == null) { + log.error("There is a consistency problem cause " + getUserObject() + + " hold null objects"); + continue; + } this.add(nodeFor(current)); ins[i] = this.getChildCount() - 1; *************** *** 1006,1009 **** --- 1033,1086 ---- /** + * Menu container for materials + */ + public class MaterialContainer extends ContainerNode { + /** + * Create a container for materials + * @param label The container label + * @param object The list of objects + * @param sort if the list should be sorted before displayed + */ + public MaterialContainer(Object label, Collection<Material> object, boolean sort) { + super(label, object, sort); + insertChildren(object); + } + + /** + * Return icon + * @return icon + */ + public ImageIcon icon() { + //TODO make a proper icon + return genericgroupicon; + } + + /** {@inheritDoc} */ + public EntityNode nodeFor(Object entity) { + return new EntityNode((Material) entity); + } + + /** + * Context menu for ParameterBlockNode + * @return the menu + */ + public JPopupMenu menu() { + JPopupMenu pm = new JPopupMenu(); + AbstractAction add = new EntityAction(null, "Add Material") { + public void actionPerformed(ActionEvent arg0) { + Material m = new Material(); + m.setName("new material"); + Project.getInstance().add(m); + AttributeView.instance().display(m); + Project.getInstance().changed(Project.getInstance()); + Project.getInstance().checkpoint(); + } + }; + pm.add(add); + return pm; + } + } + + /** * Constructor Container */ *************** *** 1014,1018 **** * @param constructors The constructors */ ! public ConstructorContainer(String name, Collection constructors) { super(name, constructors, true); insertChildren(constructors); --- 1091,1095 ---- * @param constructors The constructors */ ! public ConstructorContainer(String name, Collection<Constructor> constructors) { super(name, constructors, true); insertChildren(constructors); *************** *** 1043,1047 **** * @param sort Sort the edges */ ! public EdgeContainer(String name, Collection edges, boolean sort) { super(name, edges, sort); insertChildren(edges); --- 1120,1124 ---- * @param sort Sort the edges */ ! public EdgeContainer(String name, Collection<Edge> edges, boolean sort) { super(name, edges, sort); insertChildren(edges); *************** *** 1101,1104 **** --- 1178,1272 ---- * CameraNode */ + public class CatalogContainer extends ContainerNode { + /** + * Constructor for EdgeContainer + * @param p The project + */ + public CatalogContainer(Project p) { + super("Catalog objects", p.getCatalogObjects(), true); + insertChildren(p.getCatalogObjects()); + } + + /** + * Update the node with the given object + * @param o The object + */ + public void update(Object o) { + if (o instanceof Project) { + Project proj = (Project)o; + if (proj == updated) { + model.nodeChanged(this); + } + super.update(proj.getCatalogObjects()); + } else { + log.warn("Were a " + o + " not a Project"); + } + } + + /** {@inheritDoc} */ + public EntityNode nodeFor(Object entity) { + Space s = (Space) entity; + return new CatalogNode(s); + } + } + + /** + * A container for catalog items + * @author rimestad + */ + public class CatalogNode extends EntityNode { + /** + * Constructor + * @param s The space that represent the catalog object + */ + public CatalogNode(Space s) { + super(s); + this.add(new SurfaceContainer("Surfaces", s.getSurfaces())); + this.add(new EdgeContainer("Edges", s.getEdges(), true)); + this.add(new VertexContainer("Vertices", s.getVertices(), true)); + } + + /** {@inheritDoc} */ + @Override + public String toString() { + return ((Space)getUserObject()).getName(); + } + + /** {@inheritDoc} */ + @Override + public void update(Object o) { + if (o instanceof Space) { + Space s = (Space)o; + ((GenericNode)root.getChildAt(0)).update(s.getSurfaces()); + ((GenericNode)root.getChildAt(1)).update(s.getEdges()); + ((GenericNode)root.getChildAt(2)).update(s.getVertices()); + } + } + + /** {@inheritDoc} */ + @Override + public JPopupMenu menu() { + JPopupMenu menu = new JPopupMenu(); + Collection<Space> spaces = new LinkedList<Space>(); + spaces.add((Space)getUserObject()); + menu.add(new GeometricMenuAction(spaces, "Duplicate") { + public void actionPerformed(ActionEvent e) { + Command command = new Command.Duplicate((Space) entities.iterator().next()); + AttributeView.instance().display(command); + }; + }); + menu.add(new GeometricMenuAction(spaces, "Instanciate") { + public void actionPerformed(ActionEvent e) { + Command command = new Command.Instance((Space) entities.iterator().next()); + AttributeView.instance().display(command); + }; + }); + return menu; + } + } + + /** + * CameraNode + */ public class CameraNode extends ContainerNode { /** *************** *** 1353,1357 **** GenericNode node = (GenericNode) selected; if (event.isPopupTrigger()) { ! setSelectionPath(path); JPopupMenu menu = node.menu(); if (menu != null) { --- 1521,1527 ---- GenericNode node = (GenericNode) selected; if (event.isPopupTrigger()) { ! if (!isPathSelected(path)) { ! setSelectionPath(path); ! } JPopupMenu menu = node.menu(); if (menu != null) { Index: SpaceTreeView.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/treeview/SpaceTreeView.java,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** SpaceTreeView.java 20 Sep 2007 09:39:32 -0000 1.25 --- SpaceTreeView.java 6 Nov 2007 08:06:12 -0000 1.26 *************** *** 10,14 **** import org.apache.log4j.Logger; - import net.sourceforge.bprocessor.gui.treeview.GenericTreeView.SelectionObserver; import net.sourceforge.bprocessor.model.Project; import net.sourceforge.bprocessor.model.Selection; --- 10,13 ---- *************** *** 31,40 **** public SpaceTreeView() { super(); root.removeAllChildren(); ! root.add(new ProjectNode(Project.getInstance())); ! root.add(new GeometryContainer("Geometry", Project.getInstance().world())); ! 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); --- 30,42 ---- public SpaceTreeView() { super(); + Project p = Project.getInstance(); root.removeAllChildren(); ! root.add(new ProjectNode(p)); ! root.add(new GeometryContainer("Geometry", p.world())); ! root.add(new ConstraintContainer("Constraints", p.getConstraints())); ! root.add(new MaterialContainer("Materials", p.getMaterials(), true)); ! root.add(new ParameterBlockNode("Globals", p.getGlobals())); ! root.add(new ConstructorContainer("Constructors", p.getConstructors())); ! root.add(new CatalogContainer(p)); model.nodeStructureChanged(root); *************** *** 47,55 **** public void update() { try { ! ((GenericNode)root.getChildAt(0)).update(Project.getInstance()); ! ((GenericNode)root.getChildAt(1)).update(Project.getInstance().world()); ! ((GenericNode)root.getChildAt(2)).update(Project.getInstance().getConstraints()); ! ((GenericNode)root.getChildAt(3)).update(Project.getInstance().getGlobals()); ! ((GenericNode)root.getChildAt(4)).update(Project.getInstance().getConstructors()); } catch (ArrayIndexOutOfBoundsException e) { log.error("There were a inconsistent number of nodes attached to " + --- 49,60 ---- public void update() { try { ! Project p = Project.getInstance(); ! ((GenericNode)root.getChildAt(0)).update(p); ! ((GenericNode)root.getChildAt(1)).update(p.world()); ! ((GenericNode)root.getChildAt(2)).update(p.getConstraints()); ! ((GenericNode)root.getChildAt(3)).update(p.getMaterials()); ! ((GenericNode)root.getChildAt(4)).update(p.getGlobals()); ! ((GenericNode)root.getChildAt(5)).update(p.getConstructors()); ! ((GenericNode)root.getChildAt(6)).update(p); } catch (ArrayIndexOutOfBoundsException e) { log.error("There were a inconsistent number of nodes attached to " + |