Search in sources :

Example 1 with SensorIcon

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

the class SensorIconXml 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) {
    Editor ed = (Editor) o;
    SensorIcon l;
    String name;
    Attribute attr = element.getAttribute("sensor");
    if (attr == null) {
        log.error("incorrect information for sensor; must use sensor name");
        ed.loadFailed();
        return;
    } else {
        name = attr.getValue();
    }
    _icon = true;
    if (element.getAttribute("icon") != null) {
        String yesno = element.getAttribute("icon").getValue();
        if ((yesno != null) && (!yesno.equals(""))) {
            if (yesno.equals("yes")) {
                _icon = true;
            } else if (yesno.equals("no")) {
                _icon = false;
            }
        }
    }
    if (_icon) {
        l = new SensorIcon(new NamedIcon("resources/icons/smallschematics/tracksegments/circuit-error.gif", "resources/icons/smallschematics/tracksegments/circuit-error.gif"), ed);
    } else {
        l = new SensorIcon("  ", ed);
    }
    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 (loadSensorIcon("active", rotation, l, element, name, ed) == null) {
        return;
    }
    if (loadSensorIcon("inactive", rotation, l, element, name, ed) == null) {
        return;
    }
    if (loadSensorIcon("unknown", rotation, l, element, name, ed) == null) {
        return;
    }
    if (loadSensorIcon("inconsistent", rotation, l, element, name, ed) == null) {
        return;
    }
    Element elem = element.getChild("iconmaps");
    if (elem != null) {
        attr = elem.getAttribute("family");
        if (attr != null) {
            l.setFamily(attr.getValue());
        }
    }
    Attribute a = element.getAttribute("momentary");
    if ((a != null) && a.getValue().equals("true")) {
        l.setMomentary(true);
    } else {
        l.setMomentary(false);
    }
    loadTextInfo(l, element);
    l.setSensor(name);
    ed.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.SENSORS, element);
    if (l.isIcon() && l.getText() != null) {
        l.setOpaque(false);
    }
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) SensorIcon(jmri.jmrit.display.SensorIcon) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) Editor(jmri.jmrit.display.Editor)

Example 2 with SensorIcon

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

the class SensorIconXml method store.

/**
     * Default implementation for storing the contents of a SensorIcon
     *
     * @param o Object to store, of type SensorIcon
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    SensorIcon p = (SensorIcon) o;
    if (!p.isActive()) {
        // if flagged as inactive, don't store
        return null;
    }
    Element element = new Element("sensoricon");
    element.setAttribute("sensor", p.getNamedSensor().getName());
    storeCommonAttributes(p, element);
    element.setAttribute("momentary", p.getMomentary() ? "true" : "false");
    element.setAttribute("icon", p.isIcon() ? "yes" : "no");
    storeIconInfo(p, element);
    storeTextInfo(p, element);
    element.setAttribute("class", "jmri.jmrit.display.configurexml.SensorIconXml");
    return element;
}
Also used : SensorIcon(jmri.jmrit.display.SensorIcon) Element(org.jdom2.Element)

Example 3 with SensorIcon

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

the class DecoratorPanel method setAttributes.

public void setAttributes(Positionable pos) {
    if (pos instanceof SensorIcon && !((SensorIcon) pos).isIcon()) {
        SensorIcon icon = (SensorIcon) pos;
        PositionableLabel sample = _sample.get("Active");
        if (sample.isOpaque()) {
            icon.setBackgroundActive(sample.getBackground());
        } else {
            icon.setBackgroundActive(null);
        }
        icon.setTextActive(sample.getForeground());
        icon.setActiveText(sample.getText());
        sample = _sample.get("InActive");
        icon.setInactiveText(sample.getText());
        if (sample.isOpaque()) {
            icon.setBackgroundInActive(sample.getBackground());
        } else {
            icon.setBackgroundInActive(null);
        }
        icon.setTextInActive(sample.getForeground());
        sample = _sample.get("Unknown");
        icon.setUnknownText(sample.getText());
        if (sample.isOpaque()) {
            icon.setBackgroundUnknown(sample.getBackground());
        } else {
            icon.setBackgroundUnknown(null);
        }
        icon.setTextUnknown(sample.getForeground());
        sample = _sample.get("Inconsistent");
        icon.setInconsistentText(sample.getText());
        if (sample.isOpaque()) {
            icon.setBackgroundInconsistent(sample.getBackground());
        } else {
            icon.setBackgroundInconsistent(null);
        }
        icon.setTextInconsistent(sample.getForeground());
    } else {
        PositionableLabel sample = _sample.get("Text");
        pos.setForeground(sample.getForeground());
        if (pos instanceof PositionableLabel && !(pos instanceof jmri.jmrit.display.MemoryIcon)) {
            ((PositionableLabel) pos).setText(sample.getText());
        }
        if (sample.isOpaque()) {
            pos.setBackground(sample.getBackground());
        } else {
            pos.setBackground(null);
        }
        _util.setHasBackground(sample.isOpaque());
    }
}
Also used : SensorIcon(jmri.jmrit.display.SensorIcon) PositionableLabel(jmri.jmrit.display.PositionableLabel)

Example 4 with SensorIcon

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

the class ControlPanelEditor method showPopUp.

/**
     * Create popup for a Positionable object Popup items common to all
     * positionable objects are done before and after the items that pertain
     * only to specific Positionable types.
     */
