use of javax.swing.BoxLayout 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.BoxLayout 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);
}
use of javax.swing.BoxLayout in project JMRI by JMRI.
the class ConfigBaseStationFrame method initGui.
private void initGui() {
// NOTE: Look at jmri.jmrit.vsdecoder.swing.ManageLocationsFrame
// for how to add a tab for turnouts and other things.
this.setTitle(Bundle.getMessage("FieldManageBaseStationFrameTitle"));
this.buildMenu();
// Panel for managing sensors
sensorPanel = new JPanel();
sensorPanel.setLayout(new GridBagLayout());
JButton addButton = new JButton(Bundle.getMessage("ButtonAddSensor"));
addButton.setToolTipText(Bundle.getMessage("ToolTipButtonMSFAdd"));
// NOI18N
addButton.setMnemonic(Mnemonics.get("AddButton"));
addButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addButtonPressed(e);
}
});
JButton closeButton = new JButton(Bundle.getMessage("ButtonClose"));
closeButton.setToolTipText(Bundle.getMessage("ToolTipButtonMSFClose"));
// NOI18N
closeButton.setMnemonic(Mnemonics.get("CloseButton"));
closeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
closeButtonPressed(e);
}
});
JButton saveButton = new JButton(Bundle.getMessage("ButtonSaveSensors"));
saveButton.setToolTipText(Bundle.getMessage("ToolTipButtonMSFSave"));
// NOI18N
saveButton.setMnemonic(Mnemonics.get("SaveButton"));
saveButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
saveButtonPressed(e);
}
});
JScrollPane sensorScrollPanel = new JScrollPane();
sensorModel = new SensorTableModel();
sensorTable = new JTable(sensorModel);
sensorTable.setFillsViewportHeight(true);
sensorScrollPanel.getViewport().add(sensorTable);
sensorTable.setPreferredScrollableViewportSize(new Dimension(520, 200));
sensorTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).setCellRenderer(new ButtonRenderer());
sensorTable.removeColumn(sensorTable.getColumn("isNew"));
sensorTable.removeColumn(sensorTable.getColumn("isDirty"));
sensorTable.removeColumn(sensorTable.getColumn("isDelete"));
sensorTable.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
handleTableMouseClick(sensorTable, evt);
}
});
sensorTable.setAutoCreateRowSorter(true);
sensorSorter = new TableRowSorter<>(sensorTable.getModel());
sensorTable.setRowSorter(sensorSorter);
List<RowSorter.SortKey> sensorSortKeys = new ArrayList<>();
//int columnIndexToSort = 1;
sensorSortKeys.add(new RowSorter.SortKey(sensorTable.getColumn(Bundle.getMessage("FieldTableIndexColumn")).getModelIndex(), SortOrder.ASCENDING));
sensorSorter.setSortKeys(sensorSortKeys);
sensorSorter.sort();
sensorSorter.setSortable(sensorTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).getModelIndex(), false);
JScrollPane turnoutScrollPanel = new JScrollPane();
turnoutModel = new TurnoutTableModel();
turnoutTable = new JTable(turnoutModel);
turnoutTable.setFillsViewportHeight(true);
turnoutScrollPanel.getViewport().add(turnoutTable);
turnoutTable.setPreferredScrollableViewportSize(new Dimension(520, 200));
turnoutTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).setCellRenderer(new ButtonRenderer());
turnoutTable.removeColumn(turnoutTable.getColumn("isNew"));
turnoutTable.removeColumn(turnoutTable.getColumn("isDirty"));
turnoutTable.removeColumn(turnoutTable.getColumn("isDelete"));
turnoutTable.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
handleTableMouseClick(turnoutTable, evt);
}
});
turnoutTable.setAutoCreateRowSorter(true);
turnoutSorter = new TableRowSorter<>(turnoutTable.getModel());
turnoutTable.setRowSorter(turnoutSorter);
List<RowSorter.SortKey> turnoutSortKeys = new ArrayList<>();
//int columnIndexToSort = 1;
turnoutSortKeys.add(new RowSorter.SortKey(sensorTable.getColumn(Bundle.getMessage("FieldTableIndexColumn")).getModelIndex(), SortOrder.ASCENDING));
turnoutSorter.setSortKeys(turnoutSortKeys);
turnoutSorter.setSortable(sensorTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).getModelIndex(), false);
turnoutSorter.sort();
JScrollPane outputScrollPanel = new JScrollPane();
outputModel = new OutputTableModel();
outputTable = new JTable(outputModel);
outputTable.setFillsViewportHeight(true);
outputScrollPanel.getViewport().add(outputTable);
outputTable.setPreferredScrollableViewportSize(new Dimension(520, 200));
outputTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).setCellRenderer(new ButtonRenderer());
outputTable.removeColumn(outputTable.getColumn("isNew"));
outputTable.removeColumn(outputTable.getColumn("isDirty"));
outputTable.removeColumn(outputTable.getColumn("isDelete"));
outputTable.addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseClicked(java.awt.event.MouseEvent evt) {
handleTableMouseClick(outputTable, evt);
}
});
outputTable.setAutoCreateRowSorter(true);
outputSorter = new TableRowSorter<>(outputTable.getModel());
outputTable.setRowSorter(outputSorter);
List<RowSorter.SortKey> outputSortKeys = new ArrayList<>();
//int columnIndexToSort = 1;
outputSortKeys.add(new RowSorter.SortKey(sensorTable.getColumn(Bundle.getMessage("FieldTableIndexColumn")).getModelIndex(), SortOrder.ASCENDING));
outputSorter.setSortKeys(outputSortKeys);
outputSorter.setSortable(sensorTable.getColumn(Bundle.getMessage("FieldTableDeleteColumn")).getModelIndex(), false);
outputSorter.sort();
tabbedPane = new JTabbedPane();
tabbedPane.addTab(Bundle.getMessage("FieldSensorsTabTitle"), sensorScrollPanel);
tabbedPane.setToolTipTextAt(0, Bundle.getMessage("ToolTipSensorTab"));
// NOI18N
tabbedPane.setMnemonicAt(0, Mnemonics.get("SensorTab"));
tabbedPane.addTab(Bundle.getMessage("FieldTurnoutsTabTitle"), turnoutScrollPanel);
tabbedPane.setToolTipTextAt(0, Bundle.getMessage("ToolTipTurnoutTab"));
// NOI18N
tabbedPane.setMnemonicAt(0, Mnemonics.get("TurnoutTab"));
tabbedPane.addTab(Bundle.getMessage("FieldOutputsTabTitle"), outputScrollPanel);
tabbedPane.setToolTipTextAt(0, Bundle.getMessage("ToolTipOutputTab"));
// NOI18N
tabbedPane.setMnemonicAt(0, Mnemonics.get("OutputTab"));
cTab = CurrentTab.SENSOR;
tabbedPane.setSelectedIndex(0);
tabbedPane.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
switch(tabbedPane.getSelectedIndex()) {
case 2:
// Set Add to "Add Output"
cTab = CurrentTab.OUTPUT;
addButton.setText(Bundle.getMessage("ButtonAddOutput"));
saveButton.setText(Bundle.getMessage("ButtonSaveOutputs"));
log.debug("Current Tab is: {}", tabbedPane.getSelectedIndex());
break;
case 1:
// Set Add to "Add Turnout"
cTab = CurrentTab.TURNOUT;
addButton.setText(Bundle.getMessage("ButtonAddTurnout"));
saveButton.setText(Bundle.getMessage("ButtonSaveTurnouts"));
log.debug("Current Tab is: {}", tabbedPane.getSelectedIndex());
break;
case 0:
default:
// Set Add to "Add Sensor"
cTab = CurrentTab.SENSOR;
addButton.setText(Bundle.getMessage("ButtonAddSensor"));
saveButton.setText(Bundle.getMessage("ButtonSaveSensors"));
log.debug("Current Tab is: {}", tabbedPane.getSelectedIndex());
}
}
});
JPanel buttonPane = new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel buttonPane2 = new JPanel(new FlowLayout(FlowLayout.RIGHT));
buttonPane.add(addButton);
buttonPane.add(saveButton);
buttonPane2.add(closeButton);
this.getContentPane().setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));
this.getContentPane().add(tabbedPane);
this.getContentPane().add(buttonPane);
this.getContentPane().add(buttonPane2);
this.pack();
this.setVisible(true);
}
use of javax.swing.BoxLayout in project JMRI by JMRI.
the class EcosLocoAddressManager method propertyChange.
/**
* The PropertyChangeListener interface in this class is intended to keep
* track of roster entries and sync them up with the Ecos.
*/
@Override
public void propertyChange(java.beans.PropertyChangeEvent e) {
//If we are adding the loco to the roster from the ecos, we don't want to be adding it back to the ecos!
if (getLocoToRoster()) {
return;
}
if (e.getPropertyName().equals("add")) {
_re = (RosterEntry) e.getNewValue();
} else if (e.getPropertyName().equals("saved")) {
if (_re != null) {
if (_re.getAttribute(rosterAttribute) != null) {
_re = null;
return;
}
//if the ecosobject attribute exists this would then indicate that it has already been created on the ecos
if (p.getAddLocoToEcos() == EcosPreferences.ASK) {
final JDialog dialog = new JDialog();
dialog.setTitle("Add Loco to the ECoS?");
//test.setSize(300,130);
dialog.setLocation(300, 200);
dialog.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
JPanel container = new JPanel();
container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
container.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
JLabel question = new JLabel("Do you also want to add " + _re.getId() + " to the " + adaptermemo.getUserName() + "?");
question.setAlignmentX(Component.CENTER_ALIGNMENT);
container.add(question);
final JCheckBox remember = new JCheckBox("Remember this setting for next time?");
remember.setFont(remember.getFont().deriveFont(10f));
remember.setAlignmentX(Component.CENTER_ALIGNMENT);
//user preferences do not have the save option, but once complete the following line can be removed
//Need to get the method to save connection configuration.
remember.setVisible(true);
JButton yesButton = new JButton("Yes");
JButton noButton = new JButton("No");
JPanel button = new JPanel();
button.setAlignmentX(Component.CENTER_ALIGNMENT);
button.add(yesButton);
button.add(noButton);
container.add(button);
noButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (remember.isSelected()) {
p.setAddLocoToEcos(0x01);
}
_re = null;
dialog.dispose();
}
});
yesButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (remember.isSelected()) {
p.setAddLocoToEcos(0x02);
}
RosterToEcos rosterToEcos = new RosterToEcos();
rosterToEcos.createEcosLoco(_re, adaptermemo);
_re = null;
dialog.dispose();
}
});
container.add(remember);
container.setAlignmentX(Component.CENTER_ALIGNMENT);
container.setAlignmentY(Component.CENTER_ALIGNMENT);
dialog.getContentPane().add(container);
dialog.pack();
dialog.setModal(true);
dialog.setVisible(true);
}
if (p.getAddLocoToEcos() == 0x02) {
RosterToEcos rosterToEcos = new RosterToEcos();
rosterToEcos.createEcosLoco(_re, adaptermemo);
_re = null;
}
}
} else if (e.getPropertyName().equals("remove")) {
_re = (RosterEntry) e.getNewValue();
if (_re.getAttribute(rosterAttribute) != null) {
if (p.getRemoveLocoFromEcos() == EcosPreferences.YES) {
RemoveObjectFromEcos removeObjectFromEcos = new RemoveObjectFromEcos();
removeObjectFromEcos.removeObjectFromEcos(_re.getAttribute(p.getRosterAttribute()), tc);
deleteEcosLoco(provideByEcosObject(_re.getAttribute(p.getRosterAttribute())));
} else if (p.getRemoveLocoFromEcos() == EcosPreferences.ASK) {
final JDialog dialog = new JDialog();
dialog.setTitle("Remove Loco From ECoS?");
//test.setSize(300,130);
dialog.setLocation(300, 200);
dialog.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
JPanel container = new JPanel();
container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
container.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
JLabel question = new JLabel("Do you also want to remove this loco from the " + adaptermemo.getUserName());
question.setAlignmentX(Component.CENTER_ALIGNMENT);
container.add(question);
final JCheckBox remember = new JCheckBox("Remember this setting for next time?");
remember.setFont(remember.getFont().deriveFont(10f));
remember.setAlignmentX(Component.CENTER_ALIGNMENT);
//user preferences do not have the save option, but once complete the following line can be removed
//Need to get the method to save connection configuration.
remember.setVisible(true);
JButton yesButton = new JButton("Yes");
JButton noButton = new JButton("No");
JPanel button = new JPanel();
button.setAlignmentX(Component.CENTER_ALIGNMENT);
button.add(yesButton);
button.add(noButton);
container.add(button);
noButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (remember.isSelected()) {
p.setRemoveLocoFromEcos(0x01);
}
provideByEcosObject(_re.getAttribute(p.getRosterAttribute())).setRosterId(null);
dialog.dispose();
}
});
yesButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (remember.isSelected()) {
p.setRemoveLocoFromEcos(0x02);
}
RemoveObjectFromEcos removeObjectFromEcos = new RemoveObjectFromEcos();
removeObjectFromEcos.removeObjectFromEcos(_re.getAttribute(p.getRosterAttribute()), tc);
deleteEcosLoco(provideByEcosObject(_re.getAttribute(p.getRosterAttribute())));
dialog.dispose();
}
});
container.add(remember);
container.setAlignmentX(Component.CENTER_ALIGNMENT);
container.setAlignmentY(Component.CENTER_ALIGNMENT);
dialog.getContentPane().add(container);
dialog.pack();
dialog.setModal(true);
dialog.setVisible(true);
}
}
_re = null;
} else if (e.getPropertyName().equals("throttleAssigned")) {
jmri.DccLocoAddress la = (jmri.DccLocoAddress) e.getNewValue();
EcosLocoAddress ela = getByDccAddress(la.getNumber());
EcosMessage m = new EcosMessage("get(" + ela.getEcosObject() + ", speed)");
tc.sendEcosMessage(m, this);
m = new EcosMessage("get(" + ela.getEcosObject() + ", dir)");
tc.sendEcosMessage(m, this);
}
}
use of javax.swing.BoxLayout in project JMRI by JMRI.
the class RenumberFrame method initComponents.
/**
* Initialize the window
*/
@Override
public void initComponents() {
setTitle(rb.getString("WindowTitleRenumber"));
Container contentPane = getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
JPanel p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
contentPane.add(p);
p.add(new JLabel(rb.getString("LabelFrom")));
from = new JTextField(4);
p.add(from);
p.add(new JLabel(rb.getString("LabelTo")));
to = new JTextField(4);
p.add(to);
p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
contentPane.add(p);
JButton b = new JButton(rb.getString("ButtonExec"));
p.add(b);
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
execute();
}
});
// add help menu to window
addHelpMenu("package.jmri.jmrix.grapevine.nodetable.RenumberFrame", true);
// pack for display
pack();
}
Aggregations