Java Code Examples for java.awt.geom.GeneralPath#contains()
The following examples show how to use
java.awt.geom.GeneralPath#contains() .
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: HtmlArea.java From htmlunit with Apache License 2.0 | 6 votes |
/** * Indicates if this area contains the specified point. * @param x the x coordinate of the point * @param y the y coordinate of the point * @return {@code true} if the point is contained in this area */ boolean containsPoint(final int x, final int y) { final String shape = StringUtils.defaultIfEmpty(getShapeAttribute(), SHAPE_RECT).toLowerCase(Locale.ROOT); if ("default".equals(shape) && getCoordsAttribute() != null) { return true; } if (SHAPE_RECT.equals(shape) && getCoordsAttribute() != null) { final Rectangle2D rectangle = parseRect(); return rectangle.contains(x, y); } if (SHAPE_CIRCLE.equals(shape) && getCoordsAttribute() != null) { final Ellipse2D ellipse = parseCircle(); return ellipse.contains(x, y); } if (SHAPE_POLY.equals(shape) && getCoordsAttribute() != null) { final GeneralPath path = parsePoly(); return path.contains(x, y); } return false; }
Example 2
Source File: HtmlArea.java From HtmlUnit-Android with Apache License 2.0 | 6 votes |
/** * Indicates if this area contains the specified point. * @param x the x coordinate of the point * @param y the y coordinate of the point * @return {@code true} if the point is contained in this area */ boolean containsPoint(final int x, final int y) { final String shape = StringUtils.defaultIfEmpty(getShapeAttribute(), "rect").toLowerCase(Locale.ROOT); if ("default".equals(shape) && getCoordsAttribute() != null) { return true; } if ("rect".equals(shape) && getCoordsAttribute() != null) { final Rectangle2D rectangle = parseRect(); return rectangle.contains(x, y); } if ("circle".equals(shape) && getCoordsAttribute() != null) { final Ellipse2D ellipse = parseCircle(); return ellipse.contains(x, y); } if ("poly".equals(shape) && getCoordsAttribute() != null) { final GeneralPath path = parsePoly(); return path.contains(x, y); } return false; }
Example 3
Source File: DFDFunctionEllipse.java From ramus with GNU General Public License v3.0 | 6 votes |
protected int getTriangle(final FloatPoint point) { int res = -1; FloatPoint l = getLocation(); for (int type = MovingPanel.RIGHT; type <= MovingPanel.TOP; type++) { GeneralPath gp = getTrianglePath(type); double y = point.getY() + l.getY(); double x = point.getX() + l.getX(); if (gp.contains(new Point2D.Double(x, y))) { res = type; break; } } return res; }
Example 4
Source File: DFDObject.java From ramus with GNU General Public License v3.0 | 6 votes |
protected int getTriangle(final FloatPoint point) { int res = -1; FloatPoint l = getLocation(); for (int type = MovingPanel.RIGHT; type <= MovingPanel.TOP; type++) { GeneralPath gp = getTrianglePath(type); double y = point.getY() + l.getY(); double x = point.getX() + l.getX(); if (gp.contains(new Point2D.Double(x, y))) { res = type; break; } } return res; }
Example 5
Source File: DFDFunction.java From ramus with GNU General Public License v3.0 | 6 votes |
protected int getTriangle(final FloatPoint point) { int res = -1; FloatPoint l = getLocation(); for (int type = MovingPanel.RIGHT; type <= MovingPanel.TOP; type++) { GeneralPath gp = getTrianglePath(type); double y = point.getY() + l.getY(); double x = point.getX() + l.getX(); if (gp.contains(new Point2D.Double(x, y))) { res = type; break; } } return res; }
Example 6
Source File: IDEF0Object.java From ramus with GNU General Public License v3.0 | 6 votes |
protected int getTriangle(final FloatPoint point) { int res = -1; FloatPoint l = getLocation(); for (int type = MovingPanel.RIGHT; type <= MovingPanel.TOP; type++) { GeneralPath gp = getTrianglePath(type); double y = point.getY() + l.getY(); double x = point.getX() + l.getX(); if (gp.contains(new Point2D.Double(x, y))) { res = type; break; } } if (isShowRight() ^ res == Point.RIGHT) res = -1; return res; }
Example 7
Source File: ButtonShape.java From pumpernickel with MIT License | 6 votes |
private static GeneralPath findShapeToFitRectangle(Shape originalShape, int w, int h) { GeneralPath newShape = new GeneralPath(); Rectangle2D rect = new Rectangle2D.Float(); ShapeBounds.getBounds(originalShape, rect); if (originalShape.contains(rect.getX() + rect.getWidth() / 2, rect.getY() + rect.getHeight() / 2) == false) throw new IllegalArgumentException( "This custom shape is not allowed. The center of this shape must be inside the shape."); double scale = Math.min((w) / rect.getWidth(), (h) / rect.getHeight()); AffineTransform transform = new AffineTransform(); while (true) { newShape.reset(); newShape.append(originalShape, true); transform.setToScale(scale, scale); newShape.transform(transform); ShapeBounds.getBounds(newShape, rect); if (newShape.contains(rect.getX() + rect.getWidth() / 2 - w / 2, rect.getY() + rect.getHeight() / 2 - h / 2, w, h)) { return newShape; } scale += .01; } }
Example 8
Source File: Cardumen_009_s.java From coming with MIT License | 5 votes |
/** * Selects the data items within the specified region. * * @param region the region (in Java2D coordinates). * @param dataArea the data area. * @param source the rendering source. * * @since 1.2.0 */ public void select(GeneralPath region, Rectangle2D dataArea, RenderingSource source) { // cycle through the datasets and change the selection state for the // items that fall within the specified region int datasetCount = this.datasets.size(); for (int d = 0; d < datasetCount; d++) { XYDataset dataset = (XYDataset) this.datasets.get(d); if (dataset == null) { continue; } XYDatasetSelectionState state = findSelectionStateForDataset( dataset, source); if (state == null) { continue; } GeneralPath path = convertToDataSpace(region, dataArea, dataset); // now we have to iterate over all the dataset values and // convert each point to Java2D space and then check if it should // be selected. int seriesCount = dataset.getSeriesCount(); for (int s = 0; s < seriesCount; s++) { int itemCount = dataset.getItemCount(s); for (int i = 0; i < itemCount; i++) { double x = dataset.getXValue(s, i); double y = dataset.getYValue(s, i); if (path.contains(x, y)) { state.setSelected(s, i, true); // FIXME: we should fire just one dataset change event // for the whole selection } } } } }
Example 9
Source File: Cardumen_009_t.java From coming with MIT License | 5 votes |
/** * Selects the data items within the specified region. * * @param region the region (in Java2D coordinates). * @param dataArea the data area. * @param source the rendering source. * * @since 1.2.0 */ public void select(GeneralPath region, Rectangle2D dataArea, RenderingSource source) { // cycle through the datasets and change the selection state for the // items that fall within the specified region int datasetCount = this.datasets.size(); for (int d = 0; d < datasetCount; d++) { XYDataset dataset = (XYDataset) this.datasets.get(d); if (dataset == null) { continue; } XYDatasetSelectionState state = findSelectionStateForDataset( dataset, source); if (state == null) { continue; } GeneralPath path = convertToDataSpace(region, dataArea, dataset); // now we have to iterate over all the dataset values and // convert each point to Java2D space and then check if it should // be selected. int seriesCount = dataset.getSeriesCount(); for (int s = 0; s < seriesCount; s++) { int itemCount = dataset.getItemCount(s); for (int i = 0; i < itemCount; i++) { double x = dataset.getXValue(s, i); double y = dataset.getYValue(s, i); if (path.contains(x, y)) { state.setSelected(s, i, true); // FIXME: we should fire just one dataset change event // for the whole selection } } } } }
Example 10
Source File: Cardumen_0082_t.java From coming with MIT License | 5 votes |
/** * Selects the data items within the specified region. * * @param region the region (in Java2D coordinates). * @param dataArea the data area. * @param source the rendering source. * * @since 1.2.0 */ public void select(GeneralPath region, Rectangle2D dataArea, RenderingSource source) { // cycle through the datasets and change the selection state for the // items that fall within the specified region int datasetCount = this.datasets.size(); for (int d = 0; d < datasetCount; d++) { XYDataset dataset = (XYDataset) this.datasets.get(d); if (dataset == null) { continue; } XYDatasetSelectionState state = findSelectionStateForDataset( dataset, source); if (state == null) { continue; } GeneralPath path = convertToDataSpace(region, dataArea, dataset); // now we have to iterate over all the dataset values and // convert each point to Java2D space and then check if it should // be selected. int seriesCount = dataset.getSeriesCount(); for (int s = 0; s < seriesCount; s++) { int itemCount = dataset.getItemCount(s); for (int i = 0; i < itemCount; i++) { double x = dataset.getXValue(s, i); double y = dataset.getYValue(s, i); if (path.contains(x, y)) { state.setSelected(s, i, true); // FIXME: we should fire just one dataset change event // for the whole selection } } } } }
Example 11
Source File: Cardumen_0082_s.java From coming with MIT License | 5 votes |
/** * Selects the data items within the specified region. * * @param region the region (in Java2D coordinates). * @param dataArea the data area. * @param source the rendering source. * * @since 1.2.0 */ public void select(GeneralPath region, Rectangle2D dataArea, RenderingSource source) { // cycle through the datasets and change the selection state for the // items that fall within the specified region int datasetCount = this.datasets.size(); for (int d = 0; d < datasetCount; d++) { XYDataset dataset = (XYDataset) this.datasets.get(d); if (dataset == null) { continue; } XYDatasetSelectionState state = findSelectionStateForDataset( dataset, source); if (state == null) { continue; } GeneralPath path = convertToDataSpace(region, dataArea, dataset); // now we have to iterate over all the dataset values and // convert each point to Java2D space and then check if it should // be selected. int seriesCount = dataset.getSeriesCount(); for (int s = 0; s < seriesCount; s++) { int itemCount = dataset.getItemCount(s); for (int i = 0; i < itemCount; i++) { double x = dataset.getXValue(s, i); double y = dataset.getYValue(s, i); if (path.contains(x, y)) { state.setSelected(s, i, true); // FIXME: we should fire just one dataset change event // for the whole selection } } } } }
Example 12
Source File: PainterShaped.java From Logisim with GNU General Public License v3.0 | 4 votes |
private static int[] getInputLineLengths(GateAttributes attrs, AbstractGate factory) { int inputs = attrs.inputs; int mainHeight = ((Integer) attrs.size.getValue()).intValue(); Integer key = Integer.valueOf(inputs * 31 + mainHeight); Object ret = INPUT_LENGTHS.get(key); if (ret != null) { return (int[]) ret; } Direction facing = attrs.facing; if (facing != Direction.EAST) { attrs = (GateAttributes) attrs.clone(); attrs.facing = Direction.EAST; } int[] lengths = new int[inputs]; INPUT_LENGTHS.put(key, lengths); int width = mainHeight; Location loc0 = OrGate.FACTORY.getInputOffset(attrs, 0); Location locn = OrGate.FACTORY.getInputOffset(attrs, inputs - 1); int totalHeight = 10 + loc0.manhattanDistanceTo(locn); if (totalHeight < width) totalHeight = width; GeneralPath path = computeShield(width, totalHeight); for (int i = 0; i < inputs; i++) { Location loci = OrGate.FACTORY.getInputOffset(attrs, i); Point2D p = new Point2D.Float(loci.getX() + 1, loci.getY()); int iters = 0; while (path.contains(p) && iters < 15) { iters++; p.setLocation(p.getX() + 1, p.getY()); } if (iters >= 15) iters = 0; lengths[i] = iters; } /* * used prior to 2.5.1, when moved to GeneralPath int wingHeight = (totalHeight * - mainHeight) / 2; double wingCenterX = wingHeight * Math.sqrt(3) / 2; double * mainCenterX = mainHeight * Math.sqrt(3) / 2; * * for (int i = 0; i < inputs; i++) { Location loci = * factory.getInputOffset(attrs, i); int disti = 5 + * loc0.manhattanDistanceTo(loci); if (disti > totalHeight - disti) { // ensure * on top half disti = totalHeight - disti; } double dx; if (disti < wingHeight) * { // point is on wing int dy = wingHeight / 2 - disti; dx = * Math.sqrt(wingHeight * wingHeight - dy * dy) - wingCenterX; } else { // point * is on main shield int dy = totalHeight / 2 - disti; dx = Math.sqrt(mainHeight * * mainHeight - dy * dy) - mainCenterX; } lengths[i] = (int) (dx - 0.5); } */ return lengths; }
Example 13
Source File: Scribbler.java From pumpernickel with MIT License | 4 votes |
/** * * @param body * the shape to fill * @param strokeWidth * the width of the stroke. * @param angle * the angle (in radians) to scribble * @param density * a float from [0,1] * @return a shape that resembles a crayon scribbling the body */ public static Shape fillBody(Shape body, float strokeWidth, double angle, double density) { density = 1 - density; Rectangle2D bounds = ShapeBounds.getBounds(body); double cx = bounds.getCenterX(); double cy = bounds.getCenterY(); double k = strokeWidth; GeneralPath copy = new GeneralPath(); copy.append(body, false); AffineTransform tx = AffineTransform.getRotateInstance(-angle, cx, cy); copy.transform(tx); GeneralPath result = new GeneralPath(); Random r = new Random(0); boolean moved = false; Rectangle2D rotatedBounds = ShapeBounds.getBounds(copy); for (int y = (int) rotatedBounds.getY(); y < rotatedBounds.getMaxY(); y += k * (1 + density) / 2) { for (int x = (int) rotatedBounds.getX(); x < rotatedBounds .getMaxX(); x += 3) { if (copy.contains(x - k / 2, y - k / 2, k, k)) { if (!moved) { result.moveTo(x + 2 - 4 * r.nextDouble(), y + 2 - 4 * r.nextDouble()); moved = true; } else { result.lineTo(x + 2 - 4 * r.nextDouble(), y + 2 - 4 * r.nextDouble()); } int x2 = x; readRemainingLine: while (x2 < rotatedBounds.getMaxX()) { if (!copy.contains(x2 - k / 2, y - k / 2, k, k)) { break readRemainingLine; } x2 += 2; } x2 -= 2; result.lineTo(x2 + 2 - 4 * r.nextDouble(), y + 2 - 4 * r.nextDouble()); x = x2; } } } tx = AffineTransform.getRotateInstance(angle, cx, cy); result.transform(tx); return new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND).createStrokedShape(result); }
Example 14
Source File: JSoftGraph.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void drawArrow(Graphics2D g, Link link, int x1, int y1, int x2, int y2, Color fillColor, Color lineColor, boolean bFind) { if((link.getDetail() >= 25 || link.getDepth() > 3)) { double dist = 10; if(bFind && mousePoint != null) { dist = dist(x1, y1, x2, y2, mousePoint.getX(), mousePoint.getY()); if(dist <= 2) { mouseObject = link; } } g.setColor(fillColor); g.drawLine(x1, y1, x2, y2); return; } Stroke oldStroke = g.getStroke(); Util.setAntialias(g, true); try { int dx = x2 - x1; int dy = y2 - y1; double len = Math.sqrt(dx * dx + dy * dy); double aDir=Math.atan2(dy, dx); AffineTransform trans = g.getTransform(); int type = link.getType(); g.translate(x1, y1); g.rotate(aDir); GeneralPath path = new GeneralPath(); double k = 1.0; if(Math.abs(type) == 2) { k = 0; } Shape s1 = new CubicCurve2D.Double(0, len/20, len/4, k* len/4, 3*len/4, k * -len/5, len, 0); path.append(s1, false); Shape s2 = new CubicCurve2D.Double(len, 0, 3*len/4, k * -len/4, len/4, k * len/6, 0, -len/20); path.append(s2, true); path.closePath(); if(bFind) { try { if(path.contains(g.getTransform().inverseTransform(mousePoint, null))) { mouseObject = link; } } catch (Exception e) { throw new RuntimeException("Failed to transform", e); } } g.setColor(fillColor); g.fill(path); if(lineColor != null) { if(len > 20) { g.setColor(Util.rgbInterpolate(fillColor, Color.red, .3)); g.setStroke(getStroke(link.getDepth())); g.draw(s2); } } g.setStroke(oldStroke); if(lineColor != null) { g.setColor(lineColor); g.draw(path); } // g.drawLine(0, 0, (int)len, 0); g.setTransform(trans); } finally { g.setStroke(oldStroke); } }
Example 15
Source File: JSoftGraph.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void drawLine(Graphics2D g, Link link, int x1, int y1, int x2, int y2, Color fillColor, Color lineColor, boolean bFind) { Stroke oldStroke = g.getStroke(); try { int dx = x2 - x1; int dy = y2 - y1; double len = Math.sqrt(dx * dx + dy * dy); double aDir=Math.atan2(dy, dx); AffineTransform trans = g.getTransform(); g.translate(x1, y1); g.rotate(aDir); GeneralPath path = new GeneralPath(); Polygon p1 = new Polygon(); Node n1 = link.getFrom(); int h = (int)n1.getSize(); p1.addPoint(0, h); p1.addPoint((int)len, 0); p1.addPoint(0, -h); path.append(p1, false); path.closePath(); if(bFind) { try { if(path.contains(g.getTransform().inverseTransform(mousePoint, null))) { mouseObject = link; } } catch (Exception e) { throw new RuntimeException("Failed to transform", e); } } g.setColor(fillColor); g.fill(path); if(lineColor != null) { g.setColor(lineColor); g.draw(path); } // g.drawLine(0, 0, (int)len, 0); g.setTransform(trans); } finally { g.setStroke(oldStroke); } }