use of jmri.jmrit.display.Positionable in project JMRI by JMRI.
the class PortalIcon method setPositionableMenu.
private void setPositionableMenu(JPopupMenu popup) {
JCheckBoxMenuItem lockItem = new JCheckBoxMenuItem(Bundle.getMessage("LockPosition"));
lockItem.setSelected(!isPositionable());
lockItem.addActionListener(new ActionListener() {
Positionable comp;
JCheckBoxMenuItem checkBox;
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
comp.setPositionable(!checkBox.isSelected());
}
ActionListener init(Positionable pos, JCheckBoxMenuItem cb) {
comp = pos;
checkBox = cb;
return this;
}
}.init(this, lockItem));
JMenuItem jmi = popup.add(lockItem);
jmi.setEnabled(false);
}
use of jmri.jmrit.display.Positionable in project JMRI by JMRI.
the class EditPortalFrame method iconIntersectsBlock.
/**
* Query whether icon intersects any track icons of block
*
* @return null if intersection, otherwise a messags
*/
private String iconIntersectsBlock(PortalIcon icon, OBlock block) {
java.util.List<Positionable> list = _parent.getCircuitIcons(block);
if (list == null || list.size() == 0) {
return Bundle.getMessage("needIcons", block.getDisplayName(), Bundle.getMessage("editCircuitItem"));
}
Rectangle rect = new Rectangle();
Rectangle iconRect = icon.getBounds(new Rectangle());
for (int i = 0; i < list.size(); i++) {
Positionable comp = list.get(i);
if (CircuitBuilder.isTrack(comp)) {
rect = list.get(i).getBounds(rect);
if (iconRect.intersects(rect)) {
return null;
}
}
}
return Bundle.getMessage("iconNotOnBlock", block.getDisplayName(), icon.getNameString());
}
use of jmri.jmrit.display.Positionable in project JMRI by JMRI.
the class EditCircuitPaths method updatePath.
/**
* Sets the path icons for display
*
*/
protected void updatePath(boolean pathChanged) {
// to avoid ConcurrentModificationException now set data
Iterator<Positionable> iter = _pathGroup.iterator();
while (iter.hasNext()) {
Positionable pos = iter.next();
if (pos instanceof IndicatorTrack) {
((IndicatorTrack) pos).addPath(TEST_PATH);
} else {
((PortalIcon) pos).setStatus(PortalIcon.PATH);
}
}
_pathChange = pathChanged;
String name = _pathName.getText();
if (name == null || name.length() == 0) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("needPathName"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
} else {
}
}
use of jmri.jmrit.display.Positionable 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.Positionable in project JMRI by JMRI.
the class EditCircuitFrame method changeBlockName.
/**
* *********************** end setup *************************
*/
private void changeBlockName() {
String name = _blockName.getText();
if (name == null || name.trim().length() == 0) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("changeBlockName"), Bundle.getMessage("editCiruit"), JOptionPane.INFORMATION_MESSAGE);
return;
}
_block.setUserName(name);
// block user name change will change portal names. Change PortalIcon names to match
java.util.List<Positionable> list = _parent.getCircuitIcons(_block);
if (list != null) {
for (int i = 0; i < list.size(); i++) {
if (list.get(i) instanceof PortalIcon) {
PortalIcon icon = (PortalIcon) list.get(i);
Portal portal = icon.getPortal();
icon.setName(portal.getName());
icon.setTooltip(new ToolTip(portal.getDescription(), 0, 0));
}
}
}
}
Aggregations