use of javax.swing.JToggleButton in project JMRI by JMRI.
the class RosterGroupsPanel method getButtons.
private JToolBar getButtons() {
JToolBar controls = new JToolBar();
controls.setLayout(new GridLayout(1, 0, 0, 0));
controls.setFloatable(false);
final JToggleButton addGroupBtn = new JToggleButton(new ImageIcon(FileUtil.findURL("resources/icons/misc/gui3/Add.png")), false);
final JToggleButton actGroupBtn = new JToggleButton(new ImageIcon(FileUtil.findURL("resources/icons/misc/gui3/Action.png")), false);
addGroupBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
new CreateRosterGroupAction("", scrollPane.getTopLevelAncestor()).actionPerformed(e);
addGroupBtn.setSelected(false);
}
});
actGroupBtn.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent ie) {
if (ie.getStateChange() == ItemEvent.SELECTED) {
TreePath g = new TreePath(_model.getPathToRoot(_groups));
if (_tree.getSelectionPath() != null) {
if (_tree.getSelectionPath().getLastPathComponent().toString().equals(Roster.ALLENTRIES)) {
allEntriesMenu.show((JComponent) ie.getSource(), actGroupBtn.getX() - actGroupBtn.getWidth(), actGroupBtn.getY() - allEntriesMenu.getPreferredSize().height);
} else if (g.isDescendant(_tree.getSelectionPath()) && !_tree.getSelectionPath().isDescendant(g)) {
groupsMenu.show((JComponent) ie.getSource(), actGroupBtn.getX() - actGroupBtn.getWidth(), actGroupBtn.getY() - groupsMenu.getPreferredSize().height);
}
}
}
}
});
PopupMenuListener PML = new PopupMenuListener() {
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent pme) {
// do nothing
}
@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent pme) {
actGroupBtn.setSelected(false);
}
@Override
public void popupMenuCanceled(PopupMenuEvent pme) {
actGroupBtn.setSelected(false);
}
};
allEntriesMenu.addPopupMenuListener(PML);
groupsMenu.addPopupMenuListener(PML);
controls.add(addGroupBtn);
controls.add(actGroupBtn);
return controls;
}
use of javax.swing.JToggleButton in project JMRI by JMRI.
the class CombinedLocoSelListPane method layoutDecoderSelection.
/**
* Create the panel used to select the decoder
*/
@Override
protected JPanel layoutDecoderSelection() {
JPanel pane1a = new JPanel();
pane1a.setLayout(new BoxLayout(pane1a, BoxLayout.X_AXIS));
pane1a.add(new JLabel("Decoder installed: "));
// create the list of manufacturers
mMfgList = new JList<>();
updateMfgListContents(null);
mMfgList.clearSelection();
mMfgList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
mMfgListener = new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (!mMfgList.isSelectionEmpty()) {
// manufacturer selected, update decoder list
String vMfg = mMfgList.getSelectedValue();
try {
int vMfgID = Integer.parseInt(DecoderIndexFile.instance().mfgIdFromName(vMfg));
listDecodersFromMfg(vMfgID, vMfg);
} catch (java.lang.NumberFormatException ex) {
// mfg number lookup failed for some reason
}
} else {
// no manufacturer selected, do nothing
}
}
};
mMfgList.addListSelectionListener(mMfgListener);
mDecoderList = new JList<String>(DecoderIndexFile.instance().matchingComboBox(null, null, null, null, null, null).getModel());
mDecoderList.clearSelection();
mDecoderList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
mDecoderListener = new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (!mDecoderList.isSelectionEmpty()) {
// decoder selected - reset and disable loco selection
locoBox.setSelectedIndex(0);
go2.setEnabled(true);
go2.setToolTipText("Click to open the programmer");
updateMfgListToSelectedDecoder();
} else {
// decoder not selected - require one
go2.setEnabled(false);
go2.setToolTipText("Select a locomotive or decoder to enable");
}
}
};
mDecoderList.addListSelectionListener(mDecoderListener);
pane1a.add(new JScrollPane(mMfgList));
pane1a.add(new JScrollPane(mDecoderList));
iddecoder = new JToggleButton("Ident");
iddecoder.setToolTipText("Read the decoders mfg and version, then attempt to select its type");
if (jmri.InstanceManager.getNullableDefault(jmri.ProgrammerManager.class) != null && jmri.InstanceManager.getDefault(jmri.ProgrammerManager.class).getGlobalProgrammer() != null && !jmri.InstanceManager.getDefault(jmri.ProgrammerManager.class).getGlobalProgrammer().getCanRead()) {
// can't read, disable the button
iddecoder.setEnabled(false);
iddecoder.setToolTipText("Button disabled because configured command station can't read CVs");
}
iddecoder.addActionListener(new ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
if (log.isDebugEnabled()) {
log.debug("identify decoder pressed");
}
startIdentifyDecoder();
}
});
pane1a.add(iddecoder);
pane1a.setAlignmentX(JLabel.RIGHT_ALIGNMENT);
return pane1a;
}
use of javax.swing.JToggleButton in project JMRI by JMRI.
the class DieselPane method initComponents.
@Override
public void initComponents() {
listenerList = new javax.swing.event.EventListenerList();
this.setLayout(new GridLayout(2, 0));
//Setup the throttle slider.
throttle_slider = new JSlider(JSlider.HORIZONTAL, THROTTLE_MIN, THROTTLE_MAX, THROTTLE_INIT);
throttle_slider.setMajorTickSpacing(1);
throttle_slider.setPaintTicks(true);
throttle_slider.setMinimumSize(new Dimension(400, 0));
throttle_slider.setSnapToTicks(true);
throttle_slider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
throttleChange(e);
}
});
this.add(throttle_slider);
// Setup the start button
start_button = new JToggleButton();
start_button.setText("Engine Start");
start_button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
startButtonChange(e);
}
});
this.add(start_button);
throttle_slider.setVisible(true);
start_button.setVisible(true);
this.setVisible(true);
this.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
}
use of javax.swing.JToggleButton in project JMRI by JMRI.
the class AbstractBoardProgPanel method provideAddressing.
/**
* Creates a JPanel to allow the user to specify a board address and to
* read and write the device. The "read" and "write" buttons have text which
* uses the specified "board type name" from the method parameter.
*
* @param boardTypeName - device type name, to be included in read and write GUI buttons
* @return - a JPanel containing a JTextField and read and write JButtons
*/
protected JPanel provideAddressing(String boardTypeName) {
JPanel pane0 = new JPanel();
pane0.setLayout(new FlowLayout());
pane0.add(new JLabel(Bundle.getMessage("LABEL_UNIT_ADDRESS") + " "));
pane0.add(addrField);
readAllButton = new JToggleButton(Bundle.getMessage("AbstractBoardProgPanel_ReadFrom", boardTypeName));
writeAllButton = new JToggleButton(Bundle.getMessage("AbstractBoardProgPanel_WriteTo", boardTypeName));
// make both buttons a little bit bigger, with identical (preferred) sizes
// (width increased because some computers/displays trim the button text)
java.awt.Dimension d = writeAllButton.getPreferredSize();
int w = d.width;
d = readAllButton.getPreferredSize();
if (d.width > w) {
w = d.width;
}
writeAllButton.setPreferredSize(new java.awt.Dimension((int) (w * 1.1), d.height));
readAllButton.setPreferredSize(new java.awt.Dimension((int) (w * 1.1), d.height));
pane0.add(readAllButton);
pane0.add(writeAllButton);
// install read all, write all button handlers
readAllButton.addActionListener((ActionEvent a) -> {
if (readAllButton.isSelected()) {
readAll();
}
});
writeAllButton.addActionListener((ActionEvent a) -> {
if (writeAllButton.isSelected()) {
writeAll();
}
});
return pane0;
}
use of javax.swing.JToggleButton in project JMRI by JMRI.
the class ToggleSoundEvent method setXml.
@Override
public void setXml(Element el, VSDFile vf) {
// Create the button first... (put this in constructor?)
button = new JToggleButton();
// Handle common stuff
super.setXml(el, vf);
// Get the SoundEvent's button type and create it.
button.setText(el.getAttributeValue("label"));
/*
for (ButtonTrigger bt : button_trigger_list.values()) {
log.debug("Button Trigger: " + bt.getName());
log.debug(" Target: " + bt.getTarget().getName());
log.debug(" Action: " + bt.getTargetAction().toString());
}
MouseListener [] listeners = button.getListeners(MouseListener.class);
for (MouseListener l : listeners) {
log.debug("Listener: " + l.toString());
}
*/
}
Aggregations