Java Code Examples for org.jfree.util.TableOrder#BY_COLUMN

The following examples show how to use org.jfree.util.TableOrder#BY_COLUMN . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CategoryToPieDataset.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a value from the dataset.
 *
 * @param item  the item index (zero-based).
 *
 * @return The value (possibly <code>null</code>).
 *
 * @throws IndexOutOfBoundsException if <code>item</code> is not in the
 *     range <code>0</code> to <code>getItemCount() - 1</code>.
 */
@Override
public Number getValue(int item) {
    Number result = null;
    if (item < 0 || item >= getItemCount()) {
        // this will include the case where the underlying dataset is null
        throw new IndexOutOfBoundsException(
                "The 'item' index is out of bounds.");
    }
    if (this.extract == TableOrder.BY_ROW) {
        result = this.source.getValue(this.index, item);
    }
    else if (this.extract == TableOrder.BY_COLUMN) {
        result = this.source.getValue(item, this.index);
    }
    return result;
}
 
Example 2
Source File: CategoryToPieDataset.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a value from the dataset.
 *
 * @param item  the item index (zero-based).
 *
 * @return The value (possibly <code>null</code>).
 *
 * @throws IndexOutOfBoundsException if <code>item</code> is not in the
 *     range <code>0</code> to <code>getItemCount() - 1</code>.
 */
@Override
public Number getValue(int item) {
    Number result = null;
    if (item < 0 || item >= getItemCount()) {
        // this will include the case where the underlying dataset is null
        throw new IndexOutOfBoundsException(
                "The 'item' index is out of bounds.");
    }
    if (this.extract == TableOrder.BY_ROW) {
        result = this.source.getValue(this.index, item);
    }
    else if (this.extract == TableOrder.BY_COLUMN) {
        result = this.source.getValue(item, this.index);
    }
    return result;
}
 
Example 3
Source File: CategoryToPieDatasetTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    DefaultCategoryDataset underlying = new DefaultCategoryDataset();
    underlying.addValue(1.1, "R1", "C1");
    underlying.addValue(2.2, "R1", "C2");
    CategoryToPieDataset d1 = new CategoryToPieDataset(underlying,
            TableOrder.BY_COLUMN, 1);
    CategoryToPieDataset d2 = (CategoryToPieDataset) 
            TestUtilities.serialised(d1);
    assertEquals(d1, d2);

    // regular equality for the datasets doesn't check the fields, just
    // the data values...so let's check some more things...
    assertEquals(d1.getUnderlyingDataset(), d2.getUnderlyingDataset());
    assertEquals(d1.getExtractType(), d2.getExtractType());
    assertEquals(d1.getExtractIndex(), d2.getExtractIndex());
}
 
Example 4
Source File: CategoryToPieDatasetTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    DefaultCategoryDataset underlying = new DefaultCategoryDataset();
    underlying.addValue(1.1, "R1", "C1");
    underlying.addValue(2.2, "R1", "C2");
    CategoryToPieDataset d1 = new CategoryToPieDataset(underlying,
            TableOrder.BY_COLUMN, 1);
    CategoryToPieDataset d2 = (CategoryToPieDataset) 
            TestUtilities.serialised(d1);
    assertEquals(d1, d2);

    // regular equality for the datasets doesn't check the fields, just
    // the data values...so let's check some more things...
    assertEquals(d1.getUnderlyingDataset(), d2.getUnderlyingDataset());
    assertEquals(d1.getExtractType(), d2.getExtractType());
    assertEquals(d1.getExtractIndex(), d2.getExtractIndex());
}
 
Example 5
Source File: CategoryToPieDatasetTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization() {
    DefaultCategoryDataset underlying = new DefaultCategoryDataset();
    underlying.addValue(1.1, "R1", "C1");
    underlying.addValue(2.2, "R1", "C2");
    CategoryToPieDataset d1 = new CategoryToPieDataset(underlying,
            TableOrder.BY_COLUMN, 1);
    CategoryToPieDataset d2 = (CategoryToPieDataset) 
            TestUtilities.serialised(d1);
    assertEquals(d1, d2);

    // regular equality for the datasets doesn't check the fields, just
    // the data values...so let's check some more things...
    assertEquals(d1.getUnderlyingDataset(), d2.getUnderlyingDataset());
    assertEquals(d1.getExtractType(), d2.getExtractType());
    assertEquals(d1.getExtractIndex(), d2.getExtractIndex());
}
 