@Override
protected void showPopUp(Positionable p, MouseEvent event) {
    if (!((JComponent) p).isVisible()) {
        // component must be showing on the screen to determine its location
        return;
    }
    JPopupMenu popup = new JPopupMenu();
    PositionablePopupUtil util = p.getPopupUtility();
    if (p.isEditable()) {
        // items common to all
        if (p.doViemMenu()) {
            popup.add(p.getNameString());
            setPositionableMenu(p, popup);
            if (p.isPositionable()) {
                setShowCoordinatesMenu(p, popup);
                setShowAlignmentMenu(p, popup);
            }
            setDisplayLevelMenu(p, popup);
            setHiddenMenu(p, popup);
            popup.addSeparator();
            setCopyMenu(p, popup);
        }
        // items with defaults or using overrides
        boolean popupSet = false;
        //            popupSet |= p.setRotateOrthogonalMenu(popup);
        popupSet |= p.setRotateMenu(popup);
        popupSet |= p.setScaleMenu(popup);
        if (popupSet) {
            popup.addSeparator();
            popupSet = false;
        }
        popupSet = p.setEditItemMenu(popup);
        if (popupSet) {
            popup.addSeparator();
            popupSet = false;
        }
        if (p instanceof PositionableLabel) {
            PositionableLabel pl = (PositionableLabel) p;
            /*                if (pl.isIcon() && "javax.swing.JLabel".equals(pl.getClass().getSuperclass().getName()) ) {
                    popupSet |= setTextAttributes(pl, popup);       // only for plain icons
                }   Add backgrounds & text over icons later */
            if (!pl.isIcon()) {
                popupSet |= setTextAttributes(pl, popup);
                if (p instanceof MemoryIcon) {
                    popupSet |= p.setTextEditMenu(popup);
                }
            } else if (p instanceof SensorIcon) {
                popup.add(CoordinateEdit.getTextEditAction(p, "OverlayText"));
                if (pl.isText()) {
                    popupSet |= setTextAttributes(p, popup);
                }
            } else {
                popupSet = p.setTextEditMenu(popup);
            }
        } else if (p instanceof PositionableJPanel) {
            popupSet |= setTextAttributes(p, popup);
        }
        if (p instanceof LinkingObject) {
            ((LinkingObject) p).setLinkMenu(popup);
        }
        if (popupSet) {
            popup.addSeparator();
            popupSet = false;
        }
        p.setDisableControlMenu(popup);
        if (util != null) {
            util.setAdditionalEditPopUpMenu(popup);
        }
        // for Positionables with unique settings
        p.showPopUp(popup);
        if (p.doViemMenu()) {
            setShowTooltipMenu(p, popup);
            setRemoveMenu(p, popup);
        }
    } else {
        if (p instanceof LocoIcon) {
            setCopyMenu(p, popup);
        }
        p.showPopUp(popup);
        if (util != null) {
            util.setAdditionalViewPopUpMenu(popup);
        }
    }
    popup.show((Component) p, p.getWidth() / 2 + (int) ((getPaintScale() - 1.0) * p.getX()), p.getHeight() / 2 + (int) ((getPaintScale() - 1.0) * p.getY()));
    _currentSelection = null;
}
Also used : PositionablePopupUtil(jmri.jmrit.display.PositionablePopupUtil) SensorIcon(jmri.jmrit.display.SensorIcon) LinkingObject(jmri.jmrit.display.LinkingObject) LocoIcon(jmri.jmrit.display.LocoIcon) MemoryIcon(jmri.jmrit.display.MemoryIcon) PositionableLabel(jmri.jmrit.display.PositionableLabel) JPopupMenu(javax.swing.JPopupMenu) PositionableJPanel(jmri.jmrit.display.PositionableJPanel)

Example 5 with SensorIcon

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

the class DecoratorPanel method initDecoratorPanel.

