Java Code Examples for org.jfree.chart.plot.Crosshair#isLabelVisible()
The following examples show how to use
org.jfree.chart.plot.Crosshair#isLabelVisible() .
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: CrosshairOverlay.java From openstock with GNU General Public License v3.0 | 4 votes |
/** * Draws a crosshair horizontally across the plot. * * @param g2 the graphics target. * @param dataArea the data area. * @param y the y-value in Java2D space. * @param crosshair the crosshair. */ protected void drawHorizontalCrosshair(Graphics2D g2, Rectangle2D dataArea, double y, Crosshair crosshair) { if (y >= dataArea.getMinY() && y <= dataArea.getMaxY()) { Line2D line = new Line2D.Double(dataArea.getMinX(), y, dataArea.getMaxX(), y); Paint savedPaint = g2.getPaint(); Stroke savedStroke = g2.getStroke(); g2.setPaint(crosshair.getPaint()); g2.setStroke(crosshair.getStroke()); g2.draw(line); if (crosshair.isLabelVisible()) { String label = crosshair.getLabelGenerator().generateLabel( crosshair); RectangleAnchor anchor = crosshair.getLabelAnchor(); Point2D pt = calculateLabelPoint(line, anchor, 5, 5); float xx = (float) pt.getX(); float yy = (float) pt.getY(); TextAnchor alignPt = textAlignPtForLabelAnchorH(anchor); Shape hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); if (!dataArea.contains(hotspot.getBounds2D())) { anchor = flipAnchorV(anchor); pt = calculateLabelPoint(line, anchor, 5, 5); xx = (float) pt.getX(); yy = (float) pt.getY(); alignPt = textAlignPtForLabelAnchorH(anchor); hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); } g2.setPaint(crosshair.getLabelBackgroundPaint()); g2.fill(hotspot); g2.setPaint(crosshair.getLabelOutlinePaint()); g2.draw(hotspot); TextUtilities.drawAlignedString(label, g2, xx, yy, alignPt); } g2.setPaint(savedPaint); g2.setStroke(savedStroke); } }
Example 2
Source File: CrosshairOverlay.java From openstock with GNU General Public License v3.0 | 4 votes |
/** * Draws a crosshair vertically on the plot. * * @param g2 the graphics target. * @param dataArea the data area. * @param x the x-value in Java2D space. * @param crosshair the crosshair. */ protected void drawVerticalCrosshair(Graphics2D g2, Rectangle2D dataArea, double x, Crosshair crosshair) { if (x >= dataArea.getMinX() && x <= dataArea.getMaxX()) { Line2D line = new Line2D.Double(x, dataArea.getMinY(), x, dataArea.getMaxY()); Paint savedPaint = g2.getPaint(); Stroke savedStroke = g2.getStroke(); g2.setPaint(crosshair.getPaint()); g2.setStroke(crosshair.getStroke()); g2.draw(line); if (crosshair.isLabelVisible()) { String label = crosshair.getLabelGenerator().generateLabel( crosshair); RectangleAnchor anchor = crosshair.getLabelAnchor(); Point2D pt = calculateLabelPoint(line, anchor, 5, 5); float xx = (float) pt.getX(); float yy = (float) pt.getY(); TextAnchor alignPt = textAlignPtForLabelAnchorV(anchor); Shape hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); if (!dataArea.contains(hotspot.getBounds2D())) { anchor = flipAnchorH(anchor); pt = calculateLabelPoint(line, anchor, 5, 5); xx = (float) pt.getX(); yy = (float) pt.getY(); alignPt = textAlignPtForLabelAnchorV(anchor); hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); } g2.setPaint(crosshair.getLabelBackgroundPaint()); g2.fill(hotspot); g2.setPaint(crosshair.getLabelOutlinePaint()); g2.draw(hotspot); TextUtilities.drawAlignedString(label, g2, xx, yy, alignPt); } g2.setPaint(savedPaint); g2.setStroke(savedStroke); } }
Example 3
Source File: CrosshairOverlay.java From ccu-historian with GNU General Public License v3.0 | 4 votes |
/** * Draws a crosshair horizontally across the plot. * * @param g2 the graphics target. * @param dataArea the data area. * @param y the y-value in Java2D space. * @param crosshair the crosshair. */ protected void drawHorizontalCrosshair(Graphics2D g2, Rectangle2D dataArea, double y, Crosshair crosshair) { if (y >= dataArea.getMinY() && y <= dataArea.getMaxY()) { Line2D line = new Line2D.Double(dataArea.getMinX(), y, dataArea.getMaxX(), y); Paint savedPaint = g2.getPaint(); Stroke savedStroke = g2.getStroke(); g2.setPaint(crosshair.getPaint()); g2.setStroke(crosshair.getStroke()); g2.draw(line); if (crosshair.isLabelVisible()) { String label = crosshair.getLabelGenerator().generateLabel( crosshair); RectangleAnchor anchor = crosshair.getLabelAnchor(); Point2D pt = calculateLabelPoint(line, anchor, 5, 5); float xx = (float) pt.getX(); float yy = (float) pt.getY(); TextAnchor alignPt = textAlignPtForLabelAnchorH(anchor); Shape hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); if (!dataArea.contains(hotspot.getBounds2D())) { anchor = flipAnchorV(anchor); pt = calculateLabelPoint(line, anchor, 5, 5); xx = (float) pt.getX(); yy = (float) pt.getY(); alignPt = textAlignPtForLabelAnchorH(anchor); hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); } g2.setPaint(crosshair.getLabelBackgroundPaint()); g2.fill(hotspot); g2.setPaint(crosshair.getLabelOutlinePaint()); g2.draw(hotspot); TextUtilities.drawAlignedString(label, g2, xx, yy, alignPt); } g2.setPaint(savedPaint); g2.setStroke(savedStroke); } }
Example 4
Source File: CrosshairOverlay.java From ccu-historian with GNU General Public License v3.0 | 4 votes |
/** * Draws a crosshair vertically on the plot. * * @param g2 the graphics target. * @param dataArea the data area. * @param x the x-value in Java2D space. * @param crosshair the crosshair. */ protected void drawVerticalCrosshair(Graphics2D g2, Rectangle2D dataArea, double x, Crosshair crosshair) { if (x >= dataArea.getMinX() && x <= dataArea.getMaxX()) { Line2D line = new Line2D.Double(x, dataArea.getMinY(), x, dataArea.getMaxY()); Paint savedPaint = g2.getPaint(); Stroke savedStroke = g2.getStroke(); g2.setPaint(crosshair.getPaint()); g2.setStroke(crosshair.getStroke()); g2.draw(line); if (crosshair.isLabelVisible()) { String label = crosshair.getLabelGenerator().generateLabel( crosshair); RectangleAnchor anchor = crosshair.getLabelAnchor(); Point2D pt = calculateLabelPoint(line, anchor, 5, 5); float xx = (float) pt.getX(); float yy = (float) pt.getY(); TextAnchor alignPt = textAlignPtForLabelAnchorV(anchor); Shape hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); if (!dataArea.contains(hotspot.getBounds2D())) { anchor = flipAnchorH(anchor); pt = calculateLabelPoint(line, anchor, 5, 5); xx = (float) pt.getX(); yy = (float) pt.getY(); alignPt = textAlignPtForLabelAnchorV(anchor); hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); } g2.setPaint(crosshair.getLabelBackgroundPaint()); g2.fill(hotspot); g2.setPaint(crosshair.getLabelOutlinePaint()); g2.draw(hotspot); TextUtilities.drawAlignedString(label, g2, xx, yy, alignPt); } g2.setPaint(savedPaint); g2.setStroke(savedStroke); } }
Example 5
Source File: CrosshairOverlay.java From SIMVA-SoS with Apache License 2.0 | 4 votes |
/** * Draws a crosshair horizontally across the plot. * * @param g2 the graphics target. * @param dataArea the data area. * @param y the y-value in Java2D space. * @param crosshair the crosshair. */ protected void drawHorizontalCrosshair(Graphics2D g2, Rectangle2D dataArea, double y, Crosshair crosshair) { if (y >= dataArea.getMinY() && y <= dataArea.getMaxY()) { Line2D line = new Line2D.Double(dataArea.getMinX(), y, dataArea.getMaxX(), y); Paint savedPaint = g2.getPaint(); Stroke savedStroke = g2.getStroke(); g2.setPaint(crosshair.getPaint()); g2.setStroke(crosshair.getStroke()); g2.draw(line); if (crosshair.isLabelVisible()) { String label = crosshair.getLabelGenerator().generateLabel( crosshair); RectangleAnchor anchor = crosshair.getLabelAnchor(); Point2D pt = calculateLabelPoint(line, anchor, 5, 5); float xx = (float) pt.getX(); float yy = (float) pt.getY(); TextAnchor alignPt = textAlignPtForLabelAnchorH(anchor); Shape hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); if (!dataArea.contains(hotspot.getBounds2D())) { anchor = flipAnchorV(anchor); pt = calculateLabelPoint(line, anchor, 5, 5); xx = (float) pt.getX(); yy = (float) pt.getY(); alignPt = textAlignPtForLabelAnchorH(anchor); hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); } g2.setPaint(crosshair.getLabelBackgroundPaint()); g2.fill(hotspot); g2.setPaint(crosshair.getLabelOutlinePaint()); g2.draw(hotspot); TextUtilities.drawAlignedString(label, g2, xx, yy, alignPt); } g2.setPaint(savedPaint); g2.setStroke(savedStroke); } }
Example 6
Source File: CrosshairOverlay.java From SIMVA-SoS with Apache License 2.0 | 4 votes |
/** * Draws a crosshair vertically on the plot. * * @param g2 the graphics target. * @param dataArea the data area. * @param x the x-value in Java2D space. * @param crosshair the crosshair. */ protected void drawVerticalCrosshair(Graphics2D g2, Rectangle2D dataArea, double x, Crosshair crosshair) { if (x >= dataArea.getMinX() && x <= dataArea.getMaxX()) { Line2D line = new Line2D.Double(x, dataArea.getMinY(), x, dataArea.getMaxY()); Paint savedPaint = g2.getPaint(); Stroke savedStroke = g2.getStroke(); g2.setPaint(crosshair.getPaint()); g2.setStroke(crosshair.getStroke()); g2.draw(line); if (crosshair.isLabelVisible()) { String label = crosshair.getLabelGenerator().generateLabel( crosshair); RectangleAnchor anchor = crosshair.getLabelAnchor(); Point2D pt = calculateLabelPoint(line, anchor, 5, 5); float xx = (float) pt.getX(); float yy = (float) pt.getY(); TextAnchor alignPt = textAlignPtForLabelAnchorV(anchor); Shape hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); if (!dataArea.contains(hotspot.getBounds2D())) { anchor = flipAnchorH(anchor); pt = calculateLabelPoint(line, anchor, 5, 5); xx = (float) pt.getX(); yy = (float) pt.getY(); alignPt = textAlignPtForLabelAnchorV(anchor); hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); } g2.setPaint(crosshair.getLabelBackgroundPaint()); g2.fill(hotspot); g2.setPaint(crosshair.getLabelOutlinePaint()); g2.draw(hotspot); TextUtilities.drawAlignedString(label, g2, xx, yy, alignPt); } g2.setPaint(savedPaint); g2.setStroke(savedStroke); } }
Example 7
Source File: CrosshairOverlay.java From ECG-Viewer with GNU General Public License v2.0 | 4 votes |
/** * Draws a crosshair horizontally across the plot. * * @param g2 the graphics target. * @param dataArea the data area. * @param y the y-value in Java2D space. * @param crosshair the crosshair. */ protected void drawHorizontalCrosshair(Graphics2D g2, Rectangle2D dataArea, double y, Crosshair crosshair) { if (y >= dataArea.getMinY() && y <= dataArea.getMaxY()) { Line2D line = new Line2D.Double(dataArea.getMinX(), y, dataArea.getMaxX(), y); Paint savedPaint = g2.getPaint(); Stroke savedStroke = g2.getStroke(); g2.setPaint(crosshair.getPaint()); g2.setStroke(crosshair.getStroke()); g2.draw(line); if (crosshair.isLabelVisible()) { String label = crosshair.getLabelGenerator().generateLabel( crosshair); RectangleAnchor anchor = crosshair.getLabelAnchor(); Point2D pt = calculateLabelPoint(line, anchor, 5, 5); float xx = (float) pt.getX(); float yy = (float) pt.getY(); TextAnchor alignPt = textAlignPtForLabelAnchorH(anchor); Shape hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); if (!dataArea.contains(hotspot.getBounds2D())) { anchor = flipAnchorV(anchor); pt = calculateLabelPoint(line, anchor, 5, 5); xx = (float) pt.getX(); yy = (float) pt.getY(); alignPt = textAlignPtForLabelAnchorH(anchor); hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); } g2.setPaint(crosshair.getLabelBackgroundPaint()); g2.fill(hotspot); g2.setPaint(crosshair.getLabelOutlinePaint()); g2.draw(hotspot); TextUtilities.drawAlignedString(label, g2, xx, yy, alignPt); } g2.setPaint(savedPaint); g2.setStroke(savedStroke); } }
Example 8
Source File: CrosshairOverlay.java From ECG-Viewer with GNU General Public License v2.0 | 4 votes |
/** * Draws a crosshair vertically on the plot. * * @param g2 the graphics target. * @param dataArea the data area. * @param x the x-value in Java2D space. * @param crosshair the crosshair. */ protected void drawVerticalCrosshair(Graphics2D g2, Rectangle2D dataArea, double x, Crosshair crosshair) { if (x >= dataArea.getMinX() && x <= dataArea.getMaxX()) { Line2D line = new Line2D.Double(x, dataArea.getMinY(), x, dataArea.getMaxY()); Paint savedPaint = g2.getPaint(); Stroke savedStroke = g2.getStroke(); g2.setPaint(crosshair.getPaint()); g2.setStroke(crosshair.getStroke()); g2.draw(line); if (crosshair.isLabelVisible()) { String label = crosshair.getLabelGenerator().generateLabel( crosshair); RectangleAnchor anchor = crosshair.getLabelAnchor(); Point2D pt = calculateLabelPoint(line, anchor, 5, 5); float xx = (float) pt.getX(); float yy = (float) pt.getY(); TextAnchor alignPt = textAlignPtForLabelAnchorV(anchor); Shape hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); if (!dataArea.contains(hotspot.getBounds2D())) { anchor = flipAnchorH(anchor); pt = calculateLabelPoint(line, anchor, 5, 5); xx = (float) pt.getX(); yy = (float) pt.getY(); alignPt = textAlignPtForLabelAnchorV(anchor); hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); } g2.setPaint(crosshair.getLabelBackgroundPaint()); g2.fill(hotspot); g2.setPaint(crosshair.getLabelOutlinePaint()); g2.draw(hotspot); TextUtilities.drawAlignedString(label, g2, xx, yy, alignPt); } g2.setPaint(savedPaint); g2.setStroke(savedStroke); } }
Example 9
Source File: CrosshairOverlay.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Draws a crosshair horizontally across the plot. * * @param g2 the graphics target. * @param dataArea the data area. * @param y the y-value in Java2D space. * @param crosshair the crosshair. */ protected void drawHorizontalCrosshair(Graphics2D g2, Rectangle2D dataArea, double y, Crosshair crosshair) { if (y >= dataArea.getMinY() && y <= dataArea.getMaxY()) { Line2D line = new Line2D.Double(dataArea.getMinX(), y, dataArea.getMaxX(), y); Paint savedPaint = g2.getPaint(); Stroke savedStroke = g2.getStroke(); g2.setPaint(crosshair.getPaint()); g2.setStroke(crosshair.getStroke()); g2.draw(line); if (crosshair.isLabelVisible()) { String label = crosshair.getLabelGenerator().generateLabel( crosshair); RectangleAnchor anchor = crosshair.getLabelAnchor(); Point2D pt = calculateLabelPoint(line, anchor, 5, 5); float xx = (float) pt.getX(); float yy = (float) pt.getY(); TextAnchor alignPt = textAlignPtForLabelAnchorH(anchor); Shape hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); if (!dataArea.contains(hotspot.getBounds2D())) { anchor = flipAnchorV(anchor); pt = calculateLabelPoint(line, anchor, 5, 5); xx = (float) pt.getX(); yy = (float) pt.getY(); alignPt = textAlignPtForLabelAnchorH(anchor); hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); } g2.setPaint(crosshair.getLabelBackgroundPaint()); g2.fill(hotspot); g2.setPaint(crosshair.getLabelOutlinePaint()); g2.draw(hotspot); TextUtilities.drawAlignedString(label, g2, xx, yy, alignPt); } g2.setPaint(savedPaint); g2.setStroke(savedStroke); } }
Example 10
Source File: CrosshairOverlay.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Draws a crosshair vertically on the plot. * * @param g2 the graphics target. * @param dataArea the data area. * @param x the x-value in Java2D space. * @param crosshair the crosshair. */ protected void drawVerticalCrosshair(Graphics2D g2, Rectangle2D dataArea, double x, Crosshair crosshair) { if (x >= dataArea.getMinX() && x <= dataArea.getMaxX()) { Line2D line = new Line2D.Double(x, dataArea.getMinY(), x, dataArea.getMaxY()); Paint savedPaint = g2.getPaint(); Stroke savedStroke = g2.getStroke(); g2.setPaint(crosshair.getPaint()); g2.setStroke(crosshair.getStroke()); g2.draw(line); if (crosshair.isLabelVisible()) { String label = crosshair.getLabelGenerator().generateLabel( crosshair); RectangleAnchor anchor = crosshair.getLabelAnchor(); Point2D pt = calculateLabelPoint(line, anchor, 5, 5); float xx = (float) pt.getX(); float yy = (float) pt.getY(); TextAnchor alignPt = textAlignPtForLabelAnchorV(anchor); Shape hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); if (!dataArea.contains(hotspot.getBounds2D())) { anchor = flipAnchorH(anchor); pt = calculateLabelPoint(line, anchor, 5, 5); xx = (float) pt.getX(); yy = (float) pt.getY(); alignPt = textAlignPtForLabelAnchorV(anchor); hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); } g2.setPaint(crosshair.getLabelBackgroundPaint()); g2.fill(hotspot); g2.setPaint(crosshair.getLabelOutlinePaint()); g2.draw(hotspot); TextUtilities.drawAlignedString(label, g2, xx, yy, alignPt); } g2.setPaint(savedPaint); g2.setStroke(savedStroke); } }
Example 11
Source File: CrosshairOverlay.java From buffer_bci with GNU General Public License v3.0 | 4 votes |
/** * Draws a crosshair horizontally across the plot. * * @param g2 the graphics target. * @param dataArea the data area. * @param y the y-value in Java2D space. * @param crosshair the crosshair. */ protected void drawHorizontalCrosshair(Graphics2D g2, Rectangle2D dataArea, double y, Crosshair crosshair) { if (y >= dataArea.getMinY() && y <= dataArea.getMaxY()) { Line2D line = new Line2D.Double(dataArea.getMinX(), y, dataArea.getMaxX(), y); Paint savedPaint = g2.getPaint(); Stroke savedStroke = g2.getStroke(); g2.setPaint(crosshair.getPaint()); g2.setStroke(crosshair.getStroke()); g2.draw(line); if (crosshair.isLabelVisible()) { String label = crosshair.getLabelGenerator().generateLabel( crosshair); RectangleAnchor anchor = crosshair.getLabelAnchor(); Point2D pt = calculateLabelPoint(line, anchor, 5, 5); float xx = (float) pt.getX(); float yy = (float) pt.getY(); TextAnchor alignPt = textAlignPtForLabelAnchorH(anchor); Shape hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); if (!dataArea.contains(hotspot.getBounds2D())) { anchor = flipAnchorV(anchor); pt = calculateLabelPoint(line, anchor, 5, 5); xx = (float) pt.getX(); yy = (float) pt.getY(); alignPt = textAlignPtForLabelAnchorH(anchor); hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); } g2.setPaint(crosshair.getLabelBackgroundPaint()); g2.fill(hotspot); g2.setPaint(crosshair.getLabelOutlinePaint()); g2.draw(hotspot); TextUtilities.drawAlignedString(label, g2, xx, yy, alignPt); } g2.setPaint(savedPaint); g2.setStroke(savedStroke); } }
Example 12
Source File: CrosshairOverlay.java From buffer_bci with GNU General Public License v3.0 | 4 votes |
/** * Draws a crosshair vertically on the plot. * * @param g2 the graphics target. * @param dataArea the data area. * @param x the x-value in Java2D space. * @param crosshair the crosshair. */ protected void drawVerticalCrosshair(Graphics2D g2, Rectangle2D dataArea, double x, Crosshair crosshair) { if (x >= dataArea.getMinX() && x <= dataArea.getMaxX()) { Line2D line = new Line2D.Double(x, dataArea.getMinY(), x, dataArea.getMaxY()); Paint savedPaint = g2.getPaint(); Stroke savedStroke = g2.getStroke(); g2.setPaint(crosshair.getPaint()); g2.setStroke(crosshair.getStroke()); g2.draw(line); if (crosshair.isLabelVisible()) { String label = crosshair.getLabelGenerator().generateLabel( crosshair); RectangleAnchor anchor = crosshair.getLabelAnchor(); Point2D pt = calculateLabelPoint(line, anchor, 5, 5); float xx = (float) pt.getX(); float yy = (float) pt.getY(); TextAnchor alignPt = textAlignPtForLabelAnchorV(anchor); Shape hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); if (!dataArea.contains(hotspot.getBounds2D())) { anchor = flipAnchorH(anchor); pt = calculateLabelPoint(line, anchor, 5, 5); xx = (float) pt.getX(); yy = (float) pt.getY(); alignPt = textAlignPtForLabelAnchorV(anchor); hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); } g2.setPaint(crosshair.getLabelBackgroundPaint()); g2.fill(hotspot); g2.setPaint(crosshair.getLabelOutlinePaint()); g2.draw(hotspot); TextUtilities.drawAlignedString(label, g2, xx, yy, alignPt); } g2.setPaint(savedPaint); g2.setStroke(savedStroke); } }
Example 13
Source File: CrosshairOverlay.java From buffer_bci with GNU General Public License v3.0 | 4 votes |
/** * Draws a crosshair horizontally across the plot. * * @param g2 the graphics target. * @param dataArea the data area. * @param y the y-value in Java2D space. * @param crosshair the crosshair. */ protected void drawHorizontalCrosshair(Graphics2D g2, Rectangle2D dataArea, double y, Crosshair crosshair) { if (y >= dataArea.getMinY() && y <= dataArea.getMaxY()) { Line2D line = new Line2D.Double(dataArea.getMinX(), y, dataArea.getMaxX(), y); Paint savedPaint = g2.getPaint(); Stroke savedStroke = g2.getStroke(); g2.setPaint(crosshair.getPaint()); g2.setStroke(crosshair.getStroke()); g2.draw(line); if (crosshair.isLabelVisible()) { String label = crosshair.getLabelGenerator().generateLabel( crosshair); RectangleAnchor anchor = crosshair.getLabelAnchor(); Point2D pt = calculateLabelPoint(line, anchor, 5, 5); float xx = (float) pt.getX(); float yy = (float) pt.getY(); TextAnchor alignPt = textAlignPtForLabelAnchorH(anchor); Shape hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); if (!dataArea.contains(hotspot.getBounds2D())) { anchor = flipAnchorV(anchor); pt = calculateLabelPoint(line, anchor, 5, 5); xx = (float) pt.getX(); yy = (float) pt.getY(); alignPt = textAlignPtForLabelAnchorH(anchor); hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); } g2.setPaint(crosshair.getLabelBackgroundPaint()); g2.fill(hotspot); g2.setPaint(crosshair.getLabelOutlinePaint()); g2.draw(hotspot); TextUtilities.drawAlignedString(label, g2, xx, yy, alignPt); } g2.setPaint(savedPaint); g2.setStroke(savedStroke); } }
Example 14
Source File: CrosshairOverlay.java From buffer_bci with GNU General Public License v3.0 | 4 votes |
/** * Draws a crosshair vertically on the plot. * * @param g2 the graphics target. * @param dataArea the data area. * @param x the x-value in Java2D space. * @param crosshair the crosshair. */ protected void drawVerticalCrosshair(Graphics2D g2, Rectangle2D dataArea, double x, Crosshair crosshair) { if (x >= dataArea.getMinX() && x <= dataArea.getMaxX()) { Line2D line = new Line2D.Double(x, dataArea.getMinY(), x, dataArea.getMaxY()); Paint savedPaint = g2.getPaint(); Stroke savedStroke = g2.getStroke(); g2.setPaint(crosshair.getPaint()); g2.setStroke(crosshair.getStroke()); g2.draw(line); if (crosshair.isLabelVisible()) { String label = crosshair.getLabelGenerator().generateLabel( crosshair); RectangleAnchor anchor = crosshair.getLabelAnchor(); Point2D pt = calculateLabelPoint(line, anchor, 5, 5); float xx = (float) pt.getX(); float yy = (float) pt.getY(); TextAnchor alignPt = textAlignPtForLabelAnchorV(anchor); Shape hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); if (!dataArea.contains(hotspot.getBounds2D())) { anchor = flipAnchorH(anchor); pt = calculateLabelPoint(line, anchor, 5, 5); xx = (float) pt.getX(); yy = (float) pt.getY(); alignPt = textAlignPtForLabelAnchorV(anchor); hotspot = TextUtilities.calculateRotatedStringBounds( label, g2, xx, yy, alignPt, 0.0, TextAnchor.CENTER); } g2.setPaint(crosshair.getLabelBackgroundPaint()); g2.fill(hotspot); g2.setPaint(crosshair.getLabelOutlinePaint()); g2.draw(hotspot); TextUtilities.drawAlignedString(label, g2, xx, yy, alignPt); } g2.setPaint(savedPaint); g2.setStroke(savedStroke); } }