Example 6
Source File: CategoryToPieDataset.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the key at the specified index.
 *
 * @param index  the item index (in the range <code>0</code> to
 *     <code>getItemCount() - 1</code>).
 *
 * @return The key.
 *
 * @throws IndexOutOfBoundsException if <code>index</code> is not in the
 *     specified range.
 */
@Override
public Comparable getKey(int index) {
    Comparable result = null;
    if (index < 0 || index >= getItemCount()) {
        // this includes the case where the underlying dataset is null
        throw new IndexOutOfBoundsException("Invalid 'index': " + index);
    }
    if (this.extract == TableOrder.BY_ROW) {
        result = this.source.getColumnKey(index);
    }
    else if (this.extract == TableOrder.BY_COLUMN) {
        result = this.source.getRowKey(index);
    }
    return result;
}
 
Example 7
Source File: CategoryToPieDataset.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a value from the dataset.
 *
 * @param item  the item index (zero-based).
 *
 * @return The value (possibly <code>null</code>).
 *
 * @throws IndexOutOfBoundsException if <code>item</code> is not in the
 *     range <code>0</code> to <code>getItemCount() - 1</code>.
 */
@Override
public Number getValue(int item) {
    Number result = null;
    if (item < 0 || item >= getItemCount()) {
        // this will include the case where the underlying dataset is null
        throw new IndexOutOfBoundsException(
                "The 'item' index is out of bounds.");
    }
    if (this.extract == TableOrder.BY_ROW) {
        result = this.source.getValue(this.index, item);
    }
    else if (this.extract == TableOrder.BY_COLUMN) {
        result = this.source.getValue(item, this.index);
    }
    return result;
}
 
Example 8
Source File: MultiplePiePlot.java    From opensim-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new plot.
 * 
 * @param dataset  the dataset (<code>null</code> permitted).
 */
public MultiplePiePlot(CategoryDataset dataset) {
    super();
    this.dataset = dataset;
    PiePlot piePlot = new PiePlot(null);
    this.pieChart = new JFreeChart(piePlot);
    this.pieChart.removeLegend();
    this.dataExtractOrder = TableOrder.BY_COLUMN;
    this.pieChart.setBackgroundPaint(null);
    TextTitle seriesTitle = new TextTitle("Series Title", 
            new Font("SansSerif", Font.BOLD, 12));
    seriesTitle.setPosition(RectangleEdge.BOTTOM);
    this.pieChart.setTitle(seriesTitle);
    this.aggregatedItemsKey = "Other";
    this.aggregatedItemsPaint = Color.lightGray;
    this.sectionPaints = new HashMap();
}
 
Example 9
Source File: MultiplePiePlot.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new plot.
 *
 * @param dataset  the dataset (<code>null</code> permitted).
 */
public MultiplePiePlot(CategoryDataset dataset) {
    super();
    setDataset(dataset);
    PiePlot piePlot = new PiePlot(null);
    piePlot.setIgnoreNullValues(true);
    this.pieChart = new JFreeChart(piePlot);
    this.pieChart.removeLegend();
    this.dataExtractOrder = TableOrder.BY_COLUMN;
    this.pieChart.setBackgroundPaint(null);
    TextTitle seriesTitle = new TextTitle("Series Title",
            new Font("SansSerif", Font.BOLD, 12));
    seriesTitle.setPosition(RectangleEdge.BOTTOM);
    this.pieChart.setTitle(seriesTitle);
    this.aggregatedItemsKey = "Other";
    this.aggregatedItemsPaint = Color.lightGray;
    this.sectionPaints = new HashMap();
    this.legendItemShape = new Ellipse2D.Double(-4.0, -4.0, 8.0, 8.0);
}
 
Example 10
Source File: SpiderWebPlot.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a collection of legend items for the spider web chart.
 *
 * @return The legend items (never <code>null</code>).
 */
@Override
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();
    if (getDataset() == null) {
        return result;
    }
    List keys = null;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        keys = this.dataset.getRowKeys();
    }
    else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        keys = this.dataset.getColumnKeys();
    }
    if (keys == null) {
        return result;
    }

    int series = 0;
    Iterator iterator = keys.iterator();
    Shape shape = getLegendItemShape();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        String label = key.toString();
        String description = label;
        Paint paint = getSeriesPaint(series);
        Paint outlinePaint = getSeriesOutlinePaint(series);
        Stroke stroke = getSeriesOutlineStroke(series);
        LegendItem item = new LegendItem(label, description,
                null, null, shape, paint, stroke, outlinePaint);
        item.setDataset(getDataset());
        item.setSeriesKey(key);
        item.setSeriesIndex(series);
        result.add(item);
        series++;
    }
    return result;
}
 
