Example usage for java.awt.event ItemEvent getStateChange

List of usage examples for java.awt.event ItemEvent getStateChange

Introduction

In this page you can find the example usage for java.awt.event ItemEvent getStateChange.

Prototype

public int getStateChange() 

Source Link

Document

Returns the type of state change (selected or deselected).

Usage

From source file:com.willwinder.ugs.nbp.core.windows.StateTopComponent.java

public StateTopComponent() {
    initComponents();/*from www. ja va  2 s.com*/
    setName(LocalizingService.StateTitle);
    setToolTipText(LocalizingService.StateTooltip);

    backend = CentralLookup.getDefault().lookup(BackendAPI.class);
    backend.addUGSEventListener(this);

    statePollTimer = createTimer();

    setLayout(new MigLayout("wrap 2, fillx"));

    add(new JLabel(Localization.getString("gcode.current-motion")));
    add(motionBox, "growx");
    motionBox.setEnabled(false);

    add(new JLabel(Localization.getString("gcode.setting.units")));
    add(unitBox, "growx");

    add(new JLabel(Localization.getString("gcode.distance-mode")));
    add(distanceModeBox, "growx");

    //add(new JLabel(Localization.getString("gcode.feed-rate-mode")));
    //add(feedModeBox, "growx");

    add(new JLabel(Localization.getString("gcode.work-offset")));
    add(workOffsetBox, "growx");

    add(new JLabel(Localization.getString("gcode.plane")));
    add(planeBox, "growx");

    add(new JLabel(Localization.getString("gcode.setting.feed")));
    add(feedBox, "growx");

    add(new JLabel(Localization.getString("overrides.spindle.short")));
    add(speedBox, "growx");

    ItemListener codeComboListener = (ItemEvent ie) -> {
        // Only interested in the new item, don't fire when programatically setting selection.
        if (loading || ie.getStateChange() == ItemEvent.DESELECTED)
            return;

        String item = ie.getItem().toString();

        System.out.println("item");
        String code = item;
        if (item.contains("(")) {
            code = item.substring(item.lastIndexOf('(') + 1, item.lastIndexOf(')'));
        }

        if (backend.isIdle()) {
            try {
                backend.sendGcodeCommand(code);
            } catch (Exception ex) {
                GUIHelpers.displayErrorDialog(ex.getLocalizedMessage());
            }
        }
    };

    motionBox.addItemListener(codeComboListener);
    unitBox.addItemListener(codeComboListener);
    feedModeBox.addItemListener(codeComboListener);
    distanceModeBox.addItemListener(codeComboListener);
    workOffsetBox.addItemListener(codeComboListener);
    planeBox.addItemListener(codeComboListener);

    feedBox.addActionListener((al) -> executeNumber('F', feedBox));
    speedBox.addActionListener((al) -> executeNumber('S', speedBox));
}

From source file:fxts.stations.trader.ui.dialogs.CalendarComboBoxes.java

/**
 * Fills the days combo box/*from  w w w.j  a v a 2  s  .  c  om*/
 */
private void fillDateComboBox() {
    if (mDateListener == null) {
        mDateListener = new ItemListener() {
            public void itemStateChanged(ItemEvent aEvent) {
                if (aEvent.getStateChange() == ItemEvent.SELECTED) {
                    mCalendarNew.setTime(mCalendar.getTime());
                    mCalendarNew.set(Calendar.DATE, mDateComboBox.getSelectedIndex() + 1);
                    changeDate(mCalendarNew.getTime());
                }
            }
        };
    } else {
        mDateComboBox.removeItemListener(mDateListener);
    }
    int savedSelectedIndex = mDateComboBox.getSelectedIndex();
    int maxDay = mCalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    mDateComboBox.removeAllItems();
    for (int i = 1; i <= maxDay; i++) {
        mDateComboBox.addItem(new Integer(i));
    }
    try {
        mDateComboBox.setSelectedIndex(savedSelectedIndex);
    } catch (Exception e) {
        mDateComboBox.setSelectedIndex(0);
    }
    mDateComboBox.addItemListener(mDateListener);
}

From source file:com.ibm.bluej.commonutil.visualization.PrintableVisualizationViewer.java

