Example usage for org.jfree.data.category CategoryToPieDataset getKey

List of usage examples for org.jfree.data.category CategoryToPieDataset getKey

Introduction

In this page you can find the example usage for org.jfree.data.category CategoryToPieDataset getKey.

Prototype

@Override
public Comparable getKey(int index) 

Source Link

Document

Returns the key at the specified index.

Usage

From source file:org.jfree.data.category.CategoryToPieDatasetTest.java

/**
 * Some checks for the getKey(int) method.
 *//*from w w w .ja v a  2 s .c  o m*/
@Test
public void testGetKey() {
    DefaultCategoryDataset underlying = new DefaultCategoryDataset();
    underlying.addValue(1.1, "R1", "C1");
    underlying.addValue(2.2, "R1", "C2");
    CategoryToPieDataset d1 = new CategoryToPieDataset(underlying, TableOrder.BY_ROW, 0);
    assertEquals(d1.getKey(0), "C1");
    assertEquals(d1.getKey(1), "C2");

    // check negative index throws exception
    try {
        /* Number n = */ d1.getKey(-1);
        fail("Expected IndexOutOfBoundsException.");
    } catch (IndexOutOfBoundsException e) {
        // this is expected
    }

    // check index == getItemCount() throws exception
    try {
        /* Number n = */ d1.getKey(d1.getItemCount());
        fail("Expected IndexOutOfBoundsException.");
    } catch (IndexOutOfBoundsException e) {
        // this is expected
    }

    // test null source
    CategoryToPieDataset p1 = new CategoryToPieDataset(null, TableOrder.BY_COLUMN, 0);
    try {
        /* Number n = */ p1.getKey(0);
        fail("Expected IndexOutOfBoundsException.");
    } catch (IndexOutOfBoundsException e) {
        // this is expected
    }
}

From source file:org.jfree.data.category.junit.CategoryToPieDatasetTest.java

/**
 * Some checks for the getKey(int) method.
 *///ww w  .  j  av  a  2  s.c  o  m
public void testGetKey() {
    DefaultCategoryDataset underlying = new DefaultCategoryDataset();
    underlying.addValue(1.1, "R1", "C1");
    underlying.addValue(2.2, "R1", "C2");
    CategoryToPieDataset d1 = new CategoryToPieDataset(underlying, TableOrder.BY_ROW, 0);
    assertEquals(d1.getKey(0), "C1");
    assertEquals(d1.getKey(1), "C2");

    // check negative index throws exception
    try {
        /* Number n = */ d1.getKey(-1);
        fail("Expected IndexOutOfBoundsException.");
    } catch (IndexOutOfBoundsException e) {
        // this is expected
    }

    // check index == getItemCount() throws exception
    try {
        /* Number n = */ d1.getKey(d1.getItemCount());
        fail("Expected IndexOutOfBoundsException.");
    } catch (IndexOutOfBoundsException e) {
        // this is expected
    }

    // test null source
    CategoryToPieDataset p1 = new CategoryToPieDataset(null, TableOrder.BY_COLUMN, 0);
    try {
        /* Number n = */ p1.getKey(0);
        fail("Expected IndexOutOfBoundsException.");
    } catch (IndexOutOfBoundsException e) {
        // this is expected
    }
}

From source file:org.openfaces.component.chart.impl.plots.PiePlotAdapter.java

