[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool SelectTool.java,1.32,1.33
Status: Pre-Alpha
Brought to you by:
henryml
From: Nordholt <nor...@us...> - 2005-10-27 15:02:24
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15714 Modified Files: SelectTool.java Log Message: now makes seperator pop up appear Index: SelectTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/SelectTool.java,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** SelectTool.java 21 Oct 2005 11:57:10 -0000 1.32 --- SelectTool.java 27 Oct 2005 15:02:09 -0000 1.33 *************** *** 22,29 **** 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; --- 22,28 ---- import net.sourceforge.bprocessor.model.Space; ! import java.awt.event.ActionListener; import java.awt.event.MouseEvent; import java.awt.event.KeyEvent; *************** *** 33,37 **** import javax.swing.JMenuItem; import javax.swing.JMenu; - import javax.swing.JOptionPane; import java.util.Iterator; --- 32,35 ---- *************** *** 111,170 **** if (target instanceof String) { String side = (String)target; ! JPopupMenu pp = new JPopupMenu(side); ! Set domains = Project.getInstance().getDomains(); ! Iterator domIt = domains.iterator(); ! Iterator selIt = new HashSet(selection).iterator(); ! Surface surface = null; ! if (selIt.hasNext()) { ! Object o = selIt.next(); ! if (o instanceof Surface) { ! 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(); --- 109,113 ---- if (target instanceof String) { String side = (String)target; ! glv.popup(makePopup(side), e.getX(), e.getY()); } else if (target == null) { Iterator it = new HashSet(selection).iterator(); *************** *** 194,197 **** --- 137,254 ---- } + /** + * Creates the correct type popup menu. + * @param type the type of popup should be created + * @return the popup menu. + */ + private JPopupMenu makePopup(String type) { + if (type.equals("bar")) { + return seperatorPopup(); + } else if (type.equals("front") || type.equals("back")) { + return spacePopup(type); + } else { + log.warn("\"" + type + "\" is not a recognized type of popup"); + return null; + } + } + + /** + * Creates the popup that appears when pressing a space seperator + * @return the seperatorpopup menu. + */ + private JPopupMenu seperatorPopup() { + JPopupMenu sepPop = new JPopupMenu(); + Iterator selIt = new HashSet(selection).iterator(); + if (selIt.hasNext()) { + Object o = selIt.next(); + if (o instanceof Surface) { + Surface surface = (Surface)o; + JMenuItem shift = new JMenuItem("Shift spaces"); + ActionListener shiftListener = new ShiftActionListener(surface); + shift.addActionListener(shiftListener); + sepPop.add(shift); + sepPop.pack(); + return sepPop; + } + } + log.warn("Space popup menu has no surface"); + return sepPop; + } + + /** + * Creates the popup that appears when pressing a space label + * @param side string indicating the wich space is choosen (front or back). + * @return the spacepopup menu. + */ + private JPopupMenu spacePopup(String side) { + JPopupMenu pp = new JPopupMenu(side); + Set domains = Project.getInstance().getDomains(); + Iterator domIt = domains.iterator(); + Iterator selIt = new HashSet(selection).iterator(); + Surface surface = null; + if (selIt.hasNext()) { + Object o = selIt.next(); + if (o instanceof Surface) { + surface = (Surface)o; + } + JMenuItem noneItem = new JMenuItem("NONE"); + ActionListener noneListener = new DomainPopupListener(null, + surface, + side.equals("front")); + noneItem.addActionListener(noneListener); + + 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); + + JMenu funcMenu = new JMenu("Functional Spaces"); + JMenu constMenu = new JMenu("Construction Spaces"); + boolean funcEnabled = false; + boolean constEnabled = false; + 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) { + funcEnabled = true; + funcMenu.add(domainItem); + } else { + constEnabled = true; + constMenu.add(domainItem); + } + } + } + + funcMenu.setEnabled(funcEnabled); + constMenu.setEnabled(constEnabled); + pp.add(funcMenu); + pp.add(constMenu); + pp.addSeparator(); + pp.add(createSub); + pp.addSeparator(); + pp.add(noneItem); + pp.pack(); + return pp; + } else { + log.warn("Space popup menu has no surface"); + return null; + } + } + /** * Sends the notification for select *************** *** 368,506 **** } 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); ! } ! } ! } ! } } - --- 425,428 ---- } return false; ! } } |