Search in sources :

Example 1 with ColorScheme

use of org.cytoscape.ding.customgraphics.ColorScheme in project cytoscape-impl by cytoscape.

the class ColorSchemeEditor method setColorSchemes.

// ==[ PUBLIC METHODS ]=============================================================================================
public void setColorSchemes(final ColorScheme[] colorSchemes) {
    this.colorSchemes = colorSchemes;
    getColorSchemeCmb().removeAllItems();
    for (final ColorScheme scheme : colorSchemes) getColorSchemeCmb().addItem(scheme);
    updateColorSchemeCmb();
    reset();
}
Also used : ColorScheme(org.cytoscape.ding.customgraphics.ColorScheme)

Example 2 with ColorScheme

use of org.cytoscape.ding.customgraphics.ColorScheme in project cytoscape-impl by cytoscape.

the class ColorSchemeEditor method getColorSchemeCmb.

protected JComboBox<ColorScheme> getColorSchemeCmb() {
    if (colorSchemeCmb == null) {
        colorSchemeCmb = new JComboBox<>(colorSchemes);
        colorSchemeCmb.setRenderer(new ColorSchemeComboBoxRenderer());
        updateColorSchemeCmb();
        colorSchemeCmb.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                final ColorScheme newScheme = (ColorScheme) colorSchemeCmb.getSelectedItem();
                chart.set(COLOR_SCHEME, newScheme);
                updateColorList(true);
            }
        });
    }
    return colorSchemeCmb;
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) ColorScheme(org.cytoscape.ding.customgraphics.ColorScheme)

Example 3 with ColorScheme

use of org.cytoscape.ding.customgraphics.ColorScheme in project cytoscape-impl by cytoscape.

the class AbstractChart method getColors.

protected List<Color> getColors(final Map<String, List<Double>> data) {
    List<Color> colors = getList(COLORS, Color.class);
    if (colors == null || colors.isEmpty()) {
        final ColorScheme scheme = get(COLOR_SCHEME, ColorScheme.class);
        if (scheme != null && data != null && !data.isEmpty()) {
            int nColors = 0;
            for (final List<Double> values : data.values()) {
                if (values != null)
                    nColors = Math.max(nColors, values.size());
            }
            colors = scheme.getColors(nColors);
        }
    }
    return colors;
}
Also used : Color(java.awt.Color) ColorScheme(org.cytoscape.ding.customgraphics.ColorScheme)

Example 4 with ColorScheme

use of org.cytoscape.ding.customgraphics.ColorScheme in project cytoscape-impl by cytoscape.

the class ColorSchemeEditor method updateColorSchemeCmb.

private void updateColorSchemeCmb() {
    if (colorSchemeCmb == null)
        return;
    ColorScheme scheme = chart.get(COLOR_SCHEME, ColorScheme.class, ColorScheme.DEFAULT);
    if (Arrays.asList(colorSchemes).contains(scheme)) {
        colorSchemeCmb.setSelectedItem(scheme);
    } else {
        scheme = CUSTOM;
        colorSchemeCmb.setSelectedItem(scheme);
        chart.set(COLOR_SCHEME, scheme);
    }
}
Also used : ColorScheme(org.cytoscape.ding.customgraphics.ColorScheme)

Example 5 with ColorScheme

use of org.cytoscape.ding.customgraphics.ColorScheme in project cytoscape-impl by cytoscape.

the class ColorSchemeEditor method updateColorList.

protected void updateColorList(final boolean newScheme) {
    List<Color> colors = chart.getList(COLORS, Color.class);
    final ColorScheme scheme = chart.get(COLOR_SCHEME, ColorScheme.class, ColorScheme.DEFAULT);
    final int nColors = getTotal();
    if (nColors > 0) {
        if (newScheme || colors.isEmpty()) {
            if (CUSTOM.equals(scheme)) {
                int newSize = Math.max(colors.size(), nColors);
                colors = new ArrayList<Color>(newSize);
                for (int i = 0; i < newSize; i++) colors.add(i % 2 == 0 ? DEFAULT_COLOR : DEFAULT_COLOR.darker());
            } else {
                colors = scheme.getColors(nColors);
            }
        } else if (colors.size() < nColors) {
            // Just update existing list of colors (add new ones if there are more values now)
            final List<Color> newColors = scheme.getColors(nColors);
            if (newColors.size() > colors.size())
                colors.addAll(newColors.subList(colors.size(), newColors.size()));
        }
    }
    // Build list of editable colors
    getColorListPnl().removeAll();
    for (int i = 0; i < total; i++) {
        final Color c = colors.size() > i ? colors.get(i) : Color.GRAY;
        final ColorPanel cp = new ColorPanel(c, "");
        style(cp, i);
        getColorListPnl().add(cp);
    }
    getColorListPnl().repaint();
    if (!colors.isEmpty())
        chart.set(COLORS, colors);
}
Also used : Color(java.awt.Color) ColorScheme(org.cytoscape.ding.customgraphics.ColorScheme) ArrayList(java.util.ArrayList) JList(javax.swing.JList) List(java.util.List)

Aggregations

ColorScheme (org.cytoscape.ding.customgraphics.ColorScheme)5 Color (java.awt.Color)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 JList (javax.swing.JList)1