private void sectorProcessing(PiePlot plot, PieChartView chartView, PieDataset dataset,
        CategoryDataset categoryDataset) {
    List<PieSectorProperties> sectors = chartView.getSectors();
    if (sectors == null || sectors.size() == 0)
        return;//from  w  w  w .  j ava  2 s  .co m

    for (PieSectorProperties sector : sectors) {
        DynamicPieGenerator generator = new DynamicPieGenerator(chartView, null);

        int index = -1;

        Float sectorPulled = sector.getPulled();
        if (dataset instanceof CategoryToPieDataset) {
            CategoryToPieDataset cds = (CategoryToPieDataset) dataset;
            int count = getIterationCount(cds);
            for (int q = 0; q < count; q++) {
                CategoryToPieDataset currPieDataset = new CategoryToPieDataset(categoryDataset, order, q);
                List keys = currPieDataset.getKeys();
                index = -1;
                for (int j = 0; j < keys.size(); j++) {
                    index++;

                    boolean conditionValue = generator.getConditionValue(sector, q, currPieDataset,
                            currPieDataset.getKey(j));
                    if (!conditionValue)
                        continue;

                    if (sectorPulled != null && sectorPulled > 0) {
                        plot.setExplodePercent(index, (double) sectorPulled);
                    }

                    StyleObjectModel cssSectorModel = sector.getStyleObjectModel();
                    if (cssSectorModel != null && cssSectorModel.getBorder() != null) {
                        StyleBorderModel border = cssSectorModel.getBorder();
                        Color borderColor = border.getColor();
                        if (borderColor != null) {
                            plot.setSectionOutlinePaint(index, borderColor);
                            plot.setSectionOutlineStroke(index, PropertiesConverter.toStroke(border));
                        }

                        Color sectorModelColor = cssSectorModel.getColor();
                        if (sectorModelColor != null) {
                            plot.setSectionPaint(index, sectorModelColor);
                        }
                    }
                }
            }
        } else {
            if (dataset == null || dataset.getKeys() == null)
                continue;

            for (int j = 0; j < dataset.getKeys().size(); j++) {
                index++;

                boolean conditionValue = generator.getConditionValue(sector, 0, dataset, dataset.getKey(j));
                if (!conditionValue)
                    continue;

                if (sectorPulled != null && sectorPulled > 0) {
                    plot.setExplodePercent(index, (double) sectorPulled);
                }

                StyleObjectModel cssSectorModel = sector.getStyleObjectModel();
                if (cssSectorModel != null && cssSectorModel.getBorder() != null) {
                    StyleBorderModel border = cssSectorModel.getBorder();
                    if (border.getColor() != null) {
                        plot.setSectionOutlinePaint(index, border.getColor());
                        plot.setSectionOutlineStroke(index, PropertiesConverter.toStroke(border));
                    }

                }
                if (cssSectorModel != null && cssSectorModel.getColor() != null) {
                    plot.setSectionPaint(index, cssSectorModel.getColor());
                }
            }
        }

    }

}

From source file:org.openfaces.component.chart.impl.plots.PiePlot3DAdapter.java

private void sectorProcessing(PiePlot plot, PieChartView chartView, PieDataset dataset,
        CategoryDataset categoryDataset) {
    java.util.List<PieSectorProperties> sectors = chartView.getSectors();
    if (sectors == null || sectors.size() == 0)
        return;//from   ww  w. j  a  va2 s  .c om

    for (PieSectorProperties sector : sectors) {
        DynamicPieGenerator generator = new DynamicPieGenerator(chartView, null);

        int index = -1;

        Float sectorPulled = sector.getPulled();
        if (dataset instanceof CategoryToPieDataset) {
            CategoryToPieDataset cds = (CategoryToPieDataset) dataset;
            int count = getIterationCount(cds);
            for (int q = 0; q < count; q++) {
                CategoryToPieDataset currPieDataset = new CategoryToPieDataset(categoryDataset, order, q);
                java.util.List keys = currPieDataset.getKeys();
                index = -1;
                for (int j = 0; j < keys.size(); j++) {
                    index++;

                    boolean conditionValue = generator.getConditionValue(sector, q, currPieDataset,
                            currPieDataset.getKey(j));
                    if (!conditionValue)
                        continue;

                    if (sectorPulled != null && sectorPulled > 0) {
                        plot.setExplodePercent(index, (double) sectorPulled);
                    }

                    StyleObjectModel cssSectorModel = sector.getStyleObjectModel();
                    if (cssSectorModel != null && cssSectorModel.getBorder() != null) {
                        StyleBorderModel border = cssSectorModel.getBorder();
                        Color borderColor = border.getColor();
                        if (borderColor != null) {
                            plot.setSectionOutlinePaint(index, borderColor);
                            plot.setSectionOutlineStroke(index, PropertiesConverter.toStroke(border));
                        }

                        Color sectorModelColor = cssSectorModel.getColor();
                        if (sectorModelColor != null) {
                            plot.setSectionPaint(index, sectorModelColor);
                        }
                    }
                }
            }
        } else {
            if (dataset == null || dataset.getKeys() == null)
                continue;

            for (int j = 0; j < dataset.getKeys().size(); j++) {
                index++;

                boolean conditionValue = generator.getConditionValue(sector, 0, dataset, dataset.getKey(j));
                if (!conditionValue)
                    continue;

                if (sectorPulled != null && sectorPulled > 0) {
                    plot.setExplodePercent(index, (double) sectorPulled);
                }

                StyleObjectModel cssSectorModel = sector.getStyleObjectModel();
                if (cssSectorModel != null && cssSectorModel.getBorder() != null) {
                    StyleBorderModel border = cssSectorModel.getBorder();
                    if (border.getColor() != null) {
                        plot.setSectionOutlinePaint(index, border.getColor());
                        plot.setSectionOutlineStroke(index, PropertiesConverter.toStroke(border));
                    }

                }
                if (cssSectorModel != null && cssSectorModel.getColor() != null) {
                    plot.setSectionPaint(index, cssSectorModel.getColor());
                }
            }
        }

    }

}