List of usage examples for java.awt Shape intersects
public boolean intersects(Rectangle2D r);
From source file:Main.java
public static void main(String[] args) throws Exception { Shape s = new Rectangle2D.Double(0, 0, 72, 72); System.out.println(s.intersects(new Rectangle(10, 10, 20, 20))); }
From source file:com.anrisoftware.prefdialog.miscswing.lists.RubberBandingList.java
private int[] getIntersectsIdices(Shape shape) { ListModel<E> model = getModel(); List<Integer> list = new ArrayList<Integer>(model.getSize()); for (int i = 0; i < model.getSize(); i++) { Rectangle r = getCellBounds(i, i); if (shape.intersects(r)) { list.add(i);// ww w . ja v a2s. c o m } } int[] indices = new int[list.size()]; for (int i = 0; i < list.size(); i++) { indices[i] = list.get(i); } return indices; }
From source file:de.hstsoft.sdeep.model.TerrainGeneration.java
public ArrayList<TerrainNode> getTerrainNodes(Shape shape) { ArrayList<TerrainNode> retVal = new ArrayList<>(); for (TerrainNode node : terrainNodes) { float x = node.getPositionOffset().x - 128; float y = node.getPositionOffset().z - 128; Rectangle2D terrainBounds = new Rectangle2D.Float(x, y, 256, 256); boolean intersects = shape.intersects(terrainBounds); if (intersects) retVal.add(node);/*w ww .j a v a 2 s.c o m*/ } return retVal; }
From source file:savant.view.tracks.TrackRenderer.java
public boolean rectangleSelect(Rectangle2D rect) { if (!selectionAllowed(false) || !hasMappedValues()) return false; boolean repaint = false; List<Record> toAdd = new ArrayList<Record>(); for (Record o : recordToShapeMap.keySet()) { Shape s = recordToShapeMap.get(o); if (s == null) continue; if (s.intersects(rect)) { toAdd.add(o);//from ww w . j a va2 s .c o m repaint = true; } } if (repaint) { SelectionController.getInstance().addMultipleSelections(trackName, toAdd); } return repaint; }
From source file:com.rapidminer.gui.plotter.charts.ColorizedShapeItemRenderer.java
/** * Draws the block representing the specified item. * //from w w w. ja v a 2s . c o m * @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); } }
From source file:umontreal.iro.lecuyer.charts.EmpiricalRenderer.java
/** * Draws the visual representation of a single data item. * * @param g2 the graphics device. * @param state the renderer state. * @param dataArea the area within which the data is being drawn. * @param info collects information about the drawing. * @param plot the plot (can be used to obtain standard color * information etc). * @param domainAxis the domain axis./* ww w .j a va 2 s. c o m*/ * @param rangeAxis the range axis. * @param dataset the dataset. * @param series the series index (zero-based). * @param item the item index (zero-based). * @param crosshairState crosshair information for the plot * (<code>null</code> permitted). * @param pass the pass index. */ 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) { if (!getItemVisible(series, item)) return; PlotOrientation orientation = plot.getOrientation(); java.awt.Paint seriesPaint = getItemPaint(series, item); java.awt.Stroke seriesStroke = getItemStroke(series, item); g2.setPaint(seriesPaint); g2.setStroke(seriesStroke); double x0 = dataset.getXValue(series, item); double y0 = dataset.getYValue(series, item); if (java.lang.Double.isNaN(y0)) return; org.jfree.ui.RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); org.jfree.ui.RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation); double x1 = 0, y1 = 0; if (item < dataset.getItemCount(series) - 1) { x1 = dataset.getXValue(series, item + 1); y1 = dataset.getYValue(series, item + 1); } else { x1 = dataArea.getMaxX(); y1 = dataArea.getMaxY(); } boolean useFillPaint = getUseFillPaint(); ; boolean drawOutlines = getDrawOutlines(); if (!java.lang.Double.isNaN(y0)) { double transX1; double transY1; if (item < dataset.getItemCount(series) - 1) { transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); } else { transX1 = x1; transY1 = y1; } Line2D line = state.workingLine; if (orientation == PlotOrientation.HORIZONTAL) { line.setLine(transY0, transX0, transY0, transX1); g2.draw(line); } else if (orientation == PlotOrientation.VERTICAL) { line.setLine(transX0, transY0, transX1, transY0); g2.draw(line); } } if (getItemShapeVisible(series, item)) { Shape shape = getItemShape(series, item); if (orientation == PlotOrientation.HORIZONTAL) shape = ShapeUtilities.createTranslatedShape(shape, transY0, transX0); else if (orientation == PlotOrientation.VERTICAL) shape = ShapeUtilities.createTranslatedShape(shape, transX0, transY0); if (shape.intersects(dataArea)) { if (getItemShapeFilled(series, item)) { if (useFillPaint) g2.setPaint(getItemFillPaint(series, item)); else g2.setPaint(getItemPaint(series, item)); g2.fill(shape); } if (drawOutlines) { if (getUseOutlinePaint()) g2.setPaint(getItemOutlinePaint(series, item)); else g2.setPaint(getItemPaint(series, item)); g2.setStroke(getItemOutlineStroke(series, item)); g2.draw(shape); } } } if (isItemLabelVisible(series, item)) { double xx = transX0; double yy = transY0; if (orientation == PlotOrientation.HORIZONTAL) { xx = transY0; yy = transX0; } drawItemLabel(g2, orientation, dataset, series, item, xx, yy, y0 < 0.0D); } int domainAxisIndex = plot.getDomainAxisIndex(domainAxis); int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis); updateCrosshairValues(crosshairState, x0, y0, domainAxisIndex, rangeAxisIndex, transX0, transY0, orientation); if (state.getInfo() != null) { EntityCollection entities = state.getEntityCollection(); if (entities != null) { int r = getDefaultEntityRadius(); java.awt.Shape shape = orientation != PlotOrientation.VERTICAL ? ((java.awt.Shape) (new java.awt.geom.Rectangle2D.Double(transY0 - (double) r, transX0 - (double) r, 2 * r, 2 * r))) : ((java.awt.Shape) (new java.awt.geom.Rectangle2D.Double(transX0 - (double) r, transY0 - (double) r, 2 * r, 2 * r))); if (shape != null) { String tip = null; XYToolTipGenerator generator = getToolTipGenerator(series, item); if (generator != null) tip = generator.generateToolTip(dataset, series, item); String url = null; if (getURLGenerator() != null) url = getURLGenerator().generateURL(dataset, series, item); XYItemEntity entity = new XYItemEntity(shape, dataset, series, item, tip, url); entities.add(entity); } } } }
From source file:org.mwc.cmap.grideditor.chart.RendererWithDynamicFeedback.java
/** * @see drawSecondaryPass/*from w w w . j ava2s . com*/ */ private void drawFeedBackNode(final Graphics2D g2, final XYPlot plot, final XYDataset dataset, final int pass, // final int series, final int item, final ValueAxis domainAxis, final Rectangle2D dataArea, final ValueAxis rangeAxis, // final CrosshairState crosshairState, final EntityCollection entities) { // get the data point... final double x1 = myFeedBackValue != null ? myFeedBackValue.x : dataset.getXValue(series, item); final double y1 = myFeedBackValue != null ? myFeedBackValue.y : dataset.getYValue(series, item); if (Double.isNaN(y1) || Double.isNaN(x1)) { return; } final PlotOrientation orientation = plot.getOrientation(); final RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); final RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); final double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); final 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); } if (shape.intersects(dataArea)) { g2.setPaint(getFeedbackNodePaint()); g2.fill(shape); } } double xx = transX1; double yy = transY1; if (orientation == PlotOrientation.HORIZONTAL) { xx = transY1; yy = transX1; } drawFeedbackItemLabel(g2, orientation, dataset, series, item, xx, yy, (y1 < 0.0)); }
From source file:savant.view.tracks.TrackRenderer.java
public Map<Record, Shape> searchPoint(Point p) { if (!hasMappedValues() || data == null) return null; DrawingMode mode = (DrawingMode) instructions.get(DrawingInstruction.MODE); Map<Record, Shape> map = new HashMap<Record, Shape>(); boolean allowFuzzySNPs = true; Rectangle2D testIntersection = new Rectangle2D.Double(p.x - 3, p.y - 3, 7, 7); for (Record rec : recordToShapeMap.keySet()) { Shape s = recordToShapeMap.get(rec); if (s != null) { //if (contains AND (notArc OR (isEdge...)) boolean hit = false; if (mode == DrawingMode.ARC || mode == DrawingMode.ARC_PAIRED) { hit = s.intersects(testIntersection) && (!s.contains(p.x - 3, p.y - 3) || !s.contains(p.x + 3, p.y - 3)); } else { hit = s.contains(p);//from w ww . ja v a2s. c om } // At low resolutions, SNPs can be hard to hit with the mouse, so give a second chance with a fuzzier check. if (mode == DrawingMode.SNP || mode == DrawingMode.STRAND_SNP || mode == DrawingMode.MATRIX) { if (hit) { if (allowFuzzySNPs) { // We may have accumulated some fuzzy SNP hits. We now have an exact one, so dump the fuzzies. map.clear(); allowFuzzySNPs = false; } } else { if (allowFuzzySNPs) { hit = s.intersects(testIntersection); } } } if (hit) { map.put(rec, s); continue; } } else { LOG.info("Why is shape null for " + rec); } //check other artifacts Shape artifact = artifactMap.get(rec); if (artifact != null && artifact.contains(p.x, p.y)) { map.put(rec, s); } } return map.isEmpty() ? null : map; }
From source file:net.sourceforge.processdash.ev.ui.chart.RangeXYItemRenderer.java
/** Draws the visual representation of a single data item. *//*from w w w.j a va 2 s . c o m*/ @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 crosshairInfo, int pass) { // setup for collecting optional entity info... EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } Shape entityArea = null; Paint paint = getItemPaint(series, item); Stroke seriesStroke = getItemStroke(series, item); g2.setPaint(paint); g2.setStroke(seriesStroke); // get the data point... Number x1n = dataset.getX(series, item); Number y1n = dataset.getY(series, item); if (y1n == null || x1n == null) { return; } double x1 = x1n.doubleValue(); double y1 = y1n.doubleValue(); final RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); final RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); PlotOrientation orientation = plot.getOrientation(); if (item > 0) { // get the previous data point... Number x0n = dataset.getX(series, item - 1); Number y0n = dataset.getY(series, item - 1); if (y0n != null && x0n != null) { double x0 = x0n.doubleValue(); double y0 = y0n.doubleValue(); double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation); // only draw if we have good values if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) { return; } if (orientation == PlotOrientation.HORIZONTAL) { line.setLine(transY0, transX0, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { line.setLine(transX0, transY0, transX1, transY1); } if (y1n instanceof RangeInfo) { RangeInfo y1r = (RangeInfo) y1n; double transY1low = rangeAxis.valueToJava2D(y1r.getRangeLowerBound(false), dataArea, yAxisLocation); double transY1high = rangeAxis.valueToJava2D(y1r.getRangeUpperBound(false), dataArea, yAxisLocation); drawItemRangeGradient(g2, line, paint, seriesStroke, transX1, transY1low, transX1, transY1high); } else if (x1n instanceof RangeInfo) { RangeInfo x1r = (RangeInfo) x1n; double transX1low = domainAxis.valueToJava2D(x1r.getRangeLowerBound(false), dataArea, xAxisLocation); double transX1high = domainAxis.valueToJava2D(x1r.getRangeUpperBound(false), dataArea, xAxisLocation); drawItemRangeGradient(g2, line, paint, seriesStroke, transX1low, transY1, transX1high, transY1); } else if (line.intersects(dataArea)) { g2.draw(line); } } } else if (dataset.getItemCount(series) == 1) { 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); } if (shape.intersects(dataArea)) { if (getItemShapeFilled(series, item)) { g2.fill(shape); } else { g2.draw(shape); } } entityArea = shape; } if (entities != null && (dataArea.contains(transX1, transY1) || entityArea != null)) { addEntity(entities, entityArea, dataset, series, item, transX1, transY1); } }
From source file:gda.plots.SimpleXYItemRenderer.java
/** * Draws the visual representation of a single data item. This mostly reproduces the code of StandardXYItemRenderer * but using the line by line information stored in the SimpleXYSeries instead of the series indexed information * stored in the Renderer itself.//from w ww .j a v a 2s. c o m * * @param g2 * the graphics device. * @param state * the renderer state. * @param dataArea * the area within which the data is being drawn. * @param info * collects information about the drawing. * @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 series * the series index (zero-based). * @param item * the item index (zero-based). * @param crosshairState * crosshair information for the plot ( <code>null</code> permitted). * @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) { SimpleXYSeries sxys = (SimpleXYSeries) ((SimpleXYSeriesCollection) dataset).getSeries(series); if (!sxys.isVisible()) { return; } // setup for collecting optional entity info... Shape entityArea = null; EntityCollection entities = null; if (info != null) { entities = info.getOwner().getEntityCollection(); } PlotOrientation orientation = plot.getOrientation(); g2.setPaint(sxys.getPaint()); g2.setStroke(sxys.getStroke()); // get the data point double x1 = dataset.getXValue(series, item); double y1 = dataset.getYValue(series, item); // Test x1 = xValueTransformer.transformValue(x1); if (Double.isNaN(x1) || Double.isNaN(y1)) { return; } RectangleEdge xAxisLocation = plot.getDomainAxisEdge(); RectangleEdge yAxisLocation = plot.getRangeAxisEdge(); double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation); double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation); if (sxys.isDrawLines()) { if (item > 0) { // get the previous data point... double x0 = dataset.getXValue(series, item - 1); double y0 = dataset.getYValue(series, item - 1); // Test // System.out.print("tranformed " + x0); x0 = xValueTransformer.transformValue(x0); // Message.debug(" to " + x0); if (!Double.isNaN(x0) && !Double.isNaN(y0)) { boolean drawLine = true; if (getPlotDiscontinuous()) { // only draw a line if the gap between the current and // previous data // point is within the threshold int numX = dataset.getItemCount(series); double minX = dataset.getXValue(series, 0); double maxX = dataset.getXValue(series, numX - 1); drawLine = (x1 - x0) <= ((maxX - minX) / numX * getGapThreshold()); } if (drawLine) { double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation); double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation); // only draw if we have good values if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1) || Double.isNaN(transY1)) { return; } if (orientation == PlotOrientation.HORIZONTAL) { state.workingLine.setLine(transY0, transX0, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { state.workingLine.setLine(transX0, transY0, transX1, transY1); } if (state.workingLine.intersects(dataArea)) { g2.draw(state.workingLine); } } } } } if (sxys.isDrawMarkers()) { Shape shape = sxys.getSymbol(); if (orientation == PlotOrientation.HORIZONTAL) { shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1); } if (shape.intersects(dataArea)) { g2.setPaint(sxys.getSymbolPaint()); // Always use full stroke for drawing marker g2.setStroke(new BasicStroke()); if (sxys.getFilled()) { g2.fill(shape); } else { g2.draw(shape); } g2.setPaint(sxys.getPaint()); g2.setStroke(sxys.getStroke()); } entityArea = shape; } if (getPlotImages()) { // use shape scale with transform?? // double scale = getShapeScale(plot, series, item, transX1, // transY1); Image image = getImage(plot, series, item, transX1, transY1); if (image != null) { Point hotspot = getImageHotspot(plot, series, item, transX1, transY1, image); g2.drawImage(image, (int) (transX1 - hotspot.getX()), (int) (transY1 - hotspot.getY()), null); entityArea = new Rectangle2D.Double(transX1 - hotspot.getX(), transY1 - hotspot.getY(), image.getWidth(null), image.getHeight(null)); } } // draw the item label if there is one... if (isItemLabelVisible(series, item)) { drawItemLabel(g2, orientation, dataset, series, item, transX1, transY1, (y1 < 0.0)); } updateCrosshairValues(crosshairState, x1, y1, transX1, transY1, orientation); // add an entity for the item... if (entities != null) { addEntity(entities, entityArea, dataset, series, item, transX1, transY1); } }