Search in sources :

Example 1 with LocoIcon

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

the class LocoIconXml 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;
    LocoIcon l = new LocoIcon(ed);
    // create the objects
    String textName = "error";
    try {
        textName = element.getAttribute("text").getValue();
    } catch (Exception e) {
        log.error("failed to get loco text attribute ex= " + e);
    }
    String name = "error";
    NamedIcon icon;
    try {
        name = element.getAttribute("icon").getValue();
    } catch (Exception e) {
        log.error("failed to get icon attribute ex= " + e);
    }
    if (name.equals("yes")) {
        icon = loadIcon(l, "icon", element, "LocoIcon", ed);
    } else {
        icon = NamedIcon.getIconByName(name);
        if (icon == null) {
            icon = ed.loadFailed("LocoIcon", name);
            if (icon == null) {
                log.info("LocoIcon icon removed for url= " + name);
                return;
            }
        }
    }
    l.updateIcon(icon);
    try {
        int x = element.getAttribute("dockX").getIntValue();
        int y = element.getAttribute("dockY").getIntValue();
        l.setDockingLocation(x, y);
    //           l.dock();
    } catch (Exception e) {
        log.warn("failed to get docking location= " + e);
    }
    String rosterId = null;
    try {
        rosterId = element.getAttribute("rosterentry").getValue();
        RosterEntry entry = Roster.getDefault().entryFromTitle(rosterId);
        l.setRosterEntry(entry);
    } catch (Exception e) {
        log.debug("no roster entry for " + rosterId + ", ex= " + e);
    }
    ed.putLocoIcon(l, textName);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.MARKERS, element);
    loadTextInfo(l, element);
    // to detect "background" color for use in Tracker, examine icon file 
    l.init();
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) LocoIcon(jmri.jmrit.display.LocoIcon) RosterEntry(jmri.jmrit.roster.RosterEntry) Editor(jmri.jmrit.display.Editor)

Example 2 with LocoIcon

use of jmri.jmrit.display.LocoIcon 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 3 with LocoIcon

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

the class ControlPanelEditor method pasteItems.

void pasteItems() {
    if (_selectionGroup != null) {
        for (Positionable pos : _selectionGroup) {
            if (pos instanceof PositionableIcon) {
                jmri.NamedBean bean = pos.getNamedBean();
                if (bean != null) {
                    ((PositionableIcon) pos).displayState(bean.getState());
                }
            }
            putItem(pos);
            log.debug("Add {}", pos.getNameString());
        }
        if (_selectionGroup.get(0) instanceof LocoIcon) {
            LocoIcon p = (LocoIcon) _selectionGroup.get(0);
            CoordinateEdit f = new CoordinateEdit();
            f.init("Train Name", p, false);
            f.initText();
            f.setVisible(true);
            f.setLocationRelativeTo(p);
        }
    }
    _pastePending = false;
}
Also used : LocoIcon(jmri.jmrit.display.LocoIcon) PositionableIcon(jmri.jmrit.display.PositionableIcon) CoordinateEdit(jmri.jmrit.display.CoordinateEdit) Positionable(jmri.jmrit.display.Positionable)

Example 4 with LocoIcon

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

the class LocoIconXml method store.

/**
     * Default implementation for storing the contents of a LocoIcon
     *
     * @param o Object to store, of type LocoIcon
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    LocoIcon p = (LocoIcon) o;
    if (!p.isActive()) {
        // if flagged as inactive, don't store
        return null;
    }
    Element element = new Element("locoicon");
    storeCommonAttributes(p, element);
    // include contents
    if (p.getUnRotatedText() != null) {
        element.setAttribute("text", p.getUnRotatedText());
    }
    storeTextInfo(p, element);
    element.setAttribute("icon", "yes");
    element.setAttribute("dockX", "" + p.getDockX());
    element.setAttribute("dockY", "" + p.getDockY());
    element.addContent(storeIcon("icon", (NamedIcon) p.getIcon()));
    RosterEntry entry = p.getRosterEntry();
    if (entry != null) {
        element.setAttribute("rosterentry", entry.getId());
    }
    element.setAttribute("class", "jmri.jmrit.display.configurexml.LocoIconXml");
    return element;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) LocoIcon(jmri.jmrit.display.LocoIcon) Element(org.jdom2.Element) RosterEntry(jmri.jmrit.roster.RosterEntry)

Aggregations

LocoIcon (jmri.jmrit.display.LocoIcon)4 NamedIcon (jmri.jmrit.catalog.NamedIcon)2 RosterEntry (jmri.jmrit.roster.RosterEntry)2 JPopupMenu (javax.swing.JPopupMenu)1 CoordinateEdit (jmri.jmrit.display.CoordinateEdit)1 Editor (jmri.jmrit.display.Editor)1 LinkingObject (jmri.jmrit.display.LinkingObject)1 MemoryIcon (jmri.jmrit.display.MemoryIcon)1 Positionable (jmri.jmrit.display.Positionable)1 PositionableIcon (jmri.jmrit.display.PositionableIcon)1 PositionableJPanel (jmri.jmrit.display.PositionableJPanel)1 PositionableLabel (jmri.jmrit.display.PositionableLabel)1 PositionablePopupUtil (jmri.jmrit.display.PositionablePopupUtil)1 SensorIcon (jmri.jmrit.display.SensorIcon)1 Element (org.jdom2.Element)1