Search in sources :

Example 41 with ItemListener

use of java.awt.event.ItemListener 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 42 with ItemListener

use of java.awt.event.ItemListener in project JMRI by JMRI.

the class AbstractNetworkConnectionConfig method loadDetails.

@Override
public void loadDetails(final JPanel details) {
    _details = details;
    setInstance();
    if (!init) {
        //Build up list of options
        //Hashtable<String, AbstractPortController.Option> adapterOptions = ((AbstractPortController)adapter).getOptionList();
        String[] optionsAvailable = adapter.getOptions();
        options = new Hashtable<String, Option>();
        for (String i : optionsAvailable) {
            JComboBox<String> opt = new JComboBox<String>(adapter.getOptionChoices(i));
            opt.setSelectedItem(adapter.getOptionState(i));
            // check that it worked
            if (!adapter.getOptionState(i).equals(opt.getSelectedItem())) {
                // no, set 1st option choice
                opt.setSelectedIndex(0);
                // log before setting new value to show old value
                log.warn("Loading found invalid value for option {}, found \"{}\", setting to \"{}\"", i, adapter.getOptionState(i), opt.getSelectedItem());
                adapter.setOptionState(i, (String) opt.getSelectedItem());
            }
            options.put(i, new Option(adapter.getOptionDisplayName(i), opt, adapter.isOptionAdvanced(i)));
        }
    }
    if (hostNameField.getActionListeners().length > 0) {
        hostNameField.removeActionListener(hostNameField.getActionListeners()[0]);
    }
    if (adapter.getSystemConnectionMemo() != null) {
        systemPrefixField.setText(adapter.getSystemConnectionMemo().getSystemPrefix());
        connectionNameField.setText(adapter.getSystemConnectionMemo().getUserName());
        NUMOPTIONS = NUMOPTIONS + 2;
    }
    NUMOPTIONS = NUMOPTIONS + options.size();
    hostNameField.setText(adapter.getHostName());
    hostNameFieldLabel = new JLabel(rb.getString("HostFieldLabel"));
    hostNameField.setToolTipText(rb.getString("HostFieldToolTip"));
    if (adapter.getHostName() == null || adapter.getHostName().equals("")) {
        hostNameField.setText(p.getComboBoxLastSelection(adapter.getClass().getName() + ".hostname"));
        adapter.setHostName(hostNameField.getText());
    }
    portField.setToolTipText(rb.getString("PortFieldToolTip"));
    portField.setEnabled(true);
    portField.setText("" + adapter.getPort());
    portFieldLabel = new JLabel(rb.getString("PortFieldLabel"));
    adNameField.setToolTipText(rb.getString("AdNameFieldToolTip"));
    adNameField.setEnabled(false);
    adNameField.setText("" + adapter.getAdvertisementName());
    adNameFieldLabel = new JLabel(rb.getString("AdNameFieldLabel"));
    adNameFieldLabel.setEnabled(false);
    serviceTypeField.setToolTipText(rb.getString("ServiceTypeFieldToolTip"));
    serviceTypeField.setEnabled(false);
    serviceTypeField.setText("" + adapter.getServiceType());
    serviceTypeFieldLabel = new JLabel(rb.getString("ServiceTypeFieldLabel"));
    serviceTypeFieldLabel.setEnabled(false);
    showAutoConfig.setFont(showAutoConfig.getFont().deriveFont(9f));
    showAutoConfig.setForeground(Color.blue);
    showAutoConfig.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            setAutoNetworkConfig();
        }
    });
    showAutoConfig.setSelected(adapter.getMdnsConfigure());
    setAutoNetworkConfig();
    showAdvanced.setFont(showAdvanced.getFont().deriveFont(9f));
    showAdvanced.setForeground(Color.blue);
    showAdvanced.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            showAdvancedItems();
        }
    });
    showAdvancedItems();
    // need to reload action listeners
    init = false;
    checkInitDone();
}
Also used : ItemEvent(java.awt.event.ItemEvent) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) ItemListener(java.awt.event.ItemListener)

Example 43 with ItemListener

use of java.awt.event.ItemListener in project JMRI by JMRI.

the class AbstractSimulatorConnectionConfig method loadDetails.

