001/*
002 *    $RCSfile$
003 *
004 *     $Author: welker $
005 *       $Date: 2010-05-06 05:21:26 +0000 (Thu, 06 May 2010) $
006 *   $Revision: 24234 $
007 *
008 *  For Details: http://kepler-project.org
009 *
010 * Copyright (c) 2007 The Regents of the University of California.
011 * All rights reserved.
012 *
013 * Permission is hereby granted, without written agreement and without
014 * license or royalty fees, to use, copy, modify, and distribute this
015 * software and its documentation for any purpose, provided that the
016 * above copyright notice and the following two paragraphs appear in
017 * all copies of this software.
018 *
019 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
020 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
021 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
022 * IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY
023 * OF SUCH DAMAGE.
024 *
025 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
026 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
027 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
028 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY
029 * OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
030 * UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
031 */
032package org.kepler.monitor.figure;
033
034import java.awt.Color;
035import java.awt.geom.RectangularShape;
036import java.util.HashMap;
037import java.util.Map;
038
039/**
040 * A figure with a current state.
041 * 
042 * @author Carlos Rueda
043 * @version $Id: StateFigure.java 24234 2010-05-06 05:21:26Z welker $
044 */
045public abstract class StateFigure extends BaseFigure {
046
047        /**
048         * Sets the color scheme for a state.
049         * 
050         * @param state
051         *            the state
052         * @param colors
053         *            the color scheme
054         */
055        public void addColorScheme(Object state, Color[] colors) {
056                _stateColors.put(state, colors);
057        }
058
059        /**
060         * Returns the color scheme associated with a state.
061         * 
062         * @param state
063         *            the state
064         * @return color scheme
065         */
066        public Color[] getColorScheme(Object state) {
067                return _stateColors.get(state);
068        }
069
070        /**
071         * Sets the current state of this figure. Does nothing if the state is equal
072         * to the current state.
073         * 
074         * @param state
075         *            the new state.
076         * 
077         * @throw IllegalArgumentException If the state is not recognized.
078         */
079        public void setState(Object state) {
080                if (!_stateColors.keySet().contains(state)) {
081                        throw new IllegalArgumentException("State '" + state
082                                        + "' has not been associated");
083                }
084                if (_currentState == state) {
085                        return;
086                }
087
088                _currentState = state;
089
090                update();
091        }
092
093        // /////////////////////////////////////////////////////////////////
094        // // protected members ////
095
096        protected StateFigure(RectangularShape shape) {
097                super(shape);
098        }
099
100        /** Current state associated with this monitor. null by default */
101        protected Object _currentState;
102
103        protected Map<Object, Color[]> _stateColors = new HashMap<Object, Color[]>();
104
105}