Search in sources :

Example 46 with ItemEvent

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

the class LnTcpPreferencesPanel method initComponents.

private void initComponents() {
    bindingGroup = new BindingGroup();
    port = new JSpinner();
    portLabel = new JLabel();
    startup = new JCheckBox();
    port.setModel(new SpinnerNumberModel(1234, 1, 65535, 1));
    port.setEditor(new JSpinner.NumberEditor(port, "#"));
    // NOI18N
    port.setToolTipText(Bundle.getMessage("ToolTipPort"));
    Binding binding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE, preferences, ELProperty.create("${port}"), port, BeanProperty.create("value"));
    bindingGroup.addBinding(binding);
    // NOI18N
    portLabel.setText(Bundle.getMessage("LabelPort"));
    // NOI18N
    portLabel.setToolTipText(Bundle.getMessage("ToolTipPort"));
    startup.setSelected(this.isStartupAction());
    // NOI18N
    startup.setText(Bundle.getMessage("LabelStartup"));
    this.startupItemListener = (ItemEvent e) -> {
        this.startup.removeItemListener(this.startupItemListener);
        StartupActionsManager manager = InstanceManager.getDefault(StartupActionsManager.class);
        if (this.startup.isSelected()) {
            PerformActionModel model = new PerformActionModel();
            model.setClassName(LnTcpServerAction.class.getName());
            if (this.startupActionPosition == -1 || this.startupActionPosition >= manager.getActions().length) {
                manager.addAction(model);
            } else {
                manager.setActions(this.startupActionPosition, model);
            }
        } else {
            manager.getActions(PerformActionModel.class).stream().filter((model) -> (LnTcpServerAction.class.getName().equals(model.getClassName()))).forEach((model) -> {
                this.startupActionPosition = Arrays.asList(manager.getActions()).indexOf(model);
                manager.removeAction(model);
            });
        }
        this.startup.addItemListener(this.startupItemListener);
    };
    this.startup.addItemListener(this.startupItemListener);
    GroupLayout layout = new GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(port, GroupLayout.PREFERRED_SIZE, 75, GroupLayout.PREFERRED_SIZE).addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(portLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addComponent(startup, GroupLayout.DEFAULT_SIZE, 388, Short.MAX_VALUE)).addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE).addComponent(port, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE).addComponent(portLabel)).addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(startup).addContainerGap(198, Short.MAX_VALUE)));
    bindingGroup.bind();
}
Also used : AutoBinding(org.jdesktop.beansbinding.AutoBinding) Binding(org.jdesktop.beansbinding.Binding) PerformActionModel(apps.PerformActionModel) JComponent(javax.swing.JComponent) ItemEvent(java.awt.event.ItemEvent) InstanceManager(jmri.InstanceManager) BeanProperty(org.jdesktop.beansbinding.BeanProperty) Arrays(java.util.Arrays) JSpinner(javax.swing.JSpinner) SpinnerNumberModel(javax.swing.SpinnerNumberModel) Bindings(org.jdesktop.beansbinding.Bindings) ItemListener(java.awt.event.ItemListener) StartupActionsManager(apps.StartupActionsManager) AutoBinding(org.jdesktop.beansbinding.AutoBinding) LayoutStyle(javax.swing.LayoutStyle) PerformActionModel(apps.PerformActionModel) BindingGroup(org.jdesktop.beansbinding.BindingGroup) JLabel(javax.swing.JLabel) GroupLayout(javax.swing.GroupLayout) JCheckBox(javax.swing.JCheckBox) ELProperty(org.jdesktop.beansbinding.ELProperty) Binding(org.jdesktop.beansbinding.Binding) JPanel(javax.swing.JPanel) PreferencesPanel(jmri.swing.PreferencesPanel) ItemEvent(java.awt.event.ItemEvent) JLabel(javax.swing.JLabel) StartupActionsManager(apps.StartupActionsManager) JCheckBox(javax.swing.JCheckBox) SpinnerNumberModel(javax.swing.SpinnerNumberModel) BindingGroup(org.jdesktop.beansbinding.BindingGroup) GroupLayout(javax.swing.GroupLayout) JSpinner(javax.swing.JSpinner)

