001/* A menu item factory that opens a dialog to rename an object. 002 003 Copyright (c) 1999-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.Component; 031import java.awt.Frame; 032import java.awt.event.ActionEvent; 033 034import javax.swing.AbstractAction; 035import javax.swing.Action; 036import javax.swing.JMenuItem; 037 038import diva.gui.toolbox.JContextMenu; 039import ptolemy.actor.gui.RenameDialog; 040import ptolemy.kernel.util.NamedObj; 041import ptolemy.vergil.toolbox.MenuItemFactory; 042 043/////////////////////////////////////////////////////////////////// 044//// RenameDialogFactory 045 046/** 047 A factory that creates a dialog to rename an object. 048 049 @deprecated Use RenameDialogAction instead. 050 @author Edward A. Lee and Steve Neuendorffer 051 @version $Id$ 052 @since Ptolemy II 2.0 053 @Pt.ProposedRating Red (eal) 054 @Pt.AcceptedRating Red (johnr) 055 */ 056@Deprecated 057public class RenameDialogFactory implements MenuItemFactory { 058 /////////////////////////////////////////////////////////////////// 059 //// public methods //// 060 061 /** Add an item to the given context menu that will open a dialog 062 * to add or remove ports from an object. 063 * @param menu The context menu. 064 * @param object The object whose ports are being manipulated. 065 * @return The JMenuItem or null if the object argument is not an 066 * Entity. 067 * 068 */ 069 @Override 070 public JMenuItem create(final JContextMenu menu, NamedObj object) { 071 String name = "Customize Name"; 072 073 // Removed this method since it was never used. EAL 074 // final NamedObj target = _getItemTargetFromMenuTarget(object); 075 final NamedObj target = object; 076 077 // ensure that we actually have a target. 078 if (target == null) { 079 return null; 080 } 081 082 @SuppressWarnings("serial") 083 Action action = new AbstractAction(name) { 084 @Override 085 public void actionPerformed(ActionEvent e) { 086 // Create a dialog for configuring the object. 087 // First, identify the top parent frame. 088 // Normally, this is a Frame, but just in case, we check. 089 // If it isn't a Frame, then the edit parameters dialog 090 // will not have the appropriate parent, and will disappear 091 // when put in the background. 092 Component parent = menu.getInvoker(); 093 094 while (parent.getParent() != null) { 095 parent = parent.getParent(); 096 } 097 098 if (parent instanceof Frame) { 099 new RenameDialog((Frame) parent, target); 100 } else { 101 new RenameDialog(null, target); 102 } 103 } 104 }; 105 106 return menu.add(action, name); 107 } 108}