Search in sources :

Example 1 with MemoryIcon

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

the class MemoryItemPanel method makeDndIconPanel.

@Override
protected void makeDndIconPanel(java.util.HashMap<String, NamedIcon> iconMap, String displayKey) {
    if (_update) {
        return;
    }
    JPanel panel = new JPanel();
    panel.setLayout(new java.awt.GridBagLayout());
    java.awt.GridBagConstraints c = new java.awt.GridBagConstraints();
    c.gridwidth = 1;
    c.gridheight = 1;
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = java.awt.GridBagConstraints.CENTER;
    c.weightx = 1.0;
    panel.add(new JLabel(Bundle.getMessage("ReadWriteMemory")), c);
    c.gridy = 1;
    _writeMem = new MemoryInputIcon(5, _editor);
    //        JPanel p0 = makeDragIcon(_writeMem, Type.READWRITE);
    panel.add(makeDragIcon(_writeMem, Type.READWRITE), c);
    _spinner = new JSpinner(new SpinnerNumberModel(0, 0, 100, 1));
    JTextField field = ((JSpinner.DefaultEditor) _spinner.getEditor()).getTextField();
    field.setColumns(2);
    field.setText("5");
    _spinner.setMaximumSize(_spinner.getPreferredSize());
    _spinner.addChangeListener(this);
    c.gridy = 2;
    panel.add(_spinner, c);
    c.gridy = 3;
    c.anchor = java.awt.GridBagConstraints.NORTH;
    panel.add(new JLabel(Bundle.getMessage("NumColsLabel")), c);
    c.gridx = 1;
    c.gridy = 0;
    c.anchor = java.awt.GridBagConstraints.CENTER;
    panel.add(new JLabel(Bundle.getMessage("ReadMemory")), c);
    c.gridy = 1;
    _readMem = new MemoryIcon(NamedIcon.getIconByName("resources/icons/misc/X-red.gif"), _editor);
    panel.add(makeDragIcon(_readMem, Type.READONLY), c);
    c.gridx = 2;
    c.gridy = 0;
    panel.add(new JLabel(Bundle.getMessage("SpinnerMemory")), c);
    c.gridy = 1;
    _spinMem = new MemorySpinnerIcon(_editor);
    panel.add(makeDragIcon(_spinMem, Type.SPINNER), c);
    c.gridx = 0;
    c.gridy = 2;
    c.gridwidth = 4;
    panel.add(new JLabel(Bundle.getMessage("ComboMemory")), c);
    c.gridy = 3;
    _comboMem = new MemoryComboIcon(_editor, null);
    panel.add(makeDragIcon(_comboMem, Type.COMBO), c);
    _dragIconPanel = panel;
    _dragIconPanel.invalidate();
}
Also used : JPanel(javax.swing.JPanel) MemoryIcon(jmri.jmrit.display.MemoryIcon) MemorySpinnerIcon(jmri.jmrit.display.MemorySpinnerIcon) JLabel(javax.swing.JLabel) MemoryInputIcon(jmri.jmrit.display.MemoryInputIcon) JTextField(javax.swing.JTextField) MemoryComboIcon(jmri.jmrit.display.MemoryComboIcon) SpinnerNumberModel(javax.swing.SpinnerNumberModel) JSpinner(javax.swing.JSpinner)

Example 2 with MemoryIcon

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

the class ControlPanelEditor method pasteFromClipboard.

