Search in sources :

Example 61 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class JmriBeanComboBox method getDisplayList.

/**
     * Get the display list used by this combo box
     *
     * @return the display list used by this combo box
     */
public String[] getDisplayList() {
    ArrayList<String> nameList = new ArrayList<>(Arrays.asList(_manager.getSystemNameArray()));
    for (NamedBean bean : exclude) {
        if (bean != null) {
            nameList.remove(bean.getSystemName());
        }
    }
    String[] displayList = new String[nameList.size()];
    if (_displayOrder == DisplayOptions.SYSTEMNAME) {
        displayList = nameList.toArray(displayList);
    } else {
        for (int i = 0; i < nameList.size(); i++) {
            String name = nameList.get(i);
            NamedBean nBean = _manager.getBeanBySystemName(name);
            if (nBean != null) {
                String uname = nBean.getUserName();
                switch(_displayOrder) {
                    case DISPLAYNAME:
                        displayList[i] = nBean.getDisplayName();
                        break;
                    case USERNAME:
                        if (uname != null && !uname.equals("")) {
                            displayList[i] = uname;
                        } else {
                            displayList[i] = name;
                        }
                        break;
                    case USERNAMESYSTEMNAME:
                        if (uname != null && !uname.equals("")) {
                            displayList[i] = nBean.getUserName() + " - " + name;
                        } else {
                            displayList[i] = name;
                        }
                        break;
                    case SYSTEMNAMEUSERNAME:
                        if (uname != null && !uname.equals("")) {
                            displayList[i] = name + " - " + nBean.getUserName();
                        } else {
                            displayList[i] = name;
                        }
                        break;
                    default:
                        displayList[i] = nBean.getDisplayName();
                }
                displayToBean.put(displayList[i], nBean);
            }
        }
    }
    java.util.Arrays.sort(displayList, new AlphanumComparator());
    return displayList;
}
Also used : NamedBean(jmri.NamedBean) AlphanumComparator(jmri.util.AlphanumComparator) ArrayList(java.util.ArrayList)

Example 62 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class JmriBeanComboBox method getSelectedDisplayName.

/**
     * Get the display name of the selected namedBean
     *
     * @return the display name of the selected bean or null if there is no
     *         selection
     */
public String getSelectedDisplayName() {
    String result = null;
    NamedBean nBean = getSelectedBean();
    if (nBean != null) {
        result = nBean.getDisplayName();
    }
    return result;
}
Also used : NamedBean(jmri.NamedBean)

Example 63 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class JmriBeanComboBox method setDisplayOrder.

/**
     * Set the display order of the combobox
     *
     * @param inDisplayOrder - the desired display order for this combobox
     */
public void setDisplayOrder(DisplayOptions inDisplayOrder) {
    if (_displayOrder != inDisplayOrder) {
        NamedBean selectedBean = getSelectedBean();
        _displayOrder = inDisplayOrder;
        //refreshCombo();
        setSelectedBean(selectedBean);
    }
}
Also used : NamedBean(jmri.NamedBean)

Example 64 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class JmriBeanComboBox method getDisplayName.

//getUserName
/**
     * Get the display name for the selection in this JmriBeanComboBox (based on
     * typed in text or drop down list)
     *
     * @return the display name or null if no selection
     */
public String getDisplayName() {
    String result = null;
    NamedBean b = null;
    if (isEditable()) {
        result = getEditor().getItem().toString();
        result = (null != result) ? NamedBean.normalizeUserName(result) : "";
        b = getNamedBean();
    } else {
        b = getSelectedBean();
    }
    if (null != b) {
        result = b.getDisplayName();
    }
    return result;
}
Also used : NamedBean(jmri.NamedBean)

Example 65 with NamedBean

use of jmri.NamedBean in project JMRI by JMRI.

the class NamedBeanTest method testGetBeanPropertyKeys.

public void testGetBeanPropertyKeys() {
    NamedBean n = createInstance();
    n.setProperty("foo", "bar");
    n.setProperty("biff", "bar");
    java.util.Set<String> s = n.getPropertyKeys();
    Assert.assertEquals("size", 2, s.size());
    Assert.assertEquals("contains foo", true, s.contains("foo"));
    Assert.assertEquals("contains biff", true, s.contains("biff"));
}
Also used : NamedBean(jmri.NamedBean)

Aggregations

NamedBean (jmri.NamedBean)104 ArrayList (java.util.ArrayList)18 JTextField (javax.swing.JTextField)12 JmriException (jmri.JmriException)12 SignalMast (jmri.SignalMast)12 JTable (javax.swing.JTable)11 Manager (jmri.Manager)9 Sensor (jmri.Sensor)9 JButton (javax.swing.JButton)8 InstanceManager (jmri.InstanceManager)8 JComboBox (javax.swing.JComboBox)7 MouseEvent (java.awt.event.MouseEvent)6 Hashtable (java.util.Hashtable)6 SignalHead (jmri.SignalHead)6 Turnout (jmri.Turnout)6 OBlock (jmri.jmrit.logix.OBlock)5 File (java.io.File)4 JLabel (javax.swing.JLabel)4 TableCellEditor (javax.swing.table.TableCellEditor)4 TableCellRenderer (javax.swing.table.TableCellRenderer)4