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);
}
Aggregations