Search in sources :

Example 1 with TurnoutIcon

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

the class CircuitBuilder method convertIcon.

/**
     * Converts icon to IndicatorTrack
     */
private void convertIcon(Positionable pos) {
    _oldIcon = (PositionableLabel) pos;
    _editor.highlight(_oldIcon);
    _editor.toFront();
    _editor.repaint();
    if (pos instanceof TurnoutIcon) {
        makePaletteFrame("IndicatorTO");
        _trackTOPanel = new IndicatorTOItemPanel(_convertFrame, "IndicatorTO", null, null, _editor);
        ActionListener updateAction = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent a) {
                convertTO();
            }
        };
        _trackTOPanel.init(updateAction);
        _convertDialog.add(_trackTOPanel);
    } else {
        makePaletteFrame("IndicatorTrack");
        _trackPanel = new IndicatorItemPanel(_convertFrame, "IndicatorTrack", null, _editor);
        ActionListener updateAction = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent a) {
                convertSeg();
            }
        };
        _trackPanel.init(updateAction);
        _convertDialog.add(_trackPanel);
    }
    _convertDialog.pack();
    _convertDialog.setVisible(true);
    _editor.repaint();
}
Also used : IndicatorTOItemPanel(jmri.jmrit.display.palette.IndicatorTOItemPanel) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) IndicatorTurnoutIcon(jmri.jmrit.display.IndicatorTurnoutIcon) TurnoutIcon(jmri.jmrit.display.TurnoutIcon) IndicatorItemPanel(jmri.jmrit.display.palette.IndicatorItemPanel)

Example 2 with TurnoutIcon

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

the class TurnoutIconXml method load.

/**
     * Create a PositionableLabel, then add to a target JLayeredPane
     *
     * @param element Top level Element to unpack.
     * @param o       Editor as an Object
     */
@SuppressWarnings("null")
@Override
public void load(Element element, Object o) {
    // create the objects
    Editor p = (Editor) o;
    TurnoutIcon l = new TurnoutIcon(p);
    String name;
    try {
        name = element.getAttribute("turnout").getValue();
    } catch (NullPointerException e) {
        log.error("incorrect information for turnout; must use turnout name");
        p.loadFailed();
        return;
    }
    l.setTurnout(name);
    Attribute a = element.getAttribute("tristate");
    if ((a == null) || a.getValue().equals("true")) {
        l.setTristate(true);
    } else {
        l.setTristate(false);
    }
    a = element.getAttribute("momentary");
    if ((a != null) && a.getValue().equals("true")) {
        l.setMomentary(true);
    } else {
        l.setMomentary(false);
    }
    a = element.getAttribute("directControl");
    if ((a != null) && a.getValue().equals("true")) {
        l.setDirectControl(true);
    } else {
        l.setDirectControl(false);
    }
    List<Element> states = element.getChildren();
    if (states.size() > 0) {
        if (log.isDebugEnabled()) {
            log.debug("Main element has" + states.size() + " items");
        }
        // the element containing the icons
        Element elem = element;
        Element icons = element.getChild("icons");
        if (icons != null) {
            List<Element> s = icons.getChildren();
            states = s;
            // the element containing the icons
            elem = icons;
            if (log.isDebugEnabled()) {
                log.debug("icons element has" + states.size() + " items");
            }
        }
        for (int i = 0; i < states.size(); i++) {
            String state = states.get(i).getName();
            if (log.isDebugEnabled()) {
                log.debug("setIcon for state \"" + state + "\" and " + _nameMap.get(state));
            }
            NamedIcon icon = loadIcon(l, state, elem, "TurnoutIcon \"" + name + "\": icon \"" + state + "\" ", p);
            if (icon != null) {
                l.setIcon(_nameMap.get(state), icon);
            } else {
                log.info("TurnoutIcon \"" + name + "\": icon \"" + state + "\" removed");
                return;
            }
        }
        log.debug(states.size() + " icons loaded for " + l.getNameString());
    } else {
        // case when everything was attributes
        int rotation = 0;
        try {
            rotation = element.getAttribute("rotate").getIntValue();
        } catch (org.jdom2.DataConversionException e) {
        } catch (NullPointerException e) {
        // considered normal if the attributes are not present
        }
        if (loadTurnoutIcon("thrown", rotation, l, element, name, p) == null) {
            return;
        }
        if (loadTurnoutIcon("closed", rotation, l, element, name, p) == null) {
            return;
        }
        if (loadTurnoutIcon("unknown", rotation, l, element, name, p) == null) {
            return;
        }
        if (loadTurnoutIcon("inconsistent", rotation, l, element, name, p) == null) {
            return;
        }
    }
    Element elem = element.getChild("iconmaps");
    if (elem != null) {
        Attribute attr = elem.getAttribute("family");
        if (attr != null) {
            l.setFamily(attr.getValue());
        }
    }
    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) Editor(jmri.jmrit.display.Editor) TurnoutIcon(jmri.jmrit.display.TurnoutIcon)

