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);
}
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);
}
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;
}
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;
}
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);
}
}
Aggregations