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