Search in sources :

Example 1 with PositionablePolygon

use of jmri.jmrit.display.controlPanelEditor.shape.PositionablePolygon in project JMRI by JMRI.

the class PositionablePolygonXml method store.

/**
     * Default implementation for storing the contents of a PositionableShape
     *
     * @param o Object to store, of type PositionableShape
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    PositionablePolygon p = (PositionablePolygon) o;
    if (!p.isActive()) {
        // if flagged as inactive, don't store
        return null;
    }
    Element element = new Element("positionablePolygon");
    storeCommonAttributes(p, element);
    element.addContent(storePath(p));
    element.setAttribute("class", "jmri.jmrit.display.controlPanelEditor.shape.configurexml.PositionablePolygonXml");
    return element;
}
Also used : Element(org.jdom2.Element) PositionablePolygon(jmri.jmrit.display.controlPanelEditor.shape.PositionablePolygon)

Example 2 with PositionablePolygon

use of jmri.jmrit.display.controlPanelEditor.shape.PositionablePolygon 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)

Aggregations

PositionablePolygon (jmri.jmrit.display.controlPanelEditor.shape.PositionablePolygon)2 Element (org.jdom2.Element)2 GeneralPath (java.awt.geom.GeneralPath)1 Editor (jmri.jmrit.display.Editor)1