use of javax.swing.AbstractAction in project JMRI by JMRI.
the class TurnoutEditAction method speed.
BeanItemPanel speed() {
BeanItemPanel speed = new BeanItemPanel();
speed.setName(Bundle.getMessage("Speed"));
speed.addItem(new BeanEditItem(null, null, Bundle.getMessage("SpeedTabToolTip")));
defaultThrownSpeedText = (Bundle.getMessage("UseGlobal", "Global") + " " + InstanceManager.turnoutManagerInstance().getDefaultThrownSpeed());
defaultClosedSpeedText = (Bundle.getMessage("UseGlobal", "Global") + " " + InstanceManager.turnoutManagerInstance().getDefaultClosedSpeed());
useBlockSpeed = Bundle.getMessage("UseGlobal", "Block Speed");
speedListClosed.add(defaultClosedSpeedText);
speedListThrown.add(defaultThrownSpeedText);
speedListClosed.add(useBlockSpeed);
speedListThrown.add(useBlockSpeed);
java.util.Vector<String> _speedMap = jmri.InstanceManager.getDefault(SignalSpeedMap.class).getValidSpeedNames();
for (int i = 0; i < _speedMap.size(); i++) {
if (!speedListClosed.contains(_speedMap.get(i))) {
speedListClosed.add(_speedMap.get(i));
}
if (!speedListThrown.contains(_speedMap.get(i))) {
speedListThrown.add(_speedMap.get(i));
}
}
closedSpeedBox = new JComboBox<String>(speedListClosed);
closedSpeedBox.setEditable(true);
speed.addItem(new BeanEditItem(closedSpeedBox, Bundle.getMessage("ClosedSpeed"), Bundle.getMessage("ClosedSpeedToolTip")));
thrownSpeedBox = new JComboBox<String>(speedListThrown);
thrownSpeedBox.setEditable(true);
speed.addItem(new BeanEditItem(thrownSpeedBox, Bundle.getMessage("ThrownSpeed"), Bundle.getMessage("ThrownSpeedToolTip")));
speed.setSaveItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Turnout t = (Turnout) bean;
String speed = (String) closedSpeedBox.getSelectedItem();
try {
t.setStraightSpeed(speed);
if ((!speedListClosed.contains(speed)) && !speed.contains("Global")) {
speedListClosed.add(speed);
}
} catch (jmri.JmriException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage() + "\n" + speed);
}
speed = (String) thrownSpeedBox.getSelectedItem();
try {
t.setDivergingSpeed(speed);
if ((!speedListThrown.contains(speed)) && !speed.contains("Global")) {
speedListThrown.add(speed);
}
} catch (jmri.JmriException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage() + "\n" + speed);
}
}
});
speed.setResetItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Turnout t = (Turnout) bean;
String speed = t.getDivergingSpeed();
speedListThrown.remove(defaultThrownSpeedText);
defaultThrownSpeedText = (Bundle.getMessage("UseGlobal", "Global") + " " + InstanceManager.turnoutManagerInstance().getDefaultThrownSpeed());
speedListThrown.add(0, defaultThrownSpeedText);
if (!speedListThrown.contains(speed)) {
speedListThrown.add(speed);
thrownSpeedBox.addItem(speed);
}
thrownSpeedBox.setSelectedItem(speed);
speed = t.getStraightSpeed();
speedListClosed.remove(defaultClosedSpeedText);
defaultClosedSpeedText = (Bundle.getMessage("UseGlobal", "Global") + " " + InstanceManager.turnoutManagerInstance().getDefaultClosedSpeed());
speedListClosed.add(0, defaultClosedSpeedText);
if (!speedListClosed.contains(speed)) {
speedListClosed.add(speed);
closedSpeedBox.addItem(speed);
}
closedSpeedBox.setSelectedItem(speed);
}
});
bei.add(speed);
return speed;
}
use of javax.swing.AbstractAction in project JMRI by JMRI.
the class SensorDebounceEditAction method sensorDebounce.
public BeanItemPanel sensorDebounce(BeanItemPanel basic) {
if (basic == null) {
basic = new BeanItemPanel();
basic.setName(Bundle.getMessage("SensorDebounce"));
}
sensorDebounceGlobalCheck.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (sensorDebounceGlobalCheck.isSelected()) {
sensorDebounceInactiveField.setEnabled(false);
sensorDebounceActiveField.setEnabled(false);
} else {
sensorDebounceInactiveField.setEnabled(true);
sensorDebounceActiveField.setEnabled(true);
}
}
});
sensorDebounceInactiveField.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent keyEvent) {
}
@Override
public void keyReleased(KeyEvent keyEvent) {
String text = sensorDebounceInactiveField.getText();
if (!validateNumericalInput(text)) {
String msg = java.text.MessageFormat.format(Bundle.getMessage("ShouldBeNumber"), new Object[] { Bundle.getMessage("SensorInActiveDebounce") });
jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class).showInfoMessage(Bundle.getMessage("ErrorTitle"), msg, "Block Details", "Inactive", false, false);
}
}
@Override
public void keyTyped(KeyEvent keyEvent) {
}
});
sensorDebounceActiveField.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent keyEvent) {
}
@Override
public void keyReleased(KeyEvent keyEvent) {
String text = sensorDebounceActiveField.getText();
if (!validateNumericalInput(text)) {
String msg = java.text.MessageFormat.format(Bundle.getMessage("ShouldBeNumber"), new Object[] { Bundle.getMessage("SensorActiveDebounce") });
jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class).showInfoMessage(Bundle.getMessage("ErrorTitle"), msg, "Block Details", "Active", false, false);
}
}
@Override
public void keyTyped(KeyEvent keyEvent) {
}
});
basic.addItem(new BeanEditItem(null, null, Bundle.getMessage("SensorDebounceText")));
basic.addItem(new BeanEditItem(sensorDebounceGlobalCheck, Bundle.getMessage("SensorDebounceUseGlobalText"), null));
basic.addItem(new BeanEditItem(sensorDebounceInactiveField, Bundle.getMessage("SensorInActiveDebounce"), Bundle.getMessage("SensorInActiveDebounceText")));
basic.addItem(new BeanEditItem(sensorDebounceActiveField, Bundle.getMessage("SensorActiveDebounce"), Bundle.getMessage("SensorActiveDebounceText")));
basic.setSaveItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
saveDebounceItems(e);
}
});
basic.setResetItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
resetDebounceItems(e);
}
});
return basic;
}
use of javax.swing.AbstractAction in project JMRI by JMRI.
the class BlockEditAction method reporterDetails.
BeanItemPanel reporterDetails() {
BeanItemPanel reporter = new BeanItemPanel();
reporter.setName(Bundle.getMessage("BeanNameReporter"));
reporterComboBox = new JmriBeanComboBox(InstanceManager.getDefault(jmri.ReporterManager.class), ((Block) bean).getReporter(), JmriBeanComboBox.DisplayOptions.DISPLAYNAME);
reporterComboBox.setFirstItemBlank(true);
reporter.addItem(new BeanEditItem(reporterComboBox, Bundle.getMessage("BeanNameReporter"), Bundle.getMessage("BlockReporterText")));
reporterComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (reporterComboBox.getSelectedBean() != null) {
useCurrent.setEnabled(true);
} else {
useCurrent.setEnabled(false);
}
}
});
reporter.addItem(new BeanEditItem(useCurrent, Bundle.getMessage("BlockReporterCurrent"), Bundle.getMessage("BlockUseCurrentText")));
if (reporterComboBox.getSelectedBean() == null) {
useCurrent.setEnabled(false);
}
reporter.setResetItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
reporterComboBox.setSelectedBean(((Block) bean).getReporter());
useCurrent.setSelected(((Block) bean).isReportingCurrent());
}
});
reporter.setSaveItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Block blk = (Block) bean;
blk.setReporter((Reporter) reporterComboBox.getSelectedBean());
blk.setReportingCurrent(useCurrent.isSelected());
}
});
bei.add(reporter);
if (jmri.InstanceManager.getNullableDefault(jmri.ReporterManager.class) == null) {
setEnabled(false);
}
return reporter;
}
use of javax.swing.AbstractAction in project JMRI by JMRI.
the class SensorPullUpEditAction method sensorPullUp.
public BeanItemPanel sensorPullUp(BeanItemPanel basic) {
if (basic == null) {
basic = new BeanItemPanel();
basic.setName(Bundle.getMessage("SensorPullUp"));
}
basic.addItem(new BeanEditItem(null, null, Bundle.getMessage("SensorPullUpText")));
basic.addItem(new BeanEditItem(sensorPullUpComboBox, Bundle.getMessage("SensorPullUp"), null));
basic.setSaveItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
savePullUpItems(e);
}
});
basic.setResetItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
resetPullUpItems(e);
}
});
return basic;
}
use of javax.swing.AbstractAction in project JMRI by JMRI.
the class MultiSensorIcon method setEditIconMenu.
@Override
public boolean setEditIconMenu(JPopupMenu popup) {
String txt = Bundle.getMessage("EditItem", Bundle.getMessage("MultiSensor"));
popup.add(new AbstractAction(txt) {
@Override
public void actionPerformed(ActionEvent e) {
edit();
}
});
return true;
}
Aggregations