use of jmri.jmrit.display.IndicatorTrack in project JMRI by JMRI.
the class EditCircuitPaths method makeOPath.
/**
* Make the OPath from the icons in the Iterator
*/
private OPath makeOPath(String name, ArrayList<Positionable> pathGp, boolean showMsg) {
if (pathGp.size() == 0) {
if (showMsg) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("noPathIcons"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
}
return null;
}
Iterator<Positionable> it = pathGp.iterator();
ArrayList<BeanSetting> settings = new ArrayList<BeanSetting>();
Portal fromPortal = null;
Portal toPortal = null;
boolean hasTrack = false;
int portalIconCount = 0;
while (it.hasNext()) {
Positionable pos = it.next();
if (pos instanceof IndicatorTurnoutIcon) {
jmri.Turnout t = ((IndicatorTurnoutIcon) pos).getTurnout();
String turnoutName = ((IndicatorTurnoutIcon) pos).getNamedTurnout().getName();
int state = t.getKnownState();
if (state != Turnout.CLOSED && state != Turnout.THROWN) {
if (showMsg) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("turnoutNotSet", t.getDisplayName()), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
}
return null;
}
settings.add(new BeanSetting(t, turnoutName, state));
hasTrack = true;
} else if (pos instanceof PortalIcon) {
if (toPortal == null) {
toPortal = ((PortalIcon) pos).getPortal();
} else if (fromPortal == null) {
fromPortal = ((PortalIcon) pos).getPortal();
}
portalIconCount++;
} else if (pos instanceof IndicatorTrack) {
hasTrack = true;
}
}
if (showMsg) {
if (!hasTrack) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("noPathIcons"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
return null;
}
if (toPortal == null && fromPortal == null) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("tooFewPortals"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
return null;
}
if (portalIconCount == 0) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("noPortalIcons"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
}
if (portalIconCount > 2) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("tooManyPortals"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
return null;
}
}
if (hasTrack && portalIconCount > 0 && portalIconCount < 3) {
return new OPath(name, _block, fromPortal, toPortal, settings);
}
return null;
}
use of jmri.jmrit.display.IndicatorTrack in project JMRI by JMRI.
the class EditCircuitPaths method clearPath.
private void clearPath() {
for (int i = 0; i < _pathGroup.size(); i++) {
Positionable pos = _pathGroup.get(i);
if (pos instanceof PortalIcon) {
((PortalIcon) pos).setStatus(PortalIcon.VISIBLE);
} else {
((IndicatorTrack) pos).removePath(TEST_PATH);
}
}
int state = _block.getState() & ~OBlock.ALLOCATED;
_pathGroup = new ArrayList<Positionable>();
_block.pseudoPropertyChange("state", Integer.valueOf(0), Integer.valueOf(state));
}
Aggregations