Search in sources :

Example 1 with ControlPanelEditor

use of jmri.jmrit.display.controlPanelEditor.ControlPanelEditor in project JMRI by JMRI.

the class PositionableShape method propertyChange.

@Override
public void propertyChange(java.beans.PropertyChangeEvent evt) {
    if (log.isDebugEnabled()) {
        log.debug("property change: \"{}\"= {} for {}", evt.getPropertyName(), evt.getNewValue(), getClass().getName());
    }
    if (!_editor.isEditable()) {
        if (evt.getPropertyName().equals("KnownState")) {
            if (((Integer) evt.getNewValue()).intValue() == Sensor.ACTIVE) {
                if (_doHide) {
                    setVisible(true);
                } else {
                    super.setDisplayLevel(_changeLevel);
                    setVisible(true);
                }
            } else if (((Integer) evt.getNewValue()).intValue() == Sensor.INACTIVE) {
                if (_doHide) {
                    setVisible(false);
                } else {
                    super.setDisplayLevel(_saveLevel);
                    setVisible(true);
                }
            } else {
                super.setDisplayLevel(_saveLevel);
                setVisible(true);
            }
            ((ControlPanelEditor) _editor).mouseMoved(new MouseEvent(this, MouseEvent.MOUSE_MOVED, System.currentTimeMillis(), 0, getX(), getY(), 0, false));
            repaint();
            _editor.getTargetPanel().revalidate();
        }
    } else {
        super.setDisplayLevel(_saveLevel);
        setVisible(true);
    }
    if (log.isDebugEnabled()) {
        log.debug("_changeLevel= {} _saveLevel= {} displayLevel= {} _doHide= {} visible= {}", _changeLevel, _saveLevel, getDisplayLevel(), _doHide, isVisible());
    }
}
Also used : MouseEvent(java.awt.event.MouseEvent) ControlPanelEditor(jmri.jmrit.display.controlPanelEditor.ControlPanelEditor)

Example 2 with ControlPanelEditor

use of jmri.jmrit.display.controlPanelEditor.ControlPanelEditor in project JMRI by JMRI.

the class ControlPanelEditorXml method load.

/**
     * Create a ControlPanelEditor object, then register and fill it, then pop
     * it in a JFrame
     *
     * @param shared Top level Element to unpack.
     * @return true if successful
     */
