Java Code Examples for java.awt.Polygon#addPoint()
The following examples show how to use
java.awt.Polygon#addPoint() .
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: UnmanagedDrawImagePerformance.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
private static long test(Image bi, Image vi, AffineTransform atfm) { final Polygon p = new Polygon(); p.addPoint(0, 0); p.addPoint(SIZE, 0); p.addPoint(0, SIZE); p.addPoint(SIZE, SIZE); p.addPoint(0, 0); Graphics2D g2d = (Graphics2D) vi.getGraphics(); g2d.clip(p); g2d.transform(atfm); g2d.setComposite(AlphaComposite.SrcOver); final long start = System.nanoTime(); g2d.drawImage(bi, 0, 0, null); final long time = System.nanoTime() - start; g2d.dispose(); return time; }
Example 2
Source File: DrawRectEvent.java From whyline with MIT License | 6 votes |
protected Shape makeShape() { int x1 = getX() + paintState.getOriginX(), x2 = getX() + paintState.getOriginX() + getWidth(), y1 = getY() + paintState.getOriginY(), y2 = getY() + paintState.getOriginY() + getHeight(); int thickness = 2; Polygon p = new Polygon(); p.addPoint(x1 - thickness, y1 - thickness); p.addPoint(x2 + thickness, y1 - thickness); p.addPoint(x2 + thickness, y2 + thickness); p.addPoint(x1 + thickness, y2 + thickness); p.addPoint(x1 + thickness, y2 - thickness); p.addPoint(x2 - thickness, y2 - thickness); p.addPoint(x2 - thickness, y1 + thickness); p.addPoint(x1 + thickness, y1 + thickness); p.addPoint(x1 + thickness, y2 + thickness); p.addPoint(x1 - thickness, y2 + thickness); p.addPoint(x1 - thickness, y1 - thickness); return p; }
Example 3
Source File: BasicIconFactory.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public void paintIcon(Component c, Graphics g, int x, int y) { Polygon p = new Polygon(); p.addPoint(x, y); p.addPoint(x+getIconWidth(), y+getIconHeight()/2); p.addPoint(x, y+getIconHeight()); g.fillPolygon(p); }
Example 4
Source File: BasicIconFactory.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public void paintIcon(Component c, Graphics g, int x, int y) { Polygon p = new Polygon(); p.addPoint(x, y); p.addPoint(x+getIconWidth(), y+getIconHeight()/2); p.addPoint(x, y+getIconHeight()); g.fillPolygon(p); }
Example 5
Source File: ArrowPanel.java From ccu-historian with GNU General Public License v3.0 | 5 votes |
/** * Returns a down arrow. * * @return a down arrow. */ private Shape getDownArrow() { final Polygon result = new Polygon(); result.addPoint(7, 7); result.addPoint(2, 2); result.addPoint(12, 2); return result; }
Example 6
Source File: MapTools.java From addrparser with Apache License 2.0 | 5 votes |
/** * To determine whether a point in a polygon * @param p The point to determine * @param area Polygon * @return true, point in polygon, otherwise false. */ public static boolean inPolygonArea(Point p, Point area[]) { Polygon pol = new Polygon(); for ( int i = 0; i < area.length; i++ ) { pol.addPoint( (int) (area[i].getLon() * 100000), (int) (area[i].getLat() * 100000) ); } return pol.contains( (int) (p.getLon() * 100000), (int) (p.getLat() * 100000) ); }
Example 7
Source File: DefaultProcessDiagramCanvas.java From flowable-engine with Apache License 2.0 | 5 votes |
public void drawGateway(GraphicInfo graphicInfo) { Polygon rhombus = new Polygon(); int x = (int) graphicInfo.getX(); int y = (int) graphicInfo.getY(); int width = (int) graphicInfo.getWidth(); int height = (int) graphicInfo.getHeight(); rhombus.addPoint(x, y + (height / 2)); rhombus.addPoint(x + (width / 2), y + height); rhombus.addPoint(x + width, y + (height / 2)); rhombus.addPoint(x + (width / 2), y); g.draw(rhombus); }
Example 8
Source File: LivreBase.java From brModelo with GNU General Public License v3.0 | 5 votes |
public Shape getRegiaoLosanglo() { if (Regiao == null) { Rectangle r = new Rectangle(getLeft(), getTop(), getWidth(), getHeight()); //getBounds(); Polygon los = new Polygon(); los.addPoint(r.x, r.y + r.height / 2); los.addPoint(r.x + r.width / 2, r.y); los.addPoint(r.x + r.width, r.y + r.height / 2); los.addPoint(r.x + r.width / 2, r.y + r.height); Regiao = los; } return Regiao; }
Example 9
Source File: Resize.java From Pixie with MIT License | 5 votes |
/** * Computes the corespondent polygon in the original image, of the given * polygon from the resized image. * * @param polyResized the polygon from the resized image * @return the corresponding polygon in the original image */ public Polygon resizedToOriginal(Polygon polyResized) { if ((polyResized == null) || (Double.compare(ratioWidth, 0.0) == 0) || (Double.compare(ratioHeight, 0.0) == 0)) { return null; } Polygon polyOrig = new Polygon(); for (int index = 0; index < polyResized.npoints; index++) { Point point = resizedToOriginal(polyResized.xpoints[index], polyResized.ypoints[index]); polyOrig.addPoint(point.x, point.y); } return polyOrig; }
Example 10
Source File: BasicIconFactory.java From JDKSourceCode1.8 with MIT License | 5 votes |
public void paintIcon(Component c, Graphics g, int x, int y) { Polygon p = new Polygon(); p.addPoint(x, y); p.addPoint(x+getIconWidth(), y+getIconHeight()/2); p.addPoint(x, y+getIconHeight()); g.fillPolygon(p); }
Example 11
Source File: BeamSymbol.java From audiveris with GNU Affero General Public License v3.0 | 5 votes |
@Override protected void paint (Graphics2D g, Params params, Point location, Alignment alignment) { MyParams p = (MyParams) params; Point loc = alignment.translatedPoint(TOP_RIGHT, p.rect, location); // Beams Rectangle2D quarterRect = p.layout.getBounds(); int beamHeight = (int) Math.rint(quarterRect.getHeight() * 0.12); int beamDelta = (int) Math.rint(quarterRect.getHeight() * 0.18); for (int i = 0; i < beamCount; i++) { Point left = new Point(loc.x - p.quarterDx, loc.y + (i * beamDelta) + p.quarterDy); Point right = new Point(loc.x, loc.y + (i * beamDelta)); Polygon polygon = new Polygon(); polygon.addPoint(left.x, left.y); polygon.addPoint(left.x, left.y + beamHeight); polygon.addPoint(right.x, right.y + beamHeight); polygon.addPoint(right.x, right.y); g.fill(polygon); } // Decorations (using composite) Composite oldComposite = g.getComposite(); g.setComposite(decoComposite); MusicFont.paint(g, p.layout, loc, TOP_RIGHT); loc.translate(-p.quarterDx, p.quarterDy); MusicFont.paint(g, p.layout, loc, TOP_RIGHT); g.setComposite(oldComposite); }
Example 12
Source File: mxTriangleShape.java From blog-codes with Apache License 2.0 | 5 votes |
/** * */ public Shape createShape(mxGraphics2DCanvas canvas, mxCellState state) { Rectangle temp = state.getRectangle(); int x = temp.x; int y = temp.y; int w = temp.width; int h = temp.height; String direction = mxUtils.getString(state.getStyle(), mxConstants.STYLE_DIRECTION, mxConstants.DIRECTION_EAST); Polygon triangle = new Polygon(); if (direction.equals(mxConstants.DIRECTION_NORTH)) { triangle.addPoint(x, y + h); triangle.addPoint(x + w / 2, y); triangle.addPoint(x + w, y + h); } else if (direction.equals(mxConstants.DIRECTION_SOUTH)) { triangle.addPoint(x, y); triangle.addPoint(x + w / 2, y + h); triangle.addPoint(x + w, y); } else if (direction.equals(mxConstants.DIRECTION_WEST)) { triangle.addPoint(x + w, y); triangle.addPoint(x, y + h / 2); triangle.addPoint(x + w, y + h); } else // EAST { triangle.addPoint(x, y); triangle.addPoint(x + w, y + h / 2); triangle.addPoint(x, y + h); } return triangle; }
Example 13
Source File: Chord.java From libreveris with GNU Lesser General Public License v3.0 | 4 votes |
/** * Look up for all chords interleaved between the given stemed chords * * @param left the chord on the left of the area * @param right the chord on the right of the area * @return the collection of interleaved chords, which may be empty */ public static SortedSet<Chord> lookupInterleavedChords (Chord left, Chord right) { SortedSet<Chord> found = new TreeSet<>(Chord.byAbscissa); if ((left == null) || (right == null)) { return found; // Safer } // Define the area limited by the left and right chords with their stems // and check for intersection with a rest note // More precisely, we use the area half on the tail side. // And we check that the interleaved chords have the same stem dir Polygon polygon = new Polygon(); polygon.addPoint(left.getHeadLocation().x, left.getCenter().y); polygon.addPoint(left.getTailLocation().x, left.getTailLocation().y); polygon.addPoint(right.getTailLocation().x, right.getTailLocation().y); polygon.addPoint(right.getHeadLocation().x, right.getCenter().y); for (TreeNode node : left.getMeasure().getChords()) { Chord chord = (Chord) node; // Not interested in the bounding chords (TBC) if ((chord == left) || (chord == right)) { continue; } // Additional check on stem dir, if left & right agree if (left.getStemDir() == right.getStemDir()) { if (chord.getReferencePoint() == null || (chord.getStemDir() != 0 && chord.getStemDir() != left.getStemDir())) { continue; } } Rectangle box = chord.getBox(); if (polygon.intersects(box.x, box.y, box.width, box.height)) { found.add(chord); } } return found; }
Example 14
Source File: BeamSymbol.java From libreveris with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected void paint (Graphics2D g, Params params, Point location, Alignment alignment) { MyParams p = (MyParams) params; Point loc = alignment.translatedPoint( TOP_RIGHT, p.rect, location); // Beams Rectangle2D quarterRect = p.layout.getBounds(); int beamHeight = (int) Math.rint( quarterRect.getHeight() * 0.12); int beamDelta = (int) Math.rint(quarterRect.getHeight() * 0.18); for (int i = 0; i < beamCount; i++) { Point left = new Point( loc.x - p.quarterDx, loc.y + (i * beamDelta) + p.quarterDy); Point right = new Point(loc.x, loc.y + (i * beamDelta)); Polygon polygon = new Polygon(); polygon.addPoint(left.x, left.y); polygon.addPoint(left.x, left.y + beamHeight); polygon.addPoint(right.x, right.y + beamHeight); polygon.addPoint(right.x, right.y); g.fill(polygon); } // Decorations (using composite) Composite oldComposite = g.getComposite(); g.setComposite(decoComposite); MusicFont.paint(g, p.layout, loc, TOP_RIGHT); loc.translate(-p.quarterDx, p.quarterDy); MusicFont.paint(g, p.layout, loc, TOP_RIGHT); g.setComposite(oldComposite); }
Example 15
Source File: Lines_.java From ij-ridgedetection with GNU General Public License v2.0 | 4 votes |
/** * Make binary. */ public void makeBinary() { ImagePlus binary = IJ.createHyperStack(imp.getTitle() + " Detected segments", imp.getWidth(), imp.getHeight(), imp.getNChannels(), imp.getStackSize() / imp.getNChannels(), 1, 8); binary.copyScale(imp); ImageProcessor binaryProcessor = binary.getProcessor(); binaryProcessor.invertLut(); if (imp.getCompositeMode() > 0) { ((CompositeImage) binary).setLuts(imp.getLuts()); } ImageStack is = binary.getImageStack(); ImageProcessor ip = binary.getProcessor(); for (Lines contours : result) { for (Line c : contours) { float[] x = c.getXCoordinates(); float[] y = c.getYCoordinates(); int[] x_poly_r = new int[x.length]; int[] y_poly_r = new int[x.length]; Polygon LineSurface = new Polygon(); ip = is.getProcessor(c.getFrame()); ip.setLineWidth(1); ip.setColor(255); for (int j = 0; j < x.length; j++) { // this draws the identified line if (j > 0) { ip.drawLine((int) Math.round(x[j - 1]), (int) Math.round(y[j - 1]), (int) Math.round(x[j]), (int) Math.round(y[j])); } // If Estimate Width is ticked, we also draw the line surface in the binary if (doEstimateWidth) { double nx = Math.sin(c.angle[j]); double ny = Math.cos(c.angle[j]); // left point coordinates are directly added to the polygon. right coordinates // are saved to be added at the end of the coordinates list LineSurface.addPoint((int) Math.round(x[j] - c.width_l[j] * nx), (int) Math.round(y[j] - c.width_l[j] * ny)); x_poly_r[j] = (int) Math.round(x[j] + c.width_r[j] * nx); y_poly_r[j] = (int) Math.round(y[j] + c.width_r[j] * ny); } } if (doEstimateWidth) { // loop to add the right coordinates to the end of the polygon, reversed for (int j = 0; j < x.length; j++) { if (j < x.length) { LineSurface.addPoint(x_poly_r[x.length - 1 - j], y_poly_r[x.length - 1 - j]); } } // draw surfaces. ip.fillPolygon(LineSurface); } } } binary.show(); binary.updateAndDraw(); }
Example 16
Source File: GraphicsTests.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
public void initContext(TestEnvironment env, Context ctx) { ctx.graphics = env.getGraphics(); int w = env.getWidth(); int h = env.getHeight(); ctx.size = env.getIntValue(sizeList); ctx.outdim = getOutputSize(ctx.size, ctx.size); ctx.pixscale = 1.0; if (hasGraphics2D) { Graphics2D g2d = (Graphics2D) ctx.graphics; AlphaComposite ac = (AlphaComposite) env.getModifier(compRules); if (env.isEnabled(doExtraAlpha)) { ac = AlphaComposite.getInstance(ac.getRule(), 0.125f); } g2d.setComposite(ac); if (env.isEnabled(doXor)) { g2d.setXORMode(Color.white); } if (env.isEnabled(doClipping)) { Polygon p = new Polygon(); p.addPoint(0, 0); p.addPoint(w, 0); p.addPoint(0, h); p.addPoint(w, h); p.addPoint(0, 0); g2d.clip(p); } Transform tx = (Transform) env.getModifier(transforms); Dimension envdim = new Dimension(w, h); tx.init(g2d, ctx, envdim); w = envdim.width; h = envdim.height; g2d.setRenderingHint(RenderingHints.KEY_RENDERING, env.getModifier(renderHint)); } switch (env.getIntValue(animList)) { case 0: ctx.animate = false; ctx.maxX = 3; ctx.maxY = 1; ctx.orgX = (w - ctx.outdim.width) / 2; ctx.orgY = (h - ctx.outdim.height) / 2; break; case 1: ctx.animate = true; ctx.maxX = Math.max(Math.min(32, w - ctx.outdim.width), 3); ctx.maxY = 1; ctx.orgX = (w - ctx.outdim.width - ctx.maxX) / 2; ctx.orgY = (h - ctx.outdim.height) / 2; break; case 2: ctx.animate = true; ctx.maxX = (w - ctx.outdim.width) + 1; ctx.maxY = (h - ctx.outdim.height) + 1; ctx.maxX = adjustWidth(ctx.maxX, ctx.maxY); ctx.maxX = Math.max(ctx.maxX, 3); ctx.maxY = Math.max(ctx.maxY, 1); // ctx.orgX = ctx.orgY = 0; break; } ctx.initX = ctx.maxX / 2; ctx.initY = ctx.maxY / 2; }
Example 17
Source File: clsUtility.java From mil-sym-java with Apache License 2.0 | 4 votes |
/** * construct a line segment outside the polygon corresponding to some index * @param tg * @param index * @param dist * @return */ protected static Line2D getExtendedLine(TGLight tg, int index, double dist) { Line2D line=null; try { Polygon polygon=new Polygon(); int j=0; for(j=0;j<tg.Pixels.size();j++) { polygon.addPoint((int)tg.Pixels.get(j).x, (int)tg.Pixels.get(j).y); } POINT2 pt0=null; POINT2 pt1=null; if(tg.Pixels.size()>3) { pt0=tg.Pixels.get(index); pt1=tg.Pixels.get(index+1); } else { pt0=tg.Pixels.get(1); pt1=tg.Pixels.get(2); } POINT2 ptExtend=null; int extend=-1; POINT2 midPt=lineutility.MidPointDouble(pt0, pt1,0); double slope=Math.abs(pt1.y-pt0.y)/(pt1.x-pt0.x); if(slope<=1) { ptExtend=lineutility.ExtendDirectedLine(pt0, pt1, midPt, lineutility.extend_above, 2); if(polygon.contains(ptExtend.x,ptExtend.y)) extend=lineutility.extend_below; else extend=lineutility.extend_above; } else { ptExtend=lineutility.ExtendDirectedLine(pt0, pt1, midPt, lineutility.extend_left, 2); if(polygon.contains(ptExtend.x,ptExtend.y)) extend=lineutility.extend_right; else extend=lineutility.extend_left; } POINT2 pt3=null; POINT2 pt4=null; pt3=lineutility.ExtendDirectedLine(pt0, pt1, pt0, extend, dist); pt4=lineutility.ExtendDirectedLine(pt0, pt1, pt1, extend, dist); line=new Line2D.Double(pt3.x, pt3.y, pt4.x, pt4.y); } catch (Exception exc) { ErrorLogger.LogException(_className, "getExtendedLine", new RendererException("Failed inside getExtendedLine", exc)); } return line; }
Example 18
Source File: ValueAxis.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Constructs a value axis. * * @param label the axis label (<code>null</code> permitted). * @param standardTickUnits the source for standard tick units * (<code>null</code> permitted). */ protected ValueAxis(String label, TickUnitSource standardTickUnits) { super(label); this.positiveArrowVisible = false; this.negativeArrowVisible = false; this.range = DEFAULT_RANGE; this.autoRange = DEFAULT_AUTO_RANGE; this.defaultAutoRange = DEFAULT_RANGE; this.inverted = DEFAULT_INVERTED; this.autoRangeMinimumSize = DEFAULT_AUTO_RANGE_MINIMUM_SIZE; this.lowerMargin = DEFAULT_LOWER_MARGIN; this.upperMargin = DEFAULT_UPPER_MARGIN; this.fixedAutoRange = 0.0; this.autoTickUnitSelection = DEFAULT_AUTO_TICK_UNIT_SELECTION; this.standardTickUnits = standardTickUnits; Polygon p1 = new Polygon(); p1.addPoint(0, 0); p1.addPoint(-2, 2); p1.addPoint(2, 2); this.upArrow = p1; Polygon p2 = new Polygon(); p2.addPoint(0, 0); p2.addPoint(-2, -2); p2.addPoint(2, -2); this.downArrow = p2; Polygon p3 = new Polygon(); p3.addPoint(0, 0); p3.addPoint(-2, -2); p3.addPoint(-2, 2); this.rightArrow = p3; Polygon p4 = new Polygon(); p4.addPoint(0, 0); p4.addPoint(2, -2); p4.addPoint(2, 2); this.leftArrow = p4; this.verticalTickLabels = false; }
Example 19
Source File: PixmapBorder.java From stendhal with GNU General Public License v2.0 | 4 votes |
@Override public void paintBorder(Component component, Graphics graphics, int x, int y, int width, int height) { Rectangle oldClip = graphics.getClipBounds(); Graphics g = graphics.create(); int borderWidth = getBorderWidth(component); // *** Clipping for top and left borders *** Polygon p = new Polygon(); p.addPoint(x, y); p.addPoint(x + width, y); p.addPoint(x + width - borderWidth, y + borderWidth); p.addPoint(x + borderWidth, y + borderWidth); p.addPoint(x + borderWidth, y + height - borderWidth); p.addPoint(x, y + height); g.setClip(p); g.clipRect(oldClip.x, oldClip.y, oldClip.width, oldClip.height); // top border for (int i = x; i < x + width; i += imageWidth) { g.drawImage(topLeftImage, i, y, null); } // left border for (int i = y; i < y + height; i += imageHeight) { g.drawImage(topLeftImage, x, i, null); } // *** Clipping for bottom and right borders *** // We have the same number of vertices as before, so it's efficient to // reuse the polygon p.reset(); p.addPoint(x + width, y); p.addPoint(x + width, y + height); p.addPoint(x, y + height); p.addPoint(x + borderWidth, y + height - borderWidth); p.addPoint(x + width - borderWidth, y + height - borderWidth); p.addPoint(x + width - borderWidth, y + borderWidth); g.setClip(p); g.clipRect(oldClip.x, oldClip.y, oldClip.width, oldClip.height); // Bottom border. More than one y coordinate may be needed in case the // tile border coincides to be inside the bottom border. int startY = y + height - borderWidth - (height - borderWidth) % imageHeight; int endY = y + height - height % imageHeight; for (int borderY = startY; borderY <= endY; borderY += imageHeight) { for (int i = x; i < x + width; i += imageWidth) { g.drawImage(bottomRightImage, i, borderY, null); } } // Right border. More than one x coordinate may be needed in case the // tile border coincides to be inside the right border. int startX = x + width - borderWidth - (width - borderWidth) % imageWidth; int endX = x + width - width % imageWidth; for (int borderX = startX; borderX <= endX; borderX += imageWidth) { for (int i = y; i < y + height; i += imageHeight) { g.drawImage(bottomRightImage, borderX, i, null); } } g.dispose(); }
Example 20
Source File: MultiGradientTest.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
public void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D)g.create(); int w = getWidth(); int h = getHeight(); g2d.setColor(Color.black); g2d.fillRect(0, 0, w, h); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antialiasHint); g2d.setRenderingHint(RenderingHints.KEY_RENDERING, renderHint); g2d.transform(transform); g2d.setPaint(paint); switch (shapeType) { default: case RECT: g2d.fillRect(0, 0, w, h); break; case ELLIPSE: g2d.fillOval(0, 0, w, h); break; case MULTIPLE: g2d.fillRect(0, 0, w/2, h/2); g2d.fillOval(w/2, 0, w/2, h/2); g2d.drawOval(0, h/2, w/2, h/2); g2d.drawLine(0, h/2, w/2, h); g2d.drawLine(0, h, w/2, h/2); Polygon p = new Polygon(); p.addPoint(w/2, h); p.addPoint(w, h); p.addPoint(3*w/4, h/2); g2d.fillPolygon(p); break; } switch (paintType) { default: case BASIC: case LINEAR: g2d.setColor(Color.white); g2d.fillRect(startX-1, startY-1, 2, 2); g2d.drawString("1", startX, startY + 12); g2d.fillRect(endX-1, endY-1, 2, 2); g2d.drawString("2", endX, endY + 12); break; case RADIAL: g2d.setColor(Color.white); g2d.fillRect(ctrX-1, ctrY-1, 2, 2); g2d.drawString("C", ctrX, ctrY + 12); g2d.fillRect(focusX-1, focusY-1, 2, 2); g2d.drawString("F", focusX, focusY + 12); break; } g2d.dispose(); }