001/* An action that opens a dialog to rename an object.
002
003 Copyright (c) 2006-2016 The Regents of the University of California.
004 All rights reserved.
005 Permission is hereby granted, without written agreement and without
006 license or royalty fees, to use, copy, modify, and distribute this
007 software and its documentation for any purpose, provided that the above
008 copyright notice and the following two paragraphs appear in all copies
009 of this software.
010
011 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
012 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
013 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
014 THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
015 SUCH DAMAGE.
016
017 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
018 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
019 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
020 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
021 CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
022 ENHANCEMENTS, OR MODIFICATIONS.
023
024 PT_COPYRIGHT_VERSION_2
025 COPYRIGHTENDKEY
026
027 */
028package ptolemy.vergil.kernel;
029
030import java.awt.Frame;
031import java.awt.event.ActionEvent;
032import java.awt.event.KeyEvent;
033
034import javax.swing.Action;
035import javax.swing.KeyStroke;
036
037import diva.gui.GUIUtilities;
038import ptolemy.actor.gui.RenameDialog;
039import ptolemy.actor.gui.TableauFrame;
040import ptolemy.kernel.util.NamedObj;
041import ptolemy.util.MessageHandler;
042import ptolemy.vergil.toolbox.FigureAction;
043
044///////////////////////////////////////////////////////////////////
045//// RenameDialogAction
046
047/**
048 An action that creates a dialog to rename an object.
049
050 @author Edward A. Lee and Steve Neuendorffer
051 @version $Id$
052 @since Ptolemy II 5.2
053 @Pt.ProposedRating Red (eal)
054 @Pt.AcceptedRating Red (johnr)
055 */
056@SuppressWarnings("serial")
057public class RenameDialogAction extends FigureAction {
058
059    /**
060     * Construct a rename dialog action with the specified parent, which will
061     * appear in the menu that uses this action.
062     *
063     * @param parent
064     *            The parent TableauFrame
065     */
066    public RenameDialogAction(TableauFrame parent) {
067        // FIXME: This constructor is probably not used, AttributeController
068        // calls the other constructor.
069        super("");
070        if (parent == null) {
071            IllegalArgumentException iae = new IllegalArgumentException(
072                    "ActorDialogAction constructor received NULL argument for TableauFrame");
073            iae.fillInStackTrace();
074            throw iae;
075        }
076        //this.parent = parent;
077
078        putValue(Action.NAME, DISPLAY_NAME);
079        // Findbugs was reporting that the Field was only ever set to null.
080        putValue(GUIUtilities.LARGE_ICON, null /*LARGE_ICON*/);
081        putValue("tooltip", TOOLTIP);
082
083        // Findbugs was reporting that the Field was only ever set to null.
084        //putValue(GUIUtilities.ACCELERATOR_KEY, ACCELERATOR_KEY);
085        putValue(GUIUtilities.ACCELERATOR_KEY,
086                KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0));
087    }
088
089    /** Construct a rename dialog action with the specified name,
090     *  which will appear in the menu that uses this action.
091     *  @param name The name.
092     */
093    public RenameDialogAction(String name) {
094        super(name);
095
096        putValue(GUIUtilities.ACCELERATOR_KEY,
097                KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0));
098    }
099
100    ///////////////////////////////////////////////////////////////////
101    ////                         public methods                    ////
102
103    /** Open a dialog to rename the target.
104     *  @param event The action event.
105     */
106    @Override
107    public void actionPerformed(ActionEvent event) {
108        try {
109            // Determine which entity was selected for the look inside action.
110            super.actionPerformed(event);
111            NamedObj target = getTarget();
112            if (target == null) {
113                return;
114            }
115            // Create a dialog for configuring the object.
116            // First, identify the top parent frame.
117            Frame parent = getFrame();
118            new RenameDialog(parent, target);
119        } catch (Throwable throwable) {
120            // Giotto code generator on giotto/demo/Hierarchy/Hierarchy.xml
121            // was throwing an exception here that was not being displayed
122            // in the UI.
123            MessageHandler.error(
124                    "Failed to open a dialog to rename the target.", throwable);
125        }
126    }
127
128    //private TableauFrame parent;
129    private static String DISPLAY_NAME = "Configure";
130    private static String TOOLTIP = "Change Settings for Actor";
131    //private static ImageIcon LARGE_ICON = null;
132    //private static KeyStroke ACCELERATOR_KEY = null;
133}