List of usage examples for java.awt Graphics fillPolygon
public abstract void fillPolygon(int[] xPoints, int[] yPoints, int nPoints);
From source file:edu.upf.bioevo.manhattanPlotter.QQPlot.java
void drawPlot() { int dotRadius; int xIncrement = (IMAGE_WIDTH - (xMargin * 2)) / (int) (maxExpectedLogValue + 1); int yIncrement = (IMAGE_HEIGHT - (yMargin * 2)) / (int) (maxObservedLogValue + 1); Graphics g = image.getGraphics(); // Cleans image g.setColor(Color.WHITE);//from w ww . j a v a 2 s . c o m g.fillRect(0, 0, image.getWidth(), image.getHeight()); // Draws axis lines g.setColor(Color.black); g.drawLine(xMargin, IMAGE_HEIGHT - yMargin, IMAGE_WIDTH - xMargin, IMAGE_HEIGHT - yMargin); g.drawLine(xMargin, IMAGE_HEIGHT - yMargin, xMargin, yMargin); // Draws confidence interval if (ic95Option) { g.setColor(Color.lightGray); for (int i = 0; i < upperCI.length - 1; i++) { int[] xPoints = { xMargin + (int) (orderedLog10ExpectedValues[i] * xIncrement), xMargin + (int) (orderedLog10ExpectedValues[i] * xIncrement), xMargin + (int) (orderedLog10ExpectedValues[i + 1] * xIncrement), xMargin + (int) (orderedLog10ExpectedValues[i + 1] * xIncrement) }; int[] yPoints = { IMAGE_HEIGHT - (yMargin + ((int) (upperCI[i] * yIncrement))), IMAGE_HEIGHT - (yMargin + ((int) (lowerCI[i] * yIncrement))), IMAGE_HEIGHT - (yMargin + ((int) (lowerCI[i + 1] * yIncrement))), IMAGE_HEIGHT - (yMargin + ((int) (upperCI[i + 1] * yIncrement))) }; g.fillPolygon(xPoints, yPoints, 4); } } // Draws dots dotRadius = 4; g.setColor(Color.black); for (int i = 0; i < orderedLog10ObservedValues.length; i++) { int xPosition = xMargin + ((int) (orderedLog10ExpectedValues[i] * xIncrement)); int yPosition = IMAGE_HEIGHT - (yMargin + ((int) (orderedLog10ObservedValues[i] * yIncrement))); g.fillOval(xPosition - dotRadius, yPosition - dotRadius, dotRadius * 2, dotRadius * 2); } // --draw y axis scale // ----Calculates interval between labels in y axis int yInterval = 1; int verticalMaxValue = (int) maxObservedLogValue + 1; if (verticalMaxValue > 20) { yInterval = 5; } if (verticalMaxValue > 100) { yInterval = 50; } if (verticalMaxValue > 1000) { yInterval = verticalMaxValue; } g.setColor(Color.BLACK); for (int i = 0; i <= verticalMaxValue; i = i + yInterval) { int yPos = IMAGE_HEIGHT - (yMargin + (int) (((float) i / verticalMaxValue) * (IMAGE_HEIGHT - 2 * yMargin))); g.fillRect(45, yPos, 15, 3); g.setFont(new Font("courier", 1, 30)); String value = String.valueOf(i); if (value.length() == 1) { value = " " + value; } g.drawString(value, 5, yPos + 10); } // --draw x axis scale // ----Calculates interval between labels in x axis int xInterval = 1; int horizontalMaxValue = (int) maxExpectedLogValue + 1; if (horizontalMaxValue > 20) { xInterval = 5; } if (horizontalMaxValue > 100) { xInterval = 50; } if (horizontalMaxValue > 1000) { xInterval = verticalMaxValue; } g.setColor(Color.BLACK); for (int i = 0; i <= horizontalMaxValue; i = i + xInterval) { int xPos = (xMargin + (int) (((float) i / horizontalMaxValue) * (IMAGE_WIDTH - 2 * xMargin))); g.fillRect(xPos, IMAGE_HEIGHT - yMargin, 3, 15); g.setFont(new Font("courier", 1, 30)); String value = String.valueOf(i); if (value.length() == 1) { value = " " + value; } g.drawString(value, xPos - 15, IMAGE_HEIGHT - yMargin + 45); } // Draws identity line g.setColor(Color.RED); int endLineValue = horizontalMaxValue < verticalMaxValue ? horizontalMaxValue : verticalMaxValue; g.drawLine(xMargin, IMAGE_HEIGHT - yMargin, xMargin + ((int) (endLineValue * xIncrement)), IMAGE_HEIGHT - (yMargin + ((int) (endLineValue * yIncrement)))); // -- title g.setColor(Color.blue); g.setFont(new Font("arial", 1, 35)); g.drawString(label, IMAGE_WIDTH / 7, 40); }
From source file:edu.umn.cs.spatialHadoop.core.OGCJTSShape.java
/** * Draw the given JTS Geometry to the graphics using specific scales in x and y * @param g Graphics to draw to// w ww . ja va 2s . c o m * @param geom The geometry to draw * @param xscale The scale of the x-axis in terms in pixels/units * @param yscale The scale of the y-axis in terms of pixels/units * @param fill Whether to fill the shape or just draw an outline */ public static void drawJTSGeom(Graphics g, Geometry geom, double xscale, double yscale, boolean fill) { if (geom instanceof GeometryCollection) { GeometryCollection geom_coll = (GeometryCollection) geom; for (int i = 0; i < geom_coll.getNumGeometries(); i++) { Geometry sub_geom = geom_coll.getGeometryN(i); // Recursive call to draw each geometry drawJTSGeom(g, sub_geom, xscale, yscale, fill); } } else if (geom instanceof com.vividsolutions.jts.geom.Polygon) { com.vividsolutions.jts.geom.Polygon poly = (com.vividsolutions.jts.geom.Polygon) geom; for (int i = 0; i < poly.getNumInteriorRing(); i++) { LineString ring = poly.getInteriorRingN(i); drawJTSGeom(g, ring, xscale, yscale, fill); } drawJTSGeom(g, poly.getExteriorRing(), xscale, yscale, fill); } else if (geom instanceof LineString) { LineString line = (LineString) geom; double geom_alpha = line.getLength() * (xscale + yscale) / 2.0; int color_alpha = geom_alpha > 1.0 ? 255 : (int) Math.round(geom_alpha * 255); if (color_alpha == 0) return; int[] xpoints = new int[line.getNumPoints()]; int[] ypoints = new int[line.getNumPoints()]; int n = 0; for (int i = 0; i < xpoints.length; i++) { double px = line.getPointN(i).getX(); double py = line.getPointN(i).getY(); // Transform a point in the polygon to image coordinates xpoints[n] = (int) Math.round(px * xscale); ypoints[n] = (int) Math.round(py * yscale); // Include this point only if first point or different than previous point if (n == 0 || xpoints[n] != xpoints[n - 1] || ypoints[n] != ypoints[n - 1]) n++; } // Draw the polygon //graphics.setColor(new Color((shape_color.getRGB() & 0x00FFFFFF) | (color_alpha << 24), true)); if (n == 1) g.fillRect(xpoints[0], ypoints[0], 1, 1); else if (!fill) g.drawPolyline(xpoints, ypoints, n); else g.fillPolygon(xpoints, ypoints, n); } }
From source file:com.jcraft.weirdx.Draw.java
@SuppressWarnings("unused") static void reqFillPoly(Client c, XDrawable d, GC gc) throws IOException { int n = c.length; int foo;//from ww w .ja va2 s.c om Graphics graphics = d.getGraphics(gc, GC.GCFunction | GC.GCSubwindowMode); if (graphics == null) { c.client.readPad(n * 4); return; } byte shape; shape = (byte) c.client.readByte(); byte cmode; cmode = (byte) c.client.readByte(); c.client.readPad(2); n--; if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { java.awt.Rectangle rec = (Rectangle) (gc.clip_mask.getMask()); if (rec == null) { while (n > 0) { c.client.readPad(4); n--; } return; } } short x, y; int sx = d.width; int sy = d.height; int lx = 0; int ly = 0; if (c.xarray.length < n) { c.xarray = new int[n]; c.yarray = new int[n]; } foo = c.xarray[0] = (short) c.client.readShort(); if (foo < sx) sx = foo; if (lx < foo) lx = foo; foo = c.yarray[0] = (short) c.client.readShort(); if (foo < sy) sy = foo; if (ly < foo) ly = foo; for (int i = 1; i < n; i++) { c.xarray[i] = (short) c.client.readShort(); c.yarray[i] = (short) c.client.readShort(); if (cmode == 1) { c.xarray[i] += c.xarray[i - 1]; c.yarray[i] += c.yarray[i - 1]; } foo = c.xarray[i]; if (foo < sx) sx = foo; if (lx < foo) lx = foo; foo = c.yarray[i]; if (foo < sy) sy = foo; if (ly < foo) ly = foo; } graphics.fillPolygon(c.xarray, c.yarray, n); if (sx < 0) sx = 0; if (sy < 0) sy = 0; if (d instanceof XWindow) { ((XWindow) d).draw(sx, sy, lx - sx + 1, ly - sy + 1); } if (gc.function == GC.GXxor || gc.function == GC.GXinvert) { graphics.setPaintMode(); } if (gc.clip_mask != null && gc.clip_mask instanceof ClipRectangles) { d.restoreClip(); } }
From source file:org.processmining.analysis.performance.dottedchart.ui.DottedChartPanel.java
/** * convenience method for internal use. paints a log item handle * visualization./*from w w w.j a v a 2 s . c o m*/ * * @param x * horizontal anchor coordinate of the handle * @param y * vertical anchor coordinate of the handle * @param g * the Graphics object used for painting */ protected void paintItem_buffer(int x, int y, Graphics g, String shape) { if (shape.equals(STR_NONE)) { return; } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DOT)) { g.fillOval(x - 2, y - 2, 7, 7); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_BOX)) { g.fill3DRect(x - 3, y - 3, 6, 6, false); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_CIRCLE)) { g.fillOval(x - 2, y - 2, 7, 7); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_RHOMBUS)) { int rhombX[] = { x, x - 3, x, x + 3 }; int rhombY[] = { y - 3, y, y + 3, y }; g.fillPolygon(rhombX, rhombY, 4); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_TRIANGLE)) { int triX[] = { x, x - 3, x + 3 }; int triY[] = { y + 3, y - 3, y - 3 }; g.fillPolygon(triX, triY, 3); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_ROUND_BOX)) { g.fillRoundRect(x - 3, y - 3, 6, 6, 2, 2); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_BOX)) { g.drawRect(x - 3, y - 3, 6, 6); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_CIRCLE)) { g.drawOval(x - 2, y - 2, 7, 7); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_RHOMBUS)) { int rhombX[] = { x, x - 3, x, x + 3 }; int rhombY[] = { y - 3, y, y + 3, y }; g.drawPolygon(rhombX, rhombY, 4); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_TRIANGLE)) { int triX[] = { x, x - 3, x + 3 }; int triY[] = { y + 3, y - 3, y - 3 }; g.drawPolygon(triX, triY, 3); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_ROUND_BOX)) { g.drawRoundRect(x - 3, y - 3, 6, 6, 2, 2); } }
From source file:org.processmining.analysis.performance.dottedchart.ui.DottedChartPanel.java
/** * convenience method for internal use. paints a log item handle * visualization.//from w w w .j a v a 2s . com * * @param x * horizontal anchor coordinate of the handle * @param y * vertical anchor coordinate of the handle * @param g * the Graphics object used for painting */ protected void paintItem(int x, int y, Graphics g, String shape) { if (shape.equals(STR_NONE)) { return; } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DOT)) { g.fillOval(x - 2, y - 2, 4, 4); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_BOX)) { g.fill3DRect(x - 5, y - 5, 10, 10, false); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_CIRCLE)) { g.fillOval(x - 5, y - 5, 11, 11); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_RHOMBUS)) { int rhombX[] = { x, x - 5, x, x + 5 }; int rhombY[] = { y - 5, y, y + 5, y }; g.fillPolygon(rhombX, rhombY, 4); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_TRIANGLE)) { int triX[] = { x, x - 5, x + 5 }; int triY[] = { y + 5, y - 5, y - 5 }; g.fillPolygon(triX, triY, 3); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_ROUND_BOX)) { g.fillRoundRect(x - 5, y - 5, 10, 10, 2, 2); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_BOX)) { g.drawRect(x - 5, y - 5, 10, 10); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_CIRCLE)) { g.drawOval(x - 5, y - 5, 11, 11); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_RHOMBUS)) { int rhombX[] = { x, x - 5, x, x + 5 }; int rhombY[] = { y - 5, y, y + 5, y }; g.drawPolygon(rhombX, rhombY, 4); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_TRIANGLE)) { int triX[] = { x, x - 5, x + 5 }; int triY[] = { y + 5, y - 5, y - 5 }; g.drawPolygon(triX, triY, 3); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_ROUND_BOX)) { g.drawRoundRect(x - 5, y - 5, 10, 10, 2, 2); } }
From source file:org.processmining.analysis.performance.dottedchart.ui.DottedChartPanel.java
/** * convenience method for internal use. paints a log item handle * visualization./*from w w w. j a v a2s .c o m*/ * * @param x * horizontal anchor coordinate of the handle * @param y * vertical anchor coordinate of the handle * @param g * the Graphics object used for painting */ protected void paintHighligtedItem(int x, int y, Graphics g, String shape) { Color color = g.getColor(); if (shape.equals(STR_NONE)) { return; } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DOT)) { if (!color.equals(Color.red)) g.setColor(Color.red); else g.setColor(Color.black); g.fillOval(x - 3, y - 3, 6, 6); g.setColor(color); g.fillOval(x - 2, y - 2, 4, 4); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_BOX)) { if (!color.equals(Color.black)) g.setColor(Color.black); else g.setColor(Color.red); g.fillRect(x - 6, y - 6, 12, 12); g.setColor(color); g.fill3DRect(x - 5, y - 5, 10, 10, false); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_CIRCLE)) { if (!color.equals(Color.black)) g.setColor(Color.black); else g.setColor(Color.red); g.fillOval(x - 6, y - 6, 13, 13); g.setColor(color); g.fillOval(x - 5, y - 5, 11, 11); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_RHOMBUS)) { int rhombX[] = { x, x - 5, x, x + 5 }; int rhombY[] = { y - 5, y, y + 5, y }; g.fillPolygon(rhombX, rhombY, 4); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_TRIANGLE)) { int triX[] = { x, x - 5, x + 5 }; int triY[] = { y + 5, y - 5, y - 5 }; g.fillPolygon(triX, triY, 3); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_ROUND_BOX)) { if (!color.equals(Color.black)) g.setColor(Color.black); else g.setColor(Color.red); g.fillRoundRect(x - 6, y - 6, 13, 13, 2, 2); g.setColor(color); g.fillRoundRect(x - 5, y - 5, 10, 10, 2, 2); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_BOX)) { g.drawRect(x - 5, y - 5, 10, 10); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_CIRCLE)) { if (!color.equals(Color.black)) g.setColor(Color.black); else g.setColor(Color.red); g.fillOval(x - 6, y - 6, 13, 13); g.setColor(color); g.drawOval(x - 5, y - 5, 11, 11); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_RHOMBUS)) { int rhombX[] = { x, x - 5, x, x + 5 }; int rhombY[] = { y - 5, y, y + 5, y }; g.drawPolygon(rhombX, rhombY, 4); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_TRIANGLE)) { int triX[] = { x, x - 5, x + 5 }; int triY[] = { y + 5, y - 5, y - 5 }; g.drawPolygon(triX, triY, 3); } else if (shape.equals(DottedChartPanel.ITEM_HANDLE_DRAW_ROUND_BOX)) { g.drawRoundRect(x - 5, y - 5, 10, 10, 2, 2); } }