use of jmri.jmrit.logix.OPath in project JMRI by JMRI.
the class EditCircuitPaths method makeContentPanel.
private JPanel makeContentPanel() {
JPanel pathPanel = new JPanel();
pathPanel.setLayout(new BoxLayout(pathPanel, BoxLayout.Y_AXIS));
pathPanel.add(Box.createVerticalStrut(STRUT_SIZE));
JPanel panel = new JPanel();
panel.add(new JLabel(Bundle.getMessage("PathTitle", _block.getDisplayName())));
pathPanel.add(panel);
_pathListModel = new PathListModel();
_pathList = new JList<OPath>();
_pathList.setModel(_pathListModel);
_pathList.addListSelectionListener(this);
_pathList.setCellRenderer(new PathCellRenderer());
JScrollPane pane = new JScrollPane(_pathList);
pathPanel.add(pane);
pathPanel.add(Box.createVerticalStrut(STRUT_SIZE));
panel = new JPanel();
panel.setLayout(new FlowLayout());
JButton clearButton = new JButton(Bundle.getMessage("buttonClearSelection"));
clearButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent a) {
clearListSelection();
}
});
clearButton.setToolTipText(Bundle.getMessage("ToolTipClearList"));
panel.add(clearButton);
pathPanel.add(panel);
pathPanel.add(Box.createVerticalStrut(STRUT_SIZE));
panel = new JPanel();
panel.add(CircuitBuilder.makeTextBoxPanel(false, _pathName, "pathName", true, "TooltipPathName"));
_pathName.setPreferredSize(new Dimension(300, _pathName.getPreferredSize().height));
pathPanel.add(panel);
panel = new JPanel();
JButton addButton = new JButton(Bundle.getMessage("buttonAddPath"));
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent a) {
addPath();
}
});
addButton.setToolTipText(Bundle.getMessage("ToolTipAddPath"));
panel.add(addButton);
JButton changeButton = new JButton(Bundle.getMessage("buttonChangeName"));
changeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent a) {
changePathName();
}
});
changeButton.setToolTipText(Bundle.getMessage("ToolTipChangeName"));
panel.add(changeButton);
JButton deleteButton = new JButton(Bundle.getMessage("buttonDeletePath"));
deleteButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent a) {
deletePath();
}
});
deleteButton.setToolTipText(Bundle.getMessage("ToolTipDeletePath"));
panel.add(deleteButton);
pathPanel.add(panel);
pathPanel.add(Box.createVerticalStrut(STRUT_SIZE));
JPanel pp = new JPanel();
// pp.setLayout(new BoxLayout(pp, BoxLayout.X_AXIS));
_length.setText("0.0");
pp.add(CircuitBuilder.makeTextBoxPanel(false, _length, "Length", true, "TooltipPathLength"));
_length.setPreferredSize(new Dimension(100, _length.getPreferredSize().height));
_length.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
_pathChange = true;
}
});
_units = new JToggleButton("", !_block.isMetric());
_units.setToolTipText(Bundle.getMessage("TooltipPathUnitButton"));
_units.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
changeUnits();
}
});
pp.add(_units);
pathPanel.add(pp);
pathPanel.add(Box.createVerticalStrut(STRUT_SIZE));
panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
JLabel l = new JLabel(Bundle.getMessage("enterNewPath"));
l.setAlignmentX(JComponent.LEFT_ALIGNMENT);
panel.add(l);
l = new JLabel(Bundle.getMessage("selectPathIcons"));
l.setAlignmentX(JComponent.LEFT_ALIGNMENT);
panel.add(l);
l = new JLabel(Bundle.getMessage("pressAddButton", Bundle.getMessage("buttonAddPath")));
l.setAlignmentX(JComponent.LEFT_ALIGNMENT);
panel.add(l);
panel.add(Box.createVerticalStrut(STRUT_SIZE / 2));
l = new JLabel(Bundle.getMessage("selectPath"));
l.setAlignmentX(JComponent.LEFT_ALIGNMENT);
panel.add(l);
l = new JLabel(Bundle.getMessage("editPathIcons"));
l.setAlignmentX(JComponent.LEFT_ALIGNMENT);
panel.add(l);
panel.add(Box.createVerticalStrut(STRUT_SIZE / 2));
l = new JLabel(Bundle.getMessage("throwPathTO"));
l.setAlignmentX(JComponent.LEFT_ALIGNMENT);
panel.add(l);
l = new JLabel(Bundle.getMessage("holdShiftDown"));
l.setAlignmentX(JComponent.LEFT_ALIGNMENT);
panel.add(l);
JPanel p = new JPanel();
p.add(panel);
pathPanel.add(p);
pathPanel.add(Box.createVerticalStrut(STRUT_SIZE));
pathPanel.add(MakeButtonPanel());
changeUnits();
return pathPanel;
}
use of jmri.jmrit.logix.OPath in project JMRI by JMRI.
the class EditCircuitPaths method addPath.
/**
* Create or update the selected path named in the text field
* Checks that icons have been selected for the path
*/
private void addPath() {
String name = _pathName.getText();
if (name == null || name.trim().length() == 0) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("TooltipPathName"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE);
return;
}
OPath otherPath = _block.getPathByName(name);
boolean sameName = false;
if (otherPath != null) {
_pathList.setSelectedValue(otherPath, true);
sameName = true;
if (!_pathChange) {
// check portals OK
Portal p = otherPath.getFromPortal();
if (p != null && !p.isValidPath(otherPath)) {
p.addPath(otherPath);
}
p = otherPath.getToPortal();
if (p != null && !p.isValidPath(otherPath)) {
p.addPath(otherPath);
}
setPathLength(otherPath);
return;
}
}
OPath path = makeOPath(name, _pathGroup, true);
if (path == null) {
// proper OPath cannot be made
return;
}
if (otherPath == null) {
// is this path already defined?
Iterator<Path> iter = _block.getPaths().iterator();
while (iter.hasNext()) {
OPath p = (OPath) iter.next();
if (pathsEqual(path, p)) {
otherPath = p;
break;
}
}
}
// match icons to current selections
changePathNameInIcons(name, path);
if (otherPath != null) {
// same path
if (!sameName) {
int result = JOptionPane.showConfirmDialog(this, Bundle.getMessage("samePath", otherPath.getName(), name), Bundle.getMessage("makePath"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (result == JOptionPane.YES_OPTION) {
changePathName();
}
}
_pathList.setSelectedValue(otherPath, true);
}
Portal toPortal = path.getToPortal();
Portal fromPortal = path.getFromPortal();
if (fromPortal != null && fromPortal.equals(toPortal)) {
int result = JOptionPane.showConfirmDialog(this, Bundle.getMessage("balloonTrack", name, fromPortal.getDescription()), Bundle.getMessage("makePath"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (result == JOptionPane.NO_OPTION) {
fromPortal = null;
}
}
_pathChange = false;
// Just update OPath changes
if (sameName) {
OPath oldPath = _block.getPathByName(name);
oldPath.setToPortal(toPortal);
oldPath.setFromPortal(fromPortal);
setPathLength(oldPath);
oldPath.clearSettings();
Iterator<BeanSetting> it = path.getSettings().iterator();
while (it.hasNext()) {
oldPath.addSetting(it.next());
}
toPortal.addPath(oldPath);
if (fromPortal != null) {
fromPortal.addPath(oldPath);
}
} else {
// OBlock adds path to portals and checks for duplicate path names
_block.addPath(path);
setPathLength(path);
}
_pathList.setSelectedValue(path, true);
_pathListModel.dataChange();
}
use of jmri.jmrit.logix.OPath 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.logix.OPath in project JMRI by JMRI.
the class EditCircuitPaths method deletePath.
private void deletePath() {
OPath path = _pathList.getSelectedValue();
if (path == null) {
// check that name was typed in and not selected
path = _block.getPathByName(_pathName.getText());
}
if (path == null) {
return;
}
_pathChange = false;
_block.removePath(path);
_pathListModel.dataChange();
// Get icons for path
_pathGroup = makePathGroup(path);
clearPath();
}
use of jmri.jmrit.logix.OPath in project JMRI by JMRI.
the class DetectionPanel method makePathList.
private void makePathList(OBlock block) {
_blockPathPanel.remove(_checkBoxPanel);
_checkBoxPanel = new JPanel();
_checkBoxPanel.setLayout(new BoxLayout(_checkBoxPanel, BoxLayout.Y_AXIS));
_checkBoxPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(java.awt.Color.black), Bundle.getMessage("circuitPaths")));
_checkBoxPanel.add(Box.createHorizontalStrut(100));
_block = block;
_pathBoxes = new ArrayList<JCheckBox>();
List<Path> paths = _block.getPaths();
for (int i = 0; i < paths.size(); i++) {
String name = ((OPath) paths.get(i)).getName();
if (name.length() < 25) {
char[] ca = new char[25];
for (int j = 0; j < name.length(); j++) {
ca[j] = name.charAt(j);
}
for (int j = name.length(); j < 25; j++) {
ca[j] = ' ';
}
name = new String(ca);
}
JCheckBox box = new JCheckBox(name);
box.setName(name);
_pathBoxes.add(box);
_checkBoxPanel.add(box);
}
_blockPathPanel.add(_checkBoxPanel, 1);
_blockPathPanel.setVisible(true);
}
Aggregations