Thread: [Bprocessor-commit] gui/src/net/sourceforge/bprocessor/gui/treeview GenericTreeView.java,NONE,1.1 Sp
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2006-01-03 10:53:59
|
Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/treeview In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4168/src/net/sourceforge/bprocessor/gui/treeview Modified Files: TreeView.java Added Files: GenericTreeView.java SpaceTreeView.java SurfaceTreeView.java Log Message: Added some simple treeview classes --- NEW FILE: SurfaceTreeView.java --- //--------------------------------------------------------------------------------- // $Id: SurfaceTreeView.java,v 1.1 2006/01/03 10:53:50 henryml Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.gui.treeview; import java.util.Set; import net.sourceforge.bprocessor.model.Project; /** * SurfaceTreeView */ public class SurfaceTreeView extends GenericTreeView { /** * Constructor for SurfaceTreeView */ public SurfaceTreeView() { super(); } /** * Update the TreeView * */ public void update() { System.out.println("update " + System.currentTimeMillis()); root.removeAllChildren(); Set surfaces = Project.getInstance().getSurfaces(); root.add(new SurfaceContainer("Surfaces", surfaces)); model.nodeStructureChanged(root); } } Index: TreeView.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/treeview/TreeView.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** TreeView.java 27 Jun 2005 09:32:23 -0000 1.1.1.1 --- TreeView.java 3 Jan 2006 10:53:50 -0000 1.2 *************** *** 7,10 **** --- 7,12 ---- package net.sourceforge.bprocessor.gui.treeview; + import java.awt.Font; + import javax.swing.JTree; import javax.swing.tree.TreeSelectionModel; *************** *** 26,29 **** --- 28,33 ---- getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); setEditable(false); + Font font = new Font("Sans-serif", Font.PLAIN, 12); + this.setFont(font); } --- NEW FILE: GenericTreeView.java --- //--------------------------------------------------------------------------------- // $Id: GenericTreeView.java,v 1.1 2006/01/03 10:53:50 henryml Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.gui.treeview; import java.util.Iterator; import java.util.List; import java.util.Set; import javax.swing.SwingUtilities; import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.TreePath; import net.sourceforge.bprocessor.kernel.notification.Notification; import net.sourceforge.bprocessor.kernel.notification.NotificationListener; import net.sourceforge.bprocessor.kernel.notification.Notifier; import net.sourceforge.bprocessor.model.Edge; import net.sourceforge.bprocessor.model.Entity; import net.sourceforge.bprocessor.model.Space; import net.sourceforge.bprocessor.model.Surface; import net.sourceforge.bprocessor.model.Vertex; /** * The GenericTreeView */ public class GenericTreeView extends TreeView implements NotificationListener { /** The model */ protected DefaultTreeModel model; /** The root */ protected DefaultMutableTreeNode root; /** Flag saying that we are changed */ private boolean isChanged; /** Current selection */ private Object selection; /** * Constructor for GenericTreeView */ public GenericTreeView() { super(); setRootVisible(false); setShowsRootHandles(true); Notifier.getInstance().addListener(this); this.addTreeSelectionListener(new SelectionListener()); model = (DefaultTreeModel) getModel(); root = (DefaultMutableTreeNode) model.getRoot(); root.removeAllChildren(); model.nodeStructureChanged(root); isChanged = false; changed(); } /** * Tell the TreeView we are changed * */ public void changed() { if (!isChanged) { isChanged = true; SwingUtilities.invokeLater ( new Runnable() { public void run() { flush(); } } ); } } /** * Update the TreeView * */ public void update() { } /** * Flush update * */ public void flush() { if (isChanged) { update(); isChanged = false; } } /** * Set selection to target * @param target Object */ public void select(Object target) { if (selection != null) { if (selection instanceof Space) { Space space = (Space) selection; if (space.isFunctionalSpace()) { Notification n = new Notification(Notification.FUNCTIONAL_SPACE_DESELECTED, space.getId()); Notifier.getInstance().sendNotification(n); } else { Notification n = new Notification(Notification.CONSTRUCTION_SPACE_DESELECTED, space.getId()); Notifier.getInstance().sendNotification(n); } } else if (selection instanceof Surface) { Surface surface = (Surface) selection; Notification n = new Notification(Notification.SURFACE_DESELECTED, surface.getId()); Notifier.getInstance().sendNotification(n); } } selection = target; if (selection != null) { if (selection instanceof Space) { Space space = (Space) selection; if (space.isFunctionalSpace()) { Notification n = new Notification(Notification.FUNCTIONAL_SPACE_SELECTED, space.getId()); Notifier.getInstance().sendNotification(n); } else { Notification n = new Notification(Notification.CONSTRUCTION_SPACE_SELECTED, space.getId()); Notifier.getInstance().sendNotification(n); } } else if (selection instanceof Surface) { Surface surface = (Surface) selection; Notification n = new Notification(Notification.SURFACE_SELECTED, surface.getId()); Notifier.getInstance().sendNotification(n); } } } /** * ContainerNode */ public class ContainerNode extends DefaultMutableTreeNode { /** * Constructor for ContainerNode * @param object User object */ public ContainerNode(Object object) { super(object); } /** * Always not be leaf * @return answer */ public boolean isLeaf() { return false; } } /** * The EntityNode */ public class EntityNode extends DefaultMutableTreeNode { /** * Constructor for EntityNode * @param object User object */ public EntityNode(Object object) { super(object); } /** * Return the displaystring for this EntityNode * @return Display string */ public String toString() { Object object = this.getUserObject(); if (object instanceof Entity) { Entity entity = (Entity) object; return entity.getName(); } else { return object.toString(); } } } /** * SpaceNode */ public class SpaceNode extends EntityNode { /** * Constructor for SpaceNode * @param space Space */ public SpaceNode(Space space) { super(space); Set surfaces = space.getSurfaces(); add(new SurfaceContainer("Surfaces", surfaces)); } } /** * SurfaceNode */ public class SurfaceNode extends EntityNode { /** * Constructor for SurfaceNode * @param surface The surface */ public SurfaceNode(Surface surface) { super(surface); add(new EdgeContainer("Edges", surface.getEdges())); } } /** * EdgeNode */ public class EdgeNode extends EntityNode { /** * Constructor for SurfaceNode * @param edge The edge */ public EdgeNode(Edge edge) { super(edge); add(new VertexNode(edge.getFrom())); add(new VertexNode(edge.getTo())); } } /** * VertexNode */ public class VertexNode extends EntityNode { /** * Constructor for VertexNode * @param vertex The vertex */ public VertexNode(Vertex vertex) { super(vertex); } } /** * SpaceContainer */ public class SpaceContainer extends ContainerNode { /** * Constructor for SpaceContainer * @param name Display name * @param spaces The spaces */ public SpaceContainer(String name, Set spaces) { super(name); Iterator iter = spaces.iterator(); while (iter.hasNext()) { Space current = (Space) iter.next(); add(new SpaceNode(current)); } } } /** * SurfaceContainer */ public class SurfaceContainer extends ContainerNode { /** * Constructor for SurfaceContainer * @param name The name * @param surfaces The surfaces */ public SurfaceContainer(String name, Set surfaces) { super(name); Iterator iter = surfaces.iterator(); while (iter.hasNext()) { Surface current = (Surface) iter.next(); add(new SurfaceNode(current)); } } } /** * EdgeContainer */ public class EdgeContainer extends ContainerNode { /** * Constructor for EdgeContainer * @param name The name * @param edges The edges */ public EdgeContainer(String name, List edges) { super(name); Iterator iter = edges.iterator(); while (iter.hasNext()) { Edge current = (Edge) iter.next(); add(new EdgeNode(current)); } } } /** * Selection Listener */ private class SelectionListener implements TreeSelectionListener { /** * ValueChanged * @param event The Event */ public void valueChanged(TreeSelectionEvent event) { TreePath path = event.getPath(); Object object = path.getLastPathComponent(); if (object instanceof DefaultMutableTreeNode) { DefaultMutableTreeNode node = (DefaultMutableTreeNode) object; Object target = node.getUserObject(); select(target); } } } /** * Handle notification * @param arg0 The notification */ public void handleNotification(Notification arg0) { changed(); } /** * Specify if we want to handle notification * @param type String specifying type of notification * @return True if we want to handle it */ public boolean isNotificationEnabled(String type) { if (type.equals(Notification.FUNCTIONAL_SPACE_CREATED) || type.equals(Notification.FUNCTIONAL_SPACE_DELETED) || type.equals(Notification.FUNCTIONAL_SPACE_MODIFIED) || type.equals(Notification.CONSTRUCTION_SPACE_CREATED) || type.equals(Notification.CONSTRUCTION_SPACE_DELETED) || type.equals(Notification.CONSTRUCTION_SPACE_MODIFIED)) { return true; } return false; } } --- NEW FILE: SpaceTreeView.java --- //--------------------------------------------------------------------------------- // $Id: SpaceTreeView.java,v 1.1 2006/01/03 10:53:50 henryml Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.gui.treeview; import java.util.Set; import net.sourceforge.bprocessor.model.Project; /** * The SpaceTreeView */ public class SpaceTreeView extends GenericTreeView { /** * Constructor for SpaceTreeView */ public SpaceTreeView() { super(); } /** * Update the treeview */ public void update() { System.out.println("update " + System.currentTimeMillis()); root.removeAllChildren(); Set construction = Project.getInstance().getConstructionSpaces(); Set functional = Project.getInstance().getFunctionalSpaces(); Set surfaces = Project.getInstance().getSurfaces(); root.add(new SpaceContainer("Functional", functional)); root.add(new SpaceContainer("Construction", construction)); model.nodeStructureChanged(root); } } |