Example 3 with TurnoutIcon

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

the class EditCircuitFrame method updateIconList.

protected void updateIconList(java.util.List<Positionable> icons) {
    //if (log.isDebugEnabled()) log.debug( 
    int segments = 0;
    int turnouts = 0;
    if (icons != null) {
        if (log.isDebugEnabled()) {
            log.debug("updateIconList: icons.size()= {}", icons.size());
        }
        for (int i = 0; i < icons.size(); i++) {
            Positionable pos = icons.get(i);
            if (pos instanceof IndicatorTurnoutIcon) {
                turnouts++;
            } else if (pos instanceof IndicatorTrackIcon) {
                segments++;
            } else if (pos instanceof TurnoutIcon) {
                turnouts++;
            } else {
                segments++;
            }
        }
    }
    _numTrackSeg.setText(String.valueOf(segments));
    _numTurnouts.setText(String.valueOf(turnouts));
}
Also used : IndicatorTrackIcon(jmri.jmrit.display.IndicatorTrackIcon) IndicatorTurnoutIcon(jmri.jmrit.display.IndicatorTurnoutIcon) Positionable(jmri.jmrit.display.Positionable) IndicatorTurnoutIcon(jmri.jmrit.display.IndicatorTurnoutIcon) TurnoutIcon(jmri.jmrit.display.TurnoutIcon) Point(java.awt.Point)

Example 4 with TurnoutIcon

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

the class TurnoutIconXml method store.

/**
     * Default implementation for storing the contents of a TurnoutIcon
     *
     * @param o Object to store, of type TurnoutIcon
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    TurnoutIcon p = (TurnoutIcon) o;
    if (!p.isActive()) {
        // if flagged as inactive, don't store
        return null;
    }
    Element element = new Element("turnouticon");
    element.setAttribute("turnout", p.getNamedTurnout().getName());
    storeCommonAttributes(p, element);
    element.setAttribute("tristate", p.getTristate() ? "true" : "false");
    element.setAttribute("momentary", p.getMomentary() ? "true" : "false");
    element.setAttribute("directControl", p.getDirectControl() ? "true" : "false");
    Element elem = new Element("icons");
    elem.addContent(storeIcon("closed", p.getIcon("TurnoutStateClosed")));
    elem.addContent(storeIcon("thrown", p.getIcon("TurnoutStateThrown")));
    elem.addContent(storeIcon("unknown", p.getIcon("BeanStateUnknown")));
    elem.addContent(storeIcon("inconsistent", p.getIcon("BeanStateInconsistent")));
    element.addContent(elem);
    elem = new Element("iconmaps");
    String family = p.getFamily();
    if (family != null) {
        elem.setAttribute("family", family);
    }
    element.addContent(elem);
    element.setAttribute("class", "jmri.jmrit.display.configurexml.TurnoutIconXml");
    return element;
}
Also used : Element(org.jdom2.Element) TurnoutIcon(jmri.jmrit.display.TurnoutIcon)

Aggregations

TurnoutIcon (jmri.jmrit.display.TurnoutIcon)4 IndicatorTurnoutIcon (jmri.jmrit.display.IndicatorTurnoutIcon)2 Element (org.jdom2.Element)2 Point (java.awt.Point)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 NamedIcon (jmri.jmrit.catalog.NamedIcon)1 Editor (jmri.jmrit.display.Editor)1 IndicatorTrackIcon (jmri.jmrit.display.IndicatorTrackIcon)1 Positionable (jmri.jmrit.display.Positionable)1 IndicatorItemPanel (jmri.jmrit.display.palette.IndicatorItemPanel)1 IndicatorTOItemPanel (jmri.jmrit.display.palette.IndicatorTOItemPanel)1 Attribute (org.jdom2.Attribute)1