@Override
public void loadDetails(final JPanel details) {
    _details = details;
    setInstance();
    if (!init) {
        String[] optionsAvailable = adapter.getOptions();
        options = new Hashtable<String, Option>();
        for (String i : optionsAvailable) {
            JComboBox<String> opt = new JComboBox<String>(adapter.getOptionChoices(i));
            opt.setSelectedItem(adapter.getOptionState(i));
            // check that it worked
            if (!adapter.getOptionState(i).equals(opt.getSelectedItem())) {
                // no, set 1st option choice
                opt.setSelectedIndex(0);
                // log before setting new value to show old value
                log.warn("Loading found invalid value for option {}, found \"{}\", setting to \"{}\"", i, adapter.getOptionState(i), opt.getSelectedItem());
                adapter.setOptionState(i, (String) opt.getSelectedItem());
            }
            options.put(i, new Option(adapter.getOptionDisplayName(i), opt, adapter.isOptionAdvanced(i)));
        }
    }
    if (adapter.getSystemConnectionMemo() != null) {
        systemPrefixField.setText(adapter.getSystemConnectionMemo().getSystemPrefix());
        connectionNameField.setText(adapter.getSystemConnectionMemo().getUserName());
    }
    NUMOPTIONS = NUMOPTIONS + options.size();
    showAdvanced.setFont(showAdvanced.getFont().deriveFont(9f));
    showAdvanced.setForeground(Color.blue);
    showAdvanced.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            showAdvancedItems();
        }
    });
    showAdvancedItems();
    // need to reload action listeners
    init = false;
    checkInitDone();
}
Also used : ItemEvent(java.awt.event.ItemEvent) JComboBox(javax.swing.JComboBox) ItemListener(java.awt.event.ItemListener)

Example 44 with ItemListener

use of java.awt.event.ItemListener in project JMRI by JMRI.

the class AbstractStreamConnectionConfig method loadDetails.

@Override
public void loadDetails(final JPanel details) {
    _details = details;
    setInstance();
    if (!init) {
        String[] optionsAvailable = adapter.getOptions();
        options = new Hashtable<String, Option>();
        for (String i : optionsAvailable) {
            JComboBox<String> opt = new JComboBox<String>(adapter.getOptionChoices(i));
            opt.setSelectedItem(adapter.getOptionState(i));
            // check that it worked
            if (!adapter.getOptionState(i).equals(opt.getSelectedItem())) {
                // no, set 1st option choice
                opt.setSelectedIndex(0);
                // log before setting new value to show old value
                log.warn("Loading found invalid value for option {}, found \"{}\", setting to \"{}\"", i, adapter.getOptionState(i), opt.getSelectedItem());
                adapter.setOptionState(i, (String) opt.getSelectedItem());
            }
            options.put(i, new Option(adapter.getOptionDisplayName(i), opt, adapter.isOptionAdvanced(i)));
        }
    }
    if (adapter.getSystemConnectionMemo() != null) {
        systemPrefixField.setText(adapter.getSystemConnectionMemo().getSystemPrefix());
        connectionNameField.setText(adapter.getSystemConnectionMemo().getUserName());
    }
    NUMOPTIONS = NUMOPTIONS + options.size();
    showAdvanced.setFont(showAdvanced.getFont().deriveFont(9f));
    showAdvanced.setForeground(Color.blue);
    showAdvanced.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            showAdvancedItems();
        }
    });
    showAdvancedItems();
    // need to reload action listeners
    init = false;
    checkInitDone();
}
Also used : ItemEvent(java.awt.event.ItemEvent) JComboBox(javax.swing.JComboBox) ItemListener(java.awt.event.ItemListener)

Example 45 with ItemListener

use of java.awt.event.ItemListener in project JMRI by JMRI.

the class LogixTableAction method setMenuBar.

/**
     * Insert 2 table specific menus.
     * <p>
     * Accounts for the Window and Help menus, which are already added to the menu bar
     * as part of the creation of the JFrame, by adding the new menus 2 places earlier
     * unless the table is part of the ListedTableFrame, which adds the Help menu later on.
     * @param f the JFrame of this table
     */
