Java Code Examples for org.jfree.chart.labels.XYItemLabelGenerator#generateLabel()
The following examples show how to use
org.jfree.chart.labels.XYItemLabelGenerator#generateLabel() .
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: CustomClusteredXYBarRenderer.java From openbd-core with GNU General Public License v3.0 | 5 votes |
private void drawItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, Rectangle2D bar, boolean negative) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); if (generator == null) return; String label = generator.generateLabel(dataset, series, item); if (label == null) { return; // nothing to do } Font labelFont = getItemLabelFont(series, item); g2.setFont(labelFont); Paint paint = getItemLabelPaint(series, item); g2.setPaint(paint); // find out where to place the label... ItemLabelPosition position = null; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, orientation); TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); }
Example 2
Source File: AbstractXYItemRenderer.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * Draws an item label. * * @param g2 the graphics device. * @param orientation the orientation. * @param dataset the dataset. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param x the x coordinate (in Java2D space). * @param y the y coordinate (in Java2D space). * @param negative indicates a negative value (which affects the item * label position). */ protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, double x, double y, boolean negative) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); if (generator != null) { Font labelFont = getItemLabelFont(series, item); Paint paint = getItemLabelPaint(series, item); g2.setFont(labelFont); g2.setPaint(paint); String label = generator.generateLabel(dataset, series, item); // get the label position.. ItemLabelPosition position; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), x, y, orientation); TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
Example 3
Source File: AbstractXYItemRenderer.java From opensim-gui with Apache License 2.0 | 5 votes |
/** * Draws an item label. * * @param g2 the graphics device. * @param orientation the orientation. * @param dataset the dataset. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param x the x coordinate (in Java2D space). * @param y the y coordinate (in Java2D space). * @param negative indicates a negative value (which affects the item * label position). */ protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, double x, double y, boolean negative) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); if (generator != null) { Font labelFont = getItemLabelFont(series, item); Paint paint = getItemLabelPaint(series, item); g2.setFont(labelFont); g2.setPaint(paint); String label = generator.generateLabel(dataset, series, item); // get the label position.. ItemLabelPosition position = null; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), x, y, orientation); TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
Example 4
Source File: AbstractXYItemRenderer.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Draws an item label. * * @param g2 the graphics device. * @param orientation the orientation. * @param dataset the dataset. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param x the x coordinate (in Java2D space). * @param y the y coordinate (in Java2D space). * @param negative indicates a negative value (which affects the item * label position). */ protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, double x, double y, boolean negative) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); if (generator != null) { Font labelFont = getItemLabelFont(series, item); Paint paint = getItemLabelPaint(series, item); g2.setFont(labelFont); g2.setPaint(paint); String label = generator.generateLabel(dataset, series, item); // get the label position.. ItemLabelPosition position = null; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), x, y, orientation); TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
Example 5
Source File: AbstractXYItemRenderer.java From ECG-Viewer with GNU General Public License v2.0 | 5 votes |
/** * Draws an item label. * * @param g2 the graphics device. * @param orientation the orientation. * @param dataset the dataset. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param x the x coordinate (in Java2D space). * @param y the y coordinate (in Java2D space). * @param negative indicates a negative value (which affects the item * label position). */ protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, double x, double y, boolean negative) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); if (generator != null) { Font labelFont = getItemLabelFont(series, item); Paint paint = getItemLabelPaint(series, item); g2.setFont(labelFont); g2.setPaint(paint); String label = generator.generateLabel(dataset, series, item); // get the label position.. ItemLabelPosition position; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), x, y, orientation); TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
Example 6
Source File: AbstractXYItemRenderer.java From openstock with GNU General Public License v3.0 | 5 votes |
/** * Draws an item label. * * @param g2 the graphics device. * @param orientation the orientation. * @param dataset the dataset. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param x the x coordinate (in Java2D space). * @param y the y coordinate (in Java2D space). * @param negative indicates a negative value (which affects the item * label position). */ protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, double x, double y, boolean negative) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); if (generator != null) { Font labelFont = getItemLabelFont(series, item); Paint paint = getItemLabelPaint(series, item); g2.setFont(labelFont); g2.setPaint(paint); String label = generator.generateLabel(dataset, series, item); // get the label position.. ItemLabelPosition position; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), x, y, orientation); TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
Example 7
Source File: ScatterPlotRenderer.java From mzmine2 with GNU General Public License v2.0 | 5 votes |
/** * Draws an item label. * * @param g2 the graphics device. * @param orientation the orientation. * @param dataset the dataset. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param x the x coordinate (in Java2D space). * @param y the y coordinate (in Java2D space). * @param negative indicates a negative value (which affects the item label position). */ protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, double x, double y, boolean negative) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); Font labelFont = getItemLabelFont(series, item); g2.setFont(labelFont); String label = generator.generateLabel(dataset, series, item); if ((label == null) || (label.length() == 0)) return; // get the label position.. ItemLabelPosition position = null; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), x, y, orientation); FontMetrics metrics = g2.getFontMetrics(labelFont); int width = SwingUtilities.computeStringWidth(metrics, label) + 2; int height = metrics.getHeight(); int X = (int) (anchorPoint.getX() - (width / 2)); int Y = (int) (anchorPoint.getY() - (height)); g2.setPaint(searchColor); g2.fillRect(X, Y, width, height); super.drawItemLabel(g2, orientation, dataset, series, item, x, y, negative); }
Example 8
Source File: AbstractXYItemRenderer.java From buffer_bci with GNU General Public License v3.0 | 5 votes |
/** * Draws an item label. * * @param g2 the graphics device. * @param orientation the orientation. * @param dataset the dataset. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param x the x coordinate (in Java2D space). * @param y the y coordinate (in Java2D space). * @param negative indicates a negative value (which affects the item * label position). */ protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, double x, double y, boolean negative) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); if (generator != null) { Font labelFont = getItemLabelFont(series, item); Paint paint = getItemLabelPaint(series, item); g2.setFont(labelFont); g2.setPaint(paint); String label = generator.generateLabel(dataset, series, item); // get the label position.. ItemLabelPosition position; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), x, y, orientation); TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
Example 9
Source File: AbstractXYItemRenderer.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
/** * Draws an item label. * * @param g2 the graphics device. * @param orientation the orientation. * @param dataset the dataset. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param x the x coordinate (in Java2D space). * @param y the y coordinate (in Java2D space). * @param negative indicates a negative value (which affects the item * label position). */ protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, double x, double y, boolean negative) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); if (generator != null) { Font labelFont = getItemLabelFont(series, item); Paint paint = getItemLabelPaint(series, item); g2.setFont(labelFont); g2.setPaint(paint); String label = generator.generateLabel(dataset, series, item); // get the label position.. ItemLabelPosition position; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), x, y, orientation); TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
Example 10
Source File: ScatterPlotRenderer.java From mzmine3 with GNU General Public License v2.0 | 5 votes |
/** * Draws an item label. * * @param g2 the graphics device. * @param orientation the orientation. * @param dataset the dataset. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param x the x coordinate (in Java2D space). * @param y the y coordinate (in Java2D space). * @param negative indicates a negative value (which affects the item label position). */ protected void drawItemLabel(Graphics2D g2, PlotOrientation orientation, XYDataset dataset, int series, int item, double x, double y, boolean negative) { XYItemLabelGenerator generator = getItemLabelGenerator(series, item); Font labelFont = getItemLabelFont(series, item); g2.setFont(labelFont); String label = generator.generateLabel(dataset, series, item); if ((label == null) || (label.length() == 0)) return; // get the label position.. ItemLabelPosition position = null; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), x, y, orientation); FontMetrics metrics = g2.getFontMetrics(labelFont); int width = SwingUtilities.computeStringWidth(metrics, label) + 2; int height = metrics.getHeight(); int X = (int) (anchorPoint.getX() - (width / 2)); int Y = (int) (anchorPoint.getY() - (height)); g2.setPaint(searchColor); g2.fillRect(X, Y, width, height); super.drawItemLabel(g2, orientation, dataset, series, item, x, y, negative); }
Example 11
Source File: XYBarRenderer.java From SIMVA-SoS with Apache License 2.0 | 4 votes |
/** * Draws an item label. This method is provided as an alternative to * {@link #drawItemLabel(Graphics2D, PlotOrientation, XYDataset, int, int, * double, double, boolean)} so that the bar can be used to calculate the * label anchor point. * * @param g2 the graphics device. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param plot the plot. * @param generator the label generator (<code>null</code> permitted, in * which case the method does nothing, just returns). * @param bar the bar. * @param negative a flag indicating a negative value. */ protected void drawItemLabel(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot, XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) { if (generator == null) { return; // nothing to do } String label = generator.generateLabel(dataset, series, item); if (label == null) { return; // nothing to do } Font labelFont = getItemLabelFont(series, item); g2.setFont(labelFont); Paint paint = getItemLabelPaint(series, item); g2.setPaint(paint); // find out where to place the label... ItemLabelPosition position; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), bar, plot.getOrientation()); if (isInternalAnchor(position.getItemLabelAnchor())) { Shape bounds = TextUtilities.calculateRotatedStringBounds(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); if (bounds != null) { if (!bar.contains(bounds.getBounds2D())) { if (!negative) { position = getPositiveItemLabelPositionFallback(); } else { position = getNegativeItemLabelPositionFallback(); } if (position != null) { anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), bar, plot.getOrientation()); } } } } if (position != null) { TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
Example 12
Source File: PseudoSpectraRenderer.java From mzmine2 with GNU General Public License v2.0 | 4 votes |
@Override protected void drawItemLabel(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot, XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) { // super.drawItemLabel(g2, dataset, series, item, plot, generator, bar, negative); if (generator != null) { String label = generator.generateLabel(dataset, series, item); if (label != null) { Font labelFont = getItemLabelFont(series, item); Paint paint = getItemLabelPaint(series, item); g2.setFont(labelFont); g2.setPaint(paint); // get the label position.. ItemLabelPosition position; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, plot.getOrientation()); // split by \n String symbol = "\n"; String[] splitted = label.split(symbol); if (splitted.length > 1) { FontRenderContext frc = g2.getFontRenderContext(); GlyphVector gv = g2.getFont().createGlyphVector(frc, "Fg,"); int height = 4 + (int) gv.getPixelBounds(null, 0, 0).getHeight(); // draw more than one row for (int i = 0; i < splitted.length; i++) { int offset = -height * (splitted.length - i - 1); TextUtils.drawRotatedString(splitted[i], g2, (float) anchorPoint.getX(), (float) anchorPoint.getY() + offset, position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } } else { // one row TextUtils.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } } } }
Example 13
Source File: XYBarRenderer.java From ccu-historian with GNU General Public License v3.0 | 4 votes |
/** * Draws an item label. This method is provided as an alternative to * {@link #drawItemLabel(Graphics2D, PlotOrientation, XYDataset, int, int, * double, double, boolean)} so that the bar can be used to calculate the * label anchor point. * * @param g2 the graphics device. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param plot the plot. * @param generator the label generator (<code>null</code> permitted, in * which case the method does nothing, just returns). * @param bar the bar. * @param negative a flag indicating a negative value. */ protected void drawItemLabel(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot, XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) { if (generator == null) { return; // nothing to do } String label = generator.generateLabel(dataset, series, item); if (label == null) { return; // nothing to do } Font labelFont = getItemLabelFont(series, item); g2.setFont(labelFont); Paint paint = getItemLabelPaint(series, item); g2.setPaint(paint); // find out where to place the label... ItemLabelPosition position; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), bar, plot.getOrientation()); if (isInternalAnchor(position.getItemLabelAnchor())) { Shape bounds = TextUtilities.calculateRotatedStringBounds(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); if (bounds != null) { if (!bar.contains(bounds.getBounds2D())) { if (!negative) { position = getPositiveItemLabelPositionFallback(); } else { position = getNegativeItemLabelPositionFallback(); } if (position != null) { anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), bar, plot.getOrientation()); } } } } if (position != null) { TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
Example 14
Source File: XYBarRenderer.java From buffer_bci with GNU General Public License v3.0 | 4 votes |
/** * Draws an item label. This method is provided as an alternative to * {@link #drawItemLabel(Graphics2D, PlotOrientation, XYDataset, int, int, * double, double, boolean)} so that the bar can be used to calculate the * label anchor point. * * @param g2 the graphics device. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param plot the plot. * @param generator the label generator (<code>null</code> permitted, in * which case the method does nothing, just returns). * @param bar the bar. * @param negative a flag indicating a negative value. */ protected void drawItemLabel(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot, XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) { if (generator == null) { return; // nothing to do } String label = generator.generateLabel(dataset, series, item); if (label == null) { return; // nothing to do } Font labelFont = getItemLabelFont(series, item); g2.setFont(labelFont); Paint paint = getItemLabelPaint(series, item); g2.setPaint(paint); // find out where to place the label... ItemLabelPosition position; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), bar, plot.getOrientation()); if (isInternalAnchor(position.getItemLabelAnchor())) { Shape bounds = TextUtilities.calculateRotatedStringBounds(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); if (bounds != null) { if (!bar.contains(bounds.getBounds2D())) { if (!negative) { position = getPositiveItemLabelPositionFallback(); } else { position = getNegativeItemLabelPositionFallback(); } if (position != null) { anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), bar, plot.getOrientation()); } } } } if (position != null) { TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
Example 15
Source File: XYBarRenderer.java From buffer_bci with GNU General Public License v3.0 | 4 votes |
/** * Draws an item label. This method is provided as an alternative to * {@link #drawItemLabel(Graphics2D, PlotOrientation, XYDataset, int, int, * double, double, boolean)} so that the bar can be used to calculate the * label anchor point. * * @param g2 the graphics device. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param plot the plot. * @param generator the label generator (<code>null</code> permitted, in * which case the method does nothing, just returns). * @param bar the bar. * @param negative a flag indicating a negative value. */ protected void drawItemLabel(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot, XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) { if (generator == null) { return; // nothing to do } String label = generator.generateLabel(dataset, series, item); if (label == null) { return; // nothing to do } Font labelFont = getItemLabelFont(series, item); g2.setFont(labelFont); Paint paint = getItemLabelPaint(series, item); g2.setPaint(paint); // find out where to place the label... ItemLabelPosition position; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), bar, plot.getOrientation()); if (isInternalAnchor(position.getItemLabelAnchor())) { Shape bounds = TextUtilities.calculateRotatedStringBounds(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); if (bounds != null) { if (!bar.contains(bounds.getBounds2D())) { if (!negative) { position = getPositiveItemLabelPositionFallback(); } else { position = getNegativeItemLabelPositionFallback(); } if (position != null) { anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), bar, plot.getOrientation()); } } } } if (position != null) { TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
Example 16
Source File: XYBarRenderer.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Draws an item label. This method is provided as an alternative to * {@link #drawItemLabel(Graphics2D, PlotOrientation, XYDataset, int, int, * double, double, boolean)} so that the bar can be used to calculate the * label anchor point. * * @param g2 the graphics device. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param selected is the data item selected? * @param plot the plot. * @param generator the label generator (<code>null</code> permitted, in * which case the method does nothing, just returns). * @param bar the bar. * @param negative a flag indicating a negative value. * * @since 1.2.0 */ protected void drawItemLabelForBar(Graphics2D g2, XYPlot plot, XYDataset dataset, int series, int item, boolean selected, XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) { if (generator == null) { return; // nothing to do } String label = generator.generateLabel(dataset, series, item); if (label == null) { return; // nothing to do } Font labelFont = getItemLabelFont(series, item, selected); g2.setFont(labelFont); Paint paint = getItemLabelPaint(series, item, selected); g2.setPaint(paint); // find out where to place the label... ItemLabelPosition position = null; if (!negative) { position = getPositiveItemLabelPosition(series, item, selected); } else { position = getNegativeItemLabelPosition(series, item, selected); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), bar, plot.getOrientation()); if (isInternalAnchor(position.getItemLabelAnchor())) { Shape bounds = TextUtilities.calculateRotatedStringBounds(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); if (bounds != null) { if (!bar.contains(bounds.getBounds2D())) { if (!negative) { position = getPositiveItemLabelPositionFallback(); } else { position = getNegativeItemLabelPositionFallback(); } if (position != null) { anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), bar, plot.getOrientation()); } } } } if (position != null) { TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
Example 17
Source File: XYBarRenderer.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Draws an item label. This method is provided as an alternative to * {@link #drawItemLabel(Graphics2D, PlotOrientation, XYDataset, int, int, * double, double, boolean)} so that the bar can be used to calculate the * label anchor point. * * @param g2 the graphics device. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param plot the plot. * @param generator the label generator (<code>null</code> permitted, in * which case the method does nothing, just returns). * @param bar the bar. * @param negative a flag indicating a negative value. */ protected void drawItemLabel(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot, XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) { if (generator == null) { return; // nothing to do } String label = generator.generateLabel(dataset, series, item); if (label == null) { return; // nothing to do } Font labelFont = getItemLabelFont(series, item); g2.setFont(labelFont); Paint paint = getItemLabelPaint(series, item); g2.setPaint(paint); // find out where to place the label... ItemLabelPosition position = null; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), bar, plot.getOrientation()); if (isInternalAnchor(position.getItemLabelAnchor())) { Shape bounds = TextUtilities.calculateRotatedStringBounds(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); if (bounds != null) { if (!bar.contains(bounds.getBounds2D())) { if (!negative) { position = getPositiveItemLabelPositionFallback(); } else { position = getNegativeItemLabelPositionFallback(); } if (position != null) { anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), bar, plot.getOrientation()); } } } } if (position != null) { TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
Example 18
Source File: PseudoSpectraRenderer.java From mzmine3 with GNU General Public License v2.0 | 4 votes |
@Override protected void drawItemLabel(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot, XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) { // super.drawItemLabel(g2, dataset, series, item, plot, generator, bar, // negative); if (generator != null) { String label = generator.generateLabel(dataset, series, item); if (label != null) { Font labelFont = getItemLabelFont(series, item); Paint paint = getItemLabelPaint(series, item); g2.setFont(labelFont); g2.setPaint(paint); // get the label position.. ItemLabelPosition position; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint(position.getItemLabelAnchor(), bar, plot.getOrientation()); // split by \n String symbol = "\n"; String[] splitted = label.split(symbol); if (splitted.length > 1) { FontRenderContext frc = g2.getFontRenderContext(); GlyphVector gv = g2.getFont().createGlyphVector(frc, "Fg,"); int height = 4 + (int) gv.getPixelBounds(null, 0, 0).getHeight(); // draw more than one row for (int i = 0; i < splitted.length; i++) { int offset = -height * (splitted.length - i - 1); TextUtils.drawRotatedString(splitted[i], g2, (float) anchorPoint.getX(), (float) anchorPoint.getY() + offset, position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } } else { // one row TextUtils.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } } } }
Example 19
Source File: XYBarRenderer.java From opensim-gui with Apache License 2.0 | 4 votes |
/** * Draws an item label. This method is overridden so that the bar can be * used to calculate the label anchor point. * * @param g2 the graphics device. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param plot the plot. * @param generator the label generator. * @param bar the bar. * @param negative a flag indicating a negative value. */ protected void drawItemLabel(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot, XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) { String label = generator.generateLabel(dataset, series, item); if (label == null) { return; // nothing to do } Font labelFont = getItemLabelFont(series, item); g2.setFont(labelFont); Paint paint = getItemLabelPaint(series, item); g2.setPaint(paint); // find out where to place the label... ItemLabelPosition position = null; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), bar, plot.getOrientation()); if (isInternalAnchor(position.getItemLabelAnchor())) { Shape bounds = TextUtilities.calculateRotatedStringBounds(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); if (bounds != null) { if (!bar.contains(bounds.getBounds2D())) { if (!negative) { position = getPositiveItemLabelPositionFallback(); } else { position = getNegativeItemLabelPositionFallback(); } if (position != null) { anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), bar, plot.getOrientation()); } } } } if (position != null) { TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }
Example 20
Source File: XYBarRenderer.java From openstock with GNU General Public License v3.0 | 4 votes |
/** * Draws an item label. This method is provided as an alternative to * {@link #drawItemLabel(Graphics2D, PlotOrientation, XYDataset, int, int, * double, double, boolean)} so that the bar can be used to calculate the * label anchor point. * * @param g2 the graphics device. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param plot the plot. * @param generator the label generator (<code>null</code> permitted, in * which case the method does nothing, just returns). * @param bar the bar. * @param negative a flag indicating a negative value. */ protected void drawItemLabel(Graphics2D g2, XYDataset dataset, int series, int item, XYPlot plot, XYItemLabelGenerator generator, Rectangle2D bar, boolean negative) { if (generator == null) { return; // nothing to do } String label = generator.generateLabel(dataset, series, item); if (label == null) { return; // nothing to do } Font labelFont = getItemLabelFont(series, item); g2.setFont(labelFont); Paint paint = getItemLabelPaint(series, item); g2.setPaint(paint); // find out where to place the label... ItemLabelPosition position; if (!negative) { position = getPositiveItemLabelPosition(series, item); } else { position = getNegativeItemLabelPosition(series, item); } // work out the label anchor point... Point2D anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), bar, plot.getOrientation()); if (isInternalAnchor(position.getItemLabelAnchor())) { Shape bounds = TextUtilities.calculateRotatedStringBounds(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); if (bounds != null) { if (!bar.contains(bounds.getBounds2D())) { if (!negative) { position = getPositiveItemLabelPositionFallback(); } else { position = getNegativeItemLabelPositionFallback(); } if (position != null) { anchorPoint = calculateLabelAnchorPoint( position.getItemLabelAnchor(), bar, plot.getOrientation()); } } } } if (position != null) { TextUtilities.drawRotatedString(label, g2, (float) anchorPoint.getX(), (float) anchorPoint.getY(), position.getTextAnchor(), position.getAngle(), position.getRotationAnchor()); } }