[Bprocessor-commit] gui/src/net/sourceforge/bprocessor/gui PopupMenu.java, 1.9, 1.10
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2006-10-30 10:30:22
|
Update of /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv23519/src/net/sourceforge/bprocessor/gui Modified Files: PopupMenu.java Log Message: changed the static methods to handle collections of elements, to support multi delete, union and the other multi entity methods Index: PopupMenu.java =================================================================== RCS file: /cvsroot/bprocessor/gui/src/net/sourceforge/bprocessor/gui/PopupMenu.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** PopupMenu.java 13 Oct 2006 15:44:16 -0000 1.9 --- PopupMenu.java 30 Oct 2006 10:30:11 -0000 1.10 *************** *** 11,22 **** --- 11,25 ---- import java.util.HashSet; import java.util.Iterator; + import java.util.LinkedList; import java.util.Set; import javax.swing.AbstractAction; import javax.swing.JMenu; + import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPopupMenu; import net.sourceforge.bprocessor.gui.actions.AttributeMenuAction; + import net.sourceforge.bprocessor.gui.actions.CollectionMenuAction; import net.sourceforge.bprocessor.gui.actions.EntitiesMenuAction; import net.sourceforge.bprocessor.gui.actions.EntityMenuAction; *************** *** 26,30 **** import net.sourceforge.bprocessor.model.Attribute; import net.sourceforge.bprocessor.model.Entity; - import net.sourceforge.bprocessor.model.Geometric; import net.sourceforge.bprocessor.model.Geometry; import net.sourceforge.bprocessor.model.Project; --- 29,32 ---- *************** *** 36,39 **** --- 38,42 ---- import net.sourceforge.bprocessor.model.Translate; import net.sourceforge.bprocessor.model.Vertex; + import net.sourceforge.bprocessor.model.constraints.OffsetConstraint; import net.sourceforge.bprocessor.model.modellor.Modellor; *************** *** 42,45 **** --- 45,100 ---- */ public class PopupMenu { + /** + * make a popup menu for a surface + * @param surface the surface + * @return the popupmenu + */ + public static JPopupMenu getSurfaceMenu(Surface surface) { + Collection c = new LinkedList(); + c.add(surface); + return getSurfaceMenu(c); + } + + /** + * Make a popupmenu for a list of surfaces + * @param c the list of surfaces + * @return the popupmenu + */ + public static JPopupMenu getSurfaceMenu(Collection c) { + JPopupMenu jm = getEntiesMenu(c); + + if (c.size() == 1) { + Surface s = (Surface)c.iterator().next(); + AbstractAction fromAbove = new EntityMenuAction(s, "See from above") { + public void actionPerformed(ActionEvent arg0) { + Vertex n = ((Surface)entity).normal(); + Project.getInstance().checkpoint(); + } + }; + jm.add(fromAbove); + AbstractAction fromBelow = new EntityMenuAction(s, "See from below") { + public void actionPerformed(ActionEvent arg0) { + Vertex n = ((Surface)entity).normal(); + Project.getInstance().checkpoint(); + } + }; + jm.add(fromBelow); + } + if (c.size() == 2) { + JMenuItem offsetItem = new JMenuItem("Offset Constraint"); + offsetItem.addActionListener(new CollectionMenuAction(c, "Offset") { + public void actionPerformed(ActionEvent event) { + OffsetConstraint.addOffsetConstraint(col); + Project p = Project.getInstance(); + p.changed(p); + p.checkpoint(); + } + } + ); + jm.add(offsetItem); + } + return jm; + } + /** *************** *** 103,132 **** /** * A popup generator for a space ! * @param s the space * @return the popup menu */ ! public static JPopupMenu getSpaceMenu(Space s) { ! JPopupMenu pm = PopupMenu.getEntityMenu(s); pm.addSeparator(); if (s != null) { ! AbstractAction copy = new SpaceMenuAction(s, "Duplicate") { public void actionPerformed(ActionEvent arg0) { ! if (space != null) { ! Space spaceCopy = space.copy(); ! Selection.primary().set(spaceCopy); ! Project.getInstance().checkpoint(); } } }; pm.add(copy); ! AbstractAction instantiate = new SpaceMenuAction(s, "Instantiate") { public void actionPerformed(ActionEvent arg0) { ! if (space != null) { ! Space instance = new Space("Instance of " + space.getName(), ! Space.CONSTRUCTION, space.getLevel(), false); ! instance.setProto(space); ! space.getOwner().add(instance); Project.getInstance().changed(Project.getInstance()); Project.getInstance().checkpoint(); --- 158,208 ---- /** * A popup generator for a space ! * @param space the space * @return the popup menu */ ! public static JPopupMenu getSpaceMenu(Space space) { ! Collection c = new LinkedList(); ! c.add(space); ! return getSpaceMenu(c); ! } ! ! /** ! * A popup generator for a collection of space ! * @param s the collection of spaces ! * @return the popup menu ! */ ! public static JPopupMenu getSpaceMenu(Collection s) { ! JPopupMenu pm = PopupMenu.getEntiesMenu(s); pm.addSeparator(); if (s != null) { ! AbstractAction copy = new CollectionMenuAction(s, "Duplicate") { public void actionPerformed(ActionEvent arg0) { ! if (col != null) { ! Iterator iter = col.iterator(); ! while (iter.hasNext()) { ! Space space = (Space)iter.next(); ! Space spaceCopy = space.copy(); ! Selection.primary().set(spaceCopy); ! Project.getInstance().checkpoint(); ! } } } }; pm.add(copy); ! AbstractAction instantiate = new CollectionMenuAction(s, "Instantiate") { public void actionPerformed(ActionEvent arg0) { ! if (col != null) { ! /*FIXME better if there were made a union if more than one ! and a instance of it */ ! Iterator iter = col.iterator(); ! while (iter.hasNext()) { ! Space space = (Space)iter.next(); ! Space instance = new Space("Instance of " + space.getName(), ! Space.CONSTRUCTION, space.getLevel(), false); ! instance.setProto(space); ! space.getOwner().add(instance); ! } Project.getInstance().changed(Project.getInstance()); Project.getInstance().checkpoint(); *************** *** 135,150 **** }; pm.add(instantiate); ! AbstractAction makeunion = new AbstractAction("Make Union") { public void actionPerformed(ActionEvent arg0) { Set internal = new HashSet(); ! { ! Iterator iter = Selection.primary().iterator(); ! while (iter.hasNext()) { ! Geometric current = (Geometric) iter.next(); ! if (current instanceof Space) { ! internal.add(current); ! } ! } ! } Set envelope = new HashSet(); { --- 211,219 ---- }; pm.add(instantiate); ! AbstractAction makeunion = new CollectionMenuAction(s, "Make Union") { public void actionPerformed(ActionEvent arg0) { Set internal = new HashSet(); ! internal.addAll(col); ! Set envelope = new HashSet(); { *************** *** 169,236 **** }; pm.add(makeunion); ! if (s.getLevel() < Space.PART_LEVEL) { ! AbstractAction edit = new SpaceMenuAction(s, "Edit") { public void actionPerformed(ActionEvent arg0) { ! Selection.primary().clear(); ! Project.getInstance().setActiveSpace(space); } }; ! pm.add(edit); ! } ! AbstractAction envelope = new SpaceMenuAction(s, "Compute Envelope") { ! public void actionPerformed(ActionEvent arg0) { ! if (space != null) { ! space.computeEnvelope(); ! Project.getInstance().changed(Project.getInstance()); Project.getInstance().checkpoint(); } ! } ! }; ! pm.add(envelope); ! AbstractAction flip = new SpaceMenuAction(s, "Rotate 90 degrees CCW") { ! public void actionPerformed(ActionEvent arg0) { ! Iterator it = space.collect().iterator(); ! Vertex center = space.center(); ! while (it.hasNext()) { ! Geometry.rotate(Math.PI / 2, ! 0, 0, 1, ! (Vertex)it.next(), ! center); ! } ! space.changed(); ! Project.getInstance().checkpoint(); ! } ! }; ! pm.add(flip); ! AbstractAction check = new SpaceMenuAction(s, "Check") { ! public void actionPerformed(ActionEvent arg0) { ! space.check(); ! } ! }; ! pm.add(check); ! pm.add(getTransformMenu(s)); ! JMenu mm = new JMenu("Modellors"); ! Collection c = Modellor.getRegisteredModellors(); ! Iterator iter = c.iterator(); ! while (iter.hasNext()) { ! Modellor m = (Modellor)iter.next(); ! AbstractAction modellor = new ModellorMenuAction(s, m) { public void actionPerformed(ActionEvent arg0) { ! Modellor created = modellor.newInstance(space); ! if (created != null) { ! space.setModellor(created); ! AttributeView.instance().display(created); ! space.changed(); ! } else { ! JOptionPane.showMessageDialog( ! null, ! "The chosen space havn't been assigned to any surface", ! "No envolope surface error", JOptionPane.ERROR_MESSAGE); ! } } }; ! mm.add(modellor); } - pm.add(mm); } return pm; --- 238,310 ---- }; pm.add(makeunion); ! ! if (s.size() == 1) { ! // Some options do only apply to one space ! Space sp = (Space)s.iterator().next(); ! if (((Space)s.iterator().next()).getLevel() < Space.PART_LEVEL) { ! AbstractAction edit = new SpaceMenuAction(sp, "Edit") { ! public void actionPerformed(ActionEvent arg0) { ! Selection.primary().clear(); ! Project.getInstance().setActiveSpace(space); ! } ! }; ! pm.add(edit); ! } ! AbstractAction envelope = new SpaceMenuAction(sp, "Compute Envelope") { public void actionPerformed(ActionEvent arg0) { ! if (space != null) { ! space.computeEnvelope(); ! Project.getInstance().changed(Project.getInstance()); ! Project.getInstance().checkpoint(); ! } } }; ! pm.add(envelope); ! AbstractAction flip = new SpaceMenuAction(sp, "Rotate 90 degrees CCW") { ! public void actionPerformed(ActionEvent arg0) { ! Iterator it = space.collect().iterator(); ! Vertex center = space.center(); ! while (it.hasNext()) { ! Geometry.rotate(Math.PI / 2, ! 0, 0, 1, ! (Vertex)it.next(), ! center); ! } ! space.changed(); Project.getInstance().checkpoint(); } ! }; ! pm.add(flip); ! AbstractAction check = new SpaceMenuAction(sp, "Check") { public void actionPerformed(ActionEvent arg0) { ! space.check(); } }; ! pm.add(check); ! pm.add(getTransformMenu(sp)); ! JMenu mm = new JMenu("Modellors"); ! Collection c = Modellor.getRegisteredModellors(); ! Iterator iter = c.iterator(); ! while (iter.hasNext()) { ! Modellor m = (Modellor)iter.next(); ! AbstractAction modellor = new ModellorMenuAction(sp, m) { ! public void actionPerformed(ActionEvent arg0) { ! Modellor created = modellor.newInstance(space); ! if (created != null) { ! space.setModellor(created); ! AttributeView.instance().display(created); ! space.changed(); ! } else { ! JOptionPane.showMessageDialog( ! null, ! "The chosen space havn't been assigned to any surface", ! "No envolope surface error", JOptionPane.ERROR_MESSAGE); ! } ! } ! }; ! mm.add(modellor); ! } ! pm.add(mm); } } return pm; *************** *** 243,260 **** */ public static JPopupMenu getEntityMenu(Entity e) { ! JPopupMenu pm = new JPopupMenu(); ! AbstractAction delete = new EntityMenuAction(e, "Delete") { ! public void actionPerformed(ActionEvent arg0) { ! if (entity != null) { ! entity.delete(); ! Selection.primary().clear(); ! Project.getInstance().changed(entity); ! Project.getInstance().checkpoint(); ! } ! } ! }; ! pm.add(delete); ! ! return pm; } --- 317,323 ---- */ public static JPopupMenu getEntityMenu(Entity e) { ! Collection c = new LinkedList(); ! c.add(e); ! return getEntiesMenu(c); } *************** *** 288,298 **** public void actionPerformed(ActionEvent arg0) { if (entities != null) { ! Iterator iter = entities.iterator(); while (iter.hasNext()) { ! ((Entity)iter.next()).delete(); } ! Project.getInstance().changed(Geometry.collect(entities)); ! Project.getInstance().checkpoint(); ! Selection.primary().clear(); } } --- 351,367 ---- public void actionPerformed(ActionEvent arg0) { if (entities != null) { ! Collection c = new LinkedList(); ! c.addAll(entities); ! Iterator iter = c.iterator(); ! Project p = Project.getInstance(); ! Selection.primary().clear(); while (iter.hasNext()) { ! Entity e = (Entity)iter.next(); ! e.delete(); ! p.changed(e); } ! p.changed(Geometry.collect(c)); ! p.checkpoint(); ! } } |