add(turnoutCanvas);
}
private void validateTurnout() {
TurnoutPersistenceIface turnoutPersistence = AdHocRailway.getInstance()
.getTurnoutPersistence();
boolean bus1Valid = true;
if (turnout.getBus1() == 0) {
setBackground(UIConstants.ERROR_COLOR);
bus1Valid = false;
} else {
setBackground(UIConstants.DEFAULT_PANEL_COLOR);
}
boolean address1Valid = true;
if (turnout.getAddress1() == 0
|| turnout.getAddress1() > MMTurnout.MAX_MM_TURNOUT_ADDRESS) {
setBackground(UIConstants.ERROR_COLOR);
address1Valid = false;
} else {
setBackground(UIConstants.DEFAULT_PANEL_COLOR);
}
if (bus1Valid && address1Valid) {
int bus1 = turnout.getBus1();
int address1 = turnout.getAddress1();
boolean unique1 = true;
for (Turnout t : turnoutPersistence.getAllTurnouts()) {
if (t.getBus1() == bus1 && t.getAddress1() == address1
&& !t.equals(turnout))
unique1 = false;
}
if (!unique1) {
setBackground(UIConstants.WARN_COLOR);
} else {
setBackground(UIConstants.DEFAULT_PANEL_COLOR);
}
}
if (turnout.isThreeWay()) {
boolean bus2Valid = true;
if (turnout.getBus2() == 0) {
setBackground(UIConstants.ERROR_COLOR);
bus2Valid = false;
} else {
setBackground(UIConstants.DEFAULT_PANEL_COLOR);
}
boolean address2Valid = true;
if (turnout.getAddress2() == 0
|| turnout.getAddress2() > MMTurnout.MAX_MM_TURNOUT_ADDRESS) {
setBackground(UIConstants.ERROR_COLOR);
address2Valid = false;
} else {
setBackground(UIConstants.DEFAULT_PANEL_COLOR);
}
if (bus2Valid && address2Valid) {
int bus2 = turnout.getBus2();
int address2 = turnout.getAddress2();
boolean unique2 = true;
for (Turnout t : turnoutPersistence.getAllTurnouts()) {
if (t.equals(turnout))
continue;
if ((t.getBus1() == bus2 && t.getAddress1() == address2)
|| (t.getBus2() == bus2 && t.getAddress2() == address2))
unique2 = false;