Example usage for java.awt.event ItemListener ItemListener

List of usage examples for java.awt.event ItemListener ItemListener

Introduction

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

Prototype

ItemListener

Source Link

Usage

From source file:com.emr.schemas.ForeignDataMover.java

/**
 * Form for moving foreign data//from  www.  ja v  a 2  s.c o  m
 * @param emrConn Connection to the emr database
 * @param mpiConn Connection to the mpi database
 * @param sourceColumn The column that has the foreign key
 */
public ForeignDataMover(final Connection emrConn, final Connection mpiConn, String sourceColumn) {
    this.emrConn = emrConn;
    this.mpiConn = mpiConn;
    this.sourceColumn = sourceColumn;
    sourceTables = getDatabaseTables(emrConn);
    sourceTablesModel = new DefaultComboBoxModel(sourceTables.toArray(new String[sourceTables.size()]));

    destTables = getDatabaseTables(mpiConn);
    destTablesModel = new DefaultComboBoxModel(destTables.toArray(new String[destTables.size()]));

    initComponents();
    txtSelectedCollumn.setText("<html><b color='green'>" + sourceColumn + "</b></html>");
    cmbForeignTables.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                String selectedTable = (String) e.getItem();
                //populate primary table columns
                List primaryColumns = getTableColumns(selectedTable, emrConn);
                sourcePrimaryFields = new DefaultComboBoxModel(
                        primaryColumns.toArray(new String[primaryColumns.size()]));
                cmbPrimaryKey.setModel(sourcePrimaryFields);
                sourceUniqueFields = new DefaultComboBoxModel(
                        primaryColumns.toArray(new String[primaryColumns.size()]));
                cmbUniquekey.setModel(sourceUniqueFields);
            }
        }
    });
    cmbMPITables.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                String selectedTable = (String) e.getItem();
                //populate primary table columns
                List columns = getTableColumns(selectedTable, mpiConn);
                mpiPrimarycolumns = new DefaultComboBoxModel(columns.toArray(new String[columns.size()]));
                cmbMPIPrimaryKey.setModel(mpiPrimarycolumns);
                mpiUniquFields = new DefaultComboBoxModel(columns.toArray(new String[columns.size()]));
                cmbMPIUniqueField.setModel(mpiUniquFields);
            }
        }
    });
}

From source file:DatabaseBrowser.java

protected JPanel getSelectionPanel() {
    JPanel panel = new JPanel();
    panel.add(new JLabel("Catalog"));
    panel.add(new JLabel("Schema"));
    panel.add(new JLabel("Table"));

    catalogBox = new JComboBox();
    populateCatalogBox();//from w w w  . ja va  2s.  co m
    panel.add(catalogBox);
    schemaBox = new JComboBox();
    populateSchemaBox();
    panel.add(schemaBox);
    tableBox = new JComboBox();
    populateTableBox();
    panel.add(tableBox);

    catalogBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent event) {
            String newCatalog = (String) (catalogBox.getSelectedItem());
            try {
                connection.setCatalog(newCatalog);
            } catch (Exception e) {
            }
            populateSchemaBox();
            populateTableBox();
            refreshTable();
        }
    });

    schemaBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent event) {
            populateTableBox();
            refreshTable();
        }
    });

    tableBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent event) {
            refreshTable();
        }
    });
    return panel;
}

From source file:org.pentaho.ui.xul.swing.tags.SwingRadio.java

public SwingRadio(Element self, XulComponent parent, XulDomContainer domContainer, String tagName) {
    super("radio");
    radioButton = new JRadioButton();
    setManagedObject(radioButton);//from www . ja v a  2s.c o  m

    // wrong type of event to listen to.. this one fires even on mouse over. use itemlistener
    // radioButton.addChangeListener(new ChangeListener(){
    // public void stateChanged(ChangeEvent evt){
    // logger.debug("firing selected property change: isSelected="+SwingRadio.this.isSelected());
    // SwingRadio.this.changeSupport.firePropertyChange("selected", null, SwingRadio.this.isSelected());
    // }
    // });

    radioButton.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
            logger.debug("firing selected property change: isSelected=" + selected);
            SwingRadio.this.changeSupport.firePropertyChange("selected", null, selected);
        }

    });
}

From source file:ca.sqlpower.wabit.swingui.report.selectors.FancyComboBoxSelector.java

public FancyComboBoxSelector(ComboBoxSelector selector, Runnable refreshRoutine) {

    this.selector = selector;
    this.refreshRoutine = refreshRoutine;

    this.selector.addSPListener(selectorListener);
    this.selector.addSelectorListener(selectionListener);

    addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (ignoreEvents.get())
                return;
            if (!ObjectUtils.equals(getSelectedItem(), FancyComboBoxSelector.this.selector.getCurrentValue())) {
                FancyComboBoxSelector.this.selector.setSelectedValue(getSelectedItem());
            }//from   w w  w  .j a  v  a 2s. c  om
        }
    });

    refresh();
}

From source file:com.choicemaker.cm.modelmaker.gui.utils.HistoChartPanel.java

