use of javax.swing.AbstractAction in project JMRI by JMRI.
the class PanelPro method statusPanel.
@Override
protected JPanel statusPanel() {
JPanel j = new JPanel();
j.setLayout(new BoxLayout(j, BoxLayout.Y_AXIS));
j.add(super.statusPanel());
// Buttons
Action quit = new AbstractAction(Bundle.getMessage("MenuItemQuit")) {
@Override
public void actionPerformed(ActionEvent e) {
Apps.handleQuit();
}
};
JPanel p3 = new JPanel();
p3.setLayout(new java.awt.FlowLayout());
JButton h1 = new JButton(Bundle.getMessage("ButtonHelp"));
jmri.util.HelpUtil.addHelpToComponent(h1, "html.apps.PanelPro.PanelPro");
h1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
p3.add(h1);
JButton q1 = new JButton(Bundle.getMessage("ButtonQuit"));
q1.addActionListener(quit);
q1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
p3.add(q1);
j.add(p3);
return j;
}
use of javax.swing.AbstractAction in project JMRI by JMRI.
the class InstallTest method statusPanel.
@Override
protected JPanel statusPanel() {
JPanel j = new JPanel();
j.setLayout(new BoxLayout(j, BoxLayout.Y_AXIS));
j.add(super.statusPanel());
Action serviceprog = new jmri.jmrit.symbolicprog.tabbedframe.PaneProgAction(Bundle.getMessage("DpButtonUseProgrammingTrack"));
Action opsprog = new jmri.jmrit.symbolicprog.tabbedframe.PaneOpsProgAction(Bundle.getMessage("DpButtonProgramOnMainTrack"));
Action quit = new AbstractAction(Bundle.getMessage("MenuItemQuit")) {
@Override
public void actionPerformed(ActionEvent e) {
Apps.handleQuit();
}
};
// Buttons
JButton b1 = new JButton(Bundle.getMessage("DpButtonUseProgrammingTrack"));
b1.addActionListener(serviceprog);
b1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
j.add(b1);
if (jmri.InstanceManager.getNullableDefault(jmri.ProgrammerManager.class) == null || !jmri.InstanceManager.getDefault(jmri.ProgrammerManager.class).isGlobalProgrammerAvailable()) {
b1.setEnabled(false);
b1.setToolTipText(Bundle.getMessage("MsgServiceButtonDisabled"));
}
JButton m1 = new JButton(Bundle.getMessage("DpButtonProgramOnMainTrack"));
m1.addActionListener(opsprog);
m1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
j.add(m1);
if (jmri.InstanceManager.getNullableDefault(jmri.ProgrammerManager.class) == null || !jmri.InstanceManager.getDefault(jmri.ProgrammerManager.class).isAddressedModePossible()) {
m1.setEnabled(false);
m1.setToolTipText(Bundle.getMessage("MsgOpsButtonDisabled"));
}
JButton q1 = new JButton(Bundle.getMessage("ButtonQuit"));
q1.addActionListener(quit);
q1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
j.add(q1);
return j;
}
use of javax.swing.AbstractAction in project JMRI by JMRI.
the class BlockEditAction method physcialDetails.
BeanItemPanel physcialDetails() {
defaultBlockSpeedText = (Bundle.getMessage("UseGlobal", "Global") + " " + jmri.InstanceManager.getDefault(jmri.BlockManager.class).getDefaultSpeed());
speedList.add(defaultBlockSpeedText);
java.util.Vector<String> _speedMap = jmri.InstanceManager.getDefault(SignalSpeedMap.class).getValidSpeedNames();
for (int i = 0; i < _speedMap.size(); i++) {
if (!speedList.contains(_speedMap.get(i))) {
speedList.add(_speedMap.get(i));
}
}
BeanItemPanel basic = new BeanItemPanel();
basic.setName(Bundle.getMessage("BlockPhysicalProperties"));
basic.addItem(new BeanEditItem(null, null, Bundle.getMessage("BlockPropertiesText")));
basic.addItem(new BeanEditItem(lengthField, Bundle.getMessage("BlockLengthColName"), Bundle.getMessage("BlockLengthText")));
lengthField.addKeyListener(new KeyListener() {
@Override
public void keyPressed(KeyEvent keyEvent) {
}
@Override
public void keyReleased(KeyEvent keyEvent) {
String text = lengthField.getText();
// ensure data valid
try {
jmri.util.IntlUtilities.floatValue(text);
} catch (java.text.ParseException e) {
String msg = java.text.MessageFormat.format(Bundle.getMessage("ShouldBeNumber"), new Object[] { Bundle.getMessage("BlockLengthColName") });
jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class).showInfoMessage(Bundle.getMessage("ErrorTitle"), msg, "Block Details", "length", false, false);
}
}
@Override
public void keyTyped(KeyEvent keyEvent) {
}
});
ButtonGroup rg = new ButtonGroup();
rg.add(inch);
rg.add(cm);
JPanel p = new JPanel();
p.add(inch);
p.add(cm);
p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
inch.setSelected(true);
inch.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cm.setSelected(!inch.isSelected());
updateLength();
}
});
cm.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
inch.setSelected(!cm.isSelected());
updateLength();
}
});
basic.addItem(new BeanEditItem(p, Bundle.getMessage("BlockLengthUnits"), Bundle.getMessage("BlockLengthUnitsText")));
basic.addItem(new BeanEditItem(curvatureField, Bundle.getMessage("BlockCurveColName"), ""));
basic.addItem(new BeanEditItem(speedField = new JComboBox<String>(speedList), Bundle.getMessage("BlockSpeedColName"), Bundle.getMessage("BlockMaxSpeedText")));
basic.addItem(new BeanEditItem(permissiveField, Bundle.getMessage("BlockPermColName"), Bundle.getMessage("BlockPermissiveText")));
permissiveField.setSelected(((Block) bean).getPermissiveWorking());
basic.setSaveItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Block blk = (Block) bean;
String cName = (String) curvatureField.getSelectedItem();
if (cName.equals(noneText)) {
blk.setCurvature(Block.NONE);
} else if (cName.equals(gradualText)) {
blk.setCurvature(Block.GRADUAL);
} else if (cName.equals(tightText)) {
blk.setCurvature(Block.TIGHT);
} else if (cName.equals(severeText)) {
blk.setCurvature(Block.SEVERE);
}
String speed = (String) speedField.getSelectedItem();
try {
blk.setBlockSpeed(speed);
} catch (jmri.JmriException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage() + "\n" + speed);
return;
}
if (!speedList.contains(speed) && !speed.contains("Global")) {
speedList.add(speed);
}
float len = 0.0f;
try {
len = jmri.util.IntlUtilities.floatValue(lengthField.getText());
} catch (java.text.ParseException ex2) {
log.error("Error parsing length value of \"{}\"", lengthField.getText());
}
if (inch.isSelected()) {
blk.setLength(len * 25.4f);
} else {
blk.setLength(len * 10.0f);
}
blk.setPermissiveWorking(permissiveField.isSelected());
}
});
basic.setResetItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Block blk = (Block) bean;
lengthField.setText(twoDigit.format(((Block) bean).getLengthMm()));
if (blk.getCurvature() == Block.NONE) {
curvatureField.setSelectedItem(0);
} else if (blk.getCurvature() == Block.GRADUAL) {
curvatureField.setSelectedItem(gradualText);
} else if (blk.getCurvature() == Block.TIGHT) {
curvatureField.setSelectedItem(tightText);
} else if (blk.getCurvature() == Block.SEVERE) {
curvatureField.setSelectedItem(severeText);
}
String speed = blk.getBlockSpeed();
if (!speedList.contains(speed)) {
speedList.add(speed);
}
speedField.setEditable(true);
speedField.setSelectedItem(speed);
double len = 0.0;
if (inch.isSelected()) {
len = blk.getLengthIn();
} else {
len = blk.getLengthCm();
}
lengthField.setText(twoDigit.format(len));
permissiveField.setSelected(((Block) bean).getPermissiveWorking());
}
});
bei.add(basic);
return basic;
}
use of javax.swing.AbstractAction in project JMRI by JMRI.
the class BlockEditAction method sensor.
BeanItemPanel sensor() {
BeanItemPanel basic = new BeanItemPanel();
basic.setName(Bundle.getMessage("BeanNameSensor"));
sensorComboBox = new JmriBeanComboBox(InstanceManager.sensorManagerInstance(), ((Block) bean).getSensor(), JmriBeanComboBox.DisplayOptions.DISPLAYNAME);
sensorComboBox.setFirstItemBlank(true);
basic.addItem(new BeanEditItem(sensorComboBox, Bundle.getMessage("BeanNameSensor"), Bundle.getMessage("BlockAssignSensorText")));
final SensorDebounceEditAction debounce = new SensorDebounceEditAction();
//debounce.setBean(bean);
debounce.sensorDebounce(basic);
sensorComboBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
debounce.setBean(sensorComboBox.getSelectedBean());
debounce.resetDebounceItems(e);
}
});
basic.setSaveItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Block blk = (Block) bean;
jmri.jmrit.display.layoutEditor.LayoutBlock lBlk = InstanceManager.getDefault(jmri.jmrit.display.layoutEditor.LayoutBlockManager.class).getLayoutBlock(blk);
//If the block is related to a layoutblock then set the sensor details there and allow that to propergate the changes down.
if (lBlk != null) {
lBlk.validateSensor(sensorComboBox.getSelectedDisplayName(), null);
} else {
blk.setSensor(sensorComboBox.getSelectedDisplayName());
}
debounce.saveDebounceItems(e);
}
});
basic.setResetItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Block blk = (Block) bean;
//From basic details
sensorComboBox.setSelectedBean(blk.getSensor());
debounce.setBean(blk.getSensor());
debounce.resetDebounceItems(e);
}
});
bei.add(basic);
return basic;
}
use of javax.swing.AbstractAction in project JMRI by JMRI.
the class TurnoutEditAction method lock.
BeanItemPanel lock() {
BeanItemPanel lock = new BeanItemPanel();
lock.setName(Bundle.getMessage("Lock"));
lock.addItem(new BeanEditItem(null, null, Bundle.getMessage("LockToolTip")));
String[] lockOperations = { bothText, cabOnlyText, pushbutText, noneText };
lockOperationBox = new JComboBox<String>(lockOperations);
lock.addItem(new BeanEditItem(lockOperationBox, Bundle.getMessage("LockMode"), Bundle.getMessage("LockModeToolTip")));
lockOperationBox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (lockOperationBox.getSelectedItem().equals(noneText)) {
lockBox.setEnabled(false);
} else {
lockBox.setEnabled(true);
}
}
});
lockBox = new JComboBox<String>(((Turnout) bean).getValidDecoderNames());
lock.addItem(new BeanEditItem(lockBox, Bundle.getMessage("LockModeDecoder"), Bundle.getMessage("LockModeDecoderToolTip")));
lock.setSaveItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Turnout t = (Turnout) bean;
String lockOpName = (String) lockOperationBox.getSelectedItem();
if (lockOpName.equals(bothText)) {
t.enableLockOperation(Turnout.CABLOCKOUT + Turnout.PUSHBUTTONLOCKOUT, true);
}
if (lockOpName.equals(cabOnlyText)) {
t.enableLockOperation(Turnout.CABLOCKOUT, true);
t.enableLockOperation(Turnout.PUSHBUTTONLOCKOUT, false);
}
if (lockOpName.equals(pushbutText)) {
t.enableLockOperation(Turnout.CABLOCKOUT, false);
t.enableLockOperation(Turnout.PUSHBUTTONLOCKOUT, true);
}
String decoderName = (String) lockBox.getSelectedItem();
t.setDecoderName(decoderName);
}
});
lock.setResetItem(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
Turnout t = (Turnout) bean;
lockBox.setSelectedItem(t.getDecoderName());
lockBox.setEnabled(true);
if (t.canLock(Turnout.CABLOCKOUT) && t.canLock(Turnout.PUSHBUTTONLOCKOUT)) {
lockOperationBox.setSelectedItem(bothText);
} else if (t.canLock(Turnout.PUSHBUTTONLOCKOUT)) {
lockOperationBox.setSelectedItem(pushbutText);
} else if (t.canLock(Turnout.CABLOCKOUT)) {
lockOperationBox.setSelectedItem(cabOnlyText);
} else {
lockOperationBox.setSelectedItem(noneText);
lockBox.setEnabled(false);
}
}
});
bei.add(lock);
return lock;
}
Aggregations