001/* An attribute for displaying a note instead of a parameter value.
002
003 Copyright (c) 1998-2018 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 java.awt.Color;
031
032import ptolemy.actor.gui.PtolemyQuery;
033import ptolemy.kernel.util.IllegalActionException;
034import ptolemy.kernel.util.NameDuplicationException;
035import ptolemy.kernel.util.NamedObj;
036import ptolemy.kernel.util.Settable;
037import ptolemy.kernel.util.StringAttribute;
038
039///////////////////////////////////////////////////////////////////
040//// NoteStyle
041
042/**
043 This attribute displays a note instead of a parameter value.
044 This style can be used with any Settable attribute.
045
046 @see ptolemy.actor.gui.EditorPaneFactory
047 @see ParameterEditorStyle
048 @author Edward A. Lee
049 @version $Id$
050 @since Ptolemy II 11.0
051 @Pt.ProposedRating Yellow (eal)
052 @Pt.AcceptedRating Red (johnr)
053 */
054public class NoteStyle extends ParameterEditorStyle {
055
056    /** Construct an attribute with the specified container and name.
057     *  @param container The container.
058     *  @param name The name of the attribute.
059     *  @exception IllegalActionException If the attribute is not of an
060     *   acceptable attribute for the container, or if the container
061     *   is not an instance of Settable.
062     *  @exception NameDuplicationException If the name coincides with
063     *   an attribute already in the container.
064     */
065    public NoteStyle(NamedObj container, String name)
066            throws IllegalActionException, NameDuplicationException {
067        super(container, name);
068
069        note = new StringAttribute(this, "note");
070    }
071
072    ///////////////////////////////////////////////////////////////////
073    ////                         parameters                        ////
074
075    /** The note to display. */
076    public StringAttribute note;
077
078    ///////////////////////////////////////////////////////////////////
079    ////                         public methods                    ////
080
081    /** Return true if this style is acceptable for the given parameter.
082     *  @param param The attribute that this annotates.
083     *  @return True.
084     */
085    @Override
086    public boolean acceptable(Settable param) {
087        return true;
088    }
089
090    /** Create a new type-in line
091     *  entry in the given query associated with the
092     *  attribute containing this style.  The name of the entry is
093     *  the name of the attribute.  Attach the attribute to the created entry.
094     *
095     *  @param query The query into which to add the entry.
096     */
097    @Override
098    public void addEntry(PtolemyQuery query) {
099        Settable container = (Settable) getContainer();
100        String name = container.getName();
101        String noteValue = note.getExpression();
102        query.addDisplay(name, container.getDisplayName(), noteValue,
103                Color.YELLOW, Color.BLACK);
104        query.attachParameter(container, name);
105    }
106}