protected void setStandardOptions() {
    PluggableRenderer r = (PluggableRenderer) this.getRenderer();
    r.setVertexStringer(new StringVertexStringer());
    r.setEdgeStringer(new StringEdgeStringer());
    r.setEdgeShapeFunction(new SpacedCurve());
    r.setVertexPaintFunction(new SmartVertexPaintFunction(r, callbacks));
    r.setEdgeLabelClosenessFunction(new ConstantEdgeValue(.5));
    r.setEdgePaintFunction(new SmartEdgePaintFunction(r, callbacks));
    r.setEdgeFontFunction(new FontHandler());

    this.setDoubleBuffered(true);
    DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse();
    this.setGraphMouse(graphMouse);
    graphMouse.setMode(ModalGraphMouse.Mode.PICKING);
    this.getPickedState().addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getItem() instanceof LabeledDirectedSparseVertex) {
                LabeledDirectedSparseVertex v = (LabeledDirectedSparseVertex) e.getItem();
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    callbacks.picked((T) v.marked);
                    return;
                }/*from   ww w.ja  v a 2s.c  o  m*/
                if (e.getStateChange() == ItemEvent.DESELECTED) {
                    callbacks.unpicked((T) v.marked);
                    return;
                }
                System.err.println(e.toString());
                System.err.println(e.getItem().toString());
            } else {
                LabeledDirectedSparseEdge edge = (LabeledDirectedSparseEdge) e.getItem();
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    callbacks.picked((T) edge.getFrom(), edge.getLabel(), (T) edge.getTo());
                    return;
                }
                if (e.getStateChange() == ItemEvent.DESELECTED) {
                    callbacks.unpicked((T) edge.getFrom(), edge.getLabel(), (T) edge.getTo());
                    return;
                }
                System.out.println("Edge pick");
                System.out.println(e.getItem().getClass().getName());
                System.out.println(e.getStateChange());
            }
        }
    });
    setToolTipFunction(new DefaultToolTipFunction() {
        public String getToolTipText(Vertex v) {
            return callbacks.getToolTip((T) ((LabeledDirectedSparseVertex) v).marked);
        }
        /*
        public String getToolTipText(Edge edge) {
           edu.uci.ics.jung.utils.Pair accts = edge.getEndpoints();
           Vertex v1 = (Vertex) accts.getFirst();
           Vertex v2 = (Vertex) accts.getSecond();
           return v1 + " -- " + v2;
        }
        */
    });
    Predicate p = new Predicate() {
        public boolean evaluate(Object arg0) {
            if (!(arg0 instanceof LabeledDirectedSparseEdge)) {
                System.err.println("Unexpected: " + arg0);
                return false;
            }
            LabeledDirectedSparseEdge edge = (LabeledDirectedSparseEdge) arg0;
            return callbacks.shouldShowEdge((T) edge.getFrom(), edge.getLabel(), (T) edge.getTo());
        }
    };
    r.setEdgeIncludePredicate(p);
    this.setPickSupport(new ShapePickSupport(4));

    //System.out.println(getPickSupport().getClass().getName());
}

From source file:org.zaproxy.zap.extension.fuzz.httpfuzzer.ui.HttpFuzzResultsContentPanel.java

