001/* An attribute for specifying how a parameter is edited.
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
027 */
028package ptolemy.actor.gui.style;
029
030import ptolemy.actor.gui.PtolemyQuery;
031import ptolemy.kernel.util.Attribute;
032import ptolemy.kernel.util.IllegalActionException;
033import ptolemy.kernel.util.NameDuplicationException;
034import ptolemy.kernel.util.NamedObj;
035import ptolemy.kernel.util.Settable;
036import ptolemy.kernel.util.Workspace;
037
038///////////////////////////////////////////////////////////////////
039//// ParameterEditorStyle
040
041/**
042 This attribute annotates user settable attributes to specify the style
043 used for configuring the containing attribute.
044 The EditorPaneFactory class uses concrete subclasses
045 of this base class as a strategy pattern for creating entries in
046 an interactive parameter editor.  This class expects that the container
047 will implement the Settable interface.
048
049 @see ptolemy.actor.gui.EditorPaneFactory
050 @see Settable
051 @author Steve Neuendorffer and Edward A. Lee
052 @version $Id$
053 @since Ptolemy II 1.0
054 @Pt.ProposedRating Green (neuendor)
055 @Pt.AcceptedRating Yellow (neuendor)
056 */
057public abstract class ParameterEditorStyle extends Attribute {
058    /** Construct an attribute in the default workspace with an empty string
059     *  as its name.
060     *  The object is added to the directory of the workspace.
061     *  Increment the version number of the workspace.
062     */
063    public ParameterEditorStyle() {
064        super();
065    }
066
067    /** Construct an attribute in the given workspace with an empty string
068     *  as its name.
069     *  The object is added to the directory of the workspace.
070     *  Increment the version number of the workspace.
071     *  @param workspace The workspace that will contain the attribute
072     *  that is being constructed.
073     */
074    public ParameterEditorStyle(Workspace workspace) {
075        super(workspace);
076    }
077
078    /** Construct an attribute with the specified container and name.
079     *  @param container The container.
080     *  @param name The name of the attribute.
081     *  @exception IllegalActionException If the attribute is not of an
082     *   acceptable attribute for the container, or if the container
083     *   is not an instance of Settable.
084     *  @exception NameDuplicationException If the name coincides with
085     *   an attribute already in the container.
086     */
087    public ParameterEditorStyle(NamedObj container, String name)
088            throws IllegalActionException, NameDuplicationException {
089        super(container, name);
090    }
091
092    ///////////////////////////////////////////////////////////////////
093    ////                         public methods                    ////
094
095    /** Return true if this style is acceptable for the given parameter.
096     *  For instance, a check box style would return true if the
097     *  argument was a Parameter that contained a boolean token.
098     *  @param param The attribute that this annotates.
099     *  @return True if this style is acceptable.
100     */
101    public abstract boolean acceptable(Settable param);
102
103    /** Create a new entry in the given query associated with the
104     *  attribute containing this style.  The name of the entry should be
105     *  the name of the attribute.  The attribute should be attached to
106     *  the entry so that changes in its value are reflected in the
107     *  query.
108     *
109     *  @param query The query into which to add the entry.
110     *  @exception IllegalActionException If the containing attribute
111     *   has a value that cannot be edited using this style.
112     */
113    public abstract void addEntry(PtolemyQuery query)
114            throws IllegalActionException;
115
116    /** Override the base class to first check that the container is
117     *  an instance of Settable.
118     *  @param container The container to attach this attribute to.
119     *  @exception IllegalActionException If this attribute is not of the
120     *   expected class for the container, or it has no name,
121     *   or the attribute and container are not in the same workspace, or
122     *   the proposed container would result in recursive containment, or
123     *   the proposed container is not an instance of Settable.
124     *  @exception NameDuplicationException If the container already has
125     *   an attribute with the name of this attribute.
126     */
127    @Override
128    public void setContainer(NamedObj container)
129            throws IllegalActionException, NameDuplicationException {
130        // We want this check, but here is not the place.
131        //     if (container != null && !(container instanceof Settable)) {
132        //    throw new IllegalActionException(this, container,
133        //            "ParameterEditorStyle can only be "
134        //            + "contained by Settable.");
135        // }
136        super.setContainer(container);
137    }
138}