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.BasicStroke;
024import java.awt.Color;
025import java.awt.Graphics2D;
026import java.awt.Paint;
027import java.awt.Shape;
028import java.awt.Stroke;
029import java.awt.geom.GeneralPath;
030import java.awt.geom.Rectangle2D;
031
032
033/**
034 * A Glyph that paints a wide 'H' line within the bounds
035 *
036 * @author Mark Southern
037 * @since 1.5
038 */
039public class TurnGlyph implements Glyph {
040    private Paint forePaint;
041    private Stroke stroke;
042    private Rectangle2D.Float bounds = new Rectangle2D.Float(0, 0, 0, 0);
043    private Shape turnShape;
044
045    public TurnGlyph() {
046        forePaint = Color.YELLOW.darker();
047        stroke = new BasicStroke(4f);
048    }
049
050    public TurnGlyph(Rectangle2D.Float bounds) {
051        this();
052        setBounds(bounds);
053    }
054
055    public TurnGlyph(Paint paint, Stroke stroke) {
056        this.forePaint = paint;
057        this.stroke = stroke;
058    }
059
060    public Rectangle2D.Float getBounds() {
061        return bounds;
062    }
063
064    public void setBounds(Rectangle2D.Float r) {
065        if (bounds.equals(r)) {
066            return;
067        }
068
069        bounds = r;
070
071        float q1 = r.height * 0.25F;
072        float q2 = r.height * 0.5F;
073        float q3 = r.height * 0.75F;
074
075        GeneralPath p = new GeneralPath();
076        p.moveTo(r.x, r.y + q3);
077        p.lineTo(r.x, r.y + q1);
078        p.lineTo(r.x, r.y + q2);
079        p.lineTo(r.x + r.width, r.y + q2);
080        p.lineTo(r.x + r.width, r.y + q1);
081        p.lineTo(r.x + r.width, r.y + q3);
082        turnShape = p;
083    }
084
085    public void render(Graphics2D g) {
086        if (turnShape != null) {
087            g.setStroke(stroke);
088            g.setPaint(forePaint);
089            g.draw(turnShape);
090        }
091    }
092
093    /**
094     *
095     * @return The currently set paint properties of this glyph.
096     */
097        public Paint getPaint() {
098                return forePaint;
099        }
100
101        /**
102         * Allows you to set the paint properties of this glyph, i.e., its color.
103         * @param forePaint
104         */
105        public void setPaint(Paint forePaint) {
106                this.forePaint = forePaint;
107        }
108}