Example 11
Source File: CategoryToPieDataset.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the value for a given key.  If the key is not recognised, the
 * method should return <code>null</code> (but note that <code>null</code>
 * can be associated with a valid key also).
 *
 * @param key  the key.
 *
 * @return The value (possibly <code>null</code>).
 */
@Override
public Number getValue(Comparable key) {
    Number result = null;
    int keyIndex = getIndex(key);
    if (keyIndex != -1) {
        if (this.extract == TableOrder.BY_ROW) {
            result = this.source.getValue(this.index, keyIndex);
        }
        else if (this.extract == TableOrder.BY_COLUMN) {
            result = this.source.getValue(keyIndex, this.index);
        }
    }
    return result;
}
 
Example 12
Source File: CategoryToPieDataset.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the number of items (values) in the collection.  If the
 * underlying dataset is <code>null</code>, this method returns zero.
 *
 * @return The item count.
 */
@Override
public int getItemCount() {
    int result = 0;
    if (this.source != null) {
        if (this.extract == TableOrder.BY_ROW) {
            result = this.source.getColumnCount();
        }
        else if (this.extract == TableOrder.BY_COLUMN) {
            result = this.source.getRowCount();
        }
    }
    return result;
}
 
Example 13
Source File: SpiderWebPlot.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a collection of legend items for the spider web chart.
 *
 * @return The legend items (never <code>null</code>).
 */
@Override
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();
    if (getDataset() == null) {
        return result;
    }
    List keys = null;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        keys = this.dataset.getRowKeys();
    }
    else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        keys = this.dataset.getColumnKeys();
    }
    if (keys == null) {
        return result;
    }

    int series = 0;
    Iterator iterator = keys.iterator();
    Shape shape = getLegendItemShape();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        String label = key.toString();
        String description = label;
        Paint paint = getSeriesPaint(series);
        Paint outlinePaint = getSeriesOutlinePaint(series);
        Stroke stroke = getSeriesOutlineStroke(series);
        LegendItem item = new LegendItem(label, description,
                null, null, shape, paint, stroke, outlinePaint);
        item.setDataset(getDataset());
        item.setSeriesKey(key);
        item.setSeriesIndex(series);
        result.add(item);
        series++;
    }
    return result;
}
 
Example 14
Source File: CategoryToPieDataset.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the value for a given key.  If the key is not recognised, the
 * method should return <code>null</code> (but note that <code>null</code>
 * can be associated with a valid key also).
 *
 * @param key  the key.
 *
 * @return The value (possibly <code>null</code>).
 */
@Override
public Number getValue(Comparable key) {
    Number result = null;
    int keyIndex = getIndex(key);
    if (keyIndex != -1) {
        if (this.extract == TableOrder.BY_ROW) {
            result = this.source.getValue(this.index, keyIndex);
        }
        else if (this.extract == TableOrder.BY_COLUMN) {
            result = this.source.getValue(keyIndex, this.index);
        }
    }
    return result;
}
 
Example 15
Source File: CategoryToPieDatasetTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Some tests for the constructor.
 */
@Test
public void testConstructor() {
    // try a null source
    CategoryToPieDataset p1 = new CategoryToPieDataset(null,
            TableOrder.BY_COLUMN, 0);
    assertNull(p1.getUnderlyingDataset());
    assertEquals(p1.getItemCount(), 0);
    assertTrue(p1.getKeys().isEmpty());
    assertNull(p1.getValue("R1"));
}
 
Example 16
Source File: CategoryToPieDataset.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the keys for the dataset.
 * <p>
 * If the underlying dataset is <code>null</code>, this method returns an
 * empty list.
 *
 * @return The keys.
 */
@Override
public List getKeys() {
    List result = Collections.EMPTY_LIST;
    if (this.source != null) {
        if (this.extract == TableOrder.BY_ROW) {
            result = this.source.getColumnKeys();
        }
        else if (this.extract == TableOrder.BY_COLUMN) {
            result = this.source.getRowKeys();
        }
    }
    return result;
}
 
