001/* An attribute with a reference to an ellipse.
002
003 Copyright (c) 2003-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.vergil.kernel.attributes;
029
030import java.awt.Shape;
031import java.awt.geom.Ellipse2D;
032
033import ptolemy.kernel.util.IllegalActionException;
034import ptolemy.kernel.util.NameDuplicationException;
035import ptolemy.kernel.util.NamedObj;
036import ptolemy.kernel.util.Workspace;
037
038///////////////////////////////////////////////////////////////////
039//// EllipseAttribute
040
041/**
042 <p>This is an attribute that is rendered as an ellipse.
043 Unlike the base class, by default, an ellipse is centered on its origin.</p>
044
045 @author Edward A. Lee
046 @version $Id$
047 @since Ptolemy II 4.0
048 @Pt.ProposedRating Yellow (eal)
049 @Pt.AcceptedRating Red (cxh)
050 */
051public class EllipseAttribute extends FilledShapeAttribute {
052    /** Construct an attribute with the given name contained by the
053     *  specified container. The container argument must not be null, or a
054     *  NullPointerException will be thrown.  This attribute will use the
055     *  workspace of the container for synchronization and version counts.
056     *  If the name argument is null, then the name is set to the empty
057     *  string. Increment the version of the workspace.
058     *  @param container The container.
059     *  @param name The name of this attribute.
060     *  @exception IllegalActionException If the attribute is not of an
061     *   acceptable class for the container, or if the name contains a period.
062     *  @exception NameDuplicationException If the name coincides with
063     *   an attribute already in the container.
064     */
065    public EllipseAttribute(NamedObj container, String name)
066            throws IllegalActionException, NameDuplicationException {
067        super(container, name);
068
069        // NOTE: This used to be calling setExpression(), but the change
070        // does not take effect when the icon is created.
071        centered.setToken("true");
072    }
073
074    ///////////////////////////////////////////////////////////////////
075    ////                         public methods                    ////
076
077    /** Clone the object into the specified workspace. The new object is
078     *  <i>not</i> added to the directory of that workspace (you must do this
079     *  yourself if you want it there).
080     *  The result is an object with no container.
081     *  @param workspace The workspace for the cloned object.
082     *  @exception CloneNotSupportedException Not thrown in this base class
083     *  @return The new Attribute.
084     */
085    @Override
086    public Object clone(Workspace workspace) throws CloneNotSupportedException {
087        EllipseAttribute newObject = (EllipseAttribute) super.clone(workspace);
088
089        // The cloned icon ends up referring to the clonee's shape.
090        // We need to fix that here. Do not use the _newShape() method
091        // of the clone, however, because it may refer to parameters that
092        // have not been created yet. Instead, use this object to generate
093        // the new shape for the clone.
094        newObject._icon.setShape(_newShape());
095        return newObject;
096    }
097
098    ///////////////////////////////////////////////////////////////////
099    ////                         protected methods                 ////
100
101    /** Return a circle.
102     *  @return A Circle.
103     */
104    @Override
105    protected Shape _getDefaultShape() {
106        return new Ellipse2D.Double(0.0, 0.0, 20.0, 20.0);
107    }
108
109    /** Return the a new ellipse given a new width and height.
110     *  @return A new shape.
111     */
112    @Override
113    protected Shape _newShape() {
114        return new Ellipse2D.Double(0.0, 0.0, _widthValue, _heightValue);
115    }
116}