public HistoChartPanel(final JFreeChart chart, boolean properties, boolean save, boolean print, boolean zoom,
        boolean tooltips, final ModelMaker modelMaker) {
    super(chart, properties, save, print, zoom, tooltips);
    this.modelMaker = modelMaker;
    // horizontal zoom doesn't work, by setting false we don't get bogus menu item
    //      setHorizontalZoom(false);
    //      setVerticalZoom(true);
    final JCheckBoxMenuItem logYScale = new JCheckBoxMenuItem(
            ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.test.logscale.y"));
    logYScale.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            CategoryPlot p = (CategoryPlot) chart.getPlot();
            Axis oldAxis = p.getRangeAxis();
            if (logYScale.isSelected()) {
                LogarithmicAxis yAxis = new LogarithmicAxis(ChoiceMakerCoreMessages.m
                        .formatMessage("train.gui.modelmaker.panel.histogram.cm.numpairs"));
                yAxis.setStrictValuesFlag(false);
                p.setRangeAxis(yAxis);// w w  w. j  a v  a 2 s  .co m
            } else {
                p.setRangeAxis(new NumberAxis(ChoiceMakerCoreMessages.m
                        .formatMessage("train.gui.modelmaker.panel.histogram.cm.numpairs")));
            }
            oldAxis.setPlot(null);
            chartChanged(new ChartChangeEvent(this));
        }
    });
    JPopupMenu popup = getPopupMenu();
    popup.addSeparator();
    popup.add(logYScale);
    popup.addSeparator();
    select = new JMenu("Select");
    final JMenuItem all = new JMenuItem("All");
    select.add(all);
    final JMenuItem cmDiffer = new JMenuItem("Human marked differ");
    select.add(cmDiffer);
    final JMenuItem cmHold = new JMenuItem("Human marked hold");
    select.add(cmHold);
    final JMenuItem cmMatch = new JMenuItem("Human marked match");
    select.add(cmMatch);
    ActionListener l = new ActionListener() {
        public void actionPerformed(ActionEvent ev) {
            ListeningMarkedRecordPairFilter filter = modelMaker.getFilter();
            filter.reset();
            filter.setFromPercentage(rangeFrom);
            filter.setToPercentage(rangeTo);
            Object src = ev.getSource();
            if (src != all) {
                boolean[] b = new boolean[Decision.NUM_DECISIONS];
                if (src == cmDiffer) {
                    b[Decision.DIFFER.toInt()] = true;
                } else if (src == cmHold) {
                    b[Decision.HOLD.toInt()] = true;
                } else if (src == cmMatch) {
                    b[Decision.MATCH.toInt()] = true;
                }
                filter.setHumanDecision(b);
            }
            modelMaker.filterMarkedRecordPairList();
        }
    };
    all.addActionListener(l);
    cmDiffer.addActionListener(l);
    cmHold.addActionListener(l);
    cmMatch.addActionListener(l);
    popup.add(select);
    addChartMouseListener(new ChartMouseListener() {
        public void chartMouseClicked(ChartMouseEvent evt) {
            ChartEntity e = evt.getEntity();
            if (e instanceof CategoryItemEntity) {
                CategoryItemEntity c = (CategoryItemEntity) e;
                int cat = c.getCategoryIndex();
                HistoCategoryDataset data = (HistoCategoryDataset) ((CategoryPlot) getChart().getPlot())
                        .getDataset();
                int len = data.getColumnCount();
                float step = 1f / len;
                rangeFrom = cat * step;
                rangeTo = rangeFrom + step;
                ListeningMarkedRecordPairFilter filter = modelMaker.getFilter();
                filter.reset();
                filter.setFromPercentage(rangeFrom);
                filter.setToPercentage(rangeTo);
                boolean[] b = new boolean[Decision.NUM_DECISIONS];
                int series = c.getSeries();
                if (data.isIncludeHolds() && series != 0) {
                    if (series == 1) {
                        series = 2;
                    } else {
                        series = 1;
                    }
                }
                b[series] = true;
                filter.setHumanDecision(b);
                modelMaker.filterMarkedRecordPairList();

            }
        }

        public void chartMouseMoved(ChartMouseEvent arg0) {
        }
    });
}

From source file:hr.fer.zemris.vhdllab.platform.ui.wizard.support.FileSelectionComponent.java

private void createComponent(Predicate projectFilter) {
    projectsCombobox = new JComboBox(projectList(projectFilter));
    new ComboBoxAutoCompletion(projectsCombobox);
    model = new DefaultListModel();
    list = new JList(model);
    list.setPreferredSize(new Dimension(150, 150));
    projectsCombobox.addItemListener(new ItemListener() {
        @Override/*from ww  w  . ja  va 2 s.  co  m*/
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                updateList(e.getItem());
            }
        }
    });

    setLayout(new BorderLayout());
    add(projectsCombobox, BorderLayout.NORTH);
    add(new JScrollPane(list), BorderLayout.CENTER);
}

From source file:org.pentaho.ui.xul.swing.tags.SwingMenuList.java