Example 47 with ItemEvent

use of java.awt.event.ItemEvent 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)

Example 48 with ItemEvent

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

the class LogixTableAction method makeAddLogixFrame.

/**
     * Create or copy Logix frame.
     *
     * @param titleId property key to fetch as title of the frame
     * @param messageId part 1 of property key to fetch as user instruction on pane,
     *                  either 1 or 2 is added to form the whole key
     * @return the button JPanel
     */
JPanel makeAddLogixFrame(String titleId, String messageId) {
    addLogixFrame = new JmriJFrame(rbx.getString(titleId));
    addLogixFrame.addHelpMenu("package.jmri.jmrit.beantable.LogixAddEdit", true);
    addLogixFrame.setLocation(50, 30);
    Container contentPane = addLogixFrame.getContentPane();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
    JPanel p;
    p = new JPanel();
    p.setLayout(new FlowLayout());
    p.setLayout(new java.awt.GridBagLayout());
    java.awt.GridBagConstraints c = new java.awt.GridBagConstraints();
    c.gridwidth = 1;
    c.gridheight = 1;
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = java.awt.GridBagConstraints.EAST;
    p.add(_sysNameLabel, c);
    c.gridy = 1;
    p.add(_userNameLabel, c);
    c.gridx = 1;
    c.gridy = 0;
    c.anchor = java.awt.GridBagConstraints.WEST;
    c.weightx = 1.0;
    // text field will expand
    c.fill = java.awt.GridBagConstraints.HORIZONTAL;
    p.add(_systemName, c);
    c.gridy = 1;
    p.add(_addUserName, c);
    c.gridx = 2;
    c.gridy = 1;
    c.anchor = java.awt.GridBagConstraints.WEST;
    c.weightx = 1.0;
    // text field will expand
    c.fill = java.awt.GridBagConstraints.HORIZONTAL;
    c.gridy = 0;
    p.add(_autoSystemName, c);
    _addUserName.setToolTipText(rbx.getString("LogixUserNameHint"));
    _systemName.setToolTipText(rbx.getString("LogixSystemNameHint"));
    contentPane.add(p);
    // set up message
    JPanel panel3 = new JPanel();
    panel3.setLayout(new BoxLayout(panel3, BoxLayout.Y_AXIS));
    JPanel panel31 = new JPanel();
    panel31.setLayout(new FlowLayout());
    JLabel message1 = new JLabel(rbx.getString(messageId + "1"));
    panel31.add(message1);
    JPanel panel32 = new JPanel();
    JLabel message2 = new JLabel(rbx.getString(messageId + "2"));
    panel32.add(message2);
    panel3.add(panel31);
    panel3.add(panel32);
    contentPane.add(panel3);
    // set up create and cancel buttons
    JPanel panel5 = new JPanel();
    panel5.setLayout(new FlowLayout());
    // Cancel
    JButton cancel = new JButton(Bundle.getMessage("ButtonCancel"));
    panel5.add(cancel);
    cancel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            cancelAddPressed(e);
        }
    });
    cancel.setToolTipText(rbx.getString("CancelLogixButtonHint"));
    addLogixFrame.addWindowListener(new java.awt.event.WindowAdapter() {

        @Override
        public void windowClosing(java.awt.event.WindowEvent e) {
            cancelAddPressed(null);
        }
    });
    contentPane.add(panel5);
    _autoSystemName.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            autoSystemName();
        }
    });
    return panel5;
}
Also used : JPanel(javax.swing.JPanel) ItemEvent(java.awt.event.ItemEvent) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Container(java.awt.Container) ActionListener(java.awt.event.ActionListener) JmriJFrame(jmri.util.JmriJFrame) ItemListener(java.awt.event.ItemListener)

Example 49 with ItemEvent

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

the class AddSignalMastPanel method loadMastDefinitions.

