001/* A top-level dialog window for renaming objects. 002 003 Copyright (c) 1998-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 */ 027package ptolemy.actor.gui; 028 029import java.awt.Frame; 030 031import ptolemy.gui.ComponentDialog; 032import ptolemy.kernel.util.NamedObj; 033 034/////////////////////////////////////////////////////////////////// 035//// RenameDialog 036 037/** 038 This class is a modal dialog box for renaming an object. 039 The dialog is modal, so the statement that creates the dialog will 040 not return until the user dismisses the dialog. 041 042 @author Edward A. Lee 043 @version $Id$ 044 @since Ptolemy II 1.0 045 @Pt.ProposedRating Yellow (eal) 046 @Pt.AcceptedRating Red (eal) 047 */ 048@SuppressWarnings("serial") 049public class RenameDialog extends ComponentDialog { 050 /** Construct a dialog with the specified owner and target. 051 * The dialog is placed relative to the owner. 052 * @param owner The object that, per the user, appears to be 053 * generating the dialog, or null if none. 054 * @param target The object being renamed. 055 */ 056 public RenameDialog(Frame owner, NamedObj target) { 057 super(owner, "Rename " + target.getName(), new RenameConfigurer(target), 058 _buttons); 059 } 060 061 /////////////////////////////////////////////////////////////////// 062 //// protected methods //// 063 064 /** If the window is closed with anything but Cancel, apply the changes. 065 */ 066 @Override 067 protected void _handleClosing() { 068 super._handleClosing(); 069 070 if (!buttonPressed().equals("Cancel")) { 071 ((RenameConfigurer) contents).apply(); 072 } 073 } 074 075 /////////////////////////////////////////////////////////////////// 076 //// private variables //// 077 // Button labels. 078 private static String[] _buttons = { "Commit", "Cancel" }; 079}