001/* An attribute for specifying that a parameter is edited with an entry line.
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.IllegalActionException;
032import ptolemy.kernel.util.NameDuplicationException;
033import ptolemy.kernel.util.NamedObj;
034import ptolemy.kernel.util.Settable;
035import ptolemy.kernel.util.Workspace;
036
037///////////////////////////////////////////////////////////////////
038//// LineStyle
039
040/**
041 This attribute annotates user settable attributes to specify
042 an arbitrary type-in line style for configuring the containing attribute.
043 This style can be used with any Settable attribute.
044
045 @see ptolemy.actor.gui.EditorPaneFactory
046 @see ParameterEditorStyle
047 @author Steve Neuendorffer
048 @version $Id$
049 @since Ptolemy II 1.0
050 @Pt.ProposedRating Red (eal)
051 @Pt.AcceptedRating Red (johnr)
052 */
053public class LineStyle extends ParameterEditorStyle {
054    /** Construct an attribute in the default workspace with an empty string
055     *  as its name.
056     *  The object is added to the directory of the workspace.
057     *  Increment the version number of the workspace.
058     */
059    public LineStyle() {
060        super();
061    }
062
063    /** Construct an attribute in the given workspace with an empty string
064     *  as its name.
065     *  The object is added to the directory of the workspace.
066     *  Increment the version number of the workspace.
067     *  @param workspace The workspace that will contain the attribute
068     *  that is being constructed.
069     */
070    public LineStyle(Workspace workspace) {
071        // This constructor is needed for Shallow codegen to work.
072        super(workspace);
073    }
074
075    /** Construct an attribute with the specified container and name.
076     *  @param container The container.
077     *  @param name The name of the attribute.
078     *  @exception IllegalActionException If the attribute is not of an
079     *   acceptable attribute for the container, or if the container
080     *   is not an instance of Settable.
081     *  @exception NameDuplicationException If the name coincides with
082     *   an attribute already in the container.
083     */
084    public LineStyle(NamedObj container, String name)
085            throws IllegalActionException, NameDuplicationException {
086        super(container, name);
087    }
088
089    ///////////////////////////////////////////////////////////////////
090    ////                         public methods                    ////
091
092    /** Return true if this style is acceptable for the given parameter.
093     *  @param param The attribute that this annotates.
094     *  @return True.
095     */
096    @Override
097    public boolean acceptable(Settable param) {
098        return true;
099    }
100
101    /** Create a new type-in line
102     *  entry in the given query associated with the
103     *  attribute containing this style.  The name of the entry is
104     *  the name of the attribute.  Attach the attribute to the created entry.
105     *
106     *  @param query The query into which to add the entry.
107     */
108    @Override
109    public void addEntry(PtolemyQuery query) {
110        Settable container = (Settable) getContainer();
111        String name = container.getName();
112        String defaultValue = "";
113        defaultValue = container.getExpression();
114        // Adjust the editability if the container is NOT_EDITABLE
115        // and _expertMode is not set.
116        if (query.adjustEditable(container, null)) {
117            query.addLine(name, container.getDisplayName(), defaultValue,
118                    PtolemyQuery.preferredBackgroundColor(container),
119                    PtolemyQuery.preferredForegroundColor(container));
120        } else {
121            // Treat this like a NotEditableLineDisplay
122            query.addDisplay(name, container.getDisplayName(), defaultValue);
123        }
124        query.attachParameter(container, name);
125    }
126}