Example usage for com.jgoodies.binding.adapter ComboBoxAdapter ComboBoxAdapter

List of usage examples for com.jgoodies.binding.adapter ComboBoxAdapter ComboBoxAdapter

Introduction

In this page you can find the example usage for com.jgoodies.binding.adapter ComboBoxAdapter ComboBoxAdapter.

Prototype

public ComboBoxAdapter(SelectionInList<E> selectionInList) 

Source Link

Document

Constructs a ComboBoxAdapter for the given SelectionInList.

Usage

From source file:ambit2.db.results.test.AmbitRowsEventTest.java

License:Open Source License

public static void main(String[] args) {
    // http://www.java2s.com/Code/Java/Swing-Components/JGoodiesBindingSelectionInListModelExample.htm
    try {/*from  w  w w.j  a  v a2 s .  c om*/
        final AmbitRows<Dictionary> dictionary = new AmbitRows<Dictionary>() {
            /**
             * 
             */
            private static final long serialVersionUID = 6274513733204291475L;

            @Override
            protected synchronized IQueryRetrieval createNewQuery(Dictionary target) throws AmbitException {
                TemplateQuery q = new TemplateQuery();
                q.setValue(target.getTemplate());
                return q;
            }
        };

        final AmbitRows<Property> properties = new AmbitRows<Property>() {
            @Override
            protected synchronized IQueryRetrieval createNewQuery(Property target) throws AmbitException {
                QueryField q = new QueryField();
                q.setFieldname(target);
                return q;
            }

        };
        dictionary.addPropertyChangeListener(dictionary.getPropertyname(), properties);
        dictionary.addPropertyChangeListener("status", properties);

        AmbitRowsEventTest test = new AmbitRowsEventTest();
        test.setUpDatabase(test.getTestDatabase());
        IDatabaseConnection c = test.getConnection("localhost", "ambit2", "3306", "guest", "guest");
        dictionary.setConnection(c.getConnection());
        properties.setConnection(c.getConnection());

        DictionaryObjectQuery q = new DictionaryObjectQuery();
        q.setValue("Dataset");

        PropertyChangeSupport ps = new PropertyChangeSupport(test);
        ps.addPropertyChangeListener("topquery", dictionary);
        ps.firePropertyChange(new QueryChangeEvent(test, "topquery", null, q));

        final QueryField qf = new QueryField();
        properties.addPropertyChangeListener(properties.getPropertyname(), new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {

                try {
                    IQueryRetrieval r = properties.process((Property) evt.getNewValue());
                    qf.setFieldname(((QueryField) r).getFieldname());
                } catch (AmbitException x) {
                    x.printStackTrace();
                }
            }
        });

        ListModel listModel = new RowsModel<Dictionary>(dictionary);
        ValueModel selectedItemHolder1 = new ValueHolder();
        SelectionInList<Dictionary> selectionInList = new SelectionInList<Dictionary>(listModel,
                selectedItemHolder1);

        final JList jlist = new JList();
        Bindings.bind(jlist, selectionInList);

        BeanAdapter beanAdapter = new BeanAdapter(selectionInList);
        ValueModel nameModel = beanAdapter.getValueModel("template");
        ValueModel parentModel = beanAdapter.getValueModel("parentTemplate");

        ListModel listModel2 = new RowsModel<Property>(properties);
        ValueModel selectedItemHolder2 = new ValueHolder();
        SelectionInList<Property> selectionInList2 = new SelectionInList<Property>(listModel2,
                selectedItemHolder2);

        BeanAdapter beanAdapter2 = new BeanAdapter(qf);
        ValueModel fieldnameModel = beanAdapter2.getValueModel("fieldname");
        // ValueModel conditionModel =
        // beanAdapter2.getValueModel("condition");
        ValueModel valueModel = beanAdapter2.getValueModel("value");

        selectionInList.addPropertyChangeListener("value", new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                try {
                    dictionary.process((Dictionary) evt.getNewValue());
                } catch (Exception x) {
                    x.printStackTrace();
                }

            }
        });

        selectionInList2.addPropertyChangeListener("value", new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                try {

                } catch (Exception x) {
                    x.printStackTrace();
                }

            }
        });
        JPanel p = new JPanel();

        p.add(BasicComponentFactory.createTextField(nameModel));
        p.add(BasicComponentFactory.createTextField(parentModel));

        p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));
        p.add(new JLabel("Dictionary"));
        p.add(new JScrollPane(jlist));
        // p.add(new JComboBox(new
        // ComboBoxAdapter<Dictionary>(selectionInList)));
        p.add(new JLabel("Properties"));
        final JComboBox combo = new JComboBox(new ComboBoxAdapter<Property>(selectionInList2));
        p.add(combo);
        p.add(BasicComponentFactory.createTextField(fieldnameModel));
        // p.add(BasicComponentFactory.createTextField(conditionModel));
        p.add(BasicComponentFactory.createIntegerField(valueModel));

        properties.addPropertyChangeListener("status", new PropertyChangeListener() {
            public void propertyChange(PropertyChangeEvent evt) {
                combo.setEnabled((Boolean) evt.getNewValue());
            }
        });
        JOptionPane.showMessageDialog(null, p);
        c.close();

    } catch (Exception x) {
        x.printStackTrace();
    }
}

