use of javax.swing.JToggleButton in project JMRI by JMRI.
the class VSDecoderPane method initComponents.
/**
* initComponents()
*
* initialzies the GUI components.
*/
@Override
public void initComponents() {
log.debug("initComponents()");
//buildMenu();
setLayout(new GridBagLayout());
setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
// Add the tabbed pane to the VSDecoderPane. The tabbedPane will contain all the other panes.
tabbedPane = new JTabbedPane();
GridBagConstraints gbc1 = new GridBagConstraints();
gbc1.gridx = 0;
gbc1.gridy = 0;
gbc1.fill = GridBagConstraints.BOTH;
gbc1.anchor = GridBagConstraints.CENTER;
gbc1.weightx = 1.0;
gbc1.weighty = 1.0;
this.add(tabbedPane, gbc1);
//-------------------------------------------------------------------
// configPanel
// The configPanel holds the stuff for addressing and configuration.
configPanel = new VSDConfigPanel(decoder_id, this);
tabbedPane.addTab("Config", configPanel);
//-------------------------------------------------------------------
// soundsPanel
// The optionPanel holds controls for selecting sound options.
optionPanel = new VSDOptionPanel(decoder_id, this);
tabbedPane.addTab("Options", optionPanel);
//-------------------------------------------------------------------
// soundsPanel
// The soundsPanel holds buttons for specific sounds.
soundsPanel = new VSDSoundsPanel(decoder_id, this);
tabbedPane.addTab("Sounds", soundsPanel);
//-------------------------------------------------------------------
// volumePanel
// The volumePanel holds the master volume and mute controls.
volumePanel = new JPanel();
volumePanel.setLayout(new BorderLayout(10, 0));
TitledBorder title = BorderFactory.createTitledBorder(BorderFactory.createLoweredBevelBorder(), "Volume");
title.setTitlePosition(TitledBorder.DEFAULT_POSITION);
volumePanel.setBorder(title);
JSlider volume = new JSlider(0, 100);
volume.setMinorTickSpacing(10);
volume.setPaintTicks(true);
volume.setValue(80);
volume.setPreferredSize(new Dimension(200, 20));
volume.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
volumeChange(e);
}
});
volumePanel.add(volume, BorderLayout.LINE_START);
JToggleButton mute_button = new JToggleButton("Mute");
mute_button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
muteButtonPressed(e);
}
});
volumePanel.add(mute_button, BorderLayout.LINE_END);
GridBagConstraints gbc2 = new GridBagConstraints();
gbc2.gridx = 0;
gbc2.gridy = 1;
gbc2.fill = GridBagConstraints.BOTH;
gbc2.anchor = GridBagConstraints.CENTER;
gbc2.weightx = 1.0;
gbc2.weighty = 0.1;
this.add(volumePanel, gbc2);
//-------------------------------------------------------------------
// statusBar
// The statusBar shows decoder status.
statusBar = new jmri.util.swing.StatusBar();
statusBar.setMessage("Status: No decoder assigned");
GridBagConstraints gbc3 = new GridBagConstraints();
gbc3.gridx = 0;
gbc3.gridy = 2;
gbc3.fill = GridBagConstraints.BOTH;
gbc3.anchor = GridBagConstraints.PAGE_END;
gbc3.weightx = 1.0;
gbc3.weighty = 0.1;
this.add(statusBar, gbc3);
//-------------------------------------------------------------------
// Pack and set visible
parent.pack();
parent.setVisible(true);
}
use of javax.swing.JToggleButton in project JMRI by JMRI.
the class VSDecoderPane method muteButtonPressed.
// PROPERTY CHANGE EVENT FUNCTIONS
/**
* Handle a mute button press event
*/
// NOTE: should this be public???
public void muteButtonPressed(ActionEvent e) {
JToggleButton b = (JToggleButton) e.getSource();
log.debug("Mute button pressed. value = " + b.isSelected());
firePropertyChange(PropertyChangeID.MUTE, !b.isSelected(), b.isSelected());
// do something.
}
use of javax.swing.JToggleButton in project JMRI by JMRI.
the class IconAdder method checkIconSizes.
void checkIconSizes() {
if (!_addButton.isEnabled()) {
return;
}
Iterator<JToggleButton> iter = _iconMap.values().iterator();
int lastWidth = 0;
int lastHeight = 0;
boolean first = true;
while (iter.hasNext()) {
JToggleButton but = iter.next();
if (first) {
lastWidth = but.getIcon().getIconWidth();
lastHeight = but.getIcon().getIconHeight();
first = false;
continue;
}
int nextWidth = but.getIcon().getIconWidth();
int nextHeight = but.getIcon().getIconHeight();
if ((Math.abs(lastWidth - nextWidth) > 3 || Math.abs(lastHeight - nextHeight) > 3)) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("IconSizeDiff"), Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE);
return;
}
lastWidth = nextWidth;
lastHeight = nextHeight;
}
if (log.isDebugEnabled()) {
log.debug("Size: width= " + lastWidth + ", height= " + lastHeight);
}
}
use of javax.swing.JToggleButton in project JMRI by JMRI.
the class IconAdder method setIcon.
/**
* @param order -the index to Sensor's name and the inverse order that icons
* are drawn in doIconPanel()
* @param label -the Sensor's name displayed in the icon panel and the key
* to the icon button in _iconMap
* @param icon -the icon displayed in the icon button
*/
protected void setIcon(int order, String label, NamedIcon icon) {
// make a button to change that icon
if (log.isDebugEnabled()) {
log.debug("setIcon at order= " + order + ", key= " + label);
}
JToggleButton button = new IconButton(label, icon);
if (icon == null || icon.getIconWidth() < 1 || icon.getIconHeight() < 1) {
button.setText(Bundle.getMessage("invisibleIcon"));
button.setForeground(Color.lightGray);
} else {
icon.reduceTo(CatalogPanel.ICON_WIDTH, CatalogPanel.ICON_HEIGHT, CatalogPanel.ICON_SCALE);
button.setToolTipText(icon.getName());
}
if (_allowDeletes) {
String fileName = "resources/icons/misc/X-red.gif";
button.setSelectedIcon(new jmri.jmrit.catalog.NamedIcon(fileName, fileName));
}
if (icon != null) {
icon.reduceTo(CatalogPanel.ICON_WIDTH, CatalogPanel.ICON_HEIGHT, CatalogPanel.ICON_SCALE);
}
_iconMap.put(label, button);
// calls may not be in ascending order, so pad array
if (order > _order.size()) {
for (int i = _order.size(); i < order; i++) {
_order.add(i, "placeHolder");
}
} else {
if (order < _order.size()) {
_order.remove(order);
}
}
_order.add(order, label);
}
use of javax.swing.JToggleButton in project JMRI by JMRI.
the class EditCircuitFrame method makeContentPanel.
private void makeContentPanel() {
JPanel contentPane = new JPanel();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent e) {
closingEvent();
}
});
contentPane.add(Box.createVerticalStrut(STRUT_SIZE));
JPanel p = new JPanel();
p.add(new JLabel(Bundle.getMessage("AddRemoveIcons")));
contentPane.add(p);
contentPane.add(Box.createVerticalStrut(STRUT_SIZE));
JPanel panel = new JPanel();
// panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(CircuitBuilder.makeTextBoxPanel(false, _blockState, "blockState", false, null));
_blockState.setPreferredSize(new Dimension(150, _blockState.getPreferredSize().height));
contentPane.add(panel);
panel = new JPanel();
_blockName.setText(_block.getDisplayName());
panel.add(CircuitBuilder.makeTextBoxPanel(false, _blockName, "blockName", true, "TooltipBlockName"));
_blockName.setPreferredSize(new Dimension(300, _blockName.getPreferredSize().height));
contentPane.add(panel);
contentPane.add(MakeButtonPanel());
contentPane.add(Box.createVerticalStrut(STRUT_SIZE));
p = new JPanel();
p.add(new JLabel(Bundle.getMessage("numTrackElements")));
contentPane.add(p);
panel = new JPanel();
// panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
panel.add(Box.createHorizontalGlue());
panel.add(CircuitBuilder.makeTextBoxPanel(false, _numTrackSeg, "Segments", false, null));
_numTrackSeg.setPreferredSize(new Dimension(20, _numTrackSeg.getPreferredSize().height));
panel.add(Box.createHorizontalStrut(STRUT_SIZE));
panel.add(CircuitBuilder.makeTextBoxPanel(false, _numTurnouts, "Turnouts", false, null));
_numTurnouts.setPreferredSize(new Dimension(20, _numTurnouts.getPreferredSize().height));
panel.add(Box.createHorizontalStrut(STRUT_SIZE));
contentPane.add(panel);
contentPane.add(Box.createVerticalStrut(STRUT_SIZE));
panel = new JPanel();
// panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
_detectorSensorName.setPreferredSize(new Dimension(300, _detectorSensorName.getPreferredSize().height));
panel.add(CircuitBuilder.makeTextBoxPanel(false, _detectorSensorName, "DetectionSensor", true, "detectorSensorName"));
_detectorSensorName.setToolTipText(Bundle.getMessage("detectorSensorName"));
contentPane.add(panel);
panel = new JPanel();
// panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
_errorSensorName.setPreferredSize(new Dimension(300, _errorSensorName.getPreferredSize().height));
panel.add(CircuitBuilder.makeTextBoxPanel(false, _errorSensorName, "ErrorSensor", true, "detectorErrorName"));
_errorSensorName.setToolTipText(Bundle.getMessage("detectorErrorName"));
contentPane.add(panel);
contentPane.add(MakePickListPanel());
contentPane.add(Box.createVerticalStrut(STRUT_SIZE));
JPanel pp = new JPanel();
// pp.setLayout(new BoxLayout(pp, BoxLayout.X_AXIS));
_length.setText(Float.toString(_block.getLengthIn()));
pp.add(CircuitBuilder.makeTextBoxPanel(false, _length, "Length", true, "TooltipBlockLength"));
_length.setPreferredSize(new Dimension(100, _length.getPreferredSize().height));
_units = new JToggleButton("foo", !_block.isMetric());
_units.setToolTipText(Bundle.getMessage("TooltipPathUnitButton"));
_units.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
changeUnits();
}
});
pp.add(_units);
contentPane.add(pp);
contentPane.add(Box.createVerticalStrut(STRUT_SIZE));
contentPane.add(MakeDoneButtonPanel());
JPanel border = new JPanel();
border.setLayout(new java.awt.BorderLayout(20, 20));
border.add(contentPane);
setContentPane(border);
pack();
if (_firstInstance) {
setLocationRelativeTo(_parent._editor);
_firstInstance = false;
} else {
setLocation(_loc);
setSize(_dim);
}
setVisible(true);
changeUnits();
}
Aggregations