Search in sources :

Example 1 with ManagerDefaultSelector

use of jmri.managers.ManagerDefaultSelector in project JMRI by JMRI.

the class ManagerDefaultsConfigPane method reloadConnections.

void reloadConnections(List<SystemConnectionMemo> connList) {
    log.debug(" reloadConnections");
    ManagerDefaultSelector manager = InstanceManager.getDefault(ManagerDefaultSelector.class);
    matrix.setLayout(new GridLayout2(connList.size() + 1, manager.knownManagers.length + 1));
    matrix.add(new JLabel(""));
    for (ManagerDefaultSelector.Item item : manager.knownManagers) {
        matrix.add(new JLabel(item.typeName));
    }
    groups = new ButtonGroup[manager.knownManagers.length];
    for (int i = 0; i < manager.knownManagers.length; i++) {
        groups[i] = new ButtonGroup();
    }
    boolean[] selected = new boolean[manager.knownManagers.length];
    for (int x = 0; x < connList.size(); x++) {
        // up to down
        jmri.jmrix.SystemConnectionMemo memo = connList.get(x);
        String name = memo.getUserName();
        matrix.add(new JLabel(name));
        int i = 0;
        for (ManagerDefaultSelector.Item item : manager.knownManagers) {
            // left to right
            if (memo.provides(item.managerClass)) {
                JRadioButton r = new SelectionButton(name, item.managerClass, this);
                matrix.add(r);
                groups[i].add(r);
                if (!selected[i] && manager.getDefault(item.managerClass) == null) {
                    r.setSelected(true);
                    selected[i] = true;
                }
            } else {
                // leave a blank
                JRadioButton r = new JRadioButton();
                r.setEnabled(false);
                matrix.add(r);
            }
            //we need to increment 'i' as we are going onto the next group even if we added a blank button
            i++;
        }
    }
    revalidate();
}
Also used : ManagerDefaultSelector(jmri.managers.ManagerDefaultSelector) JRadioButton(javax.swing.JRadioButton) GridLayout2(jmri.util.javaworld.GridLayout2) ButtonGroup(javax.swing.ButtonGroup) SystemConnectionMemo(jmri.jmrix.SystemConnectionMemo) JLabel(javax.swing.JLabel)

Aggregations

ButtonGroup (javax.swing.ButtonGroup)1 JLabel (javax.swing.JLabel)1 JRadioButton (javax.swing.JRadioButton)1 SystemConnectionMemo (jmri.jmrix.SystemConnectionMemo)1 ManagerDefaultSelector (jmri.managers.ManagerDefaultSelector)1 GridLayout2 (jmri.util.javaworld.GridLayout2)1