Thread: [Bprocessor-commit] gui/src/net/sourceforge/bprocessor/gui/treeview SpacesTreeView.java,1.1.1.1,1.2
Status: Pre-Alpha
Brought to you by:
henryml
From: Jesper P. <je...@us...> - 2005-07-01 06:42:20
|
Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/treeview In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25896 Modified Files: SpacesTreeView.java Log Message: Send SELECTED notification when node is pressed Index: SpacesTreeView.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/treeview/SpacesTreeView.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** SpacesTreeView.java 27 Jun 2005 09:32:23 -0000 1.1.1.1 --- SpacesTreeView.java 1 Jul 2005 06:42:01 -0000 1.2 *************** *** 15,18 **** --- 15,20 ---- import net.sourceforge.bprocessor.model.FunctionalSpaceFacade; + import java.awt.event.MouseEvent; + import java.awt.event.MouseListener; import java.util.ArrayList; import java.util.Enumeration; *************** *** 45,48 **** --- 47,52 ---- setModel(new SpaceModel()); + addMouseListener(new MouseAdaptor()); + Notifier.getInstance().addListener(this); } *************** *** 65,69 **** RootNode rn = (RootNode)getModel().getRoot(); SpaceContainerNode scn = rn.getFunctionalSpaceContainer(); ! SpaceNode sn = new SpaceNode(n.getObject(), fs.getName(), scn); scn.add(sn); --- 69,73 ---- RootNode rn = (RootNode)getModel().getRoot(); SpaceContainerNode scn = rn.getFunctionalSpaceContainer(); ! SpaceNode sn = new SpaceNode(n.getObject(), fs.getName(), true, scn); scn.add(sn); *************** *** 76,80 **** RootNode rn = (RootNode)getModel().getRoot(); SpaceContainerNode scn = rn.getConstructionSpaceContainer(); ! SpaceNode sn = new SpaceNode(n.getObject(), cs.getName(), scn); scn.add(sn); --- 80,84 ---- RootNode rn = (RootNode)getModel().getRoot(); SpaceContainerNode scn = rn.getConstructionSpaceContainer(); ! SpaceNode sn = new SpaceNode(n.getObject(), cs.getName(), false, scn); scn.add(sn); *************** *** 236,244 **** */ abstract class GenericNode implements TreeNode { /** * Constructor */ ! GenericNode() { } --- 240,261 ---- */ abstract class GenericNode implements TreeNode { + /** Type: Root */ + static final int TYPE_ROOT = 0; + + /** Type: Space container */ + static final int TYPE_SPACE_CONTAINER = 1; + + /** Type: Space */ + static final int TYPE_SPACE = 0; + + /** Type */ + private int type; /** * Constructor + * @param type The type */ ! GenericNode(int type) { ! this.type = type; } *************** *** 292,296 **** * @return The node or null if not found */ ! public TreeNode findNode(Object o) { if (this == o) { return this; --- 309,313 ---- * @return The node or null if not found */ ! public GenericNode findNode(Object o) { if (this == o) { return this; *************** *** 300,304 **** while (e.hasMoreElements()) { GenericNode gn = (GenericNode)e.nextElement(); ! TreeNode result = gn.findNode(o); if (result != null) { return result; --- 317,321 ---- while (e.hasMoreElements()) { GenericNode gn = (GenericNode)e.nextElement(); ! GenericNode result = gn.findNode(o); if (result != null) { return result; *************** *** 308,311 **** --- 325,336 ---- return null; } + + /** + * Get the type of the node + * @return The type + */ + public int getType() { + return type; + } } *************** *** 330,333 **** --- 355,359 ---- */ RootNode() { + super(GenericNode.TYPE_ROOT); this.fsc = null; this.csc = null; *************** *** 457,460 **** --- 483,487 ---- */ SpaceContainerNode(String name, RootNode parent) { + super(GenericNode.TYPE_SPACE_CONTAINER); this.name = name; this.parent = parent; *************** *** 563,566 **** --- 590,596 ---- private String name; + /** Functional / construction */ + private boolean functional; + /** The parent */ private SpaceContainerNode parent; *************** *** 573,581 **** * @param id The id of the object * @param name The name * @param parent The parent */ ! SpaceNode(Long id, String name, SpaceContainerNode parent) { this.id = id; this.name = name; this.parent = parent; this.nodes = new Vector(); --- 603,614 ---- * @param id The id of the object * @param name The name + * @param functional Is the node a functional ? * @param parent The parent */ ! SpaceNode(Long id, String name, boolean functional, SpaceContainerNode parent) { ! super(GenericNode.TYPE_SPACE); this.id = id; this.name = name; + this.functional = functional; this.parent = parent; this.nodes = new Vector(); *************** *** 607,610 **** --- 640,651 ---- /** + * Is the node a functional ? + * @return True if functional; otherwise false + */ + public boolean isFunctional() { + return functional; + } + + /** * Get the children of this node * @return The children *************** *** 672,674 **** --- 713,772 ---- } } + + /** + * Mouse adaptor + */ + class MouseAdaptor implements MouseListener { + + /** + * Mouse clicked + * @param e The mouse event + */ + public void mouseClicked(MouseEvent e) { + } + + /** + * Mouse button was pressed + * @param e The mouse event + */ + public void mousePressed(MouseEvent e) { + int selRow = getRowForLocation(e.getX(), e.getY()); + TreePath selPath = getPathForLocation(e.getX(), e.getY()); + if (selRow != -1) { + GenericNode gn = (GenericNode)selPath.getLastPathComponent(); + if (gn.getType() == GenericNode.TYPE_SPACE) { + SpaceNode sn = (SpaceNode)gn; + + if (sn.isFunctional()) { + Notification n = new Notification(Notification.FUNCTIONAL_SPACE_SELECTED, sn.getId()); + Notifier.getInstance().sendNotification(n); + } else { + Notification n = new Notification(Notification.CONSTRUCTION_SPACE_SELECTED, sn.getId()); + Notifier.getInstance().sendNotification(n); + } + } + } + } + + /** + * Mouse button was released + * @param e The mouse event + */ + public void mouseReleased(MouseEvent e) { + } + + /** + * Mouse exit + * @param e The mouse event + */ + public void mouseExited(MouseEvent e) { + } + + /** + * Mouse enter + * @param e The mouse event + */ + public void mouseEntered(MouseEvent e) { + } + } } |