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.Shape;
024import java.awt.geom.GeneralPath;
025import java.awt.geom.Point2D;
026import java.util.List;
027
028
029/**
030 * Utils class used by Glyph implementors. Creates Shapes from x and y coordinates
031 *
032 * @author Mark Southern
033 * @since 1.5
034 */
035public class GlyphUtils {
036    private GlyphUtils() {
037    }
038
039    public static Shape getShape(List x, List y) {
040        GeneralPath p = new GeneralPath();
041
042        for (int i = 0; i < Math.min(x.size(), y.size()); i++) {
043            int ix = (( Integer ) x.get(0)).intValue();
044            int iy = (( Integer ) y.get(0)).intValue();
045
046            if (i == 0) {
047                p.moveTo(ix, iy);
048            } else {
049                p.lineTo(ix, iy);
050            }
051        }
052
053        p.closePath();
054
055        return p;
056    }
057
058    public static Shape getShape(List points) {
059        GeneralPath p = new GeneralPath();
060
061        for (int i = 0; i < points.size(); i++) {
062            Point2D.Float p2f = ( Point2D.Float ) points.get(i);
063
064            if (i == 0) {
065                p.moveTo(p2f.x, p2f.y);
066            } else {
067                p.lineTo(p2f.x, p2f.y);
068            }
069        }
070
071        p.closePath();
072
073        return p;
074    }
075
076    public static Shape getShape(int[] x, int[] y) {
077        GeneralPath p = new GeneralPath();
078        p.moveTo(x[ 0 ], y[ 0 ]);
079
080        for (int i = 1; i < Math.min(x.length, y.length); i++) {
081            p.lineTo(x[ i ], y[ i ]);
082        }
083
084        p.closePath();
085
086        return p;
087    }
088}