From source file:de.awtools.groovy.swinger.bean.SelectionInListTest.java

License:Open Source License

@Test
public void testSelectionInListWithGroovyPresentationModel() {
    final String[] fruits = new String[] { "apfel", "birne", "pflaume" };
    SelectionInListModel silm = new SelectionInListModel();
    silm.getSelectionList().clear();/*from   w  w  w .  ja va 2s.co m*/
    silm.getSelectionList().addAll(Arrays.asList(fruits));
    silm.setSelectedItem(fruits[0]);

    GroovyPropertyChangeSupportBuilder.preparePCLMechanics(silm);
    GroovyPresentationModel gpm = new GroovyPresentationModel(silm);

    EventListModel<String> elm = new EventListModel<String>(silm.getSelectionList());
    SelectionInList<String> sil = new SelectionInList<String>(elm, gpm.getModel("selectedItem"));
    JComboBox combobox = new JComboBox(new ComboBoxAdapter<String>(sil));

    assertEquals(0, combobox.getSelectedIndex());
    assertEquals("apfel", combobox.getSelectedItem());

    silm.setProperty("selectedItem", "birne");
    assertEquals(1, combobox.getSelectedIndex());
    assertEquals("birne", combobox.getSelectedItem());
}

From source file:org.gitools.plugins.mutex.ui.MutualExclusiveAnalysisPage.java

License:Open Source License

public MutualExclusiveAnalysisPage(Heatmap heatmap) {
    super("Mutual exclusion & Co-occurrence analysis");
    this.heatmap = heatmap;

    setTitle("Mutual Exclusion & Co-occurrence analysis");
    setMessage("Select which groups of columns and rows you want to test");

    Collection<String> colAnnlabels = heatmap.getColumns().getAnnotations().getLabels();
    Collection<String> rowAnnlabels = heatmap.getRows().getAnnotations().getLabels();

    columnAnnotationCombo//  ww  w .jav a  2s.c o  m
            .setModel(new DefaultComboBoxModel(colAnnlabels.toArray(new String[colAnnlabels.size()])));

    rowAnnotationCombo
            .setModel(new DefaultComboBoxModel(rowAnnlabels.toArray(new String[rowAnnlabels.size()])));

    ActionListener actionListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            updateControls();
        }
    };
    eventsFunctionComboBox.addActionListener(actionListener);
    eventsFunctionComboBox.setModel(new ComboBoxAdapter<>(new SelectionInList<NonEventToNullFunction>(
            heatmap.getLayers().getTopLayer().getDecorator().getEventFunctionAlternatives(),
            new PropertyAdapter<>(heatmap.getLayers().getTopLayer(), "eventFunction"))));
    allColumnsCheckBox.addActionListener(actionListener);
    columnAnnotationGroupingBox.addActionListener(actionListener);

    permutationSpinner.setModel(new SpinnerNumberModel(10000, 100, 10000000, 1000));

    testDescription.setText("All " + heatmap.getContents().getRows().size() + " "
            + heatmap.getRows().getId().getLabel() + "s will be taken into account "
            + "for a weighted permutation test to assess probability of mutual exclusion and co-occurence");

    updateControls();

}

