Thread: [Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool SelectTool.java,1.29,1.30
Status: Pre-Alpha
Brought to you by:
henryml
From: Nordholt <nor...@us...> - 2005-10-03 18:40:02
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15078 Modified Files: SelectTool.java Log Message: made inner class listeners for the popup menu. Now popup has submenu groupings and create new feature Index: SelectTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/SelectTool.java,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** SelectTool.java 3 Oct 2005 13:32:14 -0000 1.29 --- SelectTool.java 3 Oct 2005 18:39:54 -0000 1.30 *************** *** 9,13 **** import net.sourceforge.bprocessor.gl.GLView; import net.sourceforge.bprocessor.gl.view.View; - import net.sourceforge.bprocessor.gl.DomainPopupListener; import net.sourceforge.bprocessor.kernel.notification.Notification; --- 9,12 ---- *************** *** 22,34 **** import net.sourceforge.bprocessor.model.FunctionalSpace; import net.sourceforge.bprocessor.model.ConstructionSpace; import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.KeyEvent; import java.awt.event.InputEvent; - import java.awt.event.MouseListener; import javax.swing.JPopupMenu; import javax.swing.JMenuItem; import java.util.Iterator; --- 21,38 ---- import net.sourceforge.bprocessor.model.FunctionalSpace; import net.sourceforge.bprocessor.model.ConstructionSpace; + import net.sourceforge.bprocessor.model.Space; + + import net.sourceforge.bprocessor.gui.GUI; import java.awt.event.ActionListener; + import java.awt.event.ActionEvent; import java.awt.event.MouseEvent; import java.awt.event.KeyEvent; import java.awt.event.InputEvent; import javax.swing.JPopupMenu; import javax.swing.JMenuItem; + import javax.swing.JMenu; + import javax.swing.JOptionPane; import java.util.Iterator; *************** *** 132,147 **** surface = (Surface)o; } } - while (domIt.hasNext()) { - Domain domain = (Domain)domIt.next(); - JMenuItem domainItem = new JMenuItem(domain.getName()); - ActionListener ml = new DomainPopupListener(domain, - surface, - side.equals("front")); - domainItem.addActionListener(ml); - pp.add(domainItem); - } - pp.pack(); - glv.popup(pp, e.getX(), e.getY()); } else if (target == null) { Iterator it = new HashSet(selection).iterator(); --- 136,185 ---- surface = (Surface)o; } + JMenuItem noneItem = new JMenuItem("NONE"); + ActionListener noneListener = new DomainPopupListener(null, + surface, + side.equals("front")); + noneItem.addActionListener(noneListener); + pp.add(noneItem); + pp.addSeparator(); + JMenu createSub = new JMenu("Create"); + JMenuItem createFuncItem = new JMenuItem("New Functional Space"); + ActionListener funcListener = new CreateSpaceActionListener(surface, + side.equals("front"), + true); + createFuncItem.addActionListener(funcListener); + createSub.add(createFuncItem); + + JMenuItem createConstItem = new JMenuItem("New Construction Space"); + ActionListener constListener = new CreateSpaceActionListener(surface, + side.equals("front"), + false); + createConstItem.addActionListener(constListener); + createSub.add(createConstItem); + + pp.add(createSub); + pp.addSeparator(); + JMenu funcMenu = new JMenu("Functional Spaces"); + JMenu constMenu = new JMenu("Construction Spaces"); + while (domIt.hasNext()) { + Domain domain = (Domain)domIt.next(); + if (domain instanceof Space) { + JMenuItem domainItem = new JMenuItem(domain.getName()); + ActionListener ml = new DomainPopupListener(domain, + surface, + side.equals("front")); + domainItem.addActionListener(ml); + if (domain instanceof FunctionalSpace) { + funcMenu.add(domainItem); + } else { + constMenu.add(domainItem); + } + } + } + pp.add(funcMenu); + pp.add(constMenu); + pp.pack(); + glv.popup(pp, e.getX(), e.getY()); } } else if (target == null) { Iterator it = new HashSet(selection).iterator(); *************** *** 346,348 **** --- 384,521 ---- return false; } + + /** + * The listener for the domain popup menu. + */ + private class DomainPopupListener implements ActionListener { + + /** The domain */ + private Domain domain; + + /** The Surface */ + private Surface surface; + + /** Boolean telling if this is for the front or back of the surface*/ + private boolean front; + + /** + * Constructs a listener for an item in the domain popup that assigns the given domain to + * the given side of a surface. + * @param domain the domain + * @param surface the surface + * @param front werther or not this popup for the front of the back of the surface + */ + public DomainPopupListener(Domain domain, Surface surface, boolean front) { + this.domain = domain; + this.surface = surface; + this.front = front; + } + + /** + * Invoked when an action is performed + * @param arg0 an action event + */ + public void actionPerformed(ActionEvent arg0) { + if (front) { + Domain oldFront = surface.getFrontDomain(); + surface.setFrontDomain(domain); + if (domain != null) { + domain.addSurface(surface); + } + if (oldFront != null) { + Project.getInstance().update(oldFront); + } + } else { + Domain oldBack = surface.getBackDomain(); + surface.setBackDomain(domain); + if (domain != null) { + domain.addSurface(surface); + } + if (oldBack != null) { + Project.getInstance().update(oldBack); + } + } + if (domain != null) { + Project.getInstance().update(domain); + } + + Project.getInstance().update(surface); + } + } + + /** + * The create functional space action listener for the domain popupmenu. + */ + public class CreateSpaceActionListener implements ActionListener { + + /** The Surface */ + private Surface surface; + + /** Boolean telling if this is for the front or back of the surface*/ + private boolean front; + + /** Boolean telling if this is for creating functional or construction spaces*/ + private boolean functional; + + /** + * CreateSpaceActionListener + * @param surface the surface this listener is associated with + * @param front should be true if this listener is associated with the front-side of the surface + * @param functional should be true this listener is for creating functional spaces. Otherwise + * it will be for construction spaces. + */ + public CreateSpaceActionListener(Surface surface, boolean front, boolean functional) { + this.surface = surface; + this.front = front; + this.functional = functional; + } + + /** + * Action performed + * @param e The action event + */ + public void actionPerformed(ActionEvent e) { + String result; + if (functional) { + result = JOptionPane.showInputDialog(GUI.getInstance(), + "Name", + "Create Functional Space", + JOptionPane.QUESTION_MESSAGE); + } else { + result = JOptionPane.showInputDialog(GUI.getInstance(), + "Name", + "Create Construction Space", + JOptionPane.QUESTION_MESSAGE); + } + if (log.isDebugEnabled()) { + log.debug("Input: " + result); + } + + if (result != null && !result.trim().equals("")) { + Space space; + if (functional) { + space = new FunctionalSpace(result.trim()); + Project.getInstance().intern((FunctionalSpace)space); + } else { + space = new ConstructionSpace(result.trim()); + Project.getInstance().intern((ConstructionSpace)space); + } + + Domain old; + if (front) { + old = surface.getFrontDomain(); + surface.setFrontDomain(space); + } else { + old = surface.getBackDomain(); + surface.setBackDomain(space); + } + space.addSurface(surface); + Project.getInstance().update(space); + if (old != null) { + Project.getInstance().update(old); + } + } + } + } } + |