Java Code Examples for java.awt.Shape#intersects()
The following examples show how to use
java.awt.Shape#intersects() .
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: CompositePaintable.java From pumpernickel with MIT License | 6 votes |
private void paint(Graphics2D g, double dx, double dy) { if (bounds == null) refreshBounds(); for (int a = 0; a < paintables.size(); a++) { Graphics2D g2 = (Graphics2D) g.create(); g2.translate(dx, dy); g2.transform(transforms.get(a)); Paintable paintable = paintables.get(a); Shape clip = g2.getClip(); if (clip == null || clip.intersects(0, 0, paintable.getWidth(), paintable.getHeight())) { // g2.setColor(new Color( Color.HSBtoRGB( (float)(a)/.7f, .2f, // 1f) )); // g2.fillRect(0, 0, paintables.get(a).getWidth(), // paintables.get(a).getHeight() ); paintable.paint(g2); } g2.dispose(); } }
Example 2
Source File: FXGraphics2D.java From openstock with GNU General Public License v3.0 | 6 votes |
/** * Clips to the intersection of the current clipping region and the * specified shape. * * According to the Oracle API specification, this method will accept a * {@code null} argument, but there is an open bug report (since 2004) * that suggests this is wrong: * <p> * <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6206189"> * http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6206189</a> * * In this implementation, a {@code null} argument is not permitted. * * @param s the clip shape ({@code null} not permitted). */ @Override public void clip(Shape s) { if (this.clip == null) { setClip(s); return; } Shape ts = this.transform.createTransformedShape(s); Shape clipNew; if (!ts.intersects(this.clip.getBounds2D())) { clipNew = new Rectangle2D.Double(); } else { Area a1 = new Area(ts); Area a2 = new Area(this.clip); a1.intersect(a2); clipNew = new Path2D.Double(a1); } this.clip = clipNew; if (!this.clippingDisabled) { this.gc.save(); this.saveCount++; shapeToPath(this.clip); this.gc.clip(); } }
Example 3
Source File: TMAbstractEdge.java From ontopia with Apache License 2.0 | 5 votes |
@Override public double distFromPoint(double x, double y) { Shape shape = getDisplayShape(); if (shape == null) return super.distFromPoint(x, y); // Bit of a hack, but just because TG does something rather // stupid here anyway. if (shape.intersects(x -2, y-2, 4, 4)) return 0; return 1000; }
Example 4
Source File: ScreenTransform.java From rcrs-server with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** Find out if a shape is inside the current view bounds. @param s The shape to test. @return True if any part of the shape is inside the current view bounds, false otherwise. */ public boolean isInView(Shape s) { if (s == null) { return false; } return s.intersects(viewBounds); }
Example 5
Source File: Layer.java From rcrs-server with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Object[] getObjectsInArea(Rectangle2D r) { Collection result = new ArrayList(); for (Iterator it = objects.iterator();it.hasNext();) { Object next = it.next(); Shape s = (Shape)shapes.get(next); if (s!=null && s.intersects(r)) { result.add(next); } } return result.toArray(); }
Example 6
Source File: XYLineAndShapeRenderer.java From ccu-historian with GNU General Public License v3.0 | 4 votes |
/** * Draws the item shapes and adds chart entities (second pass). This method * draws the shapes which mark the item positions. If <code>entities</code> * is not <code>null</code> it will be populated with entity information * for points that fall within the data area. * * @param g2 the graphics device. * @param plot the plot (can be used to obtain standard color * information etc). * @param domainAxis the domain axis. * @param dataArea the area within which the data is being drawn. * @param rangeAxis the range axis. * @param dataset the dataset. * @param pass the pass. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState the crosshair state. * @param entities the entity collection. */ protected void drawSecondaryPass(Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, Rectangle2D dataArea, ValueAxis rangeAxis, CrosshairState crosshairState, EntityCollection entities) { Shape entityArea = null; // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(y1) || Double.isNaN(x1)) { return; } PlotOrientation orientation = plot.getOrientation(); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); if (getItemShapeVisible(series, item)) { Shape shape = getItemShape(series, item); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1); } entityArea = shape; if (shape.intersects(dataArea)) { if (getItemShapeFilled(series, item)) { if (this.useFillPaint) { g2.setPaint(getItemFillPaint(series, item)); } else { g2.setPaint(getItemPaint(series, item)); } g2.fill(shape); } if (this.drawOutlines) { if (getUseOutlinePaint()) { g2.setPaint(getItemOutlinePaint(series, item)); } else { g2.setPaint(getItemPaint(series, item)); } g2.setStroke(getItemOutlineStroke(series, item)); g2.draw(shape); } } } double xx = transX1; double yy = transY1; if (orientation == PlotOrientation.HORIZONTAL) { xx = transY1; yy = transX1; } // draw the item label if there is one... if (isItemLabelVisible(series, item)) { drawItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0)); } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, orientation); // add an entity for the item, but only if it falls within the data // area... if (entities != null && isPointInRect(dataArea, xx, yy)) { addEntity(entities, entityArea, dataset, series, item, xx, yy); } }
Example 7
Source File: XYLineAndShapeRenderer.java From buffer_bci with GNU General Public License v3.0 | 4 votes |
/** * Draws the item shapes and adds chart entities (second pass). This method * draws the shapes which mark the item positions. If <code>entities</code> * is not <code>null</code> it will be populated with entity information * for points that fall within the data area. * * @param g2 the graphics device. * @param plot the plot (can be used to obtain standard color * information etc). * @param domainAxis the domain axis. * @param dataArea the area within which the data is being drawn. * @param rangeAxis the range axis. * @param dataset the dataset. * @param pass the pass. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState the crosshair state. * @param entities the entity collection. */ protected void drawSecondaryPass(Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, Rectangle2D dataArea, ValueAxis rangeAxis, CrosshairState crosshairState, EntityCollection entities) { Shape entityArea = null; // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(y1) || Double.isNaN(x1)) { return; } PlotOrientation orientation = plot.getOrientation(); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); if (getItemShapeVisible(series, item)) { Shape shape = getItemShape(series, item); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1); } entityArea = shape; if (shape.intersects(dataArea)) { if (getItemShapeFilled(series, item)) { if (this.useFillPaint) { g2.setPaint(getItemFillPaint(series, item)); } else { g2.setPaint(getItemPaint(series, item)); } g2.fill(shape); } if (this.drawOutlines) { if (getUseOutlinePaint()) { g2.setPaint(getItemOutlinePaint(series, item)); } else { g2.setPaint(getItemPaint(series, item)); } g2.setStroke(getItemOutlineStroke(series, item)); g2.draw(shape); } } } double xx = transX1; double yy = transY1; if (orientation == PlotOrientation.HORIZONTAL) { xx = transY1; yy = transX1; } // draw the item label if there is one... if (isItemLabelVisible(series, item)) { drawItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0)); } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, orientation); // add an entity for the item, but only if it falls within the data // area... if (entities != null && isPointInRect(dataArea, xx, yy)) { addEntity(entities, entityArea, dataset, series, item, xx, yy); } }
Example 8
Source File: ColorizedShapeItemRenderer.java From rapidminer-studio with GNU Affero General Public License v3.0 | 4 votes |
/** * Draws the block representing the specified item. * * @param g2 * the graphics device. * @param state * the state. * @param dataArea * the data area. * @param info * the plot rendering info. * @param plot * the plot. * @param domainAxis * the x-axis. * @param rangeAxis * the y-axis. * @param dataset * the dataset. * @param series * the series index. * @param item * the item index. * @param crosshairState * the crosshair state. * @param pass * the pass index. */ @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { Shape hotspot = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); double colorValue = ((XYZDataset) dataset).getZValue(series, item); double normalized = (colorValue - minColor) / (maxColor - minColor); if (Double.isNaN(x) || Double.isNaN(y)) { // can't draw anything return; } double transX = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge()); double transY = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge()); PlotOrientation orientation = plot.getOrientation(); Shape shape = getItemShape(series, item); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY, transX); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX, transY); } hotspot = shape; if (shape.intersects(dataArea)) { g2.setPaint(colorProvider.getPointColor(normalized)); g2.fill(shape); if (getDrawOutlines()) { if (getUseOutlinePaint()) { g2.setPaint(getItemOutlinePaint(series, item)); } else { g2.setPaint(getItemPaint(series, item)); } g2.setStroke(getItemOutlineStroke(series, item)); g2.draw(shape); } } // add an entity for the item... if (entities != null) { addEntity(entities, hotspot, dataset, series, item, transX, transY); } }
Example 9
Source File: XYShapeRenderer.java From SIMVA-SoS with Apache License 2.0 | 4 votes |
/** * Draws the block representing the specified item. * * @param g2 the graphics device. * @param state the state. * @param dataArea the data area. * @param info the plot rendering info. * @param plot the plot. * @param domainAxis the x-axis. * @param rangeAxis the y-axis. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param crosshairState the crosshair state. * @param pass the pass index. */ @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { Shape hotspot; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); if (Double.isNaN(x) || Double.isNaN(y)) { // can't draw anything return; } double transX = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge()); double transY = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge()); PlotOrientation orientation = plot.getOrientation(); // draw optional guide lines if ((pass == 0) && this.guideLinesVisible) { g2.setStroke(this.guideLineStroke); g2.setPaint(this.guideLinePaint); if (orientation == PlotOrientation.HORIZONTAL) { g2.draw(new Line2D.Double(transY, dataArea.getMinY(), transY, dataArea.getMaxY())); g2.draw(new Line2D.Double(dataArea.getMinX(), transX, dataArea.getMaxX(), transX)); } else { g2.draw(new Line2D.Double(transX, dataArea.getMinY(), transX, dataArea.getMaxY())); g2.draw(new Line2D.Double(dataArea.getMinX(), transY, dataArea.getMaxX(), transY)); } } else if (pass == 1) { Shape shape = getItemShape(series, item); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY, transX); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX, transY); } hotspot = shape; if (shape.intersects(dataArea)) { //if (getItemShapeFilled(series, item)) { g2.setPaint(getPaint(dataset, series, item)); g2.fill(shape); //} if (this.drawOutlines) { if (getUseOutlinePaint()) { g2.setPaint(getItemOutlinePaint(series, item)); } else { g2.setPaint(getItemPaint(series, item)); } g2.setStroke(getItemOutlineStroke(series, item)); g2.draw(shape); } } // add an entity for the item... if (entities != null) { addEntity(entities, hotspot, dataset, series, item, transX, transY); } } }
Example 10
Source File: XYShapeRenderer.java From ECG-Viewer with GNU General Public License v2.0 | 4 votes |
/** * Draws the block representing the specified item. * * @param g2 the graphics device. * @param state the state. * @param dataArea the data area. * @param info the plot rendering info. * @param plot the plot. * @param domainAxis the x-axis. * @param rangeAxis the y-axis. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param crosshairState the crosshair state. * @param pass the pass index. */ @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { Shape hotspot; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); if (Double.isNaN(x) || Double.isNaN(y)) { // can't draw anything return; } double transX = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge()); double transY = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge()); PlotOrientation orientation = plot.getOrientation(); // draw optional guide lines if ((pass == 0) && this.guideLinesVisible) { g2.setStroke(this.guideLineStroke); g2.setPaint(this.guideLinePaint); if (orientation == PlotOrientation.HORIZONTAL) { g2.draw(new Line2D.Double(transY, dataArea.getMinY(), transY, dataArea.getMaxY())); g2.draw(new Line2D.Double(dataArea.getMinX(), transX, dataArea.getMaxX(), transX)); } else { g2.draw(new Line2D.Double(transX, dataArea.getMinY(), transX, dataArea.getMaxY())); g2.draw(new Line2D.Double(dataArea.getMinX(), transY, dataArea.getMaxX(), transY)); } } else if (pass == 1) { Shape shape = getItemShape(series, item); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY, transX); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX, transY); } hotspot = shape; if (shape.intersects(dataArea)) { //if (getItemShapeFilled(series, item)) { g2.setPaint(getPaint(dataset, series, item)); g2.fill(shape); //} if (this.drawOutlines) { if (getUseOutlinePaint()) { g2.setPaint(getItemOutlinePaint(series, item)); } else { g2.setPaint(getItemPaint(series, item)); } g2.setStroke(getItemOutlineStroke(series, item)); g2.draw(shape); } } // add an entity for the item... if (entities != null) { addEntity(entities, hotspot, dataset, series, item, transX, transY); } } }
Example 11
Source File: XYLineAndShapeRenderer.java From buffer_bci with GNU General Public License v3.0 | 4 votes |
/** * Draws the item shapes and adds chart entities (second pass). This method * draws the shapes which mark the item positions. If <code>entities</code> * is not <code>null</code> it will be populated with entity information * for points that fall within the data area. * * @param g2 the graphics device. * @param plot the plot (can be used to obtain standard color * information etc). * @param domainAxis the domain axis. * @param dataArea the area within which the data is being drawn. * @param rangeAxis the range axis. * @param dataset the dataset. * @param pass the pass. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState the crosshair state. * @param entities the entity collection. */ protected void drawSecondaryPass(Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, Rectangle2D dataArea, ValueAxis rangeAxis, CrosshairState crosshairState, EntityCollection entities) { Shape entityArea = null; // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(y1) || Double.isNaN(x1)) { return; } PlotOrientation orientation = plot.getOrientation(); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); if (getItemShapeVisible(series, item)) { Shape shape = getItemShape(series, item); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1); } entityArea = shape; if (shape.intersects(dataArea)) { if (getItemShapeFilled(series, item)) { if (this.useFillPaint) { g2.setPaint(getItemFillPaint(series, item)); } else { g2.setPaint(getItemPaint(series, item)); } g2.fill(shape); } if (this.drawOutlines) { if (getUseOutlinePaint()) { g2.setPaint(getItemOutlinePaint(series, item)); } else { g2.setPaint(getItemPaint(series, item)); } g2.setStroke(getItemOutlineStroke(series, item)); g2.draw(shape); } } } double xx = transX1; double yy = transY1; if (orientation == PlotOrientation.HORIZONTAL) { xx = transY1; yy = transX1; } // draw the item label if there is one... if (isItemLabelVisible(series, item)) { drawItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0)); } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, orientation); // add an entity for the item, but only if it falls within the data // area... if (entities != null && isPointInRect(dataArea, xx, yy)) { addEntity(entities, entityArea, dataset, series, item, xx, yy); } }
Example 12
Source File: XYLineAndShapeRenderer.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Draws the item shapes and adds chart entities (second pass). This method * draws the shapes which mark the item positions. If <code>entities</code> * is not <code>null</code> it will be populated with entity information * for points that fall within the data area. * * @param g2 the graphics device. * @param plot the plot (can be used to obtain standard color * information etc). * @param domainAxis the domain axis. * @param dataArea the area within which the data is being drawn. * @param rangeAxis the range axis. * @param dataset the dataset. * @param pass the pass. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param selected is the data item selected? * @param crosshairState the crosshair state. * @param entities the entity collection. */ protected void drawShape2(Graphics2D g2, Rectangle2D dataArea, XYPlot plot, XYDataset dataset, int pass, int series, int item, boolean selected, ValueAxis domainAxis, ValueAxis rangeAxis, CrosshairState crosshairState, EntityCollection entities) { Shape entityArea = null; // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(y1) || Double.isNaN(x1)) { return; } PlotOrientation orientation = plot.getOrientation(); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); if (getItemShapeVisible(series, item)) { Shape shape = getItemShape(series, item, selected); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1); } entityArea = shape; if (shape.intersects(dataArea)) { if (getItemShapeFilled(series, item)) { if (this.useFillPaint) { g2.setPaint(getItemFillPaint(series, item, selected)); } else { g2.setPaint(getItemPaint(series, item, selected)); } g2.fill(shape); } if (this.drawOutlines) { if (getUseOutlinePaint()) { g2.setPaint(getItemOutlinePaint(series, item, selected)); } else { g2.setPaint(getItemPaint(series, item, selected)); } g2.setStroke(getItemOutlineStroke(series, item, selected)); g2.draw(shape); } } } double xx = transX1; double yy = transY1; if (orientation == PlotOrientation.HORIZONTAL) { xx = transY1; yy = transX1; } // draw the item label if there is one... if (isItemLabelVisible(series, item, selected)) { drawItemLabel(g2, orientation, dataset, series, item, selected, xx, yy, (y1 < 0.0)); } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, orientation); // add an entity for the item, but only if it falls within the data // area... if (entities != null && ShapeUtilities.isPointInRect(xx, yy, dataArea)) { addEntity(entities, entityArea, dataset, series, item, selected, xx, yy); } }
Example 13
Source File: XYShapeRenderer.java From ccu-historian with GNU General Public License v3.0 | 4 votes |
/** * Draws the block representing the specified item. * * @param g2 the graphics device. * @param state the state. * @param dataArea the data area. * @param info the plot rendering info. * @param plot the plot. * @param domainAxis the x-axis. * @param rangeAxis the y-axis. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param crosshairState the crosshair state. * @param pass the pass index. */ @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { Shape hotspot; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); if (Double.isNaN(x) || Double.isNaN(y)) { // can't draw anything return; } double transX = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge()); double transY = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge()); PlotOrientation orientation = plot.getOrientation(); // draw optional guide lines if ((pass == 0) && this.guideLinesVisible) { g2.setStroke(this.guideLineStroke); g2.setPaint(this.guideLinePaint); if (orientation == PlotOrientation.HORIZONTAL) { g2.draw(new Line2D.Double(transY, dataArea.getMinY(), transY, dataArea.getMaxY())); g2.draw(new Line2D.Double(dataArea.getMinX(), transX, dataArea.getMaxX(), transX)); } else { g2.draw(new Line2D.Double(transX, dataArea.getMinY(), transX, dataArea.getMaxY())); g2.draw(new Line2D.Double(dataArea.getMinX(), transY, dataArea.getMaxX(), transY)); } } else if (pass == 1) { Shape shape = getItemShape(series, item); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY, transX); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX, transY); } hotspot = shape; if (shape.intersects(dataArea)) { //if (getItemShapeFilled(series, item)) { g2.setPaint(getPaint(dataset, series, item)); g2.fill(shape); //} if (this.drawOutlines) { if (getUseOutlinePaint()) { g2.setPaint(getItemOutlinePaint(series, item)); } else { g2.setPaint(getItemPaint(series, item)); } g2.setStroke(getItemOutlineStroke(series, item)); g2.draw(shape); } } // add an entity for the item... if (entities != null) { addEntity(entities, hotspot, dataset, series, item, transX, transY); } } }
Example 14
Source File: ChatPrinter.java From Spark with Apache License 2.0 | 4 votes |
private boolean printView(Graphics2D graphics2D, Shape allocation, View view) { boolean pageExists = false; Rectangle clipRectangle = graphics2D.getClipBounds(); Shape childAllocation; View childView; if (view.getViewCount() > 0) { for (int i = 0; i < view.getViewCount(); i++) { childAllocation = view.getChildAllocation(i, allocation); if (childAllocation != null) { childView = view.getView(i); if (printView(graphics2D, childAllocation, childView)) { pageExists = true; } } } } else { // I if (allocation.getBounds().getMaxY() >= clipRectangle.getY()) { pageExists = true; // II if ((allocation.getBounds().getHeight() > clipRectangle.getHeight()) && (allocation.intersects(clipRectangle))) { view.paint(graphics2D, allocation); } else { // III if (allocation.getBounds().getY() >= clipRectangle.getY()) { if (allocation.getBounds().getMaxY() <= clipRectangle.getMaxY()) { view.paint(graphics2D, allocation); } else { // IV if (allocation.getBounds().getY() < pageEndY) { pageEndY = allocation.getBounds().getY(); } } } } } } return pageExists; }
Example 15
Source File: HTMLPrintable.java From ramus with GNU General Public License v3.0 | 4 votes |
private boolean printView(final Graphics2D graphics2D, final Shape allocation, final View view) { boolean pageExists = false; final Rectangle clipRectangle = new Rectangle(0, 0, (int) (pageFormat .getImageableWidth() / SCALE), (int) clientHeight); Shape childAllocation; View childView; if (view.getViewCount() > 0) { for (int i = 0; i < view.getViewCount(); i++) { childAllocation = view.getChildAllocation(i, allocation); if (childAllocation != null) { childView = view.getView(i); if (printView(graphics2D, childAllocation, childView)) { pageExists = true; } } } } else { if (allocation.getBounds().getMaxY() >= clipRectangle.getY()) { if (allocation.getBounds().getHeight() > clipRectangle .getHeight() && allocation.intersects(clipRectangle)) { paintView(graphics2D, view, allocation); pageExists = true; } else { if (allocation.getBounds().getY() >= clipRectangle.getY()) { if (allocation.getBounds().getMaxY() <= clipRectangle .getMaxY()) { paintView(graphics2D, view, allocation); pageExists = true; } else { if (allocation.getBounds().getY() < pageEndY) { pageEndY = allocation.getBounds().getY(); } } } } } } return pageExists; }
Example 16
Source File: XYLineAndShapeRenderer.java From opensim-gui with Apache License 2.0 | 4 votes |
/** * Draws the item shapes and adds chart entities (second pass). This method * draws the shapes which mark the item positions. If <code>entities</code> * is not <code>null</code> it will be populated with entity information. * * @param g2 the graphics device. * @param dataArea the area within which the data is being drawn. * @param plot the plot (can be used to obtain standard color * information etc). * @param domainAxis the domain axis. * @param rangeAxis the range axis. * @param dataset the dataset. * @param pass the pass. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState the crosshair state. * @param entities the entity collection. */ protected void drawSecondaryPass(Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, Rectangle2D dataArea, ValueAxis rangeAxis, CrosshairState crosshairState, EntityCollection entities) { Shape entityArea = null; // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(y1) || Double.isNaN(x1)) { return; } PlotOrientation orientation = plot.getOrientation(); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); if (getItemShapeVisible(series, item)) { Shape shape = getItemShape(series, item); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1); } entityArea = shape; if (shape.intersects(dataArea)) { if (getItemShapeFilled(series, item)) { if (this.useFillPaint) { g2.setPaint(getItemFillPaint(series, item)); } else { g2.setPaint(getItemPaint(series, item)); } g2.fill(shape); } if (this.drawOutlines) { if (getUseOutlinePaint()) { g2.setPaint(getItemOutlinePaint(series, item)); } else { g2.setPaint(getItemPaint(series, item)); } g2.setStroke(getItemOutlineStroke(series, item)); g2.draw(shape); } } } // draw the item label if there is one... if (isItemLabelVisible(series, item)) { double xx = transX1; double yy = transY1; if (orientation == PlotOrientation.HORIZONTAL) { xx = transY1; yy = transX1; } drawItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0)); } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, plot.getOrientation()); // add an entity for the item... if (entities != null) { addEntity(entities, entityArea, dataset, series, item, transX1, transY1); } }
Example 17
Source File: XYShapeRenderer.java From openstock with GNU General Public License v3.0 | 4 votes |
/** * Draws the block representing the specified item. * * @param g2 the graphics device. * @param state the state. * @param dataArea the data area. * @param info the plot rendering info. * @param plot the plot. * @param domainAxis the x-axis. * @param rangeAxis the y-axis. * @param dataset the dataset. * @param series the series index. * @param item the item index. * @param crosshairState the crosshair state. * @param pass the pass index. */ @Override public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { Shape hotspot; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } double x = dataset.getXValue(series, item); double y = dataset.getYValue(series, item); if (Double.isNaN(x) || Double.isNaN(y)) { // can't draw anything return; } double transX = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge()); double transY = rangeAxis.valueToJava2D(y, dataArea, plot.getRangeAxisEdge()); PlotOrientation orientation = plot.getOrientation(); // draw optional guide lines if ((pass == 0) && this.guideLinesVisible) { g2.setStroke(this.guideLineStroke); g2.setPaint(this.guideLinePaint); if (orientation == PlotOrientation.HORIZONTAL) { g2.draw(new Line2D.Double(transY, dataArea.getMinY(), transY, dataArea.getMaxY())); g2.draw(new Line2D.Double(dataArea.getMinX(), transX, dataArea.getMaxX(), transX)); } else { g2.draw(new Line2D.Double(transX, dataArea.getMinY(), transX, dataArea.getMaxY())); g2.draw(new Line2D.Double(dataArea.getMinX(), transY, dataArea.getMaxX(), transY)); } } else if (pass == 1) { Shape shape = getItemShape(series, item); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY, transX); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX, transY); } hotspot = shape; if (shape.intersects(dataArea)) { //if (getItemShapeFilled(series, item)) { g2.setPaint(getPaint(dataset, series, item)); g2.fill(shape); //} if (this.drawOutlines) { if (getUseOutlinePaint()) { g2.setPaint(getItemOutlinePaint(series, item)); } else { g2.setPaint(getItemPaint(series, item)); } g2.setStroke(getItemOutlineStroke(series, item)); g2.draw(shape); } } // add an entity for the item... if (entities != null) { addEntity(entities, hotspot, dataset, series, item, transX, transY); } } }
Example 18
Source File: XYLineAndShapeRenderer.java From openstock with GNU General Public License v3.0 | 4 votes |
/** * Draws the item shapes and adds chart entities (second pass). This method * draws the shapes which mark the item positions. If <code>entities</code> * is not <code>null</code> it will be populated with entity information * for points that fall within the data area. * * @param g2 the graphics device. * @param plot the plot (can be used to obtain standard color * information etc). * @param domainAxis the domain axis. * @param dataArea the area within which the data is being drawn. * @param rangeAxis the range axis. * @param dataset the dataset. * @param pass the pass. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState the crosshair state. * @param entities the entity collection. */ protected void drawSecondaryPass(Graphics2D g2, XYPlot plot, XYDataset dataset, int pass, int series, int item, ValueAxis domainAxis, Rectangle2D dataArea, ValueAxis rangeAxis, CrosshairState crosshairState, EntityCollection entities) { Shape entityArea = null; // get the data point... double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); if (Double.isNaN(y1) || Double.isNaN(x1)) { return; } PlotOrientation orientation = plot.getOrientation(); RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); if (getItemShapeVisible(series, item)) { Shape shape = getItemShape(series, item); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1); } entityArea = shape; if (shape.intersects(dataArea)) { if (getItemShapeFilled(series, item)) { if (this.useFillPaint) { g2.setPaint(getItemFillPaint(series, item)); } else { g2.setPaint(getItemPaint(series, item)); } g2.fill(shape); } if (this.drawOutlines) { if (getUseOutlinePaint()) { g2.setPaint(getItemOutlinePaint(series, item)); } else { g2.setPaint(getItemPaint(series, item)); } g2.setStroke(getItemOutlineStroke(series, item)); g2.draw(shape); } } } double xx = transX1; double yy = transY1; if (orientation == PlotOrientation.HORIZONTAL) { xx = transY1; yy = transX1; } // draw the item label if there is one... if (isItemLabelVisible(series, item)) { drawItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0)); } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x1, y1, domainAxisIndex, rangeAxisIndex, transX1, transY1, orientation); // add an entity for the item, but only if it falls within the data // area... if (entities != null && isPointInRect(dataArea, xx, yy)) { addEntity(entities, entityArea, dataset, series, item, xx, yy); } }
Example 19
Source File: SLGraphics.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Checks whether or not the specified <code>Shape</code> intersects * the specified {@link Rectangle}, which is in device * space. If <code>onStroke</code> is false, this method checks * whether or not the interior of the specified <code>Shape</code> * intersects the specified <code>Rectangle</code>. If * <code>onStroke</code> is <code>true</code>, this method checks * whether or not the <code>Stroke</code> of the specified * <code>Shape</code> outline intersects the specified * <code>Rectangle</code>. * The rendering attributes taken into account include the * <code>Clip</code>, <code>Transform</code>, and <code>Stroke</code> * attributes. * @param rect the area in device space to check for a hit * @param s the <code>Shape</code> to check for a hit * @param onStroke flag used to choose between testing the * stroked or the filled shape. If the flag is <code>true</code>, the * <code>Stroke</code> oultine is tested. If the flag is * <code>false</code>, the filled <code>Shape</code> is tested. * @return <code>true</code> if there is a hit; <code>false</code> * otherwise. * @see #setStroke * @see #fill(Shape) * @see #draw(Shape) * @see #_transform * @see #setTransform * @see #clip * @see #setClip(Shape) */ public boolean hit(Rectangle rect, Shape s, boolean onStroke){ if (onStroke) { s = getStroke().createStrokedShape(s); } s = getTransform().createTransformedShape(s); return s.intersects(rect); }
Example 20
Source File: EpsGraphics2D.java From osp with GNU General Public License v3.0 | 2 votes |
/** * Checks whether or not the specified Shape intersects the specified * Rectangle, which is in device space. */ public boolean hit(Rectangle rect, Shape s, boolean onStroke) { return s.intersects(rect); }