001/* The icon for groups representing design patterns.
002
003 Copyright (c) 2008-2016 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.icon;
029
030import java.awt.Color;
031
032import javax.swing.Icon;
033
034import diva.canvas.CompositeFigure;
035import diva.canvas.toolbox.BasicRectangle;
036import diva.gui.toolbox.FigureIcon;
037import ptolemy.kernel.util.IllegalActionException;
038import ptolemy.kernel.util.NameDuplicationException;
039import ptolemy.kernel.util.NamedObj;
040
041//////////////////////////////////////////////////////////////////////////
042//// GroupIcon
043
044/**
045 The icon for groups representing design patterns.
046
047 @author Thomas Huining Feng
048 @version $Id$
049 @since Ptolemy II 8.0
050 @Pt.ProposedRating Red (tfeng)
051 @Pt.AcceptedRating Red (tfeng)
052 */
053public class DesignPatternIcon extends NameIcon {
054
055    /** Create a new icon with the given name in the given container.
056     *  The container is required to implement Settable, or an exception
057     *  will be thrown.
058     *  @param container The container for this attribute.
059     *  @param name The name of this attribute.
060     *  @exception IllegalActionException If thrown by the parent
061     *  class or while setting an attribute.
062     *  @exception NameDuplicationException If the name coincides with
063     *   an attribute already in the container.
064     */
065    public DesignPatternIcon(NamedObj container, String name)
066            throws NameDuplicationException, IllegalActionException {
067        super(container, name);
068    }
069
070    /** Create an icon.
071     *
072     *  @return The icon.
073     */
074    @Override
075    public Icon createIcon() {
076        if (_iconCache != null) {
077            return _iconCache;
078        }
079
080        BasicRectangle figure1 = new BasicRectangle(0, 0, 15, 10,
081                Color.darkGray, 1.0f);
082        BasicRectangle figure2 = new BasicRectangle(2, 2, 15, 10, Color.gray,
083                1.0f);
084        BasicRectangle figure3 = new BasicRectangle(5, 5, 15, 10, _getFill(),
085                1.0f);
086        CompositeFigure figure = new CompositeFigure();
087        figure.add(figure1);
088        figure.add(figure2);
089        figure.add(figure3);
090
091        _iconCache = new FigureIcon(figure, 20, 15);
092        return _iconCache;
093    }
094
095    /** The cached Swing icon. */
096    //protected Icon _iconCache = null;
097}