Author: bobtarling Date: 2009-04-07 17:41:30-0700 New Revision: 17069 Added: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ActionBuilder.java Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/PopupMenuNewAction.java trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/PopupMenuNewEvent.java trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLStateDeferrableEventListModel.java trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLTransitionTriggerListModel.java
Log: Provide base class for PopupMenuNewAction and PopupMenuNewEvent Added: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ActionBuilder.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ActionBuilder.java?view=markup&pathrev=17069 ============================================================================== --- (empty file) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/ActionBuilder.java 2009-04-07 17:41:30-0700 @@ -0,0 +1,86 @@ +// $Id: PopupMenuNewEvent.java 15918 2008-10-14 06:40:41Z mvw $ +// Copyright (c) 1996-2008 The Regents of the University of California. All +// Rights Reserved. Permission to use, copy, modify, and distribute this +// software and its documentation without fee, and without a written +// agreement is hereby granted, provided that the above copyright notice +// and this paragraph appear in all copies. This software program and +// documentation are copyrighted by The Regents of the University of +// California. The software program and documentation are supplied "AS +// IS", without any accompanying services from The Regents. The Regents +// does not warrant that the operation of the program will be +// uninterrupted or error-free. The end-user understands that the program +// was developed for research purposes and is advised not to rely +// exclusively on the program for any reason. IN NO EVENT SHALL THE +// UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, +// SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, +// ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF +// THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF +// SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY +// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE +// PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF +// CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, +// UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + +package org.argouml.core.propertypanels.ui; + +import javax.swing.Action; +import javax.swing.JMenu; +import javax.swing.JMenuItem; +import javax.swing.JPopupMenu; + +import org.argouml.i18n.Translator; +import org.argouml.uml.ui.ActionRemoveModelElement; +import org.argouml.uml.ui.behavior.activity_graphs.ActionAddEventAsTrigger; +import org.argouml.uml.ui.behavior.common_behavior.ActionNewActionSequence; +import org.argouml.uml.ui.behavior.common_behavior.ActionNewCallAction; +import org.argouml.uml.ui.behavior.common_behavior.ActionNewCreateAction; +import org.argouml.uml.ui.behavior.common_behavior.ActionNewDestroyAction; +import org.argouml.uml.ui.behavior.common_behavior.ActionNewReturnAction; +import org.argouml.uml.ui.behavior.common_behavior.ActionNewSendAction; +import org.argouml.uml.ui.behavior.common_behavior.ActionNewTerminateAction; +import org.argouml.uml.ui.behavior.common_behavior.ActionNewUninterpretedAction; +import org.argouml.uml.ui.behavior.state_machines.ActionAddEventAsDeferrableEvent; +import org.argouml.uml.ui.behavior.state_machines.ActionNewCallEvent; +import org.argouml.uml.ui.behavior.state_machines.ActionNewChangeEvent; +import org.argouml.uml.ui.behavior.state_machines.ActionNewEvent; +import org.argouml.uml.ui.behavior.state_machines.ActionNewSignalEvent; +import org.argouml.uml.ui.behavior.state_machines.ActionNewTimeEvent; + +/** + * @since Dec 15, 2002 + * @author [email protected] + */ +class ActionBuilder extends JPopupMenu { + + void buildMenu( + final JPopupMenu pmenu, + final String role, + final Object target, + String label, + Object[] actions) { + + JMenu newMenu = new JMenu(); + newMenu.setText(Translator.localize(label)); + + for (Object action : actions) { + if (action == null) { + pmenu.addSeparator(); + } else if (action instanceof String) { + label = (String) action; + } else if (action instanceof Action) { + pmenu.add((Action) action); + } else { + JMenu innerMenu = new JMenu(Translator.localize(label)); + for (Object innerAction : (Object[]) action) { + if (innerAction == null) { + innerMenu.addSeparator(); + } else if (innerAction instanceof Action) { + innerMenu.add((Action) innerAction); + } + } + pmenu.add(innerMenu); + } + } + } +} Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/PopupMenuNewAction.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/PopupMenuNewAction.java?view=diff&pathrev=17069&r1=17068&r2=17069 ============================================================================== --- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/PopupMenuNewAction.java (original) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/PopupMenuNewAction.java 2009-04-07 17:41:30-0700 @@ -25,8 +25,6 @@ package org.argouml.core.propertypanels.ui; import javax.swing.Action; -import javax.swing.JMenu; -import javax.swing.JPopupMenu; import org.argouml.i18n.Translator; import org.argouml.uml.ui.ActionRemoveModelElement; @@ -45,7 +43,7 @@ * @since Dec 15, 2002 * @author [email protected] */ -class PopupMenuNewAction extends JPopupMenu { +class PopupMenuNewAction extends ActionBuilder { private static final Object[] actions = new Object[] { @@ -72,40 +70,12 @@ * @param role the role * @param list the list */ - public PopupMenuNewAction(String role, UMLMutableLinkedList list) { + PopupMenuNewAction(String role, UMLMutableLinkedList list) { super(); - buildMenu(this, role, list.getTarget()); - } - - public void buildMenu(JPopupMenu pmenu, - String role, Object target) { - - init(role, target); + init(role, list.getTarget()); - JMenu newMenu = new JMenu(); - newMenu.setText(Translator.localize("action.new")); - - String label = null; - for (Object action : actions) { - if (action == null) { - pmenu.addSeparator(); - } else if (action instanceof String) { - label = (String) action; - } else if (action instanceof Action) { - pmenu.add((Action) action); - } else { - JMenu innerMenu = new JMenu(Translator.localize(label)); - for (Object innerAction : (Object[]) action) { - if (innerAction == null) { - innerMenu.addSeparator(); - } else if (innerAction instanceof Action) { - innerMenu.add((Action) innerAction); - } - } - pmenu.add(innerMenu); - } - } + buildMenu(this, role, list.getTarget(), "action.new", actions); } private void init( Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/PopupMenuNewEvent.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/PopupMenuNewEvent.java?view=diff&pathrev=17069&r1=17068&r2=17069 ============================================================================== --- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/PopupMenuNewEvent.java (original) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/PopupMenuNewEvent.java 2009-04-07 17:41:30-0700 @@ -25,8 +25,6 @@ package org.argouml.core.propertypanels.ui; import javax.swing.Action; -import javax.swing.JMenu; -import javax.swing.JMenuItem; import javax.swing.JPopupMenu; import org.argouml.i18n.Translator; @@ -43,13 +41,42 @@ * @since Dec 15, 2002 * @author [email protected] */ -class PopupMenuNewEvent extends JPopupMenu { +class PopupMenuNewEvent extends ActionBuilder { /** * The UID. */ private static final long serialVersionUID = -7624618103144695448L; + private static final Object[] dtactions = new Object[] { + "action.select", + new Object[] { + ActionAddEventAsDeferrableEvent.SINGLETON, + ActionAddEventAsTrigger.SINGLETON, + }, + "action.new", + new Object[] { + ActionNewCallEvent.getSingleton(), + ActionNewChangeEvent.getSingleton(), + ActionNewSignalEvent.getSingleton(), + ActionNewTimeEvent.getSingleton(), + }, + null, + ActionRemoveModelElement.SINGLETON + }; + + private static final Object[] actions = new Object[] { + "action.new", + new Object[] { + ActionNewCallEvent.getSingleton(), + ActionNewChangeEvent.getSingleton(), + ActionNewSignalEvent.getSingleton(), + ActionNewTimeEvent.getSingleton(), + }, + null, + ActionRemoveModelElement.SINGLETON + }; + /** * Constructor for PopupMenuNewEvent.<p> * @@ -64,10 +91,14 @@ PopupMenuNewEvent(String role, Object target) { super(); - buildMenu(this, role, target); + buildMenu(this, role, target, "action.new"); } - void buildMenu(JPopupMenu pmenu, String role, Object target) { + void buildMenu( + final JPopupMenu pmenu, + final String role, + final Object target, + String label) { assert role != null; assert target != null; @@ -76,31 +107,10 @@ if (role.equals(ActionNewEvent.Roles.DEFERRABLE_EVENT) || role.equals(ActionNewEvent.Roles.TRIGGER)) { - JMenu selectMenu = new JMenu(Translator.localize("action.select")); - if (role.equals(ActionNewEvent.Roles.DEFERRABLE_EVENT)) { - JMenuItem menuItem = new JMenuItem( - ActionAddEventAsDeferrableEvent.SINGLETON); - selectMenu.add(menuItem); - } else if (role.equals(ActionNewEvent.Roles.TRIGGER)) { - selectMenu.add(ActionAddEventAsTrigger.SINGLETON); - } - pmenu.add(selectMenu); + buildMenu(pmenu, role, target, label, dtactions); + } else { + buildMenu(pmenu, role, target, label, actions); } - - JMenu newMenu = new JMenu(Translator.localize("action.new")); - newMenu.add(ActionNewCallEvent.getSingleton()); - newMenu.add(ActionNewChangeEvent.getSingleton()); - newMenu.add(ActionNewSignalEvent.getSingleton()); - newMenu.add(ActionNewTimeEvent.getSingleton()); - pmenu.add(newMenu); - - pmenu.addSeparator(); - - ActionRemoveModelElement.SINGLETON.setObjectToRemove( - ActionNewEvent.getAction(role, target)); - ActionRemoveModelElement.SINGLETON.putValue(Action.NAME, - Translator.localize("action.delete-from-model")); - pmenu.add(ActionRemoveModelElement.SINGLETON); } private static void init( Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLStateDeferrableEventListModel.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLStateDeferrableEventListModel.java?view=diff&pathrev=17069&r1=17068&r2=17069 ============================================================================== --- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLStateDeferrableEventListModel.java (original) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLStateDeferrableEventListModel.java 2009-04-07 17:41:30-0700 @@ -64,7 +64,7 @@ new PopupMenuNewEvent(ActionNewEvent.Roles.DEFERRABLE_EVENT, getTarget()); menu.buildMenu(popup, - ActionNewEvent.Roles.DEFERRABLE_EVENT, getTarget());; + ActionNewEvent.Roles.DEFERRABLE_EVENT, getTarget(), "action.new");; return true; } Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLTransitionTriggerListModel.java Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLTransitionTriggerListModel.java?view=diff&pathrev=17069&r1=17068&r2=17069 ============================================================================== --- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLTransitionTriggerListModel.java (original) +++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLTransitionTriggerListModel.java 2009-04-07 17:41:30-0700 @@ -64,7 +64,7 @@ new PopupMenuNewEvent(ActionNewEvent.Roles.TRIGGER, getTarget()); menu.buildMenu(popup, - ActionNewEvent.Roles.TRIGGER, getTarget());; + ActionNewEvent.Roles.TRIGGER, getTarget(), "action.new"); return true; } ------------------------------------------------------ http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=1586904 To unsubscribe from this discussion, e-mail: [[email protected]].