@Override
public void setMenuBar(BeanTableFrame f) {
    loadSelectionMode();
    JMenu menu = new JMenu(Bundle.getMessage("MenuOptions"));
    menu.setMnemonic(KeyEvent.VK_O);
    javax.swing.JMenuBar menuBar = f.getJMenuBar();
    // count the number of menus to insert the TableMenus before 'Window' and 'Help'
    int pos = menuBar.getMenuCount() - 1;
    int offset = 1;
    log.debug("setMenuBar number of menu items = " + pos);
    for (int i = 0; i <= pos; i++) {
        if (menuBar.getComponent(i) instanceof JMenu) {
            if (((JMenu) menuBar.getComponent(i)).getText().equals(Bundle.getMessage("MenuHelp"))) {
                // correct for use as part of ListedTableAction where the Help Menu is not yet present
                offset = -1;
            }
        }
    }
    ButtonGroup enableButtonGroup = new ButtonGroup();
    JRadioButtonMenuItem r = new JRadioButtonMenuItem(rbx.getString("EnableAll"));
    r.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            enableAll(true);
        }
    });
    enableButtonGroup.add(r);
    r.setSelected(true);
    menu.add(r);
    r = new JRadioButtonMenuItem(rbx.getString("DisableAll"));
    r.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            enableAll(false);
        }
    });
    enableButtonGroup.add(r);
    menu.add(r);
    menu.addSeparator();
    ButtonGroup modeButtonGroup = new ButtonGroup();
    r = new JRadioButtonMenuItem(rbx.getString("UseMultiPick"));
    r.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            setSelectionMode(SelectionMode.USEMULTI);
        }
    });
    modeButtonGroup.add(r);
    menu.add(r);
    r.setSelected(_selectionMode == SelectionMode.USEMULTI);
    r = new JRadioButtonMenuItem(rbx.getString("UseSinglePick"));
    r.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            setSelectionMode(SelectionMode.USESINGLE);
        }
    });
    modeButtonGroup.add(r);
    menu.add(r);
    r.setSelected(_selectionMode == SelectionMode.USESINGLE);
    r = new JRadioButtonMenuItem(rbx.getString("UseComboNameBoxes"));
    r.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            setSelectionMode(SelectionMode.USECOMBO);
        }
    });
    modeButtonGroup.add(r);
    menu.add(r);
    r.setSelected(_selectionMode == SelectionMode.USECOMBO);
    menuBar.add(menu, pos + offset);
    menu = new JMenu(Bundle.getMessage("MenuTools"));
    menu.setMnemonic(KeyEvent.VK_T);
    JMenuItem item = new JMenuItem(rbx.getString("OpenPickListTables"));
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            OpenPickListTable();
        }
    });
    menu.add(item);
    item = new JMenuItem(rbx.getString("FindOrphans"));
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            findOrphansPressed(e);
        }
    });
    menu.add(item);
    item = new JMenuItem(rbx.getString("EmptyConditionals"));
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            findEmptyPressed(e);
        }
    });
    menu.add(item);
    item = new JMenuItem(rbx.getString("CrossReference"));
    item.addActionListener(new ActionListener() {

        BeanTableFrame parent;

        @Override
        public void actionPerformed(ActionEvent e) {
            new RefDialog(parent);
        }

        ActionListener init(BeanTableFrame f) {
            parent = f;
            return this;
        }
    }.init(f));
    menu.add(item);
    item = new JMenuItem(rbx.getString("DisplayWhereUsed"));
    item.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            makeWhereUsedWindow();
        }
    });
    menu.add(item);
    // add this menu to the right of the previous
    menuBar.add(menu, pos + offset + 1);
}
Also used : ItemEvent(java.awt.event.ItemEvent) ActionEvent(java.awt.event.ActionEvent) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) ItemListener(java.awt.event.ItemListener) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Aggregations

ItemListener (java.awt.event.ItemListener)331 ItemEvent (java.awt.event.ItemEvent)314 ActionEvent (java.awt.event.ActionEvent)111 ActionListener (java.awt.event.ActionListener)108 JPanel (javax.swing.JPanel)93 JLabel (javax.swing.JLabel)81 JCheckBox (javax.swing.JCheckBox)65 JComboBox (javax.swing.JComboBox)64 JButton (javax.swing.JButton)51 Dimension (java.awt.Dimension)50 BorderLayout (java.awt.BorderLayout)47 JTextField (javax.swing.JTextField)46 ButtonGroup (javax.swing.ButtonGroup)34 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)33 GridBagConstraints (java.awt.GridBagConstraints)29 JMenu (javax.swing.JMenu)29 ChangeEvent (javax.swing.event.ChangeEvent)29 GridBagLayout (java.awt.GridBagLayout)28 JMenuItem (javax.swing.JMenuItem)28 ChangeListener (javax.swing.event.ChangeListener)28