[Bprocessor-commit] gui/src/net/sourceforge/bprocessor/gui/treeview GenericTreeView.java,1.15,1.16
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2006-02-25 09:04:54
|
Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/treeview In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32658/src/net/sourceforge/bprocessor/gui/treeview Modified Files: GenericTreeView.java Log Message: Menu in D-View Index: GenericTreeView.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/treeview/GenericTreeView.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** GenericTreeView.java 15 Feb 2006 11:35:50 -0000 1.15 --- GenericTreeView.java 25 Feb 2006 09:04:49 -0000 1.16 *************** *** 8,11 **** --- 8,15 ---- import java.awt.Component; + import java.awt.event.ActionEvent; + import java.awt.event.ActionListener; + import java.awt.event.MouseAdapter; + import java.awt.event.MouseEvent; import java.net.URL; import java.util.Collection; *************** *** 15,18 **** --- 19,24 ---- import javax.swing.ImageIcon; + import javax.swing.JMenuItem; + import javax.swing.JPopupMenu; import javax.swing.JTree; import javax.swing.SwingUtilities; *************** *** 162,165 **** --- 168,172 ---- Project.getInstance().addObserver(this); this.addTreeSelectionListener(new SelectionListener()); + this.addMouseListener(new GenericMouseAdapter()); model = (DefaultTreeModel) getModel(); root = (DefaultMutableTreeNode) model.getRoot(); *************** *** 233,237 **** --- 240,261 ---- return null; } + + /** + * JPopupMenu + * @return menu + */ + public JPopupMenu menu() { + return null; + } + } + + /** + * MenuAction for making anonymous actionlisteners + */ + protected abstract class MenuAction implements ActionListener { } + + + /** * ContainerNode *************** *** 311,316 **** super(space); Set surfaces = space.getEnvelope(); ! add(new SurfaceContainer("Envelope", surfaces)); ! add(new ContainerNode("Interior")); if (space.getModellor() != null) { add(new ModellorNode(space.getModellor())); --- 335,340 ---- super(space); Set surfaces = space.getEnvelope(); ! add(new SurfaceContainer("Surfaces", surfaces)); ! add(new ElementContainer("Elements", space)); if (space.getModellor() != null) { add(new ModellorNode(space.getModellor())); *************** *** 465,469 **** } } ! /** * Return icon --- 489,493 ---- } } ! /** * Return icon *************** *** 477,480 **** --- 501,546 ---- /** + * ElementContainer + */ + public class ElementContainer extends ContainerNode { + /** Space */ + private Space space; + + /** + * Construftor + * @param name The name + * @param space The space + */ + public ElementContainer(String name, Space space) { + super(name); + this.space = space; + } + + /** + * Return icon + * @return Icon + */ + public ImageIcon icon() { + return spacegroupicon; + } + + /** + * @return Menu + */ + public JPopupMenu menu() { + JPopupMenu menu = new JPopupMenu(); + JMenuItem offsetItem = new JMenuItem("Details"); + offsetItem.addActionListener(new MenuAction() { + public void actionPerformed(ActionEvent event) { + Project.getInstance().setActiveSpace(space); + } + } + ); + menu.add(offsetItem); + return menu; + } + } + + /** * EdgeContainer */ *************** *** 553,556 **** --- 619,648 ---- } } + + /** + * GenericMouseAdapter + */ + private class GenericMouseAdapter extends MouseAdapter { + /** + * Mouse pressed + * @param e MouseEvent + */ + public void mousePressed(MouseEvent e) { + System.out.println("e = " + e); + TreePath path = getPathForLocation(e.getX(), e.getY()); + if (path != null) { + if (e.isControlDown()) { + Object object = path.getLastPathComponent(); + if (object instanceof GenericNode) { + GenericNode node = (GenericNode) object; + JPopupMenu menu = node.menu(); + if (menu != null) { + menu.show(GenericTreeView.this, e.getX(), e.getY()); + } + } + } + } + } + } /** |