List of usage examples for java.awt Polygon Polygon
public Polygon()
From source file:Utils.java
public static Shape generatePolygon(int sides, int outsideRadius, int insideRadius) { if (sides < 3) { return new Ellipse2D.Float(0, 0, 10, 10); }//from w w w. ja va2s .c om AffineTransform trans = new AffineTransform(); Polygon poly = new Polygon(); for (int i = 0; i < sides; i++) { trans.rotate(Math.PI * 2 / (float) sides / 2); Point2D out = trans.transform(new Point2D.Float(0, outsideRadius), null); poly.addPoint((int) out.getX(), (int) out.getY()); trans.rotate(Math.PI * 2 / (float) sides / 2); if (insideRadius > 0) { Point2D in = trans.transform(new Point2D.Float(0, insideRadius), null); poly.addPoint((int) in.getX(), (int) in.getY()); } } return poly; }
From source file:Main.java
public void paintIcon(Component c, Graphics g, int x, int y) { g.setColor(color);//from w w w . jav a2 s . c om Polygon p = new Polygon(); if (state == State.NORMAL) { p.addPoint(x + (getIconWidth() / 2), y); p.addPoint(x, y + getIconHeight() - 1); p.addPoint(x + getIconWidth() - 1, y + getIconHeight() - 1); } else if (state == State.PRESSED) { p.addPoint(x, y); p.addPoint(x + getIconWidth() - 1, y); p.addPoint(x + (getIconWidth() / 2), y + getIconHeight() - 1); } else { p.addPoint(x, y); p.addPoint(x, y + getIconHeight() - 1); p.addPoint(x + getIconWidth() - 1, y + (getIconHeight() / 2)); } g.fillPolygon(p); }
From source file:Test.java
License:asdf
private Polygon getPolygon() { int x1Points[] = { 0, 20, 100, 200, 330, 300, 200, 100 }; int y1Points[] = { 100, 200, 310, 300, 200, 100, 10, 0 }; Polygon polygon = new Polygon(); for (int i = 0; i < y1Points.length; i++) { polygon.addPoint(x1Points[i], y1Points[i]); }/*from w w w. java 2s . co m*/ return polygon; }
From source file:ArrowPanel.java
/** * Returns an up arrow.// www.jav a 2 s . c o m * * @return an up arrow. */ private Shape getUpArrow() { final Polygon result = new Polygon(); result.addPoint(7, 2); result.addPoint(2, 7); result.addPoint(12, 7); return result; }
From source file:CheckBoxSample.java
private void initPolygon() { polygon = new Polygon(); int halfWidth = width / 2; int halfHeight = height / 2; polygon.addPoint(0, halfHeight);/* w w w . j a v a 2 s . c o m*/ polygon.addPoint(halfWidth, 0); polygon.addPoint(width, halfHeight); polygon.addPoint(halfWidth, height); }
From source file:Main.java
/** * Draws a single arrow head//from ww w .j a v a 2s . co m * * @param aG * the canvas to draw on; * @param aXpos * the X position of the arrow head; * @param aYpos * the (center) Y position of the arrow head; * @param aFactor * +1 to have a left-facing arrow head, -1 to have a right-facing * arrow head; * @param aArrowWidth * the total width of the arrow head; * @param aArrowHeight * the total height of the arrow head. */ public static final void drawArrowHead(final Graphics2D aG, final int aXpos, final int aYpos, final int aFactor, final int aArrowWidth, final int aArrowHeight) { final double halfHeight = aArrowHeight / 2.0; final int x1 = aXpos + (aFactor * aArrowWidth); final int y1 = (int) Math.ceil(aYpos - halfHeight); final int y2 = (int) Math.floor(aYpos + halfHeight); final Polygon arrowHead = new Polygon(); arrowHead.addPoint(aXpos, aYpos); arrowHead.addPoint(x1, y1); arrowHead.addPoint(x1, y2); aG.fill(arrowHead); }
From source file:UndoDrawing.java
public Polygon getPolygon() { Polygon returnValue;/*w w w . j ava 2 s . co m*/ if (polygon.npoints == 0) { returnValue = new Polygon(); } else { returnValue = new Polygon(polygon.xpoints, polygon.ypoints, polygon.npoints); } return returnValue; }
From source file:ArrowPanel.java
/** * Returns a down arrow.//from w ww . j a v a 2 s . c o m * * @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; }
From source file:org.uva.itast.blended.omr.scanners.SolidSquareMarkScanner.java
/** * @param pageImage/*from w ww.ja v a2s . com*/ */ public void putEmphasisMarkOnImage(PageImage pageImage, Color color) { Graphics2D g = pageImage.getReportingGraphics(); // int centerColor=imagen.getRGB(maxsimX, maxsimY); // g.setXORMode(new Color(centerColor)); // g.setColor(Color.RED); // g.fillOval(maxsimX - markWidth/2, maxsimY - markHeight/2, markWidth, // markHeight); // g.setPaintMode(); Dimension2D markDimsPx = pageImage.sizeInPixels(new Size(markWidth, markHeight)); int markWidth = (int) markDimsPx.getWidth(); int markHeight = (int) markDimsPx.getHeight(); g.setColor(color); AffineTransform t = g.getTransform(); g.drawLine(maxsimX, maxsimY - markHeight / 2 - 1, maxsimX, maxsimY - markHeight / 2 - (int) (20 / t.getScaleY())); Polygon arrowHead = new Polygon(); arrowHead.addPoint(maxsimX, (int) (maxsimY - markHeight / 2 - 1 / t.getScaleY())); arrowHead.addPoint((int) (maxsimX - 6 / t.getScaleX()), (int) (maxsimY - markHeight / 2 - 6 / t.getScaleY())); arrowHead.addPoint((int) (maxsimX + 6 / t.getScaleX()), (int) (maxsimY - markHeight / 2 - 6 / t.getScaleY())); g.fillPolygon(arrowHead); g.setStroke(new BasicStroke(2, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 1, new float[] { (float) (3 / t.getScaleX()), (float) (3 / t.getScaleY()) }, 0)); g.drawRect(maxsimX - markWidth / 2 - 1, maxsimY - markHeight / 2 - 1, markWidth + 1, markHeight + 1); }
From source file:edu.ku.brc.ui.GraphicsUtils.java
/** * Draws an arrow from <code>(xCenter,yCenter)</code> to <code>(x,y)</code>. * Code stolen from http://forum.java.sun.com/thread.jspa?threadID=378460&tstart=135. * /*from w ww . ja v a 2 s. c o m*/ * @param g the graphics context to draw in * @param headSize the size of the arrow head * @param xCenter the x-coord of the arrow tail * @param yCenter the y-coord of the arrow tail * @param x the x-coord of the arrow head's tip * @param y the y-coord of the arrow head's tip * @param stroke the <code>Stroke</code> to use */ public static void drawArrow(Graphics g, int xCenter, int yCenter, int x, int y, int headSize, float stroke) { Graphics2D g2d = (Graphics2D) g; g2d.addRenderingHints(hints); double aDir = Math.atan2(xCenter - x, yCenter - y); Stroke origStroke = g2d.getStroke(); g2d.setStroke(new BasicStroke(stroke)); // make the arrow head solid even if dash pattern has been specified g2d.drawLine(x, y, xCenter, yCenter); Polygon tmpPoly = new Polygon(); int i1 = 2 * headSize + (int) stroke; //(stroke * 2); int i2 = headSize + (int) stroke; // make the arrow head the same size regardless of the length length tmpPoly.addPoint(x, y); // arrow tip tmpPoly.addPoint(x + xCor(i1, aDir + .5), y + yCor(i1, aDir + .5)); tmpPoly.addPoint(x + xCor(i2, aDir), y + yCor(i2, aDir)); tmpPoly.addPoint(x + xCor(i1, aDir - .5), y + yCor(i1, aDir - .5)); tmpPoly.addPoint(x, y); // arrow tip g2d.drawPolygon(tmpPoly); g2d.fillPolygon(tmpPoly); // remove this line to leave arrow head unpainted g2d.setStroke(origStroke); }