Search in sources :

Example 26 with Editor

use of jmri.jmrit.display.Editor in project JMRI by JMRI.

the class PositionableLabelXml method load.

/**
     * Create a PositionableLabel, 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
    PositionableLabel l = null;
    // get object class and determine editor being used
    Editor editor = (Editor) o;
    if (element.getAttribute("icon") != null) {
        NamedIcon icon;
        String name = element.getAttribute("icon").getValue();
        //            if (log.isDebugEnabled()) log.debug("icon attribute= "+name);
        if (name.equals("yes")) {
            icon = getNamedIcon("icon", element, "PositionableLabel ", editor);
        } else {
            icon = NamedIcon.getIconByName(name);
            if (icon == null) {
                icon = editor.loadFailed("PositionableLabel", name);
                if (icon == null) {
                    log.info("PositionableLabel icon removed for url= " + name);
                    return;
                }
            }
        }
        // abort if name != yes and have null icon
        if (icon == null && !name.equals("yes")) {
            log.info("PositionableLabel icon removed for url= " + name);
            return;
        }
        l = new PositionableLabel(icon, editor);
        try {
            Attribute a = element.getAttribute("rotate");
            if (a != null && icon != null) {
                int rotation = element.getAttribute("rotate").getIntValue();
                icon.setRotation(rotation, l);
            }
        } catch (org.jdom2.DataConversionException e) {
        }
        if (name.equals("yes")) {
            NamedIcon nIcon = loadIcon(l, "icon", element, "PositionableLabel ", editor);
            if (nIcon != null) {
                l.updateIcon(nIcon);
            } else {
                log.info("PositionableLabel icon removed for url= " + name);
                return;
            }
        } else {
            l.updateIcon(icon);
        }
    }
    if (element.getAttribute("text") != null) {
        if (l == null) {
            l = new PositionableLabel(element.getAttribute("text").getValue(), editor);
        }
        loadTextInfo(l, element);
    } else if (l == null) {
        log.error("PositionableLabel is null!");
        if (log.isDebugEnabled()) {
            java.util.List<Attribute> attrs = element.getAttributes();
            log.debug("\tElement Has " + attrs.size() + " Attributes:");
            for (int i = 0; i < attrs.size(); i++) {
                Attribute a = attrs.get(i);
                log.debug("\t\t" + a.getName() + " = " + a.getValue());
            }
            java.util.List<Element> kids = element.getChildren();
            log.debug("\tElementHas " + kids.size() + " children:");
            for (int i = 0; i < kids.size(); i++) {
                Element e = kids.get(i);
                log.debug("\t\t" + e.getName() + " = \"" + e.getValue() + "\"");
            }
        }
        editor.loadFailed();
        return;
    }
    editor.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.LABELS, element);
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) PositionableLabel(jmri.jmrit.display.PositionableLabel) DataConversionException(org.jdom2.DataConversionException) Editor(jmri.jmrit.display.Editor)

Example 27 with Editor

use of jmri.jmrit.display.Editor in project JMRI by JMRI.

the class DrawPolygon method makeFigure.

/* @Override
     public void paint(Graphics g) {
     super.paint(g);
     if (_editing) {
     int hitIndex = _pShape.getHitIndex();
     if (hitIndex>=0) {
     super.paint(g);
     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 = new GeneralPath();
     if (hitIndex==0) {
     Point p0 = _vertices.get(1);
     path.moveTo(p0.x, p0.y);
     path.lineTo(_curX, _curY);   
     } else if (hitIndex==_vertices.size()-1) {
     Point p0 = _vertices.get(hitIndex-1);
     path.moveTo(p0.x, p0.y);
     path.lineTo(_curX, _curY);      
     } else {
     Point p0 = _vertices.get(hitIndex-1);
     Point p1 = _vertices.get(hitIndex+1);
     path.moveTo(p0.x, p0.y);
     path.lineTo(_curX, _curY);   
     path.lineTo(p1.x, p1.y);      
     }
     g2d.draw(path);             
     }
     }
     }  
     /**
     * Create a new PositionableShape 
     */
@Override
protected boolean makeFigure(MouseEvent event) {
    if (_editing) {
        int hitIndex = _pShape.getHitIndex();
        if (hitIndex >= 0) {
            Point pt;
            try {
                pt = _pShape.getInversePoint(event.getX(), event.getY());
            } catch (java.awt.geom.NoninvertibleTransformException nte) {
                log.error("Can't locate Hit Rectangles " + nte.getMessage());
                return false;
            }
            _vertices.remove(hitIndex);
            _vertices.add(hitIndex, pt);
            _pShape.setShape(makePath(getStartPoint()));
        }
        return false;
    } else {
        Point p = new Point(event.getX(), event.getY());
        if (hitPolygonVertex(p)) {
            if (near(_vertices.get(0), p)) {
                // close polygon       
                _vertices.add(p);
            }
            Editor ed = _parent.getEditor();
            Point spt = getStartPoint();
            PositionablePolygon ps = new PositionablePolygon(ed, makePath(spt));
            ps.setLocation(spt);
            ps.updateSize();
            setDisplayParams(ps);
            ps.setEditFrame(this);
            ed.putItem(ps);
            return true;
        }
        _vertices.add(p);
        return false;
    }
}
Also used : Point(java.awt.Point) Editor(jmri.jmrit.display.Editor) Point(java.awt.Point)

Example 28 with Editor