public HttpFuzzResultsContentPanel() {
    super(new BorderLayout());

    tabbedPane = new JTabbedPane();

    toolbar = new JToolBar();
    toolbar.setFloatable(false);/*from ww w  .  ja va2  s . c  o m*/
    toolbar.setRollover(true);

    messageCountLabel = new JLabel(Constant.messages.getString("fuzz.httpfuzzer.results.toolbar.messagesSent"));
    messageCountValueLabel = new JLabel("0");

    errorCountLabel = new JLabel(Constant.messages.getString("fuzz.httpfuzzer.results.toolbar.errors"));
    errorCountValueLabel = new JLabel("0");

    showErrorsToggleButton = new ZapToggleButton(
            Constant.messages.getString("fuzz.httpfuzzer.results.toolbar.button.showErrors.label"));
    showErrorsToggleButton.setEnabled(false);
    showErrorsToggleButton.setToolTipText(
            Constant.messages.getString("fuzz.httpfuzzer.results.toolbar.button.showErrors.tooltip"));
    showErrorsToggleButton.setSelectedToolTipText(
            Constant.messages.getString("fuzz.httpfuzzer.results.toolbar.button.showErrors.tooltip.selected"));
    showErrorsToggleButton.setDisabledToolTipText(
            Constant.messages.getString("fuzz.httpfuzzer.results.toolbar.button.showErrors.tooltip.disabled"));
    showErrorsToggleButton
            .setIcon(new ImageIcon(HttpFuzzResultsContentPanel.class.getResource("/resource/icon/16/050.png")));
    showErrorsToggleButton.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (ItemEvent.SELECTED == e.getStateChange()) {
                showTabs();
            } else {
                hideErrorsTab();
            }
        }
    });

    toolbar.add(Box.createHorizontalStrut(4));
    toolbar.add(messageCountLabel);
    toolbar.add(Box.createHorizontalStrut(4));
    toolbar.add(messageCountValueLabel);
    toolbar.add(Box.createHorizontalStrut(32));

    toolbar.add(errorCountLabel);
    toolbar.add(Box.createHorizontalStrut(4));
    toolbar.add(errorCountValueLabel);

    toolbar.add(Box.createHorizontalStrut(16));
    toolbar.add(showErrorsToggleButton);

    JButton button = new JButton(Constant.messages.getString("fuzz.httpfuzzer.results.toolbar.button.export"));
    button.setIcon(new ImageIcon(HttpFuzzResultsContentPanel.class.getResource("/resource/icon/16/115.png")));
    button.addActionListener((new AbstractAction() {
        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            WritableFileChooser chooser = new WritableFileChooser(
                    Model.getSingleton().getOptionsParam().getUserDirectory()) {

                private static final long serialVersionUID = -1660943014924270012L;

                @Override
                public void approveSelection() {
                    File file = getSelectedFile();
                    if (file != null) {
                        String filePath = file.getAbsolutePath();
                        if (!filePath.toLowerCase(Locale.ROOT).endsWith(CSV_EXTENSION)) {
                            setSelectedFile(new File(filePath + CSV_EXTENSION));
                        }
                    }

                    super.approveSelection();
                }
            };
            chooser.setSelectedFile(new File(
                    Constant.messages.getString("fuzz.httpfuzzer.results.toolbar.button.export.defaultName")));
            if (chooser
                    .showSaveDialog(View.getSingleton().getMainFrame()) == WritableFileChooser.APPROVE_OPTION) {

                boolean success = true;
                try (CSVPrinter pw = new CSVPrinter(
                        Files.newBufferedWriter(chooser.getSelectedFile().toPath(), StandardCharsets.UTF_8),
                        CSVFormat.DEFAULT)) {
                    pw.printRecord(currentFuzzer.getMessagesModel().getHeaders());
                    int count = currentFuzzer.getMessagesModel().getRowCount();
                    for (int i = 0; i < count; i++) {
                        List<Object> valueOfRow = currentFuzzer.getMessagesModel().getEntry(i)
                                .getValuesOfHeaders();
                        String customStateValue = fuzzResultTable.getCustomStateValue(
                                currentFuzzer.getMessagesModel().getEntry(i).getCustomStates());
                        valueOfRow.add(13, customStateValue);
                        pw.printRecord(valueOfRow);
                    }
                } catch (Exception ex) {
                    success = false;
                    JOptionPane.showMessageDialog(View.getSingleton().getMainFrame(),
                            Constant.messages
                                    .getString("fuzz.httpfuzzer.results.toolbar.button.export.showMessageError")
                                    + "\n" + ex.getLocalizedMessage());
                    logger.error("Export Failed: " + ex);
                }
                // Delay the presentation of success message, to ensure all the data was
                // already flushed.
                if (success) {
                    JOptionPane.showMessageDialog(View.getSingleton().getMainFrame(), Constant.messages
                            .getString("fuzz.httpfuzzer.results.toolbar.button.export.showMessageSuccessful"));
                }
            }
        }
    }));
    toolbar.add(Box.createHorizontalGlue());
    toolbar.add(button);
    mainPanel = new JPanel(new BorderLayout());

    fuzzResultTable = new HttpFuzzerResultsTable(RESULTS_PANEL_NAME, EMPTY_RESULTS_MODEL);
    errorsTable = new HttpFuzzerErrorsTable(ERRORS_PANEL_NAME, EMPTY_ERRORS_MODEL);

    fuzzResultTableScrollPane = new JScrollPane();
    fuzzResultTableScrollPane.setViewportView(fuzzResultTable);

    errorsTableScrollPane = new JScrollPane();
    errorsTableScrollPane.setViewportView(errorsTable);

    mainPanel.add(fuzzResultTableScrollPane);

    add(toolbar, BorderLayout.PAGE_START);
    add(mainPanel, BorderLayout.CENTER);
}

From source file:net.pms.encoders.AviSynthFFmpeg.java

