Search in sources :

Example 21 with JToggleButton

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;
}
Also used : ImageIcon(javax.swing.ImageIcon) ItemEvent(java.awt.event.ItemEvent) ActionEvent(java.awt.event.ActionEvent) PopupMenuListener(javax.swing.event.PopupMenuListener) JComponent(javax.swing.JComponent) JToolBar(javax.swing.JToolBar) PopupMenuEvent(javax.swing.event.PopupMenuEvent) GridLayout(java.awt.GridLayout) JToggleButton(javax.swing.JToggleButton) ActionListener(java.awt.event.ActionListener) TreePath(javax.swing.tree.TreePath) ItemListener(java.awt.event.ItemListener)

Example 22 with JToggleButton

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;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) BoxLayout(javax.swing.BoxLayout) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JLabel(javax.swing.JLabel) ListSelectionListener(javax.swing.event.ListSelectionListener) JToggleButton(javax.swing.JToggleButton) ActionListener(java.awt.event.ActionListener)

Example 23 with JToggleButton

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));
}
Also used : GridLayout(java.awt.GridLayout) ChangeEvent(javax.swing.event.ChangeEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) JToggleButton(javax.swing.JToggleButton) ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JSlider(javax.swing.JSlider) ChangeListener(javax.swing.event.ChangeListener) Dimension(java.awt.Dimension)

Example 24 with JToggleButton

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;
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) JToggleButton(javax.swing.JToggleButton) ActionEvent(java.awt.event.ActionEvent) JLabel(javax.swing.JLabel)

Example 25 with JToggleButton

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());
         }
         */
}
Also used : JToggleButton(javax.swing.JToggleButton)

Aggregations

JToggleButton (javax.swing.JToggleButton)51 ActionEvent (java.awt.event.ActionEvent)19 ActionListener (java.awt.event.ActionListener)19 JPanel (javax.swing.JPanel)17 JLabel (javax.swing.JLabel)16 ImageIcon (javax.swing.ImageIcon)14 JButton (javax.swing.JButton)12 Dimension (java.awt.Dimension)8 JScrollPane (javax.swing.JScrollPane)8 ChangeEvent (javax.swing.event.ChangeEvent)8 ChangeListener (javax.swing.event.ChangeListener)8 BoxLayout (javax.swing.BoxLayout)7 JCheckBox (javax.swing.JCheckBox)6 JSlider (javax.swing.JSlider)6 GridBagLayout (java.awt.GridBagLayout)5 GridLayout (java.awt.GridLayout)5 JTabbedPane (javax.swing.JTabbedPane)5 JToolBar (javax.swing.JToolBar)5 BorderLayout (java.awt.BorderLayout)4 Component (java.awt.Component)4