org.jfree.util.TableOrder Java Examples

The following examples show how to use org.jfree.util.TableOrder. 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: CategoryToPieDatasetTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getIndex() method.
 */
@Test
public void testGetIndex() {
    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(0, d1.getIndex("C1"));
    assertEquals(1, d1.getIndex("C2"));
    assertEquals(-1, d1.getIndex("XX"));

    // try null
    boolean pass = false;
    try {
        d1.getIndex(null);
    }
    catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #2
Source File: MultiplePiePlot.java    From ccu-historian with GNU General Public License v3.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 #3
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 #4
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 #5
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 #6
Source File: CategoryToPieDataset.java    From ccu-historian with GNU General Public License v3.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 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 #8
Source File: MultiplePiePlot.java    From SIMVA-SoS 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();
    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 #9
Source File: CategoryToPieDataset.java    From SIMVA-SoS with Apache License 2.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 #10
Source File: CategoryToPieDatasetTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Some checks for the getIndex() method.
 */
@Test
public void testGetIndex() {
    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(0, d1.getIndex("C1"));
    assertEquals(1, d1.getIndex("C2"));
    assertEquals(-1, d1.getIndex("XX"));

    // try null
    boolean pass = false;
    try {
        d1.getIndex(null);
    }
    catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #11
Source File: CategoryToPieDataset.java    From opensim-gui with Apache License 2.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>.
 */
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 #12
Source File: CategoryToPieDatasetTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Some checks for the getIndex() method.
 */
@Test
public void testGetIndex() {
    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(0, d1.getIndex("C1"));
    assertEquals(1, d1.getIndex("C2"));
    assertEquals(-1, d1.getIndex("XX"));

    // try null
    boolean pass = false;
    try {
        d1.getIndex(null);
    }
    catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #13
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 #14
Source File: CategoryToPieDatasetTest.java    From openstock 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 #15
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 #16
Source File: MultiplePiePlot.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the data extract order (by row or by column) and sends a 
 * {@link PlotChangeEvent} to all registered listeners.
 * 
 * @param order  the order (<code>null</code> not permitted).
 */
public void setDataExtractOrder(TableOrder order) {
    if (order == null) {
        throw new IllegalArgumentException("Null 'order' argument");
    }
    this.dataExtractOrder = order;
    notifyListeners(new PlotChangeEvent(this));
}
 
Example #17
Source File: SpiderWebPlot.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Draws the label for one axis.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area
 * @param value  the value of the label (ignored).
 * @param cat  the category (zero-based index).
 * @param startAngle  the starting angle.
 * @param extent  the extent of the arc.
 */
protected void drawLabel(Graphics2D g2, Rectangle2D plotArea, double value,
                         int cat, double startAngle, double extent) {
    FontRenderContext frc = g2.getFontRenderContext();

    String label;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        // if series are in rows, then the categories are the column keys
        label = this.labelGenerator.generateColumnLabel(this.dataset, cat);
    }
    else {
        // if series are in columns, then the categories are the row keys
        label = this.labelGenerator.generateRowLabel(this.dataset, cat);
    }

    Rectangle2D labelBounds = getLabelFont().getStringBounds(label, frc);
    LineMetrics lm = getLabelFont().getLineMetrics(label, frc);
    double ascent = lm.getAscent();

    Point2D labelLocation = calculateLabelLocation(labelBounds, ascent,
            plotArea, startAngle);

    Composite saveComposite = g2.getComposite();

    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            1.0f));
    g2.setPaint(getLabelPaint());
    g2.setFont(getLabelFont());
    g2.drawString(label, (float) labelLocation.getX(),
            (float) labelLocation.getY());
    g2.setComposite(saveComposite);
}
 
Example #18
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 #19
Source File: CategoryToPieDataset.java    From ECG-Viewer with GNU General Public License v2.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 #20
Source File: CategoryToPieDatasetTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * For datasets, the equals() method just checks keys and values.
 */
@Test
public void testEquals() {
    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);
    DefaultPieDataset d2 = new DefaultPieDataset();
    d2.setValue("R1", 2.2);
    assertTrue(d1.equals(d2));
}
 
Example #21
Source File: SpiderWebPlot.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Draws the label for one axis.
 * 
 * @param g2  the graphics device.
 * @param plotArea  the plot area
 * @param value  the value of the label (ignored).
 * @param cat  the category (zero-based index).
 * @param startAngle  the starting angle.
 * @param extent  the extent of the arc.
 */
