use of javax.swing.ButtonGroup in project JMRI by JMRI.
the class SignalMastIcon method showPopUp.
/**
* Pop-up just displays the name
*/
@Override
public boolean showPopUp(JPopupMenu popup) {
if (isEditable()) {
JMenu clickMenu = new JMenu(Bundle.getMessage("WhenClicked"));
ButtonGroup clickButtonGroup = new ButtonGroup();
JRadioButtonMenuItem r;
r = new JRadioButtonMenuItem(Bundle.getMessage("ChangeAspect"));
r.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setClickMode(0);
}
});
clickButtonGroup.add(r);
if (clickMode == 0) {
r.setSelected(true);
} else {
r.setSelected(false);
}
clickMenu.add(r);
r = new JRadioButtonMenuItem(Bundle.getMessage("AlternateLit"));
r.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setClickMode(1);
}
});
clickButtonGroup.add(r);
if (clickMode == 1) {
r.setSelected(true);
} else {
r.setSelected(false);
}
clickMenu.add(r);
r = new JRadioButtonMenuItem(Bundle.getMessage("AlternateHeld"));
r.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setClickMode(2);
}
});
clickButtonGroup.add(r);
if (clickMode == 2) {
r.setSelected(true);
} else {
r.setSelected(false);
}
clickMenu.add(r);
popup.add(clickMenu);
// add menu to select handling of lit parameter
JMenu litMenu = new JMenu(Bundle.getMessage("WhenNotLit"));
litButtonGroup = new ButtonGroup();
r = new JRadioButtonMenuItem(Bundle.getMessage("ShowAppearance"));
r.setIconTextGap(10);
r.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setLitMode(false);
displayState(mastState());
}
});
litButtonGroup.add(r);
if (!litMode) {
r.setSelected(true);
} else {
r.setSelected(false);
}
litMenu.add(r);
r = new JRadioButtonMenuItem(Bundle.getMessage("ShowDarkIcon"));
r.setIconTextGap(10);
r.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setLitMode(true);
displayState(mastState());
}
});
litButtonGroup.add(r);
if (litMode) {
r.setSelected(true);
} else {
r.setSelected(false);
}
litMenu.add(r);
popup.add(litMenu);
java.util.Enumeration<String> en = getSignalMast().getSignalSystem().getImageTypeList();
if (en.hasMoreElements()) {
JMenu iconSetMenu = new JMenu(Bundle.getMessage("SignalMastIconSet"));
ButtonGroup iconTypeGroup = new ButtonGroup();
setImageTypeList(iconTypeGroup, iconSetMenu, "default");
while (en.hasMoreElements()) {
setImageTypeList(iconTypeGroup, iconSetMenu, en.nextElement());
}
popup.add(iconSetMenu);
}
popup.add(new jmri.jmrit.signalling.SignallingSourceAction(Bundle.getMessage("SignalMastLogic"), getSignalMast()));
JMenu aspect = new JMenu(Bundle.getMessage("ChangeAspect"));
final java.util.Vector<String> aspects = getSignalMast().getValidAspects();
for (int i = 0; i < aspects.size(); i++) {
final int index = i;
aspect.add(new AbstractAction(aspects.elementAt(index)) {
@Override
public void actionPerformed(ActionEvent e) {
getSignalMast().setAspect(aspects.elementAt(index));
}
});
}
popup.add(aspect);
addTransitPopup(popup);
} else {
final java.util.Vector<String> aspects = getSignalMast().getValidAspects();
for (int i = 0; i < aspects.size(); i++) {
final int index = i;
popup.add(new AbstractAction(aspects.elementAt(index)) {
@Override
public void actionPerformed(ActionEvent e) {
getSignalMast().setAspect(aspects.elementAt(index));
}
});
}
}
return true;
}
use of javax.swing.ButtonGroup in project JMRI by JMRI.
the class ControlPanel method initGUI.
/**
* Create, initialize and place GUI components.
*/
private void initGUI() {
JPanel mainPanel = new JPanel();
this.setContentPane(mainPanel);
mainPanel.setLayout(new BorderLayout());
this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
speedControlPanel = new JPanel();
speedControlPanel.setLayout(new BoxLayout(speedControlPanel, BoxLayout.X_AXIS));
this.getContentPane().add(speedControlPanel, BorderLayout.CENTER);
sliderPanel = new JPanel();
sliderPanel.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.anchor = GridBagConstraints.CENTER;
constraints.fill = GridBagConstraints.BOTH;
constraints.gridheight = 1;
constraints.gridwidth = 1;
constraints.ipadx = 0;
constraints.ipady = 0;
Insets insets = new Insets(2, 2, 2, 2);
constraints.insets = insets;
constraints.weightx = 1;
constraints.weighty = 1;
constraints.gridx = 0;
constraints.gridy = 0;
sliderPanel.add(speedSlider, constraints);
//this.getContentPane().add(sliderPanel,BorderLayout.CENTER);
speedControlPanel.add(sliderPanel);
speedSlider.setOrientation(JSlider.VERTICAL);
speedSlider.setMajorTickSpacing(MAX_SPEED / 2);
java.util.Hashtable<Integer, JLabel> labelTable = new java.util.Hashtable<Integer, JLabel>();
labelTable.put(Integer.valueOf(MAX_SPEED / 2), new JLabel("50%"));
labelTable.put(Integer.valueOf(MAX_SPEED), new JLabel("100%"));
labelTable.put(Integer.valueOf(0), new JLabel(Bundle.getMessage("LabelStop")));
speedSlider.setLabelTable(labelTable);
speedSlider.setPaintTicks(true);
speedSlider.setPaintLabels(true);
// remove old actions
speedSlider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (!internalAdjust) {
boolean doIt = false;
if (!speedSlider.getValueIsAdjusting()) {
doIt = true;
} else if (System.currentTimeMillis() - lastTrackedSliderMovementTime >= trackSliderMinInterval) {
doIt = true;
lastTrackedSliderMovementTime = System.currentTimeMillis();
}
if (doIt) {
float newSpeed = (speedSlider.getValue() / (MAX_SPEED * 1.0f));
if (log.isDebugEnabled()) {
log.debug("stateChanged: slider pos: " + speedSlider.getValue() + " speed: " + newSpeed);
}
_throttle.setSpeedSetting(newSpeed);
if (speedSpinner != null) {
speedSpinnerModel.setValue(Integer.valueOf(speedSlider.getValue()));
}
}
} else {
internalAdjust = false;
}
}
});
spinnerPanel = new JPanel();
spinnerPanel.setLayout(new GridBagLayout());
if (speedSpinner != null) {
spinnerPanel.add(speedSpinner, constraints);
}
//this.getContentPane().add(spinnerPanel,BorderLayout.CENTER);
speedControlPanel.add(spinnerPanel);
// remove old actions
if (speedSpinner != null) {
speedSpinner.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (!internalAdjust) {
float newSpeed = ((Integer) speedSpinner.getValue()).floatValue() / (MAX_SPEED * 1.0f);
if (log.isDebugEnabled()) {
log.debug("stateChanged: spinner pos: " + speedSpinner.getValue() + " speed: " + newSpeed);
}
_throttle.setSpeedSetting(newSpeed);
//_throttleFrame.setSpeedSetting( newSpeed );
speedSlider.setValue(((Integer) speedSpinner.getValue()).intValue());
} else {
internalAdjust = false;
}
}
});
}
ButtonGroup speedStepButtons = new ButtonGroup();
speedStepButtons.add(SpeedStep128Button);
speedStepButtons.add(SpeedStep28Button);
speedStepButtons.add(SpeedStep27Button);
speedStepButtons.add(SpeedStep14Button);
constraints.fill = GridBagConstraints.NONE;
constraints.gridy = 1;
spinnerPanel.add(SpeedStep128Button, constraints);
constraints.gridy = 2;
spinnerPanel.add(SpeedStep28Button, constraints);
constraints.gridy = 3;
spinnerPanel.add(SpeedStep27Button, constraints);
constraints.gridy = 4;
spinnerPanel.add(SpeedStep14Button, constraints);
SpeedStep14Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setSpeedSteps(DccThrottle.SpeedStepMode14);
_throttle.setSpeedStepMode(DccThrottle.SpeedStepMode14);
}
});
SpeedStep27Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setSpeedSteps(DccThrottle.SpeedStepMode27);
_throttle.setSpeedStepMode(DccThrottle.SpeedStepMode27);
}
});
SpeedStep28Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setSpeedSteps(DccThrottle.SpeedStepMode28);
_throttle.setSpeedStepMode(DccThrottle.SpeedStepMode28);
}
});
SpeedStep128Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setSpeedSteps(DccThrottle.SpeedStepMode128);
_throttle.setSpeedStepMode(DccThrottle.SpeedStepMode128);
}
});
// set by default which speed selection method is on top
setSpeedController(_displaySlider);
}
use of javax.swing.ButtonGroup in project JMRI by JMRI.
the class TrackEditFrame method initComponents.
public void initComponents(Location location, Track track) {
_location = location;
_track = track;
// tool tips
autoDropCheckBox.setToolTipText(Bundle.getMessage("TipAutoTrack"));
autoPickupCheckBox.setToolTipText(Bundle.getMessage("TipAutoTrack"));
trackLengthTextField.setToolTipText(MessageFormat.format(Bundle.getMessage("TipTrackLength"), new Object[] { Setup.getLengthUnit().toLowerCase() }));
// property changes
_location.addPropertyChangeListener(this);
// listen for car road name and type changes
CarRoads.instance().addPropertyChangeListener(this);
CarLoads.instance().addPropertyChangeListener(this);
CarTypes.instance().addPropertyChangeListener(this);
trainManager.addPropertyChangeListener(this);
routeManager.addPropertyChangeListener(this);
// the following code sets the frame's initial state
getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
// place all panels in a scroll pane.
JPanel panels = new JPanel();
panels.setLayout(new BoxLayout(panels, BoxLayout.Y_AXIS));
JScrollPane pane = new JScrollPane(panels);
// Set up the panels
// Layout the panel by rows
// row 1
JPanel p1 = new JPanel();
p1.setLayout(new BoxLayout(p1, BoxLayout.X_AXIS));
JScrollPane p1Pane = new JScrollPane(p1);
p1Pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
p1Pane.setMinimumSize(new Dimension(300, 3 * trackNameTextField.getPreferredSize().height));
p1Pane.setBorder(BorderFactory.createTitledBorder(""));
// row 1a
JPanel pName = new JPanel();
pName.setLayout(new GridBagLayout());
pName.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Name")));
addItem(pName, trackNameTextField, 0, 0);
// row 1b
JPanel pLength = new JPanel();
pLength.setLayout(new GridBagLayout());
pLength.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Length")));
pLength.setMinimumSize(new Dimension(60, 1));
addItem(pLength, trackLengthTextField, 0, 0);
// row 1c
panelTrainDir.setLayout(new GridBagLayout());
panelTrainDir.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("TrainTrack")));
panelTrainDir.setPreferredSize(new Dimension(200, 10));
addItem(panelTrainDir, northCheckBox, 1, 1);
addItem(panelTrainDir, southCheckBox, 2, 1);
addItem(panelTrainDir, eastCheckBox, 3, 1);
addItem(panelTrainDir, westCheckBox, 4, 1);
p1.add(pName);
p1.add(pLength);
p1.add(panelTrainDir);
// row 4
panelCheckBoxes.setLayout(new GridBagLayout());
// status panel for roads and loads
JPanel panelRoadAndLoadStatus = new JPanel();
panelRoadAndLoadStatus.setLayout(new BoxLayout(panelRoadAndLoadStatus, BoxLayout.X_AXIS));
JPanel pRoadOption = new JPanel();
pRoadOption.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("RoadOption")));
pRoadOption.add(roadOption);
JPanel pLoadOption = new JPanel();
pLoadOption.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("LoadOption")));
pLoadOption.add(loadOption);
pShipLoadOption.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("ShipLoadOption")));
pShipLoadOption.add(shipLoadOption);
pDestinationOption.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Destinations")));
pDestinationOption.add(destinationOption);
panelRoadAndLoadStatus.add(pRoadOption);
panelRoadAndLoadStatus.add(pLoadOption);
panelRoadAndLoadStatus.add(pShipLoadOption);
panelRoadAndLoadStatus.add(pDestinationOption);
// only staging uses the ship load option
pShipLoadOption.setVisible(false);
// only classification/interchange tracks use the destination option
pDestinationOption.setVisible(false);
// row 10
// order panel
panelOrder.setLayout(new GridBagLayout());
panelOrder.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("PickupOrder")));
panelOrder.add(orderNormal);
panelOrder.add(orderFIFO);
panelOrder.add(orderLIFO);
ButtonGroup orderGroup = new ButtonGroup();
orderGroup.add(orderNormal);
orderGroup.add(orderFIFO);
orderGroup.add(orderLIFO);
// drop panel
dropPanel.setLayout(new GridBagLayout());
dropPanel.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("TrainsOrRoutesDrops")));
// pickup panel
pickupPanel.setLayout(new GridBagLayout());
pickupPanel.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("TrainsOrRoutesPickups")));
// row 11
JPanel panelComment = new JPanel();
panelComment.setLayout(new GridBagLayout());
panelComment.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Comment")));
addItem(panelComment, commentScroller, 0, 0);
// adjust text area width based on window size
adjustTextAreaColumnWidth(commentScroller, commentTextArea);
// reader row
JPanel readerPanel = new JPanel();
readerPanel.setLayout(new GridBagLayout());
readerPanel.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("idReader")));
addItem(readerPanel, readerSelector, 0, 0);
readerPanel.setVisible(Setup.isRfidEnabled());
// row 12
JPanel panelButtons = new JPanel();
panelButtons.setLayout(new GridBagLayout());
// row 13
addItem(panelButtons, deleteTrackButton, 0, 0);
addItem(panelButtons, addTrackButton, 1, 0);
addItem(panelButtons, saveTrackButton, 2, 0);
paneCheckBoxes.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("TypesTrack")));
panels.add(p1Pane);
panels.add(paneCheckBoxes);
panels.add(panelRoadAndLoadStatus);
panels.add(panelOrder);
panels.add(dropPanel);
panels.add(pickupPanel);
// add optional panels
panels.add(panelOpt3);
panels.add(panelOpt4);
panels.add(panelComment);
panels.add(readerPanel);
panels.add(panelButtons);
getContentPane().add(pane);
// setup buttons
addButtonAction(setButton);
addButtonAction(clearButton);
addButtonAction(deleteTrackButton);
addButtonAction(addTrackButton);
addButtonAction(saveTrackButton);
addButtonAction(deleteDropButton);
addButtonAction(addDropButton);
addButtonAction(deletePickupButton);
addButtonAction(addPickupButton);
addRadioButtonAction(orderNormal);
addRadioButtonAction(orderFIFO);
addRadioButtonAction(orderLIFO);
addRadioButtonAction(anyDrops);
addRadioButtonAction(trainDrop);
addRadioButtonAction(routeDrop);
addRadioButtonAction(excludeTrainDrop);
addRadioButtonAction(excludeRouteDrop);
addRadioButtonAction(anyPickups);
addRadioButtonAction(trainPickup);
addRadioButtonAction(routePickup);
addRadioButtonAction(excludeTrainPickup);
addRadioButtonAction(excludeRoutePickup);
// addComboBoxAction(comboBoxTypes);
addCheckBoxAction(autoDropCheckBox);
addCheckBoxAction(autoPickupCheckBox);
if (Setup.isRfidEnabled()) {
// setup the Reader dropdown.
// add an empty entry.
readerSelector.addItem(null);
for (jmri.NamedBean r : jmri.InstanceManager.getDefault(jmri.ReporterManager.class).getNamedBeanList()) {
readerSelector.addItem((Reporter) r);
}
}
// load fields and enable buttons
if (_track != null) {
_track.addPropertyChangeListener(this);
trackNameTextField.setText(_track.getName());
commentTextArea.setText(_track.getComment());
trackLengthTextField.setText(Integer.toString(_track.getLength()));
enableButtons(true);
_trackName = _track.getName();
if (Setup.isRfidEnabled()) {
readerSelector.setSelectedItem(_track.getReporter());
}
} else {
enableButtons(false);
}
// build menu
JMenuBar menuBar = new JMenuBar();
_toolMenu = new JMenu(Bundle.getMessage("MenuTools"));
_toolMenu.add(new TrackLoadEditAction(this));
_toolMenu.add(new TrackRoadEditAction(this));
_toolMenu.add(new TrackEditCommentsAction(this));
_toolMenu.add(new PoolTrackAction(this));
menuBar.add(_toolMenu);
setJMenuBar(menuBar);
// load
updateCheckboxes();
// updateTypeComboBoxes();
updateTrainDir();
updateCarOrder();
updateDropOptions();
updatePickupOptions();
updateRoadOption();
updateLoadOption();
updateDestinationOption();
setMinimumSize(new Dimension(Control.panelWidth500, Control.panelHeight600));
}
use of javax.swing.ButtonGroup in project JMRI by JMRI.
the class TrainLoadOptionsFrame method initComponents.
public void initComponents(TrainEditFrame parent) {
parent.setChildFrame(this);
_train = parent._train;
getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
// Layout the panel by rows
JPanel p1 = new JPanel();
p1.setLayout(new BoxLayout(p1, BoxLayout.X_AXIS));
p1.setMaximumSize(new Dimension(2000, 250));
// Layout the panel by rows
// row 1a
JPanel pName = new JPanel();
pName.setLayout(new GridBagLayout());
pName.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Name")));
addItem(pName, trainName, 0, 0);
// row 1b
JPanel pDesc = new JPanel();
pDesc.setLayout(new GridBagLayout());
pDesc.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Description")));
addItem(pDesc, trainDescription, 0, 0);
p1.add(pName);
p1.add(pDesc);
// row 3
JPanel p3 = new JPanel();
p3.setLayout(new BoxLayout(p3, BoxLayout.Y_AXIS));
JScrollPane pane3 = new JScrollPane(p3);
pane3.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("LoadsTrain")));
pane3.setMaximumSize(new Dimension(2000, 400));
JPanel pLoadRadioButtons = new JPanel();
pLoadRadioButtons.setLayout(new FlowLayout());
pLoadRadioButtons.add(loadNameAll);
pLoadRadioButtons.add(loadNameInclude);
pLoadRadioButtons.add(loadNameExclude);
pLoadRadioButtons.add(loadAndTypeCheckBox);
pLoadControls.setLayout(new FlowLayout());
pLoadControls.add(comboBoxTypes);
pLoadControls.add(comboBoxLoads);
pLoadControls.add(addLoadButton);
pLoadControls.add(deleteLoadButton);
pLoadControls.add(deleteAllLoadsButton);
pLoadControls.setVisible(false);
p3.add(pLoadRadioButtons);
p3.add(pLoadControls);
// row 4
panelLoads.setLayout(new GridBagLayout());
paneLoads.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Loads")));
ButtonGroup loadGroup = new ButtonGroup();
loadGroup.add(loadNameAll);
loadGroup.add(loadNameInclude);
loadGroup.add(loadNameExclude);
// row 12
JPanel panelButtons = new JPanel();
panelButtons.setLayout(new GridBagLayout());
panelButtons.setBorder(BorderFactory.createTitledBorder(""));
panelButtons.setMaximumSize(new Dimension(2000, 200));
// row 13
addItem(panelButtons, saveTrainButton, 0, 0);
getContentPane().add(p1);
getContentPane().add(pane3);
getContentPane().add(paneLoads);
getContentPane().add(panelButtons);
// setup buttons
addButtonAction(saveTrainButton);
addButtonAction(deleteLoadButton);
addButtonAction(deleteAllLoadsButton);
addButtonAction(addLoadButton);
addRadioButtonAction(loadNameAll);
addRadioButtonAction(loadNameInclude);
addRadioButtonAction(loadNameExclude);
addComboBoxAction(comboBoxTypes);
if (_train != null) {
trainName.setText(_train.getName());
trainDescription.setText(_train.getDescription());
updateButtons(true);
// listen for train changes
_train.addPropertyChangeListener(this);
} else {
updateButtons(false);
}
// NOI18N
addHelpMenu("package.jmri.jmrit.operations.Operations_TrainLoadOptions", true);
updateTypeComboBoxes();
updateLoadComboBoxes();
updateLoadNames();
// get notified if car roads, loads, and owners gets modified
CarTypes.instance().addPropertyChangeListener(this);
CarLoads.instance().addPropertyChangeListener(this);
loadAndTypeCheckBox.setSelected(loadAndType);
initMinimumSize(new Dimension(Control.panelWidth600, Control.panelHeight400));
}
use of javax.swing.ButtonGroup in project JMRI by JMRI.
the class WiThrottlePrefsPanel method allowedControllers.
private JPanel allowedControllers() {
JPanel panel = new JPanel();
powerCB = new JCheckBox(Bundle.getMessage("LabelTrackPower"));
powerCB.setToolTipText(Bundle.getMessage("ToolTipTrackPower"));
panel.add(powerCB);
turnoutCB = new JCheckBox(Bundle.getMessage("LabelTurnout"));
turnoutCB.setToolTipText(Bundle.getMessage("ToolTipTurnout"));
panel.add(turnoutCB);
routeCB = new JCheckBox(Bundle.getMessage("LabelRoute"));
routeCB.setToolTipText(Bundle.getMessage("ToolTipRoute"));
panel.add(routeCB);
consistCB = new JCheckBox(Bundle.getMessage("LabelConsist"));
consistCB.setToolTipText(Bundle.getMessage("ToolTipConsist"));
panel.add(consistCB);
JPanel conPanel = new JPanel();
conPanel.setLayout(new BoxLayout(conPanel, BoxLayout.Y_AXIS));
wifiRB = new JRadioButton(Bundle.getMessage("LabelWiFiConsist"));
wifiRB.setToolTipText(Bundle.getMessage("ToolTipWiFiConsist"));
dccRB = new JRadioButton(Bundle.getMessage("LabelDCCConsist"));
dccRB.setToolTipText(Bundle.getMessage("ToolTipDCCConsist"));
ButtonGroup group = new ButtonGroup();
group.add(wifiRB);
group.add(dccRB);
conPanel.add(wifiRB);
conPanel.add(dccRB);
panel.add(conPanel);
return panel;
}
Aggregations