void loadMastDefinitions() {
    // need to remove itemListener before addItem() or item event will occur
    if (mastBox.getItemListeners().length > 0) {
        // should this be a while loop?
        mastBox.removeItemListener(mastBox.getItemListeners()[0]);
    }
    mastBox.removeAllItems();
    try {
        mastNames = new ArrayList<File>();
        SignalSystemManager man = InstanceManager.getDefault(jmri.SignalSystemManager.class);
        // get the signals system name from the user name in combo box
        String u = (String) sigSysBox.getSelectedItem();
        sigsysname = man.getByUserName(u).getSystemName();
        map = new HashMap<String, Integer>();
        // do file IO to get all the appearances
        // gather all the appearance files
        //Look for the default system defined ones first
        URL path = FileUtil.findURL("xml/signals/" + sigsysname, FileUtil.Location.INSTALLED);
        if (path != null) {
            File[] apps = new File(path.toURI()).listFiles();
            for (File app : apps) {
                if (app.getName().startsWith("appearance") && app.getName().endsWith(".xml")) {
                    log.debug("   found file: " + app.getName());
                    // load it and get name
                    mastNames.add(app);
                    jmri.jmrit.XmlFile xf = new jmri.jmrit.XmlFile() {
                    };
                    Element root = xf.rootFromFile(app);
                    String name = root.getChild("name").getText();
                    mastBox.addItem(name);
                    map.put(name, root.getChild("appearances").getChild("appearance").getChildren("show").size());
                }
            }
        }
    } catch (org.jdom2.JDOMException e) {
        mastBox.addItem("Failed to create definition, did you select a system?");
        log.warn("in loadMastDefinitions", e);
    } catch (java.io.IOException | URISyntaxException e) {
        mastBox.addItem("Failed to read definition, did you select a system?");
        log.warn("in loadMastDefinitions", e);
    }
    try {
        URL path = FileUtil.findURL("signals/" + sigsysname, FileUtil.Location.USER, "xml", "resources");
        if (path != null) {
            File[] apps = new File(path.toURI()).listFiles();
            for (File app : apps) {
                if (app.getName().startsWith("appearance") && app.getName().endsWith(".xml")) {
                    log.debug("   found file: " + app.getName());
                    // If the mast file name already exists no point in re-adding it
                    if (!mastNames.contains(app)) {
                        mastNames.add(app);
                        jmri.jmrit.XmlFile xf = new jmri.jmrit.XmlFile() {
                        };
                        Element root = xf.rootFromFile(app);
                        String name = root.getChild("name").getText();
                        //if the mast name already exist no point in readding it.
                        if (!map.containsKey(name)) {
                            mastBox.addItem(name);
                            map.put(name, root.getChild("appearances").getChild("appearance").getChildren("show").size());
                        }
                    }
                }
            }
        }
    } catch (org.jdom2.JDOMException | java.io.IOException | URISyntaxException e) {
        log.warn("in loadMastDefinitions", e);
    }
    mastBox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            updateSelectedDriver();
        }
    });
    updateSelectedDriver();
    if (prefs.getComboBoxLastSelection(mastSelectionCombo + ":" + ((String) sigSysBox.getSelectedItem())) != null) {
        mastBox.setSelectedItem(prefs.getComboBoxLastSelection(mastSelectionCombo + ":" + ((String) sigSysBox.getSelectedItem())));
    }
}
Also used : ItemEvent(java.awt.event.ItemEvent) Element(org.jdom2.Element) URISyntaxException(java.net.URISyntaxException) URL(java.net.URL) SignalSystemManager(jmri.SignalSystemManager) ItemListener(java.awt.event.ItemListener) File(java.io.File)

Example 50 with ItemEvent

use of java.awt.event.ItemEvent in project intellij-plugins by JetBrains.

the class CPUSnapshotView method setupUI.

