001/*
002 *    $RCSfile$
003 *
004 *     $Author: crawl $
005 *       $Date: 2014-08-26 00:46:48 +0000 (Tue, 26 Aug 2014) $
006 *   $Revision: 32920 $
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.geom.RectangularShape;
035
036import javax.swing.SwingUtilities;
037
038import org.apache.commons.logging.Log;
039import org.apache.commons.logging.LogFactory;
040
041import diva.canvas.CompositeFigure;
042
043/**
044 * A base class for some of the offered figures.
045 * 
046 * @author Carlos Rueda
047 * @version $Id: BaseFigure.java 32920 2014-08-26 00:46:48Z crawl $
048 */
049public abstract class BaseFigure extends CompositeFigure {
050
051        /**
052         * Two possible orientations for a monitor figure. Orientation may be
053         * meaningless for certain figures.
054         */
055        public enum Orientation {
056                HORIZONTAL, VERTICAL
057        };
058
059        /**
060         * Updates the GUI according to the current state of this monitor. It calls
061         * _update on the AWT event thread.
062         */
063        public void update() {
064                _lastUpdate = System.currentTimeMillis();
065                Runnable doSet = new Runnable() {
066                        @Override
067            public void run() {
068                                _update();
069                        }
070                };
071                SwingUtilities.invokeLater(doSet);
072        }
073
074        /**
075         * @return the orientation
076         */
077        public Orientation getOrientation() {
078                return _orientation;
079        }
080
081        /**
082         * It only sets the orientation indicator.
083         * 
084         * @param orientation
085         *            the orientation.
086         */
087        public void setOrientation(Orientation orientation) {
088                this._orientation = orientation;
089        }
090
091        // /////////////////////////////////////////////////////////////////
092        // // protected members ////
093
094        protected BaseFigure(RectangularShape shape) {
095                this._shape = (RectangularShape) shape.clone();
096        }
097
098        /**
099         * A subclass implements this method to do the actual update of the this
100         * figure. This method is called by {@link #update()} on the AWT event
101         * thread.
102         */
103        protected abstract void _update();
104
105        /** Arbitrarily initialized to {@link Orientation.HORIZONTAL}. */
106        protected Orientation _orientation = Orientation.HORIZONTAL;
107
108        /** The shape associated with the figure */
109        protected RectangularShape _shape;
110
111        /** The last time {@link #update()} was called. */
112        protected long _lastUpdate = 0;
113
114        protected static final Log log = LogFactory.getLog(BaseFigure.class);
115        protected static final boolean isDebugging = log.isDebugEnabled();
116
117}