protected void drawLabel(Graphics2D g2, Rectangle2D plotArea, double value, 
                         int cat, double startAngle, double extent) {
    FontRenderContext frc = g2.getFontRenderContext();
 
    String label = null;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        // if series are in rows, then the categories are the column keys
        label = this.labelGenerator.generateColumnLabel(this.dataset, cat);
    }
    else {
        // if series are in columns, then the categories are the row keys
        label = this.labelGenerator.generateRowLabel(this.dataset, cat);
    }
 
    Rectangle2D labelBounds = getLabelFont().getStringBounds(label, frc);
    LineMetrics lm = getLabelFont().getLineMetrics(label, frc);
    double ascent = lm.getAscent();

    Point2D labelLocation = calculateLabelLocation(labelBounds, ascent, 
            plotArea, startAngle);

    Composite saveComposite = g2.getComposite();

    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 
            1.0f));
    g2.setPaint(getLabelPaint());
    g2.setFont(getLabelFont());
    g2.drawString(label, (float) labelLocation.getX(), 
            (float) labelLocation.getY());
    g2.setComposite(saveComposite);
}
 
Example #22
Source File: CategoryToPieDataset.java    From SIMVA-SoS with Apache License 2.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 #23
Source File: CategoryToPieDataset.java    From opensim-gui with Apache License 2.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.
 */
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 #24
Source File: SpiderWebPlot.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new spider web plot with the given dataset.
 *
 * @param dataset  the dataset.
 * @param extract  controls how data is extracted ({@link TableOrder#BY_ROW}
 *                 or {@link TableOrder#BY_COLUMN}).
 */
public SpiderWebPlot(CategoryDataset dataset, TableOrder extract) {
    super();
    ParamChecks.nullNotPermitted(extract, "extract");
    this.dataset = dataset;
    if (dataset != null) {
        dataset.addChangeListener(this);
    }

    this.dataExtractOrder = extract;
    this.headPercent = DEFAULT_HEAD;
    this.axisLabelGap = DEFAULT_AXIS_LABEL_GAP;
    this.axisLinePaint = Color.black;
    this.axisLineStroke = new BasicStroke(1.0f);

    this.interiorGap = DEFAULT_INTERIOR_GAP;
    this.startAngle = DEFAULT_START_ANGLE;
    this.direction = Rotation.CLOCKWISE;
    this.maxValue = DEFAULT_MAX_VALUE;

    this.seriesPaint = null;
    this.seriesPaintList = new PaintList();
    this.baseSeriesPaint = null;

    this.seriesOutlinePaint = null;
    this.seriesOutlinePaintList = new PaintList();
    this.baseSeriesOutlinePaint = DEFAULT_OUTLINE_PAINT;

    this.seriesOutlineStroke = null;
    this.seriesOutlineStrokeList = new StrokeList();
    this.baseSeriesOutlineStroke = DEFAULT_OUTLINE_STROKE;

    this.labelFont = DEFAULT_LABEL_FONT;
    this.labelPaint = DEFAULT_LABEL_PAINT;
    this.labelGenerator = new StandardCategoryItemLabelGenerator();

    this.legendItemShape = DEFAULT_LEGEND_ITEM_CIRCLE;
}
 
Example #25
Source File: SpiderWebPlot.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Draws the label for one axis.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area
 * @param value  the value of the label (ignored).
 * @param cat  the category (zero-based index).
 * @param startAngle  the starting angle.
 * @param extent  the extent of the arc.
 */
protected void drawLabel(Graphics2D g2, Rectangle2D plotArea, double value,
                         int cat, double startAngle, double extent) {
    FontRenderContext frc = g2.getFontRenderContext();

    String label;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        // if series are in rows, then the categories are the column keys
        label = this.labelGenerator.generateColumnLabel(this.dataset, cat);
    }
    else {
        // if series are in columns, then the categories are the row keys
        label = this.labelGenerator.generateRowLabel(this.dataset, cat);
    }

    Rectangle2D labelBounds = getLabelFont().getStringBounds(label, frc);
    LineMetrics lm = getLabelFont().getLineMetrics(label, frc);
    double ascent = lm.getAscent();

    Point2D labelLocation = calculateLabelLocation(labelBounds, ascent,
            plotArea, startAngle);

    Composite saveComposite = g2.getComposite();

    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            1.0f));
    g2.setPaint(getLabelPaint());
    g2.setFont(getLabelFont());
    g2.drawString(label, (float) labelLocation.getX(),
            (float) labelLocation.getY());
    g2.setComposite(saveComposite);
}
 
Example #26
Source File: SpiderWebPlot.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Draws the label for one axis.
 *
 * @param g2  the graphics device.
 * @param plotArea  the plot area
 * @param value  the value of the label (ignored).
 * @param cat  the category (zero-based index).
 * @param startAngle  the starting angle.
 * @param extent  the extent of the arc.
 */