private void setupUI() {
    myHotSpotsTreeTable.setRootVisible(false);
    myTracesTreeTable.setRootVisible(false);
    setColumnWidth(myHotSpotsTreeTable.getColumnModel().getColumn(1), MS_COLUMN_WIDTH);
    setColumnWidth(myHotSpotsTreeTable.getColumnModel().getColumn(2), MS_COLUMN_WIDTH);
    setColumnWidth(myTracesTreeTable.getColumnModel().getColumn(1), MS_COLUMN_WIDTH);
    setColumnWidth(myTracesTreeTable.getColumnModel().getColumn(2), MS_COLUMN_WIDTH);
    scopeLabel.setLabelFor(filterScope.getComboBox());
    invokedFunctionsLabel.setLabelFor(myHotSpotsTreeTable);
    mergedCalleesLabel.setLabelFor(myTracesTreeTable);
    new TreeTableSpeedSearch(myHotSpotsTreeTable).setComparator(new SpeedSearchComparator(false));
    new TreeTableSpeedSearch(myTracesTreeTable).setComparator(new SpeedSearchComparator(false));
    PopupHandler.installPopupHandler(myHotSpotsTreeTable, PROFILER_VIEW_GROUP_ID, ActionPlaces.UNKNOWN);
    PopupHandler.installPopupHandler(myTracesTreeTable, PROFILER_VIEW_GROUP_ID, ActionPlaces.UNKNOWN);
    final ComboBoxModel model = filterScope.getComboBox().getModel();
    if (model instanceof DefaultComboBoxModel) {
        ((DefaultComboBoxModel) model).insertElementAt(new ScopeDescriptor(new AllSearchScope(getProject())), 0);
    }
    myHotSpotsTreeTable.getTree().setCellRenderer(new FrameInfoCellRenderer(projectScope) {

        @Override
        public void customizeCellRenderer(Object value, boolean selected) {
            setPaintFocusBorder(false);
            setScopeIcon(FlexProfilerIcons.CallerArrow);
            setNonScopeIcon(FlexProfilerIcons.CallerLeafArrow);
            super.customizeCellRenderer(value, selected);
        }
    });
    myTracesTreeTable.getTree().setCellRenderer(new FrameInfoCellRenderer(projectScope) {

        @Override
        public void customizeCellRenderer(Object value, boolean selected) {
            setPaintFocusBorder(false);
            setScopeIcon(FlexProfilerIcons.CalleeArrow);
            setNonScopeIcon(FlexProfilerIcons.CalleeLeafArrow);
            super.customizeCellRenderer(value, selected);
        }
    });
    myFilterSystemStuff.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            buildPerformanceSamples(myHotSpotsTreeTable.getSortableTreeTableModel());
            TreeUtil.expand(myHotSpotsTreeTable.getTree(), 1);
        }
    });
    filterScope.getComboBox().addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            myAlarm.cancelAllRequests();
            myAlarm.addRequest(() -> {
                buildPerformanceSamples(myHotSpotsTreeTable.getSortableTreeTableModel());
                TreeUtil.expand(myHotSpotsTreeTable.getTree(), 1);
            }, 100);
        }
    });
}
Also used : TreeTableSpeedSearch(com.intellij.ui.TreeTableSpeedSearch) ScopeDescriptor(com.intellij.ide.util.scopeChooser.ScopeDescriptor) FrameInfoCellRenderer(com.jetbrains.actionscript.profiler.render.FrameInfoCellRenderer) ItemEvent(java.awt.event.ItemEvent) AllSearchScope(com.jetbrains.actionscript.profiler.util.AllSearchScope) ItemListener(java.awt.event.ItemListener) SpeedSearchComparator(com.intellij.ui.SpeedSearchComparator)

Aggregations

ItemEvent (java.awt.event.ItemEvent)339 ItemListener (java.awt.event.ItemListener)313 ActionEvent (java.awt.event.ActionEvent)120 ActionListener (java.awt.event.ActionListener)110 JPanel (javax.swing.JPanel)106 JLabel (javax.swing.JLabel)84 JCheckBox (javax.swing.JCheckBox)72 JComboBox (javax.swing.JComboBox)65 Dimension (java.awt.Dimension)59 JButton (javax.swing.JButton)53 BorderLayout (java.awt.BorderLayout)48 JTextField (javax.swing.JTextField)46 ButtonGroup (javax.swing.ButtonGroup)35 JCheckBoxMenuItem (javax.swing.JCheckBoxMenuItem)33 GridLayout (java.awt.GridLayout)30 ChangeEvent (javax.swing.event.ChangeEvent)30 GridBagConstraints (java.awt.GridBagConstraints)29 JMenu (javax.swing.JMenu)29 ChangeListener (javax.swing.event.ChangeListener)29 GridBagLayout (java.awt.GridBagLayout)28