@Override
protected JComponent config(String languageLabel) {
    FormLayout layout = new FormLayout("left:pref, 0:grow", "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu");
    PanelBuilder builder = new PanelBuilder(layout);
    builder.border(Borders.EMPTY);/*from ww w  .  j av  a 2 s  . com*/
    builder.opaque(false);

    CellConstraints cc = new CellConstraints();

    JComponent cmp = builder.addSeparator(Messages.getString(languageLabel), cc.xyw(2, 1, 1));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    multithreading = new JCheckBox(Messages.getString("MEncoderVideo.35"),
            configuration.isFfmpegAviSynthMultithreading());
    multithreading.setContentAreaFilled(false);
    multithreading.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setFfmpegAviSynthMultithreading(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(multithreading), cc.xy(2, 3));

    interframe = new JCheckBox(Messages.getString("AviSynthMEncoder.13"),
            configuration.getFfmpegAvisynthInterFrame());
    interframe.setContentAreaFilled(false);
    interframe.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            configuration.setFfmpegAvisynthInterFrame(interframe.isSelected());
            if (configuration.getFfmpegAvisynthInterFrame()) {
                JOptionPane.showMessageDialog(
                        SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame()),
                        Messages.getString("AviSynthMEncoder.16"), Messages.getString("Dialog.Information"),
                        JOptionPane.INFORMATION_MESSAGE);
            }
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(interframe), cc.xy(2, 5));

    interframegpu = new JCheckBox(Messages.getString("AviSynthMEncoder.15"),
            configuration.getFfmpegAvisynthInterFrameGPU());
    interframegpu.setContentAreaFilled(false);
    interframegpu.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setFfmpegAvisynthInterFrameGPU((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(interframegpu), cc.xy(2, 7));

    convertfps = new JCheckBox(Messages.getString("AviSynthMEncoder.3"),
            configuration.getFfmpegAvisynthConvertFps());
    convertfps.setContentAreaFilled(false);
    convertfps.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setFfmpegAvisynthConvertFps((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(convertfps), cc.xy(2, 9));

    configuration.addConfigurationListener(new ConfigurationListener() {
        @Override
        public void configurationChanged(ConfigurationEvent event) {
            if (event.getPropertyName() == null) {
                return;
            }
            if ((!event.isBeforeUpdate())
                    && event.getPropertyName().equals(PmsConfiguration.KEY_GPU_ACCELERATION)) {
                interframegpu.setEnabled(configuration.isGPUAcceleration());
            }
        }
    });

    return builder.getPanel();
}

From source file:net.pms.newgui.GeneralTab.java

/**
 * Add the renderer configuration selection after they have been intialized.
 *//*  w w  w .  ja v a  2  s  . c  o  m*/
public void addRenderers() {
    ArrayList<RendererConfiguration> allConfs = RendererConfiguration.getAllRendererConfigurations();
    ArrayList<Object> keyValues = new ArrayList<Object>();
    ArrayList<Object> nameValues = new ArrayList<Object>();
    keyValues.add("");
    nameValues.add(Messages.getString("NetworkTab.37"));

    if (allConfs != null) {
        for (RendererConfiguration renderer : allConfs) {
            if (renderer != null) {
                keyValues.add(renderer.getRendererName());
                nameValues.add(renderer.getRendererName());
            }
        }
    }

    final KeyedComboBoxModel renderersKcbm = new KeyedComboBoxModel(
            (Object[]) keyValues.toArray(new Object[keyValues.size()]),
            (Object[]) nameValues.toArray(new Object[nameValues.size()]));
    renderers.setModel(renderersKcbm);
    renderers.setEditable(false);
    String defaultRenderer = configuration.getRendererDefault();
    renderersKcbm.setSelectedKey(defaultRenderer);

    if (renderers.getSelectedIndex() == -1) {
        renderers.setSelectedIndex(0);
    }

    renderers.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                logger.info("Setting renderer default: \"" + renderersKcbm.getSelectedKey() + "\"");
                configuration.setRendererDefault((String) renderersKcbm.getSelectedKey());
            }
        }
    });
}

From source file:storybook.export.DlgExport.java

private void cbFormatItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbFormatItemStateChanged
    if (evt.getStateChange() == ItemEvent.SELECTED) {
        setOptions(evt.getItem().toString());
    }/*from w  ww  . j  a  v a2  s  .  com*/
}

From source file:br.edu.unifei.mestrado.view.GraphPartitioningVisualization.java

private JToggleButton getGroupCircleVertices() {
    if (groupCircleVertices == null) {
        groupCircleVertices = new JToggleButton("Group Circle Clusters");
        groupCircleVertices.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent e) {
                clusterAndRecolor(layout, e.getStateChange() == ItemEvent.SELECTED,
                        groupCircleVertices.isSelected());
                vv.repaint();//from ww w  . j  a  v  a  2 s.c  om
            }
        });
    }
    return groupCircleVertices;
}

From source file:storybook.export.DlgExport.java

private void cbReportItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cbReportItemStateChanged
    if (evt.getStateChange() == ItemEvent.SELECTED) {
        if (evt.getItem().toString().equals(I18N.getMsg("msg.export.book.text")))
            setOptions(cbFormat.getSelectedItem().toString());
    }// w  ww. j  a  va  2 s . c om
}

From source file:de.codesourcery.eve.skills.ui.components.AbstractComponent.java

protected void linkComponentEnabledStates(final JToggleButton parent, final Component... children) {

    final boolean selected = parent.isSelected();

    for (Component child : children) {
        child.setEnabled(selected);/*ww w. ja v  a 2  s  .com*/
    }

    parent.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {

            final boolean selected = e.getStateChange() == ItemEvent.SELECTED;

            for (Component child : children) {
                child.setEnabled(selected);
            }
        }
    });

}