@Override
public boolean load(Element shared, Element perNode) {
    boolean result = true;
    // find coordinates
    int x = 0;
    int y = 0;
    int height = 400;
    int width = 300;
    try {
        x = shared.getAttribute("x").getIntValue();
        y = shared.getAttribute("y").getIntValue();
        height = shared.getAttribute("height").getIntValue();
        width = shared.getAttribute("width").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert ControlPanelEditor's attribute");
        result = false;
    }
    // find the name
    String name = "Control Panel";
    if (shared.getAttribute("name") != null) {
        name = shared.getAttribute("name").getValue();
    }
    // confirm that panel hasn't already been loaded
    if (jmri.jmrit.display.PanelMenu.instance().isPanelNameUsed(name)) {
        log.warn("File contains a panel with the same name ({}) as an existing panel", name);
        result = false;
    }
    ControlPanelEditor panel = new ControlPanelEditor(name);
    // save painting until last
    panel.getTargetFrame().setVisible(false);
    jmri.jmrit.display.PanelMenu.instance().addEditorPanel(panel);
    // Load editor option flags. This has to be done before the content 
    // items are loaded, to preserve the individual item settings
    Attribute a;
    boolean value = true;
    if ((a = shared.getAttribute("editable")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setAllEditable(value);
    value = true;
    if ((a = shared.getAttribute("positionable")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setAllPositionable(value);
    /*
         value = false;
         if ((a = element.getAttribute("showcoordinates"))!=null && a.getValue().equals("yes"))
         value = true;
         panel.setShowCoordinates(value);
         */
    value = true;
    if ((a = shared.getAttribute("showtooltips")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setAllShowTooltip(value);
    value = true;
    if ((a = shared.getAttribute("controlling")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setAllControlling(value);
    value = false;
    if ((a = shared.getAttribute("hide")) != null && a.getValue().equals("yes")) {
        value = true;
    }
    panel.setShowHidden(value);
    value = true;
    if ((a = shared.getAttribute("panelmenu")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setPanelMenuVisible(value);
    value = true;
    if ((a = shared.getAttribute("shapeSelect")) != null && a.getValue().equals("no")) {
        value = false;
    }
    panel.setShapeSelect(value);
    if ((a = shared.getAttribute("state")) != null) {
        try {
            int xState = a.getIntValue();
            panel.setExtendedState(xState);
        } catch (org.jdom2.DataConversionException e) {
            log.error("failed to convert ControlPanelEditor's extended State");
            result = false;
        }
    }
    String state = "both";
    if ((a = shared.getAttribute("scrollable")) != null) {
        state = a.getValue();
    }
    panel.setScroll(state);
    try {
        int red = shared.getAttribute("redBackground").getIntValue();
        int blue = shared.getAttribute("blueBackground").getIntValue();
        int green = shared.getAttribute("greenBackground").getIntValue();
        panel.setBackgroundColor(new Color(red, green, blue));
    } catch (org.jdom2.DataConversionException e) {
        log.warn("Could not parse color attributes!");
    } catch (NullPointerException e) {
    // considered normal if the attributes are not present
    }
    Element icons = shared.getChild("icons");
    /*        if (icons != null) {
            HashMap<String, NamedIcon> portalIconMap = new HashMap<String, NamedIcon>();
            portalIconMap.put(PortalIcon.VISIBLE, loadIcon("visible", icons, panel));
            portalIconMap.put(PortalIcon.PATH, loadIcon("path_edit", icons, panel));
            portalIconMap.put(PortalIcon.HIDDEN, loadIcon("hidden", icons, panel));
            portalIconMap.put(PortalIcon.TO_ARROW, loadIcon("to_arrow", icons, panel));
            portalIconMap.put(PortalIcon.FROM_ARROW, loadIcon("from_arrow", icons, panel));
            panel.setDefaultPortalIcons(portalIconMap);
        }*/
    shared.removeChild("icons");
    //set the (global) editor display widgets to their flag settings
    panel.initView();
    // load the contents
    List<Element> items = shared.getChildren();
    for (Element item : items) {
        String adapterName = item.getAttribute("class").getValue();
        log.debug("load via {}", adapterName);
        try {
            XmlAdapter adapter = (XmlAdapter) Class.forName(adapterName).newInstance();
            // and do it
            adapter.load(item, panel);
            if (!panel.loadOK()) {
                result = false;
            }
        } catch (Exception e) {
            log.error("Exception while loading {}: {}", item.getName(), e.getMessage(), e);
            result = false;
        }
    }
    if (icons != null) {
        HashMap<String, NamedIcon> portalIconMap = new HashMap<String, NamedIcon>();
        portalIconMap.put(PortalIcon.VISIBLE, loadIcon("visible", icons, panel));
        portalIconMap.put(PortalIcon.PATH, loadIcon("path_edit", icons, panel));
        portalIconMap.put(PortalIcon.HIDDEN, loadIcon("hidden", icons, panel));
        portalIconMap.put(PortalIcon.TO_ARROW, loadIcon("to_arrow", icons, panel));
        portalIconMap.put(PortalIcon.FROM_ARROW, loadIcon("from_arrow", icons, panel));
        panel.setDefaultPortalIcons(portalIconMap);
    }
    // dispose of url correction data
    panel.disposeLoadData();
    // display the results, with the editor in back
    panel.pack();
    panel.setAllEditable(panel.isEditable());
    // register the resulting panel for later configuration
    ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
    if (cm != null) {
        cm.registerUser(panel);
    }
    // reset the size and position, in case the display caused it to change
    panel.getTargetFrame().setLocation(x, y);
    panel.getTargetFrame().setSize(width, height);
    panel.setTitle();
    // always show the panel
    panel.getTargetFrame().setVisible(true);
    // do last to set putItem override - unused.
    panel.loadComplete();
    return result;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) ControlPanelEditor(jmri.jmrit.display.controlPanelEditor.ControlPanelEditor) Attribute(org.jdom2.Attribute) HashMap(java.util.HashMap) Color(java.awt.Color) Element(org.jdom2.Element) Point(java.awt.Point) ConfigureManager(jmri.ConfigureManager) AbstractXmlAdapter(jmri.configurexml.AbstractXmlAdapter) XmlAdapter(jmri.configurexml.XmlAdapter)

Example 3 with ControlPanelEditor

use of jmri.jmrit.display.controlPanelEditor.ControlPanelEditor in project JMRI by JMRI.

the class ControlPanelEditorXml method store.

/**
     * Default implementation for storing the contents of a ControlPanelEditor
     *
     * @param o Object to store, of type ControlPanelEditor
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    ControlPanelEditor p = (ControlPanelEditor) o;
    Element panel = new Element("paneleditor");
    JFrame frame = p.getTargetFrame();
    Dimension size = frame.getSize();
    Point posn = frame.getLocation();
    panel.setAttribute("class", "jmri.jmrit.display.controlPanelEditor.configurexml.ControlPanelEditorXml");
    panel.setAttribute("name", "" + frame.getName());
    panel.setAttribute("x", "" + posn.x);
    panel.setAttribute("y", "" + posn.y);
    panel.setAttribute("height", "" + size.height);
    panel.setAttribute("width", "" + size.width);
    panel.setAttribute("editable", "" + (p.isEditable() ? "yes" : "no"));
    panel.setAttribute("positionable", "" + (p.allPositionable() ? "yes" : "no"));
    //panel.setAttribute("showcoordinates", ""+(p.showCoordinates()?"yes":"no"));
    panel.setAttribute("showtooltips", "" + (p.showTooltip() ? "yes" : "no"));
    panel.setAttribute("controlling", "" + (p.allControlling() ? "yes" : "no"));
    panel.setAttribute("hide", p.isVisible() ? "no" : "yes");
    panel.setAttribute("panelmenu", p.isPanelMenuVisible() ? "yes" : "no");
    panel.setAttribute("scrollable", p.getScrollable());
    if (p.getBackgroundColor() != null) {
        panel.setAttribute("redBackground", "" + p.getBackgroundColor().getRed());
        panel.setAttribute("greenBackground", "" + p.getBackgroundColor().getGreen());
        panel.setAttribute("blueBackground", "" + p.getBackgroundColor().getBlue());
    }
    panel.setAttribute("state", "" + p.getExtendedState());
    panel.setAttribute("shapeSelect", "" + (p.getShapeSelect() ? "yes" : "no"));
    Element elem = new Element("icons");
    HashMap<String, NamedIcon> map = p.getPortalIconMap();
    elem.addContent(storeIcon("visible", map.get(PortalIcon.VISIBLE)));
    elem.addContent(storeIcon("path_edit", map.get(PortalIcon.PATH)));
    elem.addContent(storeIcon("hidden", map.get(PortalIcon.HIDDEN)));
    elem.addContent(storeIcon("to_arrow", map.get(PortalIcon.TO_ARROW)));
    elem.addContent(storeIcon("from_arrow", map.get(PortalIcon.FROM_ARROW)));
    panel.addContent(elem);
    // include contents
    List<Positionable> contents = p.getContents();
    log.debug("N elements: {}", contents.size());
    for (Positionable sub : contents) {
        if (sub != null && sub.storeItem()) {
            try {
                Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
                if (e != null) {
                    panel.addContent(e);
                }
            } catch (Exception e) {
                log.error("Error storing panel element: {}", e.getMessage(), e);
            }
        }
    }
    return panel;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) ControlPanelEditor(jmri.jmrit.display.controlPanelEditor.ControlPanelEditor) JFrame(javax.swing.JFrame) Element(org.jdom2.Element) Dimension(java.awt.Dimension) Point(java.awt.Point) Positionable(jmri.jmrit.display.Positionable)

Example 4 with ControlPanelEditor

use of jmri.jmrit.display.controlPanelEditor.ControlPanelEditor in project JMRI by JMRI.

the class PortalIconXml method load.

/**
     * Create a PositionableLabel, 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) {
    if (!(o instanceof ControlPanelEditor)) {
        log.error("Can't load portalIcon.  Panel editor must use ControlPanelEditor.");
        return;
    }
    ControlPanelEditor ed = (ControlPanelEditor) o;
    String fromBlk;
    try {
        fromBlk = element.getAttribute("fromBlockName").getValue();
    } catch (NullPointerException e) {
        log.error("incorrect information for portalIcon; must use fromBlockName.");
        //            ed.loadFailed();
        return;
    }
    String portalName;
    try {
        portalName = element.getAttribute("portalName").getValue();
    } catch (NullPointerException e) {
        log.error("incorrect information for portalIcon; must use portalName.");
        //            ed.loadFailed();
        return;
    }
    OBlock block = jmri.InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class).getOBlock(fromBlk);
    Portal portal = block.getPortalByName(portalName);
    PortalIcon l = new PortalIcon(ed, portal);
    ed.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, ControlPanelEditor.MARKERS, element);
    Attribute a = element.getAttribute("scale");
    double scale = 1.0;
    if (a != null) {
        try {
            scale = a.getDoubleValue();
        } catch (org.jdom2.DataConversionException dce) {
            log.error(l.getNameString() + " can't convert scale " + dce);
        }
    }
    l.setScale(scale);
    a = element.getAttribute("rotate");
    int deg = 0;
    if (a != null) {
        try {
            deg = a.getIntValue();
        } catch (org.jdom2.DataConversionException dce) {
            log.error(l.getNameString() + " can't convert rotate " + dce);
        }
    }
    l.rotate(deg);
    boolean value = true;
    if ((a = element.getAttribute("arrowSwitch")) != null && a.getValue().equals("no")) {
        value = false;
    }
    l.setArrowOrientatuon(value);
    value = false;
    if ((a = element.getAttribute("arrowHide")) != null && a.getValue().equals("yes")) {
        value = true;
    }
    l.setHideArrows(value);
}
Also used : ControlPanelEditor(jmri.jmrit.display.controlPanelEditor.ControlPanelEditor) Attribute(org.jdom2.Attribute) PortalIcon(jmri.jmrit.display.controlPanelEditor.PortalIcon) Portal(jmri.jmrit.logix.Portal) OBlock(jmri.jmrit.logix.OBlock)

Example 5 with ControlPanelEditor

use of jmri.jmrit.display.controlPanelEditor.ControlPanelEditor in project JMRI by JMRI.

the class DrawCircle method makeFigure.

@Override
protected boolean makeFigure(MouseEvent event) {
    ControlPanelEditor ed = _parent.getEditor();
    Rectangle r = ed.getSelectRect();
    if (r != null) {
        int dia = Math.max(r.width, r.height);
        Ellipse2D.Double rr = new Ellipse2D.Double(0, 0, dia, dia);
        PositionableCircle ps = new PositionableCircle(ed, rr);
        ps.setLocation(r.x, r.y);
        ps.updateSize();
        setDisplayParams(ps);
        ps.setEditFrame(this);
        ed.putItem(ps);
    }
    return true;
}
Also used : ControlPanelEditor(jmri.jmrit.display.controlPanelEditor.ControlPanelEditor) Rectangle(java.awt.Rectangle) Ellipse2D(java.awt.geom.Ellipse2D)

Aggregations

ControlPanelEditor (jmri.jmrit.display.controlPanelEditor.ControlPanelEditor)15 Rectangle (java.awt.Rectangle)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ConfigureManager (jmri.ConfigureManager)3 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)3 Element (org.jdom2.Element)3 Point (java.awt.Point)2 Ellipse2D (java.awt.geom.Ellipse2D)2 File (java.io.File)2 JFrame (javax.swing.JFrame)2 Sensor (jmri.Sensor)2 SensorManager (jmri.SensorManager)2 NamedIcon (jmri.jmrit.catalog.NamedIcon)2 Positionable (jmri.jmrit.display.Positionable)2 SwitchboardEditor (jmri.jmrit.display.switchboardEditor.SwitchboardEditor)2 JmriJFrame (jmri.util.JmriJFrame)2 Attribute (org.jdom2.Attribute)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1