001/* An action that opens a dialog for configuring units.
002
003 Copyright (c) 2006-2014 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.unit;
029
030import java.awt.Frame;
031import java.awt.event.ActionEvent;
032
033import ptolemy.actor.gui.Configuration;
034import ptolemy.actor.gui.DialogTableau;
035import ptolemy.actor.gui.TableauFrame;
036import ptolemy.kernel.Entity;
037import ptolemy.kernel.util.NamedObj;
038import ptolemy.util.MessageHandler;
039import ptolemy.vergil.toolbox.FigureAction;
040
041///////////////////////////////////////////////////////////////////
042//// ConfigureUnitsAction
043
044/**
045 An action that creates a dialog to configure units.
046
047 @author Edward A. Lee and Steve Neuendorffer
048 @version $Id$
049 @since Ptolemy II 8.0
050 @Pt.ProposedRating Red (eal)
051 @Pt.AcceptedRating Red (johnr)
052 */
053@SuppressWarnings("serial")
054public class ConfigureUnitsAction extends FigureAction {
055
056    /** Construct a rename dialog action with the specified name,
057     *  which will appear in the menu that uses this action.
058     *  @param name The name.
059     */
060    public ConfigureUnitsAction(String name) {
061        super(name);
062    }
063
064    ///////////////////////////////////////////////////////////////////
065    ////                         public methods                    ////
066
067    /** Open a dialog to rename the target.
068     *  @param event The action event.
069     */
070    @Override
071    public void actionPerformed(ActionEvent event) {
072        try {
073            // Determine which entity was selected for the look inside action.
074            super.actionPerformed(event);
075            NamedObj target = getTarget();
076            if (target == null) {
077                return;
078            }
079            // Create a dialog for configuring the object.
080            // First, identify the top parent frame.
081            Frame parent = getFrame();
082            DialogTableau dialogTableau = DialogTableau.createDialog(parent,
083                    _configuration, ((TableauFrame) parent).getEffigy(),
084                    UnitConstraintsDialog.class, (Entity) target);
085
086            if (dialogTableau != null) {
087                dialogTableau.show();
088            }
089        } catch (Throwable throwable) {
090            // Giotto code generator on giotto/demo/Hierarchy/Hierarchy.xml
091            // was throwing an exception here that was not being displayed
092            // in the UI.
093            MessageHandler.error(
094                    "Failed to open a dialog to configure the ports the target.",
095                    throwable);
096        }
097    }
098
099    /** Set the configuration for use by the help screen.
100     *  @param configuration The configuration.
101     */
102    public void setConfiguration(Configuration configuration) {
103        _configuration = configuration;
104    }
105
106    ///////////////////////////////////////////////////////////////////
107    ////                         private variables                 ////
108
109    private Configuration _configuration;
110}