Search in sources :

Example 16 with Manager

use of jmri.Manager in project JMRI by JMRI.

the class TurnoutTableAction method addPressed.

@Override
protected void addPressed(ActionEvent e) {
    p = jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class);
    if (addFrame == null) {
        addFrame = new JmriJFrame(Bundle.getMessage("TitleAddTurnout"), false, true);
        addFrame.addHelpMenu("package.jmri.jmrit.beantable.TurnoutAddEdit", true);
        addFrame.getContentPane().setLayout(new BoxLayout(addFrame.getContentPane(), BoxLayout.Y_AXIS));
        ActionListener okListener = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                okPressed(e);
            }
        };
        ActionListener cancelListener = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                cancelPressed(e);
            }
        };
        ActionListener rangeListener = new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                canAddRange(e);
            }
        };
        /* We use the proxy manager in this instance so that we can deal with
             duplicate usernames in multiple classes */
        if (InstanceManager.turnoutManagerInstance() instanceof jmri.managers.AbstractProxyManager) {
            jmri.managers.ProxyTurnoutManager proxy = (jmri.managers.ProxyTurnoutManager) InstanceManager.turnoutManagerInstance();
            List<Manager> managerList = proxy.getManagerList();
            for (int x = 0; x < managerList.size(); x++) {
                String manuName = ConnectionNameFromSystemName.getConnectionName(managerList.get(x).getSystemPrefix());
                Boolean addToPrefix = true;
                //Simple test not to add a system with a duplicate System prefix
                for (int i = 0; i < prefixBox.getItemCount(); i++) {
                    if (prefixBox.getItemAt(i).equals(manuName)) {
                        addToPrefix = false;
                    }
                }
                if (addToPrefix) {
                    prefixBox.addItem(manuName);
                }
            }
            if (p.getComboBoxLastSelection(systemSelectionCombo) != null) {
                prefixBox.setSelectedItem(p.getComboBoxLastSelection(systemSelectionCombo));
            }
        } else {
            prefixBox.addItem(ConnectionNameFromSystemName.getConnectionName(turnManager.getSystemPrefix()));
        }
        sysNameTextField.setName("sysNameTextField");
        userNameTextField.setName("userNameTextField");
        prefixBox.setName("prefixBox");
        addFrame.add(new AddNewHardwareDevicePanel(sysNameTextField, userNameTextField, prefixBox, numberToAdd, range, "ButtonOK", okListener, cancelListener, rangeListener));
        //sysNameTextField.setToolTipText(Bundle.getMessage("HardwareAddressToolTip")); // already assigned by AddNew...
        canAddRange(null);
    }
    addFrame.pack();
    addFrame.setVisible(true);
}
Also used : ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) TurnoutOperationManager(jmri.TurnoutOperationManager) InstanceManager(jmri.InstanceManager) TurnoutManager(jmri.TurnoutManager) GuiLafPreferencesManager(apps.gui.GuiLafPreferencesManager) Manager(jmri.Manager) ActionListener(java.awt.event.ActionListener) JmriJFrame(jmri.util.JmriJFrame)

Aggregations

Manager (jmri.Manager)16 InstanceManager (jmri.InstanceManager)12 JTable (javax.swing.JTable)9 JTextField (javax.swing.JTextField)9 NamedBean (jmri.NamedBean)9 JButton (javax.swing.JButton)6 JComboBox (javax.swing.JComboBox)6 GuiLafPreferencesManager (apps.gui.GuiLafPreferencesManager)5 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 MouseEvent (java.awt.event.MouseEvent)4 SensorManager (jmri.SensorManager)4 TurnoutManager (jmri.TurnoutManager)4 Image (java.awt.Image)3 MouseAdapter (java.awt.event.MouseAdapter)3 BufferedImage (java.awt.image.BufferedImage)3 File (java.io.File)3 IOException (java.io.IOException)3 AbstractCellEditor (javax.swing.AbstractCellEditor)3 ImageIcon (javax.swing.ImageIcon)3