public SwingMenuList(Element self, XulComponent parent, XulDomContainer domContainer, String tagName) {
    super("menulist");

    this.xulDomContainer = domContainer;

    combobox = new JComboBox(new DefaultComboBoxModel());
    setManagedObject(combobox);//from  ww w .j ava2 s  .com

    combobox.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED && !inLayoutProcess && initialized) {
                fireSelectedEvents();
            }
        }

    });

}

From source file:org.codinjutsu.tools.mongo.view.AbstractAddDialog.java

void initCombo(final ComboBox combobox, final JPanel parentPanel) {
    combobox.setModel(new DefaultComboBoxModel(JsonDataType.values()));
    combobox.setRenderer(new ColoredListCellRenderer() {

        @Override/*w  w  w  .j ava2s . co m*/
        protected void customizeCellRenderer(JList jList, Object o, int i, boolean b, boolean b2) {
            append(((JsonDataType) o).type);
        }
    });

    combobox.setSelectedItem(null);
    combobox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent itemEvent) {
            JsonDataType selectedType = (JsonDataType) combobox.getSelectedItem();
            currentEditor = UI_COMPONENT_BY_JSON_DATATYPE.get(selectedType);
            currentEditor.reset();

            parentPanel.invalidate();
            parentPanel.removeAll();
            parentPanel.add(currentEditor.getComponent(), BorderLayout.CENTER);
            parentPanel.validate();
        }
    });

    combobox.setSelectedItem(JsonDataType.STRING);
}

From source file:com.diversityarrays.kdxplore.field.CollectionPathPanel.java

public CollectionPathPanel(boolean wantPlotsPerGroup, BiConsumer<VisitOrder2D, PlotsPerGroup> onChoiceChanged,
        List<? extends OrOrTr> onlyThese) {
    super(new BorderLayout());

    plotsPerGroupChoice.setSelectedItem(plotsPerGroup);
    odtChoicePanel.setOrOrTr(visitOrder);

    this.onChoiceChanged = onChoiceChanged;

    if (wantPlotsPerGroup) {
        plotsPerGroupChoice.addItemListener(new ItemListener() {
            @Override//from   www  .  java2s .c o m
            public void itemStateChanged(ItemEvent e) {
                plotsPerGroup = (PlotsPerGroup) plotsPerGroupChoice.getSelectedItem();
                onChoiceChanged.accept(visitOrder, plotsPerGroup);
            }
        });

        Box top = Box.createHorizontalBox();
        top.add(new JLabel("Plots Per Group:"));
        top.add(plotsPerGroupChoice);
        top.add(Box.createHorizontalGlue());

        add(top, BorderLayout.NORTH);
    }

    if (!Check.isEmpty(onlyThese)) {
        OrOrTr first = onlyThese.get(0);

        odtChoicePanel.setOnlyAllow(onlyThese.toArray(new OrOrTr[onlyThese.size()]));

        String msg;
        if (onlyThese.size() == 1) {
            msg = "<HTML>For now, only supporting:<BR>" + onlyThese.get(0).toString();
        } else {
            msg = onlyThese.stream().map(oot -> oot.toString())
                    .collect(Collectors.joining("<BR>", "<HTML>For now, only supporting:<BR>", ""));
        }

        JLabel label = new JLabel(msg, JLabel.CENTER);
        label.setForeground(Color.RED);
        add(label, BorderLayout.SOUTH);
    }

    add(odtChoicePanel, BorderLayout.CENTER);
}

From source file:org.cagrid.installer.steps.PresentLicenseStep.java

public void init(WizardModel m) {
    this.model = (CaGridInstallerModel) m;

    setLayout(new BorderLayout());
    setSize(new Dimension(475, 161));

    JPanel licensePanel = new JPanel();
    licensePanel.setBackground(Color.WHITE);
    JTextPane textPane = new JTextPane();
    licensePanel.add(textPane);/*from   w ww .  ja va2 s . com*/
    JScrollPane scrollPane = new JScrollPane(licensePanel);
    scrollPane.setPreferredSize(new Dimension(475, 150));
    add(scrollPane, BorderLayout.CENTER);

    try {
        StringBuilder sb = new StringBuilder();
        BufferedReader r = new BufferedReader(
                new InputStreamReader(getClass().getResourceAsStream("/cagrid_license.txt")));
        String line = null;
        while ((line = r.readLine()) != null) {
            sb.append(line).append("\n");
        }
        textPane.setText(sb.toString());
        textPane.setFont(textPane.getFont().deriveFont((float) 10));
    } catch (Exception ex) {
        String msg = "Error loading license: " + ex.getMessage();
        logger.error(msg, ex);
        JOptionPane.showMessageDialog(null, msg, this.model.getMessage("error"), JOptionPane.ERROR_MESSAGE);
    }

    JPanel controlPanel = new JPanel();
    controlPanel.setLayout(new GridBagLayout());
    add(controlPanel, BorderLayout.SOUTH);

    JLabel label = new JLabel(this.model.getMessage("accept.license"));
    controlPanel.add(label);

    JCheckBox checkBox = new JCheckBox();
    checkBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent evt) {
            PresentLicenseStep.this.setComplete(evt.getStateChange() == ItemEvent.SELECTED);
        }
    });
    controlPanel.add(checkBox);
}