001/*
002
003 Copyright (c) 2008-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 */
028
029package ptolemy.gui;
030
031import java.awt.Color;
032import java.awt.Component;
033import java.awt.event.ActionListener;
034
035import javax.swing.Box;
036import javax.swing.BoxLayout;
037import javax.swing.JLabel;
038
039/**
040 * Abstract superclass for customized entry boxes. Used to make protected
041 * methods of the <code>ptolemy.gui.Query</code> class available to derived
042 * classes outside the <code>ptolemy.gui</code> package.
043 *
044 * @author  fracpete (fracpete at waikato dot ac dot nz)
045@version $Id$
046@since Ptolemy II 8.0
047 * @version $Id$
048 */
049@SuppressWarnings("serial")
050public abstract class QueryChooser extends Box
051        implements SettableQueryChooser, ActionListener {
052
053    /**
054     * Initializes the chooser.
055     *
056     * @param owner       the owning query
057     * @param name        the name of the component
058     * @param background  the background color
059     * @param foreground  the foreground color
060     */
061    public QueryChooser(Query owner, String name, Color background,
062            Color foreground) {
063
064        super(BoxLayout.X_AXIS);
065
066        _owner = owner;
067        _name = name;
068        _background = background;
069        _foreground = foreground;
070    }
071
072    /**
073     * Returns the owning query object.
074     *
075     * @return            the query object
076     */
077    public Query getOwner() {
078        return _owner;
079    }
080
081    /**
082     * Returns the name of the component.
083     *
084     * @return            the name of the component
085     */
086    @Override
087    public String getName() {
088        return _name;
089    }
090
091    /**
092     * Returns the color for the background.
093     *
094     * @return            the background color
095     */
096    public Color getBackgroundColor() {
097        return _background;
098    }
099
100    /**
101     * Returns the color for the foreground.
102     *
103     * @return            the foreground color
104     */
105    public Color getForegroundColor() {
106        return _foreground;
107    }
108
109    /**
110     * Add a label and a widget to the panel.
111     *
112     * @param name        The name of the entry.
113     * @param label       The label.
114     * @param widget      The interactive entry to the right of the label.
115     * @param entry       The object that contains user data.
116     */
117    protected void _addPair(String name, JLabel label, Component widget,
118            Object entry) {
119        getOwner()._addPair(name, label, widget, entry);
120    }
121
122    /**
123     * Notify all registered listeners that something changed for the
124     * specified entry, if it indeed has changed.  The getStringValue()
125     * method is used to check the current value against the previously
126     * notified value, or the original value if there have been no
127     * notifications.
128     *
129     * @param name The entry that may have changed.
130     */
131    protected void _notifyListeners(String name) {
132        getOwner()._notifyListeners(name);
133    }
134
135    /** The owning query. */
136    private Query _owner;
137
138    /** The name of the chooser. */
139    private String _name;
140
141    /** The foreground color. */
142    private Color _foreground;
143
144    /** The background color. */
145    private Color _background;
146}