001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 */
021package org.biojava.bio.gui.glyph;
022
023import java.awt.Color;
024import java.awt.Graphics2D;
025import java.awt.Paint;
026import java.awt.geom.Rectangle2D;
027
028/**
029 * A Glyph that paints a rectangle shape within the bounds.
030 *
031 * @author Mark Southern
032 * @author <a href="mailto:andreas.draeger@uni-tuebingen.de>Andreas Dr&auml;ger</a>
033 * @since 1.5
034 */
035public class RectangleGlyph implements Glyph {
036        private Paint forePaint;
037        private Rectangle2D.Float bounds = new Rectangle2D.Float(0, 0, 0, 0);
038
039        public RectangleGlyph() {
040                forePaint = Color.RED.brighter();
041        }
042
043        public RectangleGlyph(Rectangle2D.Float bounds) {
044                this();
045                setBounds(bounds);
046        }
047
048        public RectangleGlyph(Paint paint) {
049                this.forePaint = paint;
050        }
051
052        public Rectangle2D.Float getBounds() {
053                return bounds;
054        }
055
056        public void setBounds(Rectangle2D.Float r) {
057                if (bounds.equals(r)) {
058                        return;
059                }
060
061                bounds = r;
062        }
063
064        public void render(Graphics2D g) {
065                g.setPaint(forePaint);
066                g.fill(bounds);
067        }
068
069        /**
070         *
071         * @return The currently set paint properties of this glyph.
072         */
073        public Paint getPaint() {
074                return forePaint;
075        }
076
077        /**
078         * Allows you to set the paint properties of this glyph, i.e., its color.
079         *
080         * @param forePaint
081         */
082        public void setPaint(Paint forePaint) {
083                this.forePaint = forePaint;
084        }
085}