use of javax.swing.ButtonGroup in project JMRI by JMRI.
the class TrackRoadEditFrame method initComponents.
public void initComponents(Location location, Track track) {
_location = location;
_track = track;
// property changes
// listen for car road name changes
CarRoads.instance().addPropertyChangeListener(this);
// the following code sets the frame's initial state
getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
// Set up the panels
// Layout the panel by rows
// row 1
JPanel p1 = new JPanel();
p1.setLayout(new BoxLayout(p1, BoxLayout.X_AXIS));
p1.setMaximumSize(new Dimension(2000, 250));
// row 1a
JPanel pTrackName = new JPanel();
pTrackName.setLayout(new GridBagLayout());
pTrackName.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Track")));
addItem(pTrackName, trackName, 0, 0);
// row 1b
JPanel pLocationName = new JPanel();
pLocationName.setLayout(new GridBagLayout());
pLocationName.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Location")));
addItem(pLocationName, new JLabel(_location.getName()), 0, 0);
p1.add(pTrackName);
p1.add(pLocationName);
// 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("RoadsTrack")));
pane3.setMaximumSize(new Dimension(2000, 400));
JPanel pRoadRadioButtons = new JPanel();
pRoadRadioButtons.setLayout(new FlowLayout());
pRoadRadioButtons.add(roadNameAll);
pRoadRadioButtons.add(roadNameInclude);
pRoadRadioButtons.add(roadNameExclude);
pRoadControls.setLayout(new FlowLayout());
pRoadControls.add(comboBoxRoads);
pRoadControls.add(addRoadButton);
pRoadControls.add(deleteRoadButton);
pRoadControls.add(deleteAllRoadsButton);
pRoadControls.setVisible(false);
p3.add(pRoadRadioButtons);
p3.add(pRoadControls);
// row 4
panelRoads.setLayout(new GridBagLayout());
paneRoads.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Roads")));
ButtonGroup roadGroup = new ButtonGroup();
roadGroup.add(roadNameAll);
roadGroup.add(roadNameInclude);
roadGroup.add(roadNameExclude);
// row 12
JPanel panelButtons = new JPanel();
panelButtons.setLayout(new GridBagLayout());
panelButtons.setBorder(BorderFactory.createTitledBorder(""));
panelButtons.setMaximumSize(new Dimension(2000, 200));
// row 13
addItem(panelButtons, saveTrackButton, 0, 0);
getContentPane().add(p1);
getContentPane().add(pane3);
getContentPane().add(paneRoads);
getContentPane().add(panelButtons);
// setup buttons
addButtonAction(saveTrackButton);
addButtonAction(deleteRoadButton);
addButtonAction(deleteAllRoadsButton);
addButtonAction(addRoadButton);
addRadioButtonAction(roadNameAll);
addRadioButtonAction(roadNameInclude);
addRadioButtonAction(roadNameExclude);
// road fields and enable buttons
if (_track != null) {
_track.addPropertyChangeListener(this);
trackName.setText(_track.getName());
enableButtons(true);
} else {
enableButtons(false);
}
updateRoadComboBox();
updateRoadNames();
// add help menu to window
// NOI18N
addHelpMenu("package.jmri.jmrit.operations.Operations_RoadOptions", true);
initMinimumSize(new Dimension(Control.panelWidth500, Control.panelHeight400));
}
use of javax.swing.ButtonGroup in project JMRI by JMRI.
the class RouteEditFrame method initComponents.
public void initComponents(Route route) {
_route = route;
String routeName = null;
// load managers
routeManager = RouteManager.instance();
// Set up the jtable in a Scroll Pane..
routePane = new JScrollPane(routeTable);
routePane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
routePane.setBorder(BorderFactory.createTitledBorder(""));
routeModel.initTable(this, routeTable, _route);
if (_route != null) {
routeName = _route.getName();
routeNameTextField.setText(routeName);
commentTextField.setText(_route.getComment());
enableButtons(true);
} else {
setTitle(Bundle.getMessage("TitleRouteAdd"));
enableButtons(false);
}
getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
// Set up the panels
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 * routeNameTextField.getPreferredSize().height));
p1Pane.setMaximumSize(new Dimension(2000, 200));
p1Pane.setBorder(BorderFactory.createTitledBorder(""));
// name panel
JPanel pName = new JPanel();
pName.setLayout(new GridBagLayout());
pName.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Name")));
addItem(pName, routeNameTextField, 0, 0);
// comment panel
JPanel pComment = new JPanel();
pComment.setLayout(new GridBagLayout());
pComment.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Comment")));
addItem(pComment, commentTextField, 0, 0);
p1.add(pName);
p1.add(pComment);
JPanel p2 = new JPanel();
p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS));
JScrollPane p2Pane = new JScrollPane(p2);
p2Pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
p2Pane.setMinimumSize(new Dimension(300, 3 * routeNameTextField.getPreferredSize().height));
p2Pane.setMaximumSize(new Dimension(2000, 200));
p2Pane.setBorder(BorderFactory.createTitledBorder(""));
// location panel
JPanel pLoc = new JPanel();
pLoc.setLayout(new GridBagLayout());
pLoc.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Location")));
addItem(pLoc, locationBox, 0, 1);
addItem(pLoc, addLocationButton, 1, 1);
addItem(pLoc, addLocAtTop, 2, 1);
addItem(pLoc, addLocAtMiddle, 3, 1);
addItem(pLoc, addLocAtBottom, 4, 1);
// Wait or Depart Time panel
JPanel pWait = new JPanel();
pWait.setLayout(new GridBagLayout());
pWait.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Display")));
addItem(pWait, showWait, 0, 1);
addItem(pWait, showDepartTime, 1, 1);
p2.add(pLoc);
p2.add(pWait);
// row 12 buttons
JPanel pB = new JPanel();
pB.setLayout(new GridBagLayout());
JScrollPane pBPane = new JScrollPane(pB);
pBPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
pBPane.setMinimumSize(new Dimension(300, 3 * routeNameTextField.getPreferredSize().height));
pBPane.setMaximumSize(new Dimension(2000, 200));
pBPane.setBorder(BorderFactory.createTitledBorder(""));
addItem(pB, deleteRouteButton, 0, 0);
addItem(pB, addRouteButton, 1, 0);
addItem(pB, saveRouteButton, 3, 0);
getContentPane().add(p1Pane);
getContentPane().add(routePane);
getContentPane().add(p2Pane);
getContentPane().add(pBPane);
// setup buttons
addButtonAction(addLocationButton);
addButtonAction(deleteRouteButton);
addButtonAction(addRouteButton);
addButtonAction(saveRouteButton);
// setup radio buttons
ButtonGroup group = new ButtonGroup();
group.add(addLocAtTop);
group.add(addLocAtMiddle);
group.add(addLocAtBottom);
addLocAtBottom.setSelected(true);
// to clear table row sorting
addRadioButtonAction(addLocAtTop);
addRadioButtonAction(addLocAtMiddle);
// to clear table row sorting
addRadioButtonAction(addLocAtBottom);
ButtonGroup groupTime = new ButtonGroup();
groupTime.add(showWait);
groupTime.add(showDepartTime);
addRadioButtonAction(showWait);
addRadioButtonAction(showDepartTime);
setTimeWaitRadioButtons();
// build menu
JMenuBar menuBar = new JMenuBar();
JMenu toolMenu = new JMenu(Bundle.getMessage("MenuTools"));
toolMenu.add(new RouteCopyAction(Bundle.getMessage("MenuItemCopy"), routeName));
toolMenu.add(new SetTrainIconRouteAction(Bundle.getMessage("MenuSetTrainIconRoute"), routeName));
toolMenu.addSeparator();
toolMenu.add(new PrintRouteAction(Bundle.getMessage("MenuItemPrint"), false, _route));
toolMenu.add(new PrintRouteAction(Bundle.getMessage("MenuItemPreview"), true, _route));
menuBar.add(toolMenu);
setJMenuBar(menuBar);
// NOI18N
addHelpMenu("package.jmri.jmrit.operations.Operations_EditRoute", true);
// get notified if combo box gets modified
LocationManager.instance().addPropertyChangeListener(this);
// set frame size and route for display
initMinimumSize(new Dimension(Control.panelWidth700, Control.panelHeight400));
}
use of javax.swing.ButtonGroup in project JMRI by JMRI.
the class ControlPanel method initGUI.
/**
* Create, initialize and place GUI components.
*/
private void initGUI() {
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));
speedControlPanel.setOpaque(false);
mainPanel.add(speedControlPanel, BorderLayout.CENTER);
sliderPanel = new JPanel();
sliderPanel.setLayout(new GridBagLayout());
sliderPanel.setOpaque(false);
speedSlider = new JSlider(0, intSpeedSteps);
speedSlider.setOpaque(false);
speedSlider.setValue(0);
speedSlider.setFocusable(false);
// add mouse-wheel support
speedSlider.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
if (e.getWheelRotation() > 0) {
for (int i = 0; i < e.getScrollAmount(); i++) {
decelerate1();
}
} else {
for (int i = 0; i < e.getScrollAmount(); i++) {
accelerate1();
}
}
}
});
speedSliderContinuous = new JSlider(-intSpeedSteps, intSpeedSteps);
speedSliderContinuous.setValue(0);
speedSliderContinuous.setOpaque(false);
speedSliderContinuous.setFocusable(false);
// add mouse-wheel support
speedSliderContinuous.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseWheelMoved(MouseWheelEvent e) {
if (e.getWheelRotation() > 0) {
for (int i = 0; i < e.getScrollAmount(); i++) {
decelerate1();
}
} else {
for (int i = 0; i < e.getScrollAmount(); i++) {
accelerate1();
}
}
}
});
speedSpinner = new JSpinner();
speedSpinnerModel = new SpinnerNumberModel(0, 0, intSpeedSteps, 1);
speedSpinner.setModel(speedSpinnerModel);
speedSpinner.setFocusable(false);
SpeedStep128Button = new JRadioButton(Bundle.getMessage("Button128SS"));
SpeedStep28Button = new JRadioButton(Bundle.getMessage("Button28SS"));
SpeedStep27Button = new JRadioButton(Bundle.getMessage("Button27SS"));
SpeedStep14Button = new JRadioButton(Bundle.getMessage("Button14SS"));
forwardButton = new JRadioButton();
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
forwardButton.setBorderPainted(false);
forwardButton.setContentAreaFilled(false);
forwardButton.setText(null);
forwardButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/up-red.png")));
forwardButton.setSelectedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/up-green.png")));
forwardButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
forwardButton.setToolTipText(Bundle.getMessage("ButtonForward"));
} else {
forwardButton.setText(Bundle.getMessage("ButtonForward"));
}
reverseButton = new JRadioButton();
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
reverseButton.setBorderPainted(false);
reverseButton.setContentAreaFilled(false);
reverseButton.setText(null);
reverseButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/down-red.png")));
reverseButton.setSelectedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/down-green.png")));
reverseButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
reverseButton.setToolTipText(Bundle.getMessage("ButtonReverse"));
} else {
reverseButton.setText(Bundle.getMessage("ButtonReverse"));
}
propertiesPopup = new JPopupMenu();
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(maxSpeed / 2);
java.util.Hashtable<Integer, JLabel> labelTable = new java.util.Hashtable<Integer, JLabel>();
labelTable.put(Integer.valueOf(maxSpeed / 2), new JLabel("50%"));
labelTable.put(Integer.valueOf(maxSpeed), 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;
lastTrackedSliderMovementTime = System.currentTimeMillis() - trackSliderMinInterval;
} else if (trackSlider && System.currentTimeMillis() - lastTrackedSliderMovementTime >= trackSliderMinInterval) {
doIt = true;
lastTrackedSliderMovementTime = System.currentTimeMillis();
}
if (doIt) {
float newSpeed = (speedSlider.getValue() / (intSpeedSteps * 1.0f));
if (log.isDebugEnabled()) {
log.debug("stateChanged: slider pos: " + speedSlider.getValue() + " speed: " + newSpeed);
}
if (sliderPanel.isVisible() && throttle != null) {
throttle.setSpeedSetting(newSpeed);
}
if (speedSpinner != null) {
speedSpinnerModel.setValue(Integer.valueOf(speedSlider.getValue()));
}
if (speedSliderContinuous != null) {
if (forwardButton.isSelected()) {
speedSliderContinuous.setValue(((Integer) speedSlider.getValue()).intValue());
} else {
speedSliderContinuous.setValue(-((Integer) speedSlider.getValue()).intValue());
}
}
}
}
}
});
speedSliderContinuousPanel = new JPanel();
speedSliderContinuousPanel.setLayout(new GridBagLayout());
constraints = new GridBagConstraints();
constraints.anchor = GridBagConstraints.CENTER;
constraints.fill = GridBagConstraints.BOTH;
constraints.gridheight = 1;
constraints.gridwidth = 1;
constraints.ipadx = 0;
constraints.ipady = 0;
insets = new Insets(2, 2, 2, 2);
constraints.insets = insets;
constraints.weightx = 1;
constraints.weighty = 1;
constraints.gridx = 0;
constraints.gridy = 0;
speedSliderContinuousPanel.add(speedSliderContinuous, constraints);
//this.getContentPane().add(sliderPanel,BorderLayout.CENTER);
speedControlPanel.add(speedSliderContinuousPanel);
speedSliderContinuous.setOrientation(JSlider.VERTICAL);
speedSliderContinuous.setMajorTickSpacing(maxSpeed / 2);
labelTable = new java.util.Hashtable<Integer, JLabel>();
labelTable.put(Integer.valueOf(maxSpeed / 2), new JLabel("50%"));
labelTable.put(Integer.valueOf(maxSpeed), new JLabel("100%"));
labelTable.put(Integer.valueOf(0), new JLabel(Bundle.getMessage("LabelStop")));
labelTable.put(Integer.valueOf(-maxSpeed / 2), new JLabel("-50%"));
labelTable.put(Integer.valueOf(-maxSpeed), new JLabel("-100%"));
speedSliderContinuous.setLabelTable(labelTable);
speedSliderContinuous.setPaintTicks(true);
speedSliderContinuous.setPaintLabels(true);
// remove old actions
speedSliderContinuous.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (!internalAdjust) {
boolean doIt = false;
if (!speedSliderContinuous.getValueIsAdjusting()) {
doIt = true;
lastTrackedSliderMovementTime = System.currentTimeMillis() - trackSliderMinInterval;
} else if (trackSlider && System.currentTimeMillis() - lastTrackedSliderMovementTime >= trackSliderMinInterval) {
doIt = true;
lastTrackedSliderMovementTime = System.currentTimeMillis();
}
if (doIt) {
float newSpeed = (java.lang.Math.abs(speedSliderContinuous.getValue()) / (intSpeedSteps * 1.0f));
boolean newDir = (speedSliderContinuous.getValue() >= 0);
if (log.isDebugEnabled()) {
log.debug("stateChanged: slider pos: " + speedSliderContinuous.getValue() + " speed: " + newSpeed + " dir: " + newDir);
}
if (speedSliderContinuousPanel.isVisible() && throttle != null) {
throttle.setSpeedSetting(newSpeed);
if ((newSpeed > 0) && (newDir != forwardButton.isSelected())) {
throttle.setIsForward(newDir);
}
}
if (speedSpinner != null) {
speedSpinnerModel.setValue(Integer.valueOf(java.lang.Math.abs(speedSliderContinuous.getValue())));
}
if (speedSlider != null) {
speedSlider.setValue(Integer.valueOf(java.lang.Math.abs(speedSliderContinuous.getValue())));
}
}
}
}
});
spinnerPanel = new JPanel();
spinnerPanel.setLayout(new GridBagLayout());
spinnerPanel.add(speedSpinner, constraints);
speedControlPanel.add(spinnerPanel);
// remove old actions
speedSpinner.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (!internalAdjust) {
//if (!speedSpinner.getValueIsAdjusting())
//{
float newSpeed = ((Integer) speedSpinner.getValue()).floatValue() / (intSpeedSteps * 1.0f);
if (log.isDebugEnabled()) {
log.debug("stateChanged: spinner pos: " + speedSpinner.getValue() + " speed: " + newSpeed);
}
if (throttle != null) {
if (spinnerPanel.isVisible()) {
throttle.setSpeedSetting(newSpeed);
}
speedSlider.setValue(((Integer) speedSpinner.getValue()).intValue());
if (speedSliderContinuous != null) {
if (forwardButton.isSelected()) {
speedSliderContinuous.setValue(((Integer) speedSpinner.getValue()).intValue());
} else {
speedSliderContinuous.setValue(-((Integer) speedSpinner.getValue()).intValue());
}
}
} else {
log.warn("no throttle object in stateChanged, ignoring change of speed to " + newSpeed);
}
//}
}
}
});
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) {
setSpeedStepsMode(DccThrottle.SpeedStepMode14);
throttle.setSpeedStepMode(DccThrottle.SpeedStepMode14);
}
});
SpeedStep27Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setSpeedStepsMode(DccThrottle.SpeedStepMode27);
throttle.setSpeedStepMode(DccThrottle.SpeedStepMode27);
}
});
SpeedStep28Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setSpeedStepsMode(DccThrottle.SpeedStepMode28);
throttle.setSpeedStepMode(DccThrottle.SpeedStepMode28);
}
});
SpeedStep128Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setSpeedStepsMode(DccThrottle.SpeedStepMode128);
throttle.setSpeedStepMode(DccThrottle.SpeedStepMode128);
}
});
buttonPanel = new JPanel();
buttonPanel.setLayout(new GridBagLayout());
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
ButtonGroup directionButtons = new ButtonGroup();
directionButtons.add(forwardButton);
directionButtons.add(reverseButton);
constraints.fill = GridBagConstraints.NONE;
constraints.gridy = 1;
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
constraints.gridx = 3;
}
buttonPanel.add(forwardButton, constraints);
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
constraints.gridx = 1;
} else {
constraints.gridy = 2;
}
buttonPanel.add(reverseButton, constraints);
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
constraints.gridx = 2;
}
forwardButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
throttle.setIsForward(true);
if (speedSliderContinuous != null) {
speedSliderContinuous.setValue(java.lang.Math.abs(speedSliderContinuous.getValue()));
}
}
});
reverseButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
throttle.setIsForward(false);
if (speedSliderContinuous != null) {
speedSliderContinuous.setValue(-java.lang.Math.abs(speedSliderContinuous.getValue()));
}
}
});
stopButton = new JButton();
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
stopButton.setBorderPainted(false);
stopButton.setContentAreaFilled(false);
stopButton.setText(null);
stopButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/estop.png")));
stopButton.setPressedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/estop24.png")));
stopButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
stopButton.setToolTipText(Bundle.getMessage("ButtonEStop"));
} else {
stopButton.setText(Bundle.getMessage("ButtonEStop"));
}
constraints.gridy = 4;
constraints.fill = GridBagConstraints.HORIZONTAL;
buttonPanel.add(stopButton, constraints);
stopButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
stop();
}
});
stopButton.addMouseListener(new MouseListener() {
@Override
public void mousePressed(MouseEvent e) {
stop();
}
@Override
public void mouseExited(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseClicked(MouseEvent e) {
}
});
idleButton = new JButton();
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
idleButton.setBorderPainted(false);
idleButton.setContentAreaFilled(false);
idleButton.setText(null);
idleButton.setIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/stop.png")));
idleButton.setPressedIcon(new ImageIcon(FileUtil.findURL("resources/icons/throttles/stop24.png")));
idleButton.setPreferredSize(new Dimension(BUTTON_SIZE, BUTTON_SIZE));
idleButton.setToolTipText(Bundle.getMessage("ButtonIdle"));
} else {
idleButton.setText(Bundle.getMessage("ButtonIdle"));
}
if (jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingExThrottle() && jmri.jmrit.throttle.ThrottleFrameManager.instance().getThrottlesPreferences().isUsingFunctionIcon()) {
constraints.gridy = 1;
} else {
constraints.gridy = 3;
}
buttonPanel.add(idleButton, constraints);
idleButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
speedSlider.setValue(0);
if (speedSpinner != null) {
speedSpinner.setValue(Integer.valueOf(0));
}
if (speedSliderContinuous != null) {
speedSliderContinuous.setValue(Integer.valueOf(0));
}
throttle.setSpeedSetting(0);
}
});
addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
changeOrientation();
}
});
JMenuItem propertiesItem = new JMenuItem(Bundle.getMessage("ControlPanelProperties"));
propertiesItem.addActionListener(this);
propertiesPopup.add(propertiesItem);
// Add a mouse listener all components to trigger the popup menu.
MouseInputAdapter popupListener = new PopupListener(propertiesPopup, this);
MouseInputAdapterInstaller.installMouseInputAdapterOnAllComponents(popupListener, this);
// Install the Key bindings on all Components
KeyListenerInstaller.installKeyListenerOnAllComponents(new ControlPadKeyListener(), this);
// set by default which speed selection method is on top
setSpeedController(_displaySlider);
}
use of javax.swing.ButtonGroup in project JMRI by JMRI.
the class ControlPanelPropertyEditor method initGUI.
/**
* Create, initilize, and place the GUI objects.
*/
private void initGUI() {
this.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
this.setTitle(Bundle.getMessage("TitleEditSpeedControlPanel"));
JPanel mainPanel = new JPanel();
this.setContentPane(mainPanel);
mainPanel.setLayout(new BorderLayout());
JPanel propertyPanel = new JPanel();
propertyPanel.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.anchor = GridBagConstraints.WEST;
constraints.fill = GridBagConstraints.HORIZONTAL;
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;
ButtonGroup modeSelectionButtons = new ButtonGroup();
displaySlider = new JRadioButton(Bundle.getMessage("ButtonDisplaySpeedSlider"));
displaySliderContinuous = new JRadioButton(Bundle.getMessage("ButtonDisplaySpeedSliderContinuous"));
displaySteps = new JRadioButton(Bundle.getMessage("ButtonDisplaySpeedSteps"));
modeSelectionButtons.add(displaySlider);
modeSelectionButtons.add(displaySteps);
modeSelectionButtons.add(displaySliderContinuous);
_displaySlider = control.getDisplaySlider();
constraints.anchor = GridBagConstraints.CENTER;
constraints.gridy = 1;
propertyPanel.add(displaySlider, constraints);
constraints.gridy = 2;
propertyPanel.add(displaySteps, constraints);
constraints.gridy = 3;
propertyPanel.add(displaySliderContinuous, constraints);
trackBox = new JCheckBox(Bundle.getMessage("CheckBoxTrackSliderInRealTime"));
constraints.gridy = 4;
trackBox.setSelected(control.getTrackSlider());
propertyPanel.add(trackBox, constraints);
JLabel functionSwitchLabel = new JLabel(Bundle.getMessage("SwitchSliderOnFunction"));
functionSwitchSlider = new JTextField(4);
functionSwitchSlider.setText(control.getSwitchSliderFunction());
constraints.gridy = 5;
constraints.gridx = 0;
propertyPanel.add(functionSwitchLabel, constraints);
constraints.gridx = 1;
propertyPanel.add(functionSwitchSlider, constraints);
displaySlider.setSelected(_displaySlider == ControlPanel.SLIDERDISPLAY);
displaySteps.setSelected(_displaySlider == ControlPanel.STEPDISPLAY);
displaySliderContinuous.setSelected(_displaySlider == ControlPanel.SLIDERDISPLAYCONTINUOUS);
displaySlider.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
displaySlider.setSelected(true);
displaySteps.setSelected(false);
displaySliderContinuous.setSelected(false);
_displaySlider = ControlPanel.SLIDERDISPLAY;
}
});
displaySteps.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
displaySlider.setSelected(false);
displaySteps.setSelected(true);
displaySliderContinuous.setSelected(false);
_displaySlider = ControlPanel.STEPDISPLAY;
}
});
displaySliderContinuous.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
displaySlider.setSelected(false);
displaySteps.setSelected(false);
displaySliderContinuous.setSelected(true);
_displaySlider = ControlPanel.SLIDERDISPLAYCONTINUOUS;
}
});
// disable the speed controls if the control panel says they
// aren't possible
displaySlider.setEnabled(control.isSpeedControllerAvailable(ControlPanel.SLIDERDISPLAY));
displaySteps.setEnabled(control.isSpeedControllerAvailable(ControlPanel.STEPDISPLAY));
displaySliderContinuous.setEnabled(control.isSpeedControllerAvailable(ControlPanel.SLIDERDISPLAYCONTINUOUS));
JPanel buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(1, 2, 4, 4));
JButton saveButton = new JButton(Bundle.getMessage("ButtonOK"));
saveButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
saveProperties();
}
});
JButton cancelButton = new JButton(Bundle.getMessage("ButtonCancel"));
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
finishEdit();
}
});
buttonPanel.add(saveButton);
buttonPanel.add(cancelButton);
mainPanel.add(propertyPanel, BorderLayout.CENTER);
mainPanel.add(buttonPanel, BorderLayout.SOUTH);
}
use of javax.swing.ButtonGroup in project JMRI by JMRI.
the class ManageLocationsFrame method initGui.
private void initGui() {
this.setTitle(Bundle.getMessage("FieldManageLocationsFrameTitle"));
this.buildMenu();
// Panel for managing listeners
listenerPanel = new JPanel();
listenerPanel.setLayout(new BoxLayout(listenerPanel, BoxLayout.Y_AXIS));
// Audio Mode Buttons
JRadioButton b1 = new JRadioButton(Bundle.getMessage("ButtonAudioModeRoom"));
b1.setToolTipText(Bundle.getMessage("ToolTipButtonAudioModeRoom"));
// NOI18N
b1.setMnemonic(Mnemonics.get("RoomMode"));
b1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
modeRadioButtonPressed(e);
}
});
JRadioButton b2 = new JRadioButton(Bundle.getMessage("ButtonAudioModeHeadphone"));
// NOI18N
b2.setMnemonic(Mnemonics.get("HeadphoneMode"));
b2.setToolTipText(Bundle.getMessage("ToolTipButtonAudioModeHeadphone"));
b2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
modeRadioButtonPressed(e);
}
});
b2.setEnabled(false);
ButtonGroup bg = new ButtonGroup();
bg.add(b1);
bg.add(b2);
b1.setSelected(true);
JPanel modePanel = new JPanel();
modePanel.setLayout(new BoxLayout(modePanel, BoxLayout.LINE_AXIS));
modePanel.add(new JLabel(Bundle.getMessage("FieldAudioMode")));
modePanel.add(b1);
modePanel.add(b2);
// Build Listener Locations Table
locData = new Object[1][7];
locData[0][0] = listenerLoc.getName();
locData[0][1] = true;
locData[0][2] = listenerLoc.getLocation().x;
locData[0][3] = listenerLoc.getLocation().y;
locData[0][4] = listenerLoc.getLocation().z;
locData[0][5] = listenerLoc.getBearing();
locData[0][6] = listenerLoc.getAzimuth();
log.debug("Listener:" + listenerLoc.toString());
log.debug("locData:");
for (int i = 0; i < 7; i++) {
log.debug("" + locData[0][i]);
}
JPanel locPanel = new JPanel();
locPanel.setLayout(new BoxLayout(locPanel, BoxLayout.LINE_AXIS));
JScrollPane locScrollPanel = new JScrollPane();
locModel = new ListenerTableModel(locData);
JTable locTable = new JTable(locModel);
locTable.setFillsViewportHeight(true);
locTable.setPreferredScrollableViewportSize(new Dimension(520, 200));
locScrollPanel.getViewport().add(locTable);
listenerPanel.add(modePanel);
listenerPanel.add(locScrollPanel);
reporterPanel = new JPanel();
reporterPanel.setLayout(new GridBagLayout());
JScrollPane reporterScrollPanel = new JScrollPane();
reporterModel = new LocationTableModel(reporterData);
JTable reporterTable = new JTable(reporterModel);
reporterTable.setFillsViewportHeight(true);
reporterScrollPanel.getViewport().add(reporterTable);
reporterTable.setPreferredScrollableViewportSize(new Dimension(520, 200));
blockPanel = new JPanel();
blockPanel.setLayout(new GridBagLayout());
JScrollPane blockScrollPanel = new JScrollPane();
blockModel = new LocationTableModel(blockData);
JTable blockTable = new JTable(blockModel);
blockTable.setFillsViewportHeight(true);
blockScrollPanel.getViewport().add(blockTable);
blockTable.setPreferredScrollableViewportSize(new Dimension(520, 200));
opsPanel = new JPanel();
opsPanel.setLayout(new GridBagLayout());
opsPanel.revalidate();
JScrollPane opsScrollPanel = new JScrollPane();
opsModel = new LocationTableModel(opsData);
JTable opsTable = new JTable(opsModel);
opsTable.setFillsViewportHeight(true);
opsTable.setPreferredScrollableViewportSize(new Dimension(520, 200));
opsScrollPanel.getViewport().add(opsTable);
tabbedPane = new JTabbedPane();
// Reporters Tab Title
tabbedPane.addTab(Bundle.getMessage("Reporters"), reporterScrollPanel);
tabbedPane.setToolTipTextAt(0, Bundle.getMessage("ToolTipReporterTab"));
// NOI18N
tabbedPane.setMnemonicAt(0, Mnemonics.get("ReporterTab"));
tabbedPane.addTab(Bundle.getMessage("Blocks"), blockScrollPanel);
tabbedPane.setToolTipTextAt(0, Bundle.getMessage("ToolTipBlockTab"));
// NOI18N
tabbedPane.setMnemonicAt(0, Mnemonics.get("BlockTab"));
tabbedPane.addTab(Bundle.getMessage("FieldOpsTabTitle"), opsScrollPanel);
tabbedPane.setToolTipTextAt(1, Bundle.getMessage("ToolTipOpsTab"));
// NOI18N
tabbedPane.setMnemonicAt(1, Mnemonics.get("OpsTab"));
tabbedPane.addTab(Bundle.getMessage("FieldListenersTabTitle"), listenerPanel);
tabbedPane.setToolTipTextAt(2, Bundle.getMessage("ToolTipListenerTab"));
// NOI18N
tabbedPane.setMnemonicAt(2, Mnemonics.get("ListenerTab"));
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
JButton closeButton = new JButton(Bundle.getMessage("ButtonCancel"));
closeButton.setToolTipText(Bundle.getMessage("ToolTipButtonMLFClose"));
// NOI18N
closeButton.setMnemonic(Mnemonics.get("CloseButton"));
closeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
closeButtonPressed(e);
}
});
JButton saveButton = new JButton(Bundle.getMessage("ButtonSave"));
saveButton.setToolTipText(Bundle.getMessage("ToolTipButtonMLFSave"));
// NOI18N
saveButton.setMnemonic(Mnemonics.get("SaveButton"));
saveButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
saveButtonPressed(e);
}
});
buttonPane.add(closeButton);
buttonPane.add(saveButton);
this.getContentPane().setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));
this.getContentPane().add(tabbedPane);
this.getContentPane().add(buttonPane);
this.pack();
this.setVisible(true);
}
Aggregations