"Please configure a group first", "Add Turnouts",
JOptionPane.INFORMATION_MESSAGE,
createImageIcon("messagebox_info.png"));
return;
}
TurnoutConfig config = null;
int selectedGroupPane = turnoutGroupsTabbedPane.getSelectedIndex();
do {
TurnoutGroup selectedTurnoutGroup = indexToTurnoutGroup
.get(selectedGroupPane);
int nextNumber = 0;
TurnoutPersistenceIface turnoutPersistence = AdHocRailway
.getInstance().getTurnoutPersistence();
if (Preferences
.getInstance()
.getBooleanValue(
PreferencesKeys.USE_FIXED_TURNOUT_AND_ROUTE_GROUP_SIZES)) {
nextNumber = turnoutPersistence
.getNextFreeTurnoutNumberOfGroup(selectedTurnoutGroup);
if (nextNumber == -1) {
JOptionPane.showMessageDialog(
AdHocRailway.getInstance(),
"No more free numbers in this group", "Error",
JOptionPane.ERROR_MESSAGE);
AdHocRailway.getInstance().updateGUI();
turnoutGroupsTabbedPane
.setSelectedIndex(selectedGroupPane);
return;
}
} else {
nextNumber = turnoutPersistence.getNextFreeTurnoutNumber();
}
Turnout newTurnout = new Turnout();
newTurnout.setNumber(nextNumber);
newTurnout.setBus1(Preferences.getInstance().getIntValue(
PreferencesKeys.DEFAULT_TURNOUT_BUS));
newTurnout.setBus2(Preferences.getInstance().getIntValue(
PreferencesKeys.DEFAULT_TURNOUT_BUS));
newTurnout.setTurnoutGroup(selectedTurnoutGroup);
newTurnout.setDefaultStateEnum(SRCPTurnoutState.STRAIGHT);
newTurnout.setOrientationEnum(TurnoutOrientation.EAST);
newTurnout.setTurnoutType(turnoutPersistence
.getTurnoutType(SRCPTurnoutTypes.DEFAULT));
config = new TurnoutConfig(AdHocRailway.getInstance(),
newTurnout);
} while (!config.isCancelPressed());
AdHocRailway.getInstance().updateGUI();
turnoutGroupsTabbedPane.setSelectedIndex(selectedGroupPane);
}