private void changePathName() { String name = _pathName.getText(); OPath path = _pathList.getSelectedValue(); if (name == null || name.trim().length() == 0 || path == null) { JOptionPane.showMessageDialog( this, Bundle.getMessage("changePathName"), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE); return; } String oldName = path.getName(); OPath oldPath = _block.getPathByName(name); if (oldPath != null) { JOptionPane.showMessageDialog( this, Bundle.getMessage("duplicatePathName", name, _block.getDisplayName()), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE); return; } path.setName(name); // Change the path name in the track icons java.util.List<Positionable> list = _parent.getCircuitGroup(); // cannot do remove/add path on the fly due to conncurrent access with Iterator ArrayList<IndicatorTrack> changeGroup = new ArrayList<IndicatorTrack>(); for (int i = 0; i < list.size(); i++) { if (list.get(i) instanceof IndicatorTrack) { IndicatorTrack icon = (IndicatorTrack) list.get(i); ArrayList<String> paths = icon.getPaths(); if (paths != null) { for (int j = 0; j < paths.size(); j++) { if (oldName.equals(paths.get(j))) { changeGroup.add(icon); } } } } } for (int i = 0; i < changeGroup.size(); i++) { IndicatorTrack track = changeGroup.get(i); track.removePath(oldName); track.addPath(name); } _pathChange = false; _pathListModel.dataChange(); }
private boolean findErrors() { boolean error = false; if (checkForSavePath()) { return true; } java.util.List<Path> list = _block.getPaths(); if (list.size() == 0) { JOptionPane.showMessageDialog( this, Bundle.getMessage("noPaths", _block.getDisplayName()), Bundle.getMessage("makePath"), JOptionPane.INFORMATION_MESSAGE); } for (int i = 0; i < list.size(); i++) { OPath path = (OPath) list.get(i); ArrayList<Positionable> pathGp = makePathGroup(path); if (pathGp.size() == 0) { error = true; break; } OPath p = makeOPath(path.getName(), pathGp, false); if (p == null) { error = true; break; } } if (error) { int result = JOptionPane.showConfirmDialog( this, Bundle.getMessage("hasPathErrors"), Bundle.getMessage("makePath"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (result == JOptionPane.YES_OPTION) { error = false; } } return error; }
public EditCircuitPaths(String title, CircuitBuilder parent, OBlock block) { _block = block; setTitle(java.text.MessageFormat.format(title, _block.getDisplayName())); _parent = parent; addWindowListener( new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent e) { closingEvent(); } }); addHelpMenu("package.jmri.jmrit.display.CircuitBuilder", true); JPanel contentPane = new JPanel(); contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); contentPane.add(Box.createVerticalStrut(STRUT_SIZE)); contentPane.add(makeContentPanel()); contentPane.add(Box.createVerticalStrut(STRUT_SIZE)); JPanel border = new JPanel(); border.setLayout(new java.awt.BorderLayout(10, 10)); border.add(contentPane); setContentPane(border); _pathList.setPreferredSize( new java.awt.Dimension(_pathList.getFixedCellWidth(), _pathList.getFixedCellHeight() * 4)); pack(); if (_firstInstance) { setLocationRelativeTo(_parent._editor); _firstInstance = false; } else { setLocation(_loc); setSize(_dim); } setVisible(true); }
@Override public void setValueAt(Object value, int row, int col) { if (log.isDebugEnabled()) { log.debug("setValueAt: row= " + row + ", col= " + col + ", value= " + value); } if (super.getRowCount() == row) { switch (col) { case SYSNAMECOL: OBlock block = _manager.createNewOBlock((String) value, tempRow[USERNAMECOL]); if (block == null) { block = _manager.getOBlock(tempRow[USERNAMECOL]); String name = (String) value + " / " + tempRow[USERNAMECOL]; if (block != null) { name = block.getDisplayName(); } else { block = _manager.getOBlock((String) value); if (block != null) { name = block.getDisplayName(); } } JOptionPane.showMessageDialog( null, Bundle.getMessage("CreateDuplBlockErr", name), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE); return; } if (tempRow[SENSORCOL] != null) { if (!sensorExists(tempRow[SENSORCOL])) { JOptionPane.showMessageDialog( null, Bundle.getMessage("NoSuchSensorErr", tempRow[SENSORCOL]), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE); } } block.setComment(tempRow[COMMENTCOL]); float len = 0.0f; try { len = IntlUtilities.floatValue(tempRow[LENGTHCOL]); } catch (ParseException e) { JOptionPane.showMessageDialog( null, Bundle.getMessage("BadNumber", tempRow[LENGTHCOL]), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE); } if (tempRow[UNITSCOL].equals(Bundle.getMessage("cm"))) { block.setLength(len * 10.0f); block.setMetricUnits(true); } else { block.setLength(len * 25.4f); block.setMetricUnits(false); } if (tempRow[CURVECOL].equals(noneText)) { block.setCurvature(Block.NONE); } else if (tempRow[CURVECOL].equals(gradualText)) { block.setCurvature(Block.GRADUAL); } else if (tempRow[CURVECOL].equals(tightText)) { block.setCurvature(Block.TIGHT); } else if (tempRow[CURVECOL].equals(severeText)) { block.setCurvature(Block.SEVERE); } block.setPermissiveWorking( tempRow[PERMISSIONCOL].equals(Bundle.getMessage("Permissive"))); block.setBlockSpeedName(tempRow[SPEEDCOL]); if (tempRow[ERR_SENSORCOL] != null) { if (tempRow[ERR_SENSORCOL].trim().length() > 0) { if (!sensorExists(tempRow[ERR_SENSORCOL])) { JOptionPane.showMessageDialog( null, Bundle.getMessage("NoSuchSensorErr", tempRow[ERR_SENSORCOL]), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE); } } } if (tempRow[REPORTERCOL] != null) { Reporter rep = null; try { rep = InstanceManager.reporterManagerInstance().getReporter(tempRow[REPORTERCOL]); if (rep != null) { block.setReporter(rep); block.setReportingCurrent( tempRow[REPORT_CURRENTCOL].equals(Bundle.getMessage("Current"))); } } catch (Exception ex) { log.error( "No Reporter named \"" + tempRow[REPORTERCOL] + "\" found. threw exception: " + ex); } if (rep == null) { JOptionPane.showMessageDialog( null, Bundle.getMessage("NoSuchReporterErr", tempRow[REPORTERCOL]), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE); } block.setReporter(rep); } initTempRow(); fireTableDataChanged(); return; case DELETE_COL: // clear initTempRow(); fireTableRowsUpdated(row, row); return; case LENGTHCOL: try { _tempLen = IntlUtilities.floatValue(value.toString()); if (tempRow[UNITSCOL].equals(Bundle.getMessage("cm"))) { _tempLen *= 10f; } else { _tempLen *= 25.4f; } } catch (ParseException e) { JOptionPane.showMessageDialog( null, Bundle.getMessage("BadNumber", tempRow[LENGTHCOL]), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE); } return; case UNITSCOL: if ((((Boolean) value).booleanValue())) { tempRow[UNITSCOL] = Bundle.getMessage("cm"); } else { tempRow[UNITSCOL] = Bundle.getMessage("in"); } fireTableRowsUpdated(row, row); return; case REPORT_CURRENTCOL: if (((Boolean) value).booleanValue()) { // toggle tempRow[REPORT_CURRENTCOL] = Bundle.getMessage("Current"); } else { tempRow[REPORT_CURRENTCOL] = Bundle.getMessage("Last"); } return; case PERMISSIONCOL: if (((Boolean) value).booleanValue()) { // toggle tempRow[PERMISSIONCOL] = Bundle.getMessage("Permissive"); } else { tempRow[PERMISSIONCOL] = Bundle.getMessage("Absolute"); } return; } tempRow[col] = (String) value; return; } String name = sysNameList.get(row); OBlock block = _manager.getBySystemName(name); switch (col) { case USERNAMECOL: OBlock b = _manager.getOBlock((String) value); if (b != null) { JOptionPane.showMessageDialog( null, Bundle.getMessage("CreateDuplBlockErr", block.getDisplayName()), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE); return; } block.setUserName((String) value); fireTableRowsUpdated(row, row); return; case COMMENTCOL: block.setComment((String) value); fireTableRowsUpdated(row, row); return; case STATECOL: /* currently STATECOL is not editable. Maybe allow it and (or not) set the sensor? Why? int state = 0; try { state = Integer.valueOf((String) value); } catch (NumberFormatException nfe) { } if (state < 0) { state = -state; } block.setState(state % 255); fireTableRowsUpdated(row, row); */ return; case SENSORCOL: if (!block.setSensor((String) value)) { JOptionPane.showMessageDialog( null, Bundle.getMessage("NoSuchSensorErr", (String) value), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE); } fireTableRowsUpdated(row, row); return; case LENGTHCOL: try { float len = IntlUtilities.floatValue(value.toString()); if (block.isMetric()) { block.setLength(len * 10.0f); } else { block.setLength(len * 25.4f); } fireTableRowsUpdated(row, row); } catch (ParseException e) { JOptionPane.showMessageDialog( null, Bundle.getMessage("BadNumber", value), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE); } return; case UNITSCOL: block.setMetricUnits(((Boolean) value).booleanValue()); fireTableRowsUpdated(row, row); return; case CURVECOL: String cName = (String) value; if (cName.equals(noneText)) { block.setCurvature(Block.NONE); } else if (cName.equals(gradualText)) { block.setCurvature(Block.GRADUAL); } else if (cName.equals(tightText)) { block.setCurvature(Block.TIGHT); } else if (cName.equals(severeText)) { block.setCurvature(Block.SEVERE); } fireTableRowsUpdated(row, row); return; case ERR_SENSORCOL: boolean err = false; try { if (((String) value).trim().length() == 0) { block.setErrorSensor(null); err = true; } else { err = block.setErrorSensor((String) value); fireTableRowsUpdated(row, row); } } catch (Exception ex) { log.error("getSensor(" + (String) value + ") threw exception: " + ex); } if (err) { JOptionPane.showMessageDialog( null, Bundle.getMessage("NoSuchSensorErr", (String) value), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE); } fireTableRowsUpdated(row, row); return; case REPORTERCOL: Reporter rep = null; try { rep = InstanceManager.reporterManagerInstance().getReporter((String) value); if (rep != null) { block.setReporter(rep); fireTableRowsUpdated(row, row); } } catch (Exception ex) { log.error("No Reporter named \"" + (String) value + "\" found. threw exception: " + ex); } if (rep == null) { JOptionPane.showMessageDialog( null, Bundle.getMessage("NoSuchReporterErr", tempRow[REPORTERCOL]), Bundle.getMessage("ErrorTitle"), JOptionPane.WARNING_MESSAGE); } block.setReporter(rep); fireTableRowsUpdated(row, row); return; case REPORT_CURRENTCOL: if (block.getReporter() != null) { block.setReportingCurrent(((Boolean) value).booleanValue()); fireTableRowsUpdated(row, row); } return; case PERMISSIONCOL: block.setPermissiveWorking(((Boolean) value).booleanValue()); fireTableRowsUpdated(row, row); return; case SPEEDCOL: block.setBlockSpeedName((String) value); fireTableRowsUpdated(row, row); return; case EDIT_COL: _parent.openBlockPathFrame(block.getSystemName()); return; case DELETE_COL: deleteBean(block); block = null; return; } super.setValueAt(value, row, col); }
@Override public Object getValueAt(int row, int col) { if (row > sysNameList.size()) { return ""; } OBlock b = null; if (row < sysNameList.size()) { String name = sysNameList.get(row); b = _manager.getBySystemName(name); } switch (col) { case SYSNAMECOL: if (b != null) { return b.getSystemName(); } return tempRow[col]; case USERNAMECOL: if (b != null) { return b.getUserName(); } return tempRow[col]; case COMMENTCOL: if (b != null) { return b.getComment(); } return tempRow[col]; case STATECOL: if (b != null) { int state = b.getState(); int num = Integer.numberOfLeadingZeros(state) - 24; if (num >= 0) { return ZEROS.substring(0, num) + Integer.toBinaryString(state); } } return ZEROS; case SENSORCOL: if (b != null) { Sensor s = b.getSensor(); if (s == null) { return ""; } return s.getDisplayName(); } return tempRow[col]; case LENGTHCOL: if (b != null) { if (b.isMetric()) { return (twoDigit.format(b.getLengthCm())); } return (twoDigit.format(b.getLengthIn())); } if (tempRow[UNITSCOL].equals(Bundle.getMessage("cm"))) { return (twoDigit.format(_tempLen / 10)); } return (twoDigit.format(_tempLen / 25.4f)); case UNITSCOL: if (b != null) { if (log.isDebugEnabled()) { log.debug( "getValueAt: row= " + row + ", col= " + col + ", " + b.getDisplayName() + " isMetric= " + b.isMetric()); } return b.isMetric(); } if (log.isDebugEnabled()) { log.debug( "getValueAt: row= " + row + ", col= " + col + ", is cm= " + tempRow[UNITSCOL].equals(Bundle.getMessage("cm"))); } return Boolean.valueOf(tempRow[UNITSCOL].equals(Bundle.getMessage("cm"))); case CURVECOL: if (b != null) { String c = ""; if (b.getCurvature() == Block.NONE) { c = noneText; } else if (b.getCurvature() == Block.GRADUAL) { c = gradualText; } else if (b.getCurvature() == Block.TIGHT) { c = tightText; } else if (b.getCurvature() == Block.SEVERE) { c = severeText; } return c; } return tempRow[col]; case ERR_SENSORCOL: if (b != null) { Sensor s = b.getErrorSensor(); if (s == null) { return ""; } return s.getDisplayName(); } return tempRow[col]; case REPORTERCOL: if (b != null) { Reporter r = b.getReporter(); if (r == null) { return ""; } return r.getDisplayName(); } return tempRow[col]; case REPORT_CURRENTCOL: if (b != null) { if (b.getReporter() != null) { return b.isReportingCurrent(); } return ""; } return Boolean.valueOf(tempRow[REPORT_CURRENTCOL].equals(Bundle.getMessage("Current"))); case PERMISSIONCOL: if (b != null) { return b.getPermissiveWorking(); } return Boolean.valueOf(tempRow[PERMISSIONCOL].equals(Bundle.getMessage("Permissive"))); case SPEEDCOL: if (b != null) { return b.getBlockSpeed(); } return tempRow[col]; case EDIT_COL: if (b != null) { return Bundle.getMessage("ButtonEditPath"); } return ""; case DELETE_COL: if (b != null) { return Bundle.getMessage("ButtonDelete"); } return Bundle.getMessage("ButtonClear"); } return super.getValueAt(row, col); }
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() { 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() { 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() { 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() { 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() { public void actionPerformed(ActionEvent event) { _pathChange = true; } }); _units = new JToggleButton("", !_block.isMetric()); _units.setToolTipText(Bundle.getMessage("TooltipPathLength")); _units.addActionListener( new ActionListener() { 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")); 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; }