use of jmri.jmrit.display.Editor in project JMRI by JMRI.

the class AnalogClock2DisplayXml method load.

/**
     * Create an AnalogClock2Display, then add to a target JLayeredPane
     *
     * @param element Top level Element to unpack.
     * @param o       an Editor as an Object
     */
@Override
public void load(Element element, Object o) {
    // get object class and create the clock object
    Editor ed = (Editor) o;
    AnalogClock2Display l = new AnalogClock2Display(ed);
    // find coordinates
    int x = 0;
    int y = 0;
    double scale = 1.0;
    Colors color = Colors.Black;
    try {
        x = element.getAttribute("x").getIntValue();
        y = element.getAttribute("y").getIntValue();
        if (element.getAttribute("scale") != null) {
            scale = element.getAttribute("scale").getDoubleValue();
        }
        if (element.getAttribute("color") != null) {
            color = Colors.valueOf(element.getAttribute("color").getValue());
        }
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert positional attribute");
    }
    if (element.getAttribute("link") != null) {
        l.setUrl(element.getAttribute("link").getValue());
    }
    l.setOpaque(false);
    l.update();
    l.setLocation(x, y);
    if (scale != 1.0 && 10.0 > scale && scale > 0.1) {
        l.setScale(scale);
    }
    l.setColor(color);
    // add the clock to the panel
    l.setDisplayLevel(Editor.CLOCK);
    ed.putItem(l);
}
Also used : Colors(jmri.jmrit.display.AnalogClock2Display.Colors) AnalogClock2Display(jmri.jmrit.display.AnalogClock2Display) Editor(jmri.jmrit.display.Editor)

Example 29 with Editor

use of jmri.jmrit.display.Editor in project JMRI by JMRI.

the class IndicatorTurnoutIconXml method load.

/**
     * Create a IndicatorTurnoutIcon, 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 p = (Editor) o;
    IndicatorTurnoutIcon l = new IndicatorTurnoutIcon(p);
    Element name = element.getChild("turnout");
    if (name == null) {
        log.error("incorrect information for turnout; must use turnout name");
    } else {
        l.setTurnout(name.getText());
    }
    Element elem = element.getChild("iconmaps");
    if (elem != null) {
        List<Element> maps = elem.getChildren();
        if (maps.size() > 0) {
            for (int i = 0; i < maps.size(); i++) {
                String status = maps.get(i).getName();
                List<Element> states = maps.get(i).getChildren();
                for (int k = 0; k < states.size(); k++) {
                    String msg = "IndicatorTurnout \"" + l.getNameString() + "\" icon \"" + states.get(k).getName() + "\" ";
                    NamedIcon icon = loadIcon(l, states.get(k).getName(), maps.get(i), msg, p);
                    if (icon != null) {
                        l.setIcon(status, states.get(k).getName(), icon);
                    } else {
                        log.info(msg + " removed for url= " + name);
                        return;
                    }
                }
            }
        }
        Attribute attr = elem.getAttribute("family");
        if (attr != null) {
            l.setFamily(attr.getValue());
        }
    }
    name = element.getChild("occupancyblock");
    if (name != null) {
        l.setOccBlock(name.getText());
    } else {
        // only write sensor if no OBlock, don't write double sensing
        name = element.getChild("occupancysensor");
        if (name != null) {
            l.setOccSensor(name.getText());
        }
    }
    l.setShowTrain(false);
    name = element.getChild("showTrainName");
    if (name != null) {
        if ("yes".equals(name.getText())) {
            l.setShowTrain(true);
        }
    }
    elem = element.getChild("paths");
    if (elem != null) {
        ArrayList<String> paths = new ArrayList<String>();
        List<Element> pth = elem.getChildren();
        for (int i = 0; i < pth.size(); i++) {
            paths.add(pth.get(i).getText());
        }
        l.setPaths(paths);
    }
    l.updateSize();
    p.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.TURNOUTS, element);
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) IndicatorTurnoutIcon(jmri.jmrit.display.IndicatorTurnoutIcon) Editor(jmri.jmrit.display.Editor)

Example 30 with Editor

use of jmri.jmrit.display.Editor in project JMRI by JMRI.

the class PositionableRoundRectXml 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;
    PositionableRoundRect ps = new PositionableRoundRect(ed);
    Element elem = element.getChild("size");
    ps.setWidth(getInt(elem, "width"));
    ps.setHeight(getInt(elem, "height"));
    ps.setCornerRadius(getInt(elem, "cornerRadius"));
    ed.putItem(ps);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(ps, Editor.MARKERS, element);
}
Also used : Element(org.jdom2.Element) PositionableRoundRect(jmri.jmrit.display.controlPanelEditor.shape.PositionableRoundRect) Editor(jmri.jmrit.display.Editor)

Aggregations

Editor (jmri.jmrit.display.Editor)36 Element (org.jdom2.Element)18 Attribute (org.jdom2.Attribute)15 NamedIcon (jmri.jmrit.catalog.NamedIcon)13 ArrayList (java.util.ArrayList)3 Memory (jmri.Memory)3 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 JMenu (javax.swing.JMenu)2 JMenuItem (javax.swing.JMenuItem)2 ImageIndexEditor (jmri.jmrit.catalog.ImageIndexEditor)2 RosterEntry (jmri.jmrit.roster.RosterEntry)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Point (java.awt.Point)1 GeneralPath (java.awt.geom.GeneralPath)1 Arrays (java.util.Arrays)1