/* Called by Editor's TextAttrDialog - i.e. update a panel item from menu */
public void initDecoratorPanel(Positionable pos) {
    // copy of PositionableLabel being edited
    Positionable item = pos.deepClone();
    _util = item.getPopupUtility();
    if (pos instanceof SensorIcon && !((SensorIcon) pos).isIcon()) {
        SensorIcon si = (SensorIcon) pos;
        if (!si.isIcon() && si.isText()) {
            PositionableLabel sample = new PositionableLabel(si.getActiveText(), _editor);
            sample.setForeground(si.getTextActive());
            Color color = si.getBackgroundActive();
            if (color != null) {
                sample.setBackground(color);
                sample.setOpaque(true);
            }
            // NOI18N
            doPopupUtility("Active", ACTIVE_FONT, sample, _util, true);
            sample = new PositionableLabel(si.getInactiveText(), _editor);
            sample.setForeground(si.getTextInActive());
            color = si.getBackgroundInActive();
            if (color != null) {
                sample.setBackground(color);
                sample.setOpaque(true);
            }
            // NOI18N
            doPopupUtility("InActive", INACTIVE_FONT, sample, _util, true);
            sample = new PositionableLabel(si.getUnknownText(), _editor);
            sample.setForeground(si.getTextUnknown());
            color = si.getBackgroundUnknown();
            if (color != null) {
                sample.setBackground(color);
                sample.setOpaque(true);
            }
            // NOI18N
            doPopupUtility("Unknown", UNKOWN_FONT, sample, _util, true);
            sample = new PositionableLabel(si.getInconsistentText(), _editor);
            sample.setForeground(si.getTextInconsistent());
            color = si.getBackgroundInconsistent();
            if (color != null) {
                sample.setBackground(color);
                sample.setOpaque(true);
            }
            // NOI18N
            doPopupUtility("Inconsistent", INCONSISTENT_FONT, sample, _util, true);
        }
    } else {
        // not a SensorIcon
        PositionableLabel sample = new PositionableLabel("", _editor);
        sample.setForeground(pos.getForeground());
        sample.setBackground(pos.getBackground());
        sample.setOpaque(_util.hasBackground());
        boolean addtextField;
        if (pos instanceof PositionableLabel) {
            sample.setText(((PositionableLabel) pos).getUnRotatedText());
            if (pos instanceof jmri.jmrit.display.MemoryIcon) {
                addtextField = false;
            } else {
                addtextField = true;
            }
        } else if (pos instanceof jmri.jmrit.display.MemoryInputIcon) {
            JTextField field = (JTextField) ((jmri.jmrit.display.MemoryInputIcon) pos).getTextComponent();
            sample.setText(field.getText());
            addtextField = false;
        } else if (pos instanceof jmri.jmrit.display.MemoryComboIcon) {
            JComboBox<String> box = ((jmri.jmrit.display.MemoryComboIcon) pos).getTextComponent();
            sample.setText(box.getSelectedItem().toString());
            addtextField = false;
        } else if (pos instanceof jmri.jmrit.display.MemorySpinnerIcon) {
            JTextField field = (JTextField) ((jmri.jmrit.display.MemorySpinnerIcon) pos).getTextComponent();
            sample.setText(field.getText());
            addtextField = false;
        } else {
            addtextField = true;
        }
        doPopupUtility("Text", TEXT_FONT, sample, _util, addtextField);
    }
    makeFontPanels();
    //        item.setVisible(false);  // otherwise leaves traces for PositionableJPanels
    _chooser.getSelectionModel().addChangeListener(this);
    _chooser.setPreviewPanel(new JPanel());
    this.add(_chooser);
    _previewPanel.add(_samplePanel, java.awt.BorderLayout.CENTER);
    this.add(_previewPanel);
    updateSamples();
}
Also used : JPanel(javax.swing.JPanel) SensorIcon(jmri.jmrit.display.SensorIcon) Color(java.awt.Color) JTextField(javax.swing.JTextField) PositionableLabel(jmri.jmrit.display.PositionableLabel) Positionable(jmri.jmrit.display.Positionable)

Aggregations

SensorIcon (jmri.jmrit.display.SensorIcon)5 PositionableLabel (jmri.jmrit.display.PositionableLabel)3 Element (org.jdom2.Element)2 Color (java.awt.Color)1 JPanel (javax.swing.JPanel)1 JPopupMenu (javax.swing.JPopupMenu)1 JTextField (javax.swing.JTextField)1 NamedIcon (jmri.jmrit.catalog.NamedIcon)1 Editor (jmri.jmrit.display.Editor)1 LinkingObject (jmri.jmrit.display.LinkingObject)1 LocoIcon (jmri.jmrit.display.LocoIcon)1 MemoryIcon (jmri.jmrit.display.MemoryIcon)1 Positionable (jmri.jmrit.display.Positionable)1 PositionableJPanel (jmri.jmrit.display.PositionableJPanel)1 PositionablePopupUtil (jmri.jmrit.display.PositionablePopupUtil)1 Attribute (org.jdom2.Attribute)1