Search in sources :

Example 1 with MemoryInputIcon

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

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

the class MemoryInputIconXml method store.

/**
     * Default implementation for storing the contents of a MemorySpinnerIcon
     *
     * @param o Object to store, of type MemorySpinnerIcon
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    MemoryInputIcon p = (MemoryInputIcon) o;
    Element element = new Element("memoryInputIcon");
    // include attributes
    element.setAttribute("colWidth", "" + p.getNumColumns());
    element.setAttribute("memory", p.getNamedMemory().getName());
    storeCommonAttributes(p, element);
    storeTextInfo(p, element);
    element.setAttribute("class", "jmri.jmrit.display.configurexml.MemoryInputIconXml");
    return element;
}
Also used : Element(org.jdom2.Element) MemoryInputIcon(jmri.jmrit.display.MemoryInputIcon)

Example 3 with MemoryInputIcon

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

the class MemoryInputIconXml method load.

/**
     * Load, starting with the memoryInputIcon 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;
    int nCol = 2;
    try {
        nCol = element.getAttribute("colWidth").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert colWidth attribute");
    }
    MemoryInputIcon l = new MemoryInputIcon(nCol, p);
    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);
    javax.swing.JComponent textField = l.getTextComponent();
    jmri.jmrit.display.PositionablePopupUtil util = l.getPopupUtility();
    if (util.hasBackground()) {
        textField.setBackground(util.getBackground());
    } else {
        textField.setBackground(null);
        textField.setOpaque(false);
    }
}
Also used : Attribute(org.jdom2.Attribute) Memory(jmri.Memory) MemoryInputIcon(jmri.jmrit.display.MemoryInputIcon) Editor(jmri.jmrit.display.Editor)

Aggregations

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