Example 17
Source File: MultiplePiePlot.java    From openstock with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a collection of legend items for the pie chart.
 *
 * @return The legend items.
 */
@Override
public LegendItemCollection getLegendItems() {

    LegendItemCollection result = new LegendItemCollection();
    if (this.dataset == null) {
        return result;
    }

    List keys = null;
    prefetchSectionPaints();
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        keys = this.dataset.getColumnKeys();
    }
    else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        keys = this.dataset.getRowKeys();
    }
    if (keys == null) {
        return result;
    }
    int section = 0;
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        String label = key.toString();  // TODO: use a generator here
        String description = label;
        Paint paint = (Paint) this.sectionPaints.get(key);
        LegendItem item = new LegendItem(label, description, null,
                null, getLegendItemShape(), paint,
                Plot.DEFAULT_OUTLINE_STROKE, paint);
        item.setSeriesKey(key);
        item.setSeriesIndex(section);
        item.setDataset(getDataset());
        result.add(item);
        section++;
    }
    if (this.limit > 0.0) {
        LegendItem a = new LegendItem(this.aggregatedItemsKey.toString(),
                this.aggregatedItemsKey.toString(), null, null,
                getLegendItemShape(), this.aggregatedItemsPaint,
                Plot.DEFAULT_OUTLINE_STROKE, this.aggregatedItemsPaint);
        result.add(a);
    }
    return result;
}
 
Example 18
Source File: MultiplePiePlot.java    From ccu-historian with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Returns a collection of legend items for the pie chart.
 *
 * @return The legend items.
 */
@Override
public LegendItemCollection getLegendItems() {

    LegendItemCollection result = new LegendItemCollection();
    if (this.dataset == null) {
        return result;
    }

    List keys = null;
    prefetchSectionPaints();
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        keys = this.dataset.getColumnKeys();
    }
    else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        keys = this.dataset.getRowKeys();
    }
    if (keys == null) {
        return result;
    }
    int section = 0;
    Iterator iterator = keys.iterator();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        String label = key.toString();  // TODO: use a generator here
        String description = label;
        Paint paint = (Paint) this.sectionPaints.get(key);
        LegendItem item = new LegendItem(label, description, null,
                null, getLegendItemShape(), paint,
                Plot.DEFAULT_OUTLINE_STROKE, paint);
        item.setSeriesKey(key);
        item.setSeriesIndex(section);
        item.setDataset(getDataset());
        result.add(item);
        section++;
    }
    if (this.limit > 0.0) {
        LegendItem a = new LegendItem(this.aggregatedItemsKey.toString(),
                this.aggregatedItemsKey.toString(), null, null,
                getLegendItemShape(), this.aggregatedItemsPaint,
                Plot.DEFAULT_OUTLINE_STROKE, this.aggregatedItemsPaint);
        result.add(a);
    }
    return result;
}
 
Example 19
Source File: SpiderWebPlot.java    From SIMVA-SoS with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the value to be plotted at the interseries of the
 * series and the category.  This allows us to plot
 * <code>BY_ROW</code> or <code>BY_COLUMN</code> which basically is just
 * reversing the definition of the categories and data series being
 * plotted.
 *
 * @param series the series to be plotted.
 * @param cat the category within the series to be plotted.
 *
 * @return The value to be plotted (possibly <code>null</code>).
 *
 * @see #getDataExtractOrder()
 */
protected Number getPlotValue(int series, int cat) {
    Number value = null;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        value = this.dataset.getValue(series, cat);
    }
    else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        value = this.dataset.getValue(cat, series);
    }
    return value;
}
 
Example 20
Source File: SpiderWebPlot.java    From opensim-gui with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the value to be plotted at the interseries of the 
 * series and the category.  This allows us to plot
 * <code>BY_ROW</code> or <code>BY_COLUMN</code> which basically is just 
 * reversing the definition of the categories and data series being 
 * plotted.
 * 
 * @param series the series to be plotted.
 * @param cat the category within the series to be plotted.
 * 
 * @return The value to be plotted (possibly <code>null</code>).
 * 
 * @see #getDataExtractOrder()
 */
protected Number getPlotValue(int series, int cat) {
    Number value = null;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        value = this.dataset.getValue(series, cat);
    }
    else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        value = this.dataset.getValue(cat, series);
    }
    return value;
}