001/* A top-level dialog window for configuring the breakpoints of an entity.
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.vergil.debugger;
028
029import java.awt.Frame;
030
031import ptolemy.actor.gui.QueryUtilities;
032import ptolemy.gui.ComponentDialog;
033import ptolemy.kernel.Entity;
034import ptolemy.util.MessageHandler;
035import ptolemy.vergil.basic.BasicGraphController;
036
037///////////////////////////////////////////////////////////////////
038//// BreakpointConfigurerDialog
039
040/**
041 A top-level dialog window for configuring the breakpoints of an
042 entity.  An instance of this class contains an instance of
043 BreakpointConfigurer.  The dialog is modal, so the statement that
044 creates the dialog will not return until the user dismisses the
045 dialog.
046
047 @see ptolemy.actor.gui.PortConfigurerDialog
048 @see BreakpointConfigurer
049
050 @author Elaine Cheong
051 @version $Id$
052 @since Ptolemy II 2.1
053 @Pt.ProposedRating Red (celaine)
054 @Pt.AcceptedRating Red (celaine)
055 */
056@SuppressWarnings("serial")
057public class BreakpointConfigurerDialog extends ComponentDialog {
058    /** Construct a dialog with the specified owner and target.
059     *  The dialog is placed relative to the owner.
060     *  @param owner The object that, per the user, appears to be
061     *   generating the dialog.
062     *  @param target The object whose breakpoints are being configured.
063     *  @param graphController The GraphController associated with the
064     *  target.
065     */
066    public BreakpointConfigurerDialog(Frame owner, Entity target,
067            BasicGraphController graphController) {
068        super(owner, "Configure breakpoints for " + target.getName(),
069                new BreakpointConfigurer(target, graphController),
070                _moreButtons);
071
072        // Once we get to here, the dialog has already been dismissed.
073        if (buttonPressed().equals("Help")) {
074            QueryUtilities.openHTMLResource(
075                    "ptolemy/vergil/debugger/breakpoints.htm", owner);
076        }
077    }
078
079    ///////////////////////////////////////////////////////////////////
080    ////                         protected methods                 ////
081
082    /** Apply the changes if the window is closed with anything but
083     *  Cancel.
084     */
085    @Override
086    protected void _handleClosing() {
087        super._handleClosing();
088
089        if (!buttonPressed().equals("Cancel")
090                && !buttonPressed().equals("Help")) {
091            try {
092                ((BreakpointConfigurer) contents).apply();
093            } catch (Throwable throwable) {
094                MessageHandler.error(
095                        "Failed to handle closing of breakpoint " + "dialog.",
096                        throwable);
097            }
098        }
099    }
100
101    ///////////////////////////////////////////////////////////////////
102    ////                         private variables                 ////
103    // Button labels.
104    private static String[] _moreButtons = { "OK", "Cancel", "Help" };
105}