Search in sources :

Example 71 with GeneralPath

use of java.awt.geom.GeneralPath in project JMRI by JMRI.

the class PositionablePolygon method finishClone.

@Override
protected Positionable finishClone(PositionableShape pos) {
    GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
    path.append(getPathIterator(null), false);
    /*
         PathIterator iter = _shape.getPathIterator(null);
         float[] coord = new float[6];
         while (!iter.isDone()) {
         int type = iter.currentSegment(coord);
         switch (type) {
         case PathIterator.SEG_MOVETO:
         path.moveTo(coord[0], coord[1]);
         break;
         case PathIterator.SEG_LINETO:
         path.lineTo(coord[0], coord[1]);
         break;
         case PathIterator.SEG_QUADTO:
         path.quadTo(coord[0], coord[1], coord[2], coord[3]);
         break;
         case PathIterator.SEG_CUBICTO:
         path.curveTo(coord[0], coord[1], coord[2], coord[3], coord[4], coord[53]);
         break;
         case PathIterator.SEG_CLOSE:
         path.closePath();
         break;
         }
         }
         */
    pos.setShape(path);
    return super.finishClone(pos);
}
Also used : GeneralPath(java.awt.geom.GeneralPath)

Example 72 with GeneralPath

use of java.awt.geom.GeneralPath in project JMRI by JMRI.

the class PositionablePolygonXml method load.

/**
     * Create a PositionableShape, then add to a target JLayeredPane
     *
     * @param element Top level Element to unpack.
     * @param o       Editor as an Object
     */
@Override
public void load(Element element, Object o) {
    // create the objects
    Editor ed = (Editor) o;
    GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
    Element elem = element.getChild("path");
    float[] coord = new float[6];
    java.util.List<Element> list = elem.getChildren("vertex");
    for (int j = 0; j < list.size(); j++) {
        Element e = list.get(j);
        int type = getInt(e, "type");
        for (int i = 0; i < coord.length; i++) {
            coord[i] = getFloat(e, "idx" + i);
        }
        switch(type) {
            case PathIterator.SEG_MOVETO:
                path.moveTo(coord[0], coord[1]);
                break;
            case PathIterator.SEG_LINETO:
                path.lineTo(coord[0], coord[1]);
                break;
            case PathIterator.SEG_QUADTO:
                path.quadTo(coord[0], coord[1], coord[2], coord[3]);
                break;
            case PathIterator.SEG_CUBICTO:
                path.curveTo(coord[0], coord[1], coord[2], coord[3], coord[4], coord[5]);
                break;
            case PathIterator.SEG_CLOSE:
                path.closePath();
                break;
            default:
                log.warn("Unhandled type: {}", type);
                break;
        }
    }
    PositionablePolygon ps = new PositionablePolygon(ed, path);
    // get object class and determine editor being used
    ed.putItem(ps);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(ps, Editor.MARKERS, element);
}
Also used : GeneralPath(java.awt.geom.GeneralPath) Element(org.jdom2.Element) PositionablePolygon(jmri.jmrit.display.controlPanelEditor.shape.PositionablePolygon) Editor(jmri.jmrit.display.Editor)

Example 73 with GeneralPath

use of java.awt.geom.GeneralPath in project JMRI by JMRI.

the class PositionablePolygon method scale.

private GeneralPath scale(float ratioX, float ratioY) {
    //     log.info("scale("+ratioX+" , "+ratioY+")");
    GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
    PathIterator iter = getPathIterator(null);
    float[] coord = new float[6];
    while (!iter.isDone()) {
        int type = iter.currentSegment(coord);
        switch(type) {
            case PathIterator.SEG_MOVETO:
                path.moveTo(coord[0] * ratioX, coord[1] * ratioY);
                break;
            case PathIterator.SEG_LINETO:
                path.lineTo(coord[0] * ratioX, coord[1] * ratioY);
                break;
            case PathIterator.SEG_QUADTO:
                path.quadTo(coord[0], coord[1], coord[2], coord[3]);
                break;
            case PathIterator.SEG_CUBICTO:
                path.curveTo(coord[0], coord[1], coord[2], coord[3], coord[4], coord[5]);
                break;
            case PathIterator.SEG_CLOSE:
                path.closePath();
                break;
            default:
                log.warn("Unhandled path iterator type: {}", type);
                break;
        }
        //      log.debug("type= "+type+"  x= "+coord[0]+", y= "+ coord[1]);
        iter.next();
    }
    return path;
}
Also used : GeneralPath(java.awt.geom.GeneralPath) PathIterator(java.awt.geom.PathIterator) Point(java.awt.Point)

Example 74 with GeneralPath

use of java.awt.geom.GeneralPath in project JMRI by JMRI.

the class DrawPolygon method makePath.

/**
     * @param pt is "startPoint" the upper left corner of the figure
     */
private GeneralPath makePath(Point pt) {
    GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, _vertices.size() + 1);
    path.moveTo(_vertices.get(0).x - pt.x, _vertices.get(0).y - pt.y);
    for (int i = 1; i < _vertices.size(); i++) {
        path.lineTo(_vertices.get(i).x - pt.x, _vertices.get(i).y - pt.y);
    }
    return path;
}
Also used : GeneralPath(java.awt.geom.GeneralPath) Point(java.awt.Point)

Example 75 with GeneralPath

use of java.awt.geom.GeneralPath in project JMRI by JMRI.

the class DrawPolygon method drawShape.

protected void drawShape(Graphics g) {
    if (!_editing) {
        if (_vertices.size() == 0) {
            return;
        }
        Graphics2D g2d = (Graphics2D) g;
        _lineWidth = _lineSlider.getValue();
        BasicStroke stroke = new BasicStroke(_lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10f);
        g2d.setColor(_lineColor);
        g2d.setStroke(stroke);
        GeneralPath path = makePath(new Point(0, 0));
        path.lineTo(_curX, _curY);
        g2d.draw(path);
    }
}
Also used : BasicStroke(java.awt.BasicStroke) GeneralPath(java.awt.geom.GeneralPath) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D)

Aggregations

GeneralPath (java.awt.geom.GeneralPath)96 Point (java.awt.Point)14 AffineTransform (java.awt.geom.AffineTransform)14 PathIterator (java.awt.geom.PathIterator)14 Graphics2D (java.awt.Graphics2D)8 Rectangle2D (java.awt.geom.Rectangle2D)8 Color (java.awt.Color)7 Paint (java.awt.Paint)7 BasicStroke (java.awt.BasicStroke)6 Point2D (java.awt.geom.Point2D)6 Stroke (java.awt.Stroke)5 Area (java.awt.geom.Area)4 Shape (java.awt.Shape)3 CubicCurve2D (java.awt.geom.CubicCurve2D)3 LayoutPathImpl (sun.font.LayoutPathImpl)3 GradientPaint (java.awt.GradientPaint)2 Rectangle (java.awt.Rectangle)2 Line2D (java.awt.geom.Line2D)2 RoundRectangle2D (java.awt.geom.RoundRectangle2D)2 JBColor (com.intellij.ui.JBColor)1