From source file:org.gitools.plugins.mutex.ui.MutualExclusiveSortPage.java

License:Open Source License

public MutualExclusiveSortPage(Heatmap hm, MatrixDimensionKey sortDimension) {
    super();/*from  w  ww .j  a v  a 2 s .c  o m*/
    patternsArea.getDocument().addDocumentListener(new DocumentChangeListener() {
        @Override
        protected void update(DocumentEvent e) {
            saveButton.setEnabled(patternsArea.getDocument().getLength() > 0);
        }
    });

    pattern = "${id}";
    patternsField.setText("id");

    setTitle("Sort by mutual exclusion");
    setMessage("Puts the selected rows/columns at the top of the matrix and "
            + "sorts them by their mutual exclusion.");
    setComplete(true);

    loadButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            loadBtnAction();
        }
    });
    saveButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            saveBtnAction();
        }
    });
    pasteSelectedButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setValues(getSelected());
        }
    });
    pasteUnselectedButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setValues(getUnselected());
        }
    });
    patternButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            changePatternAction();
        }
    });

    this.hm = hm;
    this.sortDimension = sortDimension;

    eventsFunctionComboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            updateEventDescription();
        }
    });
    eventsFunctionComboBox.setModel(new ComboBoxAdapter<>(new SelectionInList<NonEventToNullFunction>(
            hm.getLayers().getTopLayer().getDecorator().getEventFunctionAlternatives(),
            new PropertyAdapter<>(hm.getLayers().getTopLayer(), "eventFunction"))));
    updateEventDescription();

    IMatrixDimension dimension = hm.getContents().getDimension(sortDimension);
    testDescription.setText("All " + dimension.size() + " " + dimension.getId().getLabel()
            + "s will be taken into account "
            + "for a weighted permutation test to assess probability of mutual exclusion and co-occurence");

}

From source file:org.gitools.ui.app.heatmap.panel.details.boxes.LayerValuesBox.java

License:Open Source License

private void addGroupSelector() {

    HeatmapLayers layers = getHeatmap().getLayers();
    if (layers.getGroups().size() < 2) {
        return;/*  www .j  a va2s .c o  m*/
    }

    JPanel groupsSelectorPanel = new JPanel(new HorizontalLayout(2), true);
    groupsSelectorPanel.setBackground(Color.white);

    JComboBox<Object> groupsSelector = new JComboBox<>();

    List<String> groups = new ArrayList<>(layers.getGroups());
    Collections.sort(groups);

    groupsSelector.setModel(new ComboBoxAdapter<>(
            new SelectionInList<>(groups, new PropertyAdapter<>(layers, PROPERTY_SELECTED_GROUP))));

    groupsSelectorPanel.add(new WebLabel("Data listed: "));
    groupsSelectorPanel.add(groupsSelector);

    bottomPanels.add(groupsSelectorPanel);

}

From source file:org.gitools.ui.app.heatmap.panel.settings.DataManipulationSection.java

License:Open Source License

public DataManipulationSection(final HeatmapLayer layer) {
    super();/* w ww.  ja v  a2 s .c om*/

    layer.addPropertyChangeListener(HeatmapLayer.PROPERTY_DECORATOR, new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            setEventFunctions(layer);
        }
    });

    defaultSortDirectionComboBox.setModel(new ComboBoxAdapter<>(
            new SelectionInList<>(DIRECTIONS, new PropertyAdapter<>(layer, "sortDirection"))));

    defaultAggregatorComboBox
            .setModel(new ComboBoxAdapter<>(new SelectionInList<>(AggregatorFactory.getAggregatorsArray(),
                    new PropertyAdapter<>(layer, "aggregator"))));

    setEventFunctions(layer);

}

From source file:org.gitools.ui.app.heatmap.panel.settings.DataManipulationSection.java