protected void drawLabel(Graphics2D g2, Rectangle2D plotArea, double value,
                         int cat, double startAngle, double extent) {
    FontRenderContext frc = g2.getFontRenderContext();

    String label;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        // if series are in rows, then the categories are the column keys
        label = this.labelGenerator.generateColumnLabel(this.dataset, cat);
    }
    else {
        // if series are in columns, then the categories are the row keys
        label = this.labelGenerator.generateRowLabel(this.dataset, cat);
    }

    Rectangle2D labelBounds = getLabelFont().getStringBounds(label, frc);
    LineMetrics lm = getLabelFont().getLineMetrics(label, frc);
    double ascent = lm.getAscent();

    Point2D labelLocation = calculateLabelLocation(labelBounds, ascent,
            plotArea, startAngle);

    Composite saveComposite = g2.getComposite();

    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,
            1.0f));
    g2.setPaint(getLabelPaint());
    g2.setFont(getLabelFont());
    g2.drawString(label, (float) labelLocation.getX(),
            (float) labelLocation.getY());
    g2.setComposite(saveComposite);
}
 
Example #27
Source File: CategoryToPieDataset.java    From ccu-historian with GNU General Public License v3.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 #28
Source File: CategoryToPieDataset.java    From opensim-gui with Apache License 2.0 5 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.
 */
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 #29
Source File: SpiderWebPlot.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new spider web plot with the given dataset.
 * 
 * @param dataset  the dataset.
 * @param extract  controls how data is extracted ({@link TableOrder#BY_ROW}
 *                 or {@link TableOrder#BY_COLUMN}).
 */
public SpiderWebPlot(CategoryDataset dataset, TableOrder extract) {
    super();
    if (extract == null) {
        throw new IllegalArgumentException("Null 'extract' argument.");
    }
    this.dataset = dataset;
    if (dataset != null) {
        dataset.addChangeListener(this);
    }

    this.dataExtractOrder = extract;
    this.headPercent = DEFAULT_HEAD;
    this.axisLabelGap = DEFAULT_AXIS_LABEL_GAP;
    this.axisLinePaint = Color.black;
    this.axisLineStroke = new BasicStroke(1.0f);
    
    this.interiorGap = DEFAULT_INTERIOR_GAP;
    this.startAngle = DEFAULT_START_ANGLE;
    this.direction = Rotation.CLOCKWISE;
    this.maxValue = DEFAULT_MAX_VALUE;

    this.seriesPaint = null;
    this.seriesPaintList = new PaintList();
    this.baseSeriesPaint = null;

    this.seriesOutlinePaint = null;
    this.seriesOutlinePaintList = new PaintList();
    this.baseSeriesOutlinePaint = DEFAULT_OUTLINE_PAINT;

    this.seriesOutlineStroke = null;
    this.seriesOutlineStrokeList = new StrokeList();
    this.baseSeriesOutlineStroke = DEFAULT_OUTLINE_STROKE;

    this.labelFont = DEFAULT_LABEL_FONT;
    this.labelPaint = DEFAULT_LABEL_PAINT;
    this.labelGenerator = new StandardCategoryItemLabelGenerator();
    
    this.legendItemShape = DEFAULT_LEGEND_ITEM_CIRCLE;
}
 
Example #30
Source File: SpiderWebPlot.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new spider web plot with the given dataset.
 *
 * @param dataset  the dataset.
 * @param extract  controls how data is extracted ({@link TableOrder#BY_ROW}
 *                 or {@link TableOrder#BY_COLUMN}).
 */
public SpiderWebPlot(CategoryDataset dataset, TableOrder extract) {
    super();
    ParamChecks.nullNotPermitted(extract, "extract");
    this.dataset = dataset;
    if (dataset != null) {
        dataset.addChangeListener(this);
    }

    this.dataExtractOrder = extract;
    this.headPercent = DEFAULT_HEAD;
    this.axisLabelGap = DEFAULT_AXIS_LABEL_GAP;
    this.axisLinePaint = Color.black;
    this.axisLineStroke = new BasicStroke(1.0f);

    this.interiorGap = DEFAULT_INTERIOR_GAP;
    this.startAngle = DEFAULT_START_ANGLE;
    this.direction = Rotation.CLOCKWISE;
    this.maxValue = DEFAULT_MAX_VALUE;

    this.seriesPaint = null;
    this.seriesPaintList = new PaintList();
    this.baseSeriesPaint = null;

    this.seriesOutlinePaint = null;
    this.seriesOutlinePaintList = new PaintList();
    this.baseSeriesOutlinePaint = DEFAULT_OUTLINE_PAINT;

    this.seriesOutlineStroke = null;
    this.seriesOutlineStrokeList = new StrokeList();
    this.baseSeriesOutlineStroke = DEFAULT_OUTLINE_STROKE;

    this.labelFont = DEFAULT_LABEL_FONT;
    this.labelPaint = DEFAULT_LABEL_PAINT;
    this.labelGenerator = new StandardCategoryItemLabelGenerator();

    this.legendItemShape = DEFAULT_LEGEND_ITEM_CIRCLE;
}