Search in sources :

Example 1 with MemoryComboIcon

use of jmri.jmrit.display.MemoryComboIcon 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 MemoryComboIcon

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

the class MemoryComboIconXml method store.

/**
     * Default implementation for storing the contents of a MemorySpinnerIcon
     *
     * @param obj Object to store, of type MemorySpinnerIcon
     * @return Element containing the complete info
     */
@Override
public Element store(Object obj) {
    MemoryComboIcon memoryIcon = (MemoryComboIcon) obj;
    Element element = new Element("memoryComboIcon");
    Element elem = new Element("itemList");
    DefaultComboBoxModel<String> model = memoryIcon.getComboModel();
    for (int i = 0; i < model.getSize(); i++) {
        Element e = new Element("item");
        e.setAttribute("index", "" + i);
        e.addContent(model.getElementAt(i));
        elem.addContent(e);
    }
    element.addContent(elem);
    // include attributes
    element.setAttribute("memory", memoryIcon.getNamedMemory().getName());
    storeCommonAttributes(memoryIcon, element);
    storeTextInfo(memoryIcon, element);
    element.setAttribute("class", "jmri.jmrit.display.configurexml.MemoryComboIconXml");
    return element;
}
Also used : Element(org.jdom2.Element) MemoryComboIcon(jmri.jmrit.display.MemoryComboIcon)

Example 3 with MemoryComboIcon

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

the class MemoryComboIconXml method load.

/**
     * Load, starting with the memoryComboIcon 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) {
    // create the objects
    Editor p = (Editor) o;
    Element elem = element.getChild("itemList");
    List<Element> list = elem.getChildren("item");
    String[] items = new String[list.size()];
    for (int i = 0; i < list.size(); i++) {
        Element e = list.get(i);
        String item = e.getText();
        try {
            int idx = e.getAttribute("index").getIntValue();
            items[idx] = item;
        } catch (org.jdom2.DataConversionException ex) {
            log.error("failed to convert ComboBoxIcon index attribute");
            if (items[i] == null) {
                items[i] = item;
            }
        }
    }
    MemoryComboIcon l = new MemoryComboIcon(p, items);
    loadTextInfo(l, element);
    String name;
    Attribute attr = element.getAttribute("memory");
    if (attr == null) {
        log.error("incorrect information for a memory location; must use memory name");
        p.loadFailed();
        return;
    } else {
        name = attr.getValue();
    }
    Memory m = jmri.InstanceManager.memoryManagerInstance().getMemory(name);
    if (m != null) {
        l.setMemory(name);
    } else {
        log.error("Memory named '" + attr.getValue() + "' not found.");
        p.loadFailed();
        return;
    }
    p.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.MEMORIES, element);
}
Also used : Attribute(org.jdom2.Attribute) Memory(jmri.Memory) Element(org.jdom2.Element) Editor(jmri.jmrit.display.Editor) MemoryComboIcon(jmri.jmrit.display.MemoryComboIcon)

Aggregations

MemoryComboIcon (jmri.jmrit.display.MemoryComboIcon)3 Element (org.jdom2.Element)2 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)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 MemoryIcon (jmri.jmrit.display.MemoryIcon)1 MemoryInputIcon (jmri.jmrit.display.MemoryInputIcon)1 MemorySpinnerIcon (jmri.jmrit.display.MemorySpinnerIcon)1 Attribute (org.jdom2.Attribute)1