001/*
002
003 Copyright (c) 2008-2009 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 */
028
029package ptolemy.gui;
030
031import java.awt.Container;
032import java.awt.Dialog;
033import java.awt.Frame;
034
035/**
036 * A little helper class for QueryChooser classes.
037 *
038 * @author  fracpete (fracpete at waikato dot ac dot nz)
039 * @version $Revision$
040 * @since Ptolemy II 8.0
041 * @Pt.ProposedRating Red (cxh)
042 * @Pt.AcceptedRating Red (cxh)
043 */
044public class QueryChooserHelper {
045
046    /**  Determine the parent of this frame.
047     *
048     * @param container        the container
049     * @return                the parent frame if one exists or null if not
050     */
051    public static Frame getParentFrame(Container container) {
052        Frame result;
053        Container parent;
054
055        result = null;
056
057        parent = container;
058        while (parent != null) {
059            if (parent instanceof Frame) {
060                result = (Frame) parent;
061                break;
062            } else {
063                parent = parent.getParent();
064            }
065        }
066
067        return result;
068    }
069
070    /**
071     * Determine the dialog of this frame.
072     *
073     * @param container        the container
074     * @return                the parent dialog if one exists or null if not
075     */
076    public static Dialog getParentDialog(Container container) {
077        Dialog result;
078        Container parent;
079
080        result = null;
081
082        parent = container;
083        while (parent != null) {
084            if (parent instanceof Dialog) {
085                result = (Dialog) parent;
086                break;
087            } else {
088                parent = parent.getParent();
089            }
090        }
091
092        return result;
093    }
094}