private void pasteFromClipboard() {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    DataFlavor[] flavors = clipboard.getAvailableDataFlavors();
    for (DataFlavor flavor : flavors) {
        if (_positionableListDataFlavor.equals(flavor)) {
            try {
                @SuppressWarnings("unchecked") List<Positionable> clipGroup = (List<Positionable>) clipboard.getData(_positionableListDataFlavor);
                if (clipGroup != null && clipGroup.size() > 0) {
                    Positionable pos = clipGroup.get(0);
                    int minX = pos.getLocation().x;
                    int minY = pos.getLocation().y;
                    // locate group at mouse point
                    for (int i = 1; i < clipGroup.size(); i++) {
                        pos = clipGroup.get(i);
                        minX = Math.min(minX, pos.getLocation().x);
                        minY = Math.min(minY, pos.getLocation().y);
                    }
                    if (_pastePending) {
                        abortPasteItems();
                    }
                    _selectionGroup = new ArrayList<Positionable>();
                    for (int i = 0; i < clipGroup.size(); i++) {
                        pos = clipGroup.get(i);
                        // make positionable belong to this editor
                        pos.setEditor(this);
                        pos.setLocation(pos.getLocation().x + _anchorX - minX, pos.getLocation().y + _anchorY - minY);
                        // now set display level in the pane.
                        pos.setDisplayLevel(pos.getDisplayLevel());
                        putItem(pos);
                        pos.updateSize();
                        pos.setVisible(true);
                        _selectionGroup.add(pos);
                        if (pos instanceof PositionableIcon) {
                            jmri.NamedBean bean = pos.getNamedBean();
                            if (bean != null) {
                                ((PositionableIcon) pos).displayState(bean.getState());
                            }
                        } else if (pos instanceof MemoryIcon) {
                            ((MemoryIcon) pos).displayState();
                        } else if (pos instanceof PositionableJComponent) {
                            ((PositionableJComponent) pos).displayState();
                        }
                        log.debug("Paste Added at ({}, {})", pos.getLocation().x, pos.getLocation().y);
                    }
                }
                return;
            } catch (IOException ioe) {
                log.warn("Editor Paste caught IOException", ioe);
            } catch (UnsupportedFlavorException ufe) {
                log.warn("Editor Paste caught UnsupportedFlavorException", ufe);
            }
        }
    }
}
Also used : MemoryIcon(jmri.jmrit.display.MemoryIcon) PositionableIcon(jmri.jmrit.display.PositionableIcon) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) Point(java.awt.Point) DataFlavor(java.awt.datatransfer.DataFlavor) PositionableJComponent(jmri.jmrit.display.PositionableJComponent) List(java.util.List) ArrayList(java.util.ArrayList) Clipboard(java.awt.datatransfer.Clipboard) Positionable(jmri.jmrit.display.Positionable)

Example 3 with MemoryIcon

use of jmri.jmrit.display.MemoryIcon 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 4 with MemoryIcon

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

the class MemoryIconXml method load.

/**
     * Load, starting with the memoryicon element, then all the value-icon pairs
     *
     * @param element Top level Element to unpack.
     * @param o       an Editor as an Object
     */
@Override
public void load(Element element, Object o) {
    Editor ed = null;
    MemoryIcon l;
    if (o instanceof LayoutEditor) {
        ed = (LayoutEditor) o;
        l = new jmri.jmrit.display.layoutEditor.MemoryIcon("   ", (LayoutEditor) ed);
    } else if (o instanceof jmri.jmrit.display.Editor) {
        ed = (Editor) o;
        l = new MemoryIcon("", ed);
    } else {
        log.error("Unrecognizable class - " + o.getClass().getName());
        return;
    }
    String name;
    Attribute attr = element.getAttribute("memory");
    if (attr == null) {
        log.error("incorrect information for a memory location; must use memory name");
        ed.loadFailed();
        return;
    } else {
        name = attr.getValue();
    }
    loadTextInfo(l, element);
    Memory m = jmri.InstanceManager.memoryManagerInstance().getMemory(name);
    if (m != null) {
        l.setMemory(name);
    } else {
        log.error("Memory named '" + attr.getValue() + "' not found.");
        ed.loadFailed();
    }
    Attribute a = element.getAttribute("selectable");
    if (a != null && a.getValue().equals("yes")) {
        l.setSelectable(true);
    } else {
        l.setSelectable(false);
    }
    a = element.getAttribute("updateBlockValue");
    if (a != null && a.getValue().equals("yes")) {
        l.updateBlockValueOnChange(true);
    }
    // get the icon pairs
    List<Element> items = element.getChildren("memorystate");
    for (int i = 0; i < items.size(); i++) {
        // get the class, hence the adapter object to do loading
        Element item = items.get(i);
        String iconName = item.getAttribute("icon").getValue();
        NamedIcon icon = NamedIcon.getIconByName(iconName);
        if (icon == null) {
            icon = ed.loadFailed("Memory " + name, iconName);
            if (icon == null) {
                log.info("Memory \"" + name + "\" icon removed for url= " + iconName);
            }
        }
        if (icon != null) {
            String keyValue = item.getAttribute("value").getValue();
            l.addKeyAndIcon(icon, keyValue);
        }
    }
    ed.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.MEMORIES, element);
    int x = 0;
    int y = 0;
    try {
        x = element.getAttribute("x").getIntValue();
        y = element.getAttribute("y").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert positional attribute");
    }
    l.setOriginalLocation(x, y);
    l.displayState();
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) MemoryIcon(jmri.jmrit.display.MemoryIcon) Attribute(org.jdom2.Attribute) Memory(jmri.Memory) Element(org.jdom2.Element) Editor(jmri.jmrit.display.Editor) LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) Editor(jmri.jmrit.display.Editor)

Example 5 with MemoryIcon

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

the class MemoryIconXml method store.

/**
     * Default implementation for storing the contents of a MemoryIcon
     *
     * @param o Object to store, of type MemoryIcon
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    MemoryIcon p = (MemoryIcon) o;
    Element element = new Element("memoryicon");
    // include attributes
    element.setAttribute("memory", p.getNamedMemory().getName());
    storeCommonAttributes(p, element);
    storeTextInfo(p, element);
    //Then we need to replace the x, y values with the original ones.
    if (p.getPopupUtility().getFixedWidth() == 0 && p.getPopupUtility().getJustification() != 0) {
        element.setAttribute("x", "" + p.getOriginalX());
        element.setAttribute("y", "" + p.getOriginalY());
    }
    element.setAttribute("selectable", (p.isSelectable() ? "yes" : "no"));
    if (p.updateBlockValueOnChange()) {
        element.setAttribute("updateBlockValue", (p.updateBlockValueOnChange() ? "yes" : "no"));
    }
    element.setAttribute("class", "jmri.jmrit.display.configurexml.MemoryIconXml");
    if (p.getDefaultIcon() != null) {
        element.setAttribute("defaulticon", p.getDefaultIcon().getURL());
    }
    // include contents
    java.util.HashMap<String, NamedIcon> map = p.getMap();
    if (map != null) {
        java.util.Iterator<java.util.Map.Entry<String, NamedIcon>> iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            java.util.Map.Entry<String, NamedIcon> mi = iterator.next();
            String key = mi.getKey();
            String value = mi.getValue().getName();
            Element e2 = new Element("memorystate");
            e2.setAttribute("value", key);
            e2.setAttribute("icon", value);
            element.addContent(e2);
        }
    }
    return element;
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) MemoryIcon(jmri.jmrit.display.MemoryIcon) Element(org.jdom2.Element)

Aggregations

MemoryIcon (jmri.jmrit.display.MemoryIcon)5 NamedIcon (jmri.jmrit.catalog.NamedIcon)2 Element (org.jdom2.Element)2 Point (java.awt.Point)1 Clipboard (java.awt.datatransfer.Clipboard)1 DataFlavor (java.awt.datatransfer.DataFlavor)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JPopupMenu (javax.swing.JPopupMenu)1 JSpinner (javax.swing.JSpinner)1 JTextField (javax.swing.JTextField)1 SpinnerNumberModel (javax.swing.SpinnerNumberModel)1 Memory (jmri.Memory)1 Editor (jmri.jmrit.display.Editor)1 LinkingObject (jmri.jmrit.display.LinkingObject)1 LocoIcon (jmri.jmrit.display.LocoIcon)1