License:Open Source License

private void setEventFunctions(HeatmapLayer layer) {
    eventsFunctionComboBox.setModel(new ComboBoxAdapter<>(
            new SelectionInList<NonEventToNullFunction>(layer.getDecorator().getEventFunctionAlternatives(),
                    new PropertyAdapter<>(layer, "eventFunction"))));
}

From source file:org.gitools.ui.app.heatmap.panel.settings.FormatSection.java

License:Open Source License

public FormatSection(final HeatmapLayer layer) {
    super();//ww  w .  j a va2s  .  c o  m

    cellFormatComboBox.setModel(new ComboBoxAdapter<>(new SelectionInList<>(FORMATTERS,
            new PropertyAdapter<>(layer, HeatmapLayer.PROPERTY_SHORT_FORMATTER))));

    detailsFormatComboBox.setModel(new ComboBoxAdapter<>(new SelectionInList<>(FORMATTERS,
            new PropertyAdapter<>(layer, HeatmapLayer.PROPERTY_LONG_FORMATTER))));

    changeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            FontChooserDialog dlg = new FontChooserDialog(null, layer.getFont(), false);
            dlg.setVisible(true);

            if (dlg.isCancelled()) {
                return;
            }

            layer.setFont(dlg.getFont());

            fontTextField.setFont(layer.getFont());
            fontTextField.setText(FontUtils.fontText(layer.getFont()));
        }
    });

    fontTextField.setFont(layer.getFont());
    fontTextField.setText(FontUtils.fontText(layer.getFont()));
}

From source file:org.gitools.ui.app.heatmap.panel.settings.headers.FormatSection.java

License:Open Source License

public FormatSection(boolean showColors, boolean showValue, final HeatmapHeader heatmapHeader) {

    PresentationModel<HeatmapHeader> header = new PresentationModel<>(heatmapHeader);

    bind(textColorTextField, "color", header.getModel(HeatmapHeader.PROPERTY_LABEL_COLOR));
    bind(backgroundColorTextField, "color", header.getModel(HeatmapHeader.PROPERTY_BACKGROUND_COLOR));
    bind(showValueCheckBox, header.getModel(HeatmapHeader.PROPERTY_LABEL_VISIBLE));

    changeButton.addActionListener(new ActionListener() {
        @Override/*from   ww  w.jav  a  2s  . c o m*/
        public void actionPerformed(ActionEvent e) {
            FontChooserDialog dlg = new FontChooserDialog(null, heatmapHeader.getFont(), false);
            dlg.setVisible(true);

            if (dlg.isCancelled()) {
                return;
            }

            heatmapHeader.setFont(dlg.getFont());

            fontTextField.setFont(heatmapHeader.getFont());
            fontTextField.setText(FontUtils.fontText(heatmapHeader.getFont()));
        }
    });

    fontTextField.setFont(heatmapHeader.getFont());
    fontTextField.setText(FontUtils.fontText(heatmapHeader.getFont()));

    textColorTextField.setEnabled(showColors);
    backgroundColorTextField.setEnabled(showColors);
    showValueCheckBox.setVisible(showValue);

    if (heatmapHeader instanceof HeatmapDecoratorHeader) {
        HeatmapDecoratorHeader decoratorHeader = (HeatmapDecoratorHeader) heatmapHeader;
        numericFormatComboBox.setModel(new ComboBoxAdapter<>(new SelectionInList<>(FORMATTERS,
                new PropertyAdapter<>(decoratorHeader, HeatmapDecoratorHeader.PROPERTY_NUMERIC_FORMATTER))));
    } else {
        numericFormatComboBox.setVisible(false);
    }

}

From source file:org.gitools.ui.core.components.boxes.SelectionBox.java

License:Open Source License

@Override
public void update() {

    this.setVisible(isVisible());

    if (!isVisible() || isCollapsed()) {
        return;/*from  w w  w  .ja va  2  s  .c om*/
    }

    if (updating != null && !updating.isDone()) {
        updating.cancel(true);
        //return;
    }
    drawUpdating();

    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            final List<DetailsDecoration> details = new ArrayList<>();
            Heatmap heatmap = getHeatmap();

            nextRowEventAction.reset();
            nextColumnsEventAction.reset();

            Set<String> rows = heatmap.getRows().getSelected();
            Set<String> columns = heatmap.getColumns().getSelected();
            if (rows.isEmpty()) {
                rows = Sets.newHashSet(heatmap.getRows());
            }

            if (columns.isEmpty()) {
                columns = Sets.newHashSet(heatmap.getColumns());
            }

            int selectedRows = rows.size();
            int selectedColumns = columns.size();
            if (selectedColumns > 0) {
                details.add(new DetailsDecoration("Columns sel.", columns.size() + " columns"));
            }
            if (selectedRows > 0) {
                details.add(new DetailsDecoration("Rows sel.", rows.size() + " rows"));
            }

            HeatmapLayer layer = getHeatmap().getLayers().getTopLayer();
            IMatrix data = getHeatmap().getContents();

            IMatrixIterable<Double> cellValuesIterable = getHeatmap().newPosition()
                    .iterate(layer, data.getRows().subset(rows), data.getColumns().subset(columns))
                    .monitor(new NullProgressMonitor(), "Aggregating values of layer '" + layer.getId() + "'");

            //Layer events
            JComboBox eventsFunctionComboBox = new JComboBox();
            eventsFunctionComboBox.setModel(new ComboBoxAdapter<>(new SelectionInList<NonEventToNullFunction>(
                    layer.getDecorator().getEventFunctionAlternatives(),
                    new PropertyAdapter<>(layer, "eventFunction"))));

            NonEventToNullFunction eventsFunction = layer.getEventFunction();
            IMatrixIterable<Double> eventsIt = getHeatmap().newPosition()
                    .iterate(layer, data.getRows().subset(rows), data.getColumns().subset(columns))
                    .transform(eventsFunction);
            Double events = NonNullCountAggregator.INSTANCE.aggregate(eventsIt);
            String eventsDetail = valueString(events, layer.getLongFormatter());

            if (events != null) {
                Double freq = 100 * (double) events / ((double) selectedColumns * (double) selectedRows);
                eventsDetail += " (" + valueString(freq, layer.getShortFormatter()) + "%)";
            }

            details.add(new JComponentDetailsDecoration(eventsFunctionComboBox, eventsFunction.getName(),
                    eventsFunction.getDescription(), eventsDetail));

            Double stDev = StdDevAggregator.INSTANCE.aggregate(cellValuesIterable);

            if (layer.getDecorator() instanceof CategoricalDecorator) {

                CategoricalDecorator decorator = (CategoricalDecorator) layer.getDecorator();
                Map<Double, Integer> categoryCounts = new HashMap<>();
                for (ColorScalePoint p : decorator.getCategories()) {
                    categoryCounts.put(p.getValue(), 0);
                }
                for (Double value : eventsIt) {
                    if (value != null) {
                        categoryCounts.put(value, categoryCounts.get(value) + 1);
                    }
                }
                for (ColorScalePoint p : decorator.getCategories()) {
                    double count = (double) categoryCounts.get(p.getValue());
                    if (count > 0) {
                        DetailsDecoration d = new DetailsDecoration(p.getName(),
                                valueString(count, layer.getShortFormatter()));
                        d.setBgColor(p.getColor());
                        details.add(d);
                    }
                }

            } else {
                //default layer aggregator
                Double layerAggregation = layer.getAggregator().aggregate(cellValuesIterable);
                details.add(new DetailsDecoration(layer.getAggregator().toString(),
                        "Default data layer aggregator. Edit data layer to change",
                        valueString(layerAggregation, layer.getLongFormatter())));

                details.add(new DetailsDecoration("St. Dev", valueString(stDev, layer.getLongFormatter())));
                //details.add(new DetailsDecoration("Variance", var.toString()));
            }

            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    SelectionBox.this.draw(details);
                }
            });
        }
    };
    updating = EXECUTOR.schedule(runnable, 50, TimeUnit.MILLISECONDS);

}