Java Code Examples for java.awt.geom.GeneralPath#reset()
The following examples show how to use
java.awt.geom.GeneralPath#reset() .
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: Flag.java From freecol with GNU General Public License v2.0 | 6 votes |
private void drawPerSaltire(Graphics2D g) { int colors = backgroundColors.size(); GeneralPath path = new GeneralPath(); int[] x = { 0, WIDTH, WIDTH, 0 }; int[] y = { 0, 0, HEIGHT, HEIGHT }; double halfWidth = WIDTH / 2; double halfHeight = HEIGHT / 2; for (int index = 0; index < 4; index++) { path.moveTo(x[index], y[index]); path.lineTo(halfWidth, halfHeight); int nextIndex = (index + 1) % 4; path.lineTo(x[nextIndex], y[nextIndex]); g.setColor(backgroundColors.get(index % colors)); g.fill(path); path.reset(); } }
Example 2
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 3
Source File: PDFObjectExtractor.java From pdfxtk with Apache License 2.0 | 6 votes |
public void StrokePath() throws IOException{ graphics.setColor( getGraphicsState().getStrokingColor().getJavaColor() ); //per Ben's 11/15 change in StrokePath.java List subPaths = getLineSubPaths(); for( int i=0; i<subPaths.size(); i++ ) { GeneralPath subPath = (GeneralPath)subPaths.get( i ); graphics.draw( subPath ); /* Rectangle bBox = subPath.getBounds(); Point2D point1 = TransformedPoint(bBox.x, bBox.y); Point2D point2 = TransformedPoint(bBox.x + bBox.width, bBox.y + bBox.height); //RectSegment ls = new RectSegment(bBox.x, bBox.x*bBox.width, bBox.y, bBox.y+bBox.height); RectSegment ls = new RectSegment((float)point1.getX(), (float)point2.getX(), (float)point1.getY(), (float)point2.getY()); System.out.println("strokePath adding line segment: " + ls); rectList.add(ls);*/ } subPaths.clear(); GeneralPath path = getLinePath(); graphics.draw( path ); path.reset(); }
Example 4
Source File: Draw.java From MeteoInfo with GNU Lesser General Public License v3.0 | 5 votes |
/** * Draw polyline * * @param points The points * @param pbc The polyline break collection * @param g Graphics2D */ public static void drawPolyline(PointF[] points, ColorBreakCollection pbc, Graphics2D g) { GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, points.length); PointF p; PolylineBreak aPLB; List<PointF> drawPs = new ArrayList<>(); for (int i = 0; i < points.length; i++) { p = points[i]; if (i == 0) { path.moveTo(p.X, p.Y); } else { path.lineTo(p.X, p.Y); aPLB = (PolylineBreak) pbc.get(i); Color aColor = aPLB.getColor(); Float size = aPLB.getWidth(); float[] dashPattern = getDashPattern(aPLB.getStyle()); BasicStroke pen = new BasicStroke(size, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, dashPattern, 0.0f); g.setColor(aColor); g.setStroke(pen); g.draw(path); path.reset(); path.moveTo(p.X, p.Y); //Draw symbol if (aPLB.getDrawSymbol()) { Object rend = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); for (int j = 0; j < drawPs.size(); j++) { Draw.drawPoint(aPLB.getSymbolStyle(), p, aPLB.getSymbolFillColor(), aPLB.getSymbolColor(), aPLB.getSymbolSize(), true, aPLB.isFillSymbol(), g); } g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, rend); } } drawPs.add(p); } }
Example 5
Source File: BlockLetter.java From pumpernickel with MIT License | 5 votes |
public void apply(GeneralPath body, BlockLetter gbl) { body.reset(); int dx = (int) (gbl.depth * Math.cos(gbl.angle)); int dy = (int) (gbl.depth * Math.sin(gbl.angle)); body.moveTo(x1, y1); body.lineTo(x2, y2); body.lineTo(x2 + dx, y2 + dy); body.lineTo(x1 + dx, y1 + dy); body.closePath(); }
Example 6
Source File: QPanelUIDemo.java From pumpernickel with MIT License | 5 votes |
@Override public void paint(Graphics g0) { super.paint(g0); if (rolloverPreview) { Graphics2D g = (Graphics2D) g0.create(); g.setColor(new Color(0, 0, 0, 100)); Insets i = getInsets(); GeneralPath shape = new GeneralPath(); shape.moveTo(getWidth() / 3 - 4, 0); shape.lineTo(getWidth() / 3 - 0, 0); shape.lineTo(getWidth() / 3 - 0, getHeight() - 1); shape.lineTo(getWidth() / 3 - 4, getHeight() - 1); g.draw(shape); g.drawLine(getWidth() / 3 - 2, i.top, getWidth() / 3, i.top); g.drawLine(getWidth() / 3 - 2, getHeight() - i.bottom, getWidth() / 3, getHeight() - i.bottom); shape.reset(); shape.moveTo(0, getHeight() / 3 - 4); shape.lineTo(0, getHeight() / 3 - 0); shape.lineTo(getWidth() - 1, getHeight() / 3 - 0); shape.lineTo(getWidth() - 1, getHeight() / 3 - 4); g.draw(shape); g.drawLine(i.left, getHeight() / 3 - 2, i.left, getHeight() / 3); g.drawLine(getWidth() - i.right, getHeight() / 3 - 2, getWidth() - i.right, getHeight() / 3); } }
Example 7
Source File: Tree.java From energy2d with GNU Lesser General Public License v3.0 | 5 votes |
public static Area getShape(Rectangle2D.Float r, byte type) { // the positions and sizes of the circles must ensure that r is the bounding box Area a = new Area(new Rectangle2D.Float(r.x + r.width * 0.45f, r.y + r.height * 0.5f, r.width * 0.1f, r.height * 0.5f)); switch (type) { case REGULAR: float p = Math.min(r.width, r.height) * 0.6f; float q = p * 0.8f; a.add(new Area(new Ellipse2D.Float(r.x + (r.width - p) * 0.5f, r.y, p, p))); a.add(new Area(new Ellipse2D.Float(r.x, r.y + p * 0.8f, q, q))); a.add(new Area(new Ellipse2D.Float(r.x + r.width - q, r.y + p * 0.8f, q, q))); break; case PINE: GeneralPath path = new GeneralPath(); path.moveTo(r.x + r.width * 0.5f, r.y); path.lineTo(r.x + r.width * 0.3f, r.y + r.height * 0.3f); path.lineTo(r.x + r.width * 0.7f, r.y + r.height * 0.3f); a.add(new Area(path)); path.reset(); path.moveTo(r.x + r.width * 0.5f, r.y + r.height * 0.2f); path.lineTo(r.x + r.width * 0.2f, r.y + r.height * 0.5f); path.lineTo(r.x + r.width * 0.8f, r.y + r.height * 0.5f); a.add(new Area(path)); path.reset(); path.moveTo(r.x + r.width * 0.5f, r.y + r.height * 0.3f); path.lineTo(r.x, r.y + r.height * 0.8f); path.lineTo(r.x + r.width, r.y + r.height * 0.8f); a.add(new Area(path)); break; } return a; }
Example 8
Source File: GeneralPathLoader.java From osp with GNU General Public License v3.0 | 5 votes |
public Object loadObject(XMLControl control, Object obj) { GeneralPath path = (GeneralPath) obj; path.reset(); path.setWindingRule(control.getInt("winding rule")); //$NON-NLS-1$ loadPathSegments(path, control.getString("segments")); //$NON-NLS-1$ return path; }
Example 9
Source File: GridRenderer.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void drawGridHoriz(java.awt.Graphics2D g, Array data) { int count = 0; GridCoordSystem geocs = stridedGrid.getCoordinateSystem(); CoordinateAxis xaxis = geocs.getXHorizAxis(); CoordinateAxis yaxis = geocs.getYHorizAxis(); if ((xaxis instanceof CoordinateAxis1D) && (yaxis instanceof CoordinateAxis1D)) { drawGridHoriz1D(g, data, (CoordinateAxis1D) xaxis, (CoordinateAxis1D) yaxis); return; } data = data.reduce(); if (data.getRank() != 2) throw new IllegalArgumentException("must be 2D"); if (!(xaxis instanceof CoordinateAxis2D) || !(yaxis instanceof CoordinateAxis2D)) throw new IllegalArgumentException("must be CoordinateAxis2D"); // 2D case CoordinateAxis2D xaxis2D = (CoordinateAxis2D) xaxis; CoordinateAxis2D yaxis2D = (CoordinateAxis2D) yaxis; String stag = geocs.getHorizStaggerType(); if (CDM.ARAKAWA_E.equals(stag)) { drawGridHorizRotated(g, data, xaxis2D, yaxis2D); return; } ArrayDouble.D2 edgex = xaxis2D.getEdges(); ArrayDouble.D2 edgey = yaxis2D.getEdges(); Index ima = data.getIndex(); GeneralPath gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 5); int[] shape = xaxis2D.getShape(); // should both be the same int ny = shape[0]; int nx = shape[1]; for (int y = 0; y < ny; y++) { for (int x = 0; x < nx; x++) { gp.reset(); gp.moveTo((float) edgex.get(y, x), (float) edgey.get(y, x)); gp.lineTo((float) edgex.get(y, x + 1), (float) edgey.get(y, x + 1)); gp.lineTo((float) edgex.get(y + 1, x + 1), (float) edgey.get(y + 1, x + 1)); gp.lineTo((float) edgex.get(y + 1, x), (float) edgey.get(y + 1, x)); // debug F:\data2\formats\hdf4\AMSR_E_L2A_BrightnessTemperatures_V08_200801012345_A.hdf if (false) { double d1 = Math.abs(edgex.get(y, x) - edgex.get(y, x + 1)); double d2 = Math.abs(edgex.get(y, x + 1) - edgex.get(y + 1, x + 1)); double d3 = Math.abs(edgex.get(y + 1, x + 1) - edgex.get(y + 1, x)); double d4 = Math.abs(edgex.get(y + 1, x) - edgex.get(y, x)); if (Math.abs(d1) > 10 || Math.abs(d2) > 10 || Math.abs(d3) > 10 || Math.abs(d4) > 10) { System.out.printf("x=%d y=%d %n", x, y); System.out.printf("%f %f %f %f %n", edgex.get(y, x), edgex.get(y, x + 1), edgex.get(y + 1, x), edgex.get(y + 1, x + 1)); System.out.printf("%n%s", Ncdump.printArray(edgex.slice(0, y + 1), "row " + y, null)); System.out.printf("%n%s", Ncdump.printArray(edgex.slice(0, y + 1), "row " + (y + 1), null)); } } double val = data.getDouble(ima.set(y, x)); // ordering LOOK int colorIndex = cs.getIndexFromValue(val); g.setColor(cs.getColor(colorIndex)); g.fill(gp); } } }
Example 10
Source File: GridRenderer.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void drawGridLines(java.awt.Graphics2D g) { int count = 0; GridCoordSystem geocs = stridedGrid.getCoordinateSystem(); CoordinateAxis xaxis = geocs.getXHorizAxis(); CoordinateAxis yaxis = geocs.getYHorizAxis(); if (!(xaxis instanceof CoordinateAxis2D) || !(yaxis instanceof CoordinateAxis2D)) return; // 2D case CoordinateAxis2D xaxis2D = (CoordinateAxis2D) xaxis; CoordinateAxis2D yaxis2D = (CoordinateAxis2D) yaxis; ArrayDouble.D2 edgex = xaxis2D.getEdges(); ArrayDouble.D2 edgey = yaxis2D.getEdges(); GeneralPath gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 5); g.setColor(Color.BLACK); int[] shape = xaxis2D.getShape(); // should both be the same int ny = shape[0]; int nx = shape[1]; for (int y = 0; y < ny + 1; y += 10) { gp.reset(); for (int x = 0; x < nx + 1; x++) { if (x == 0) gp.moveTo((float) edgex.get(y, x), (float) edgey.get(y, x)); else gp.lineTo((float) edgex.get(y, x), (float) edgey.get(y, x)); } g.draw(gp); } for (int x = 0; x < nx + 1; x += 10) { gp.reset(); for (int y = 0; y < ny + 1; y++) { if (y == 0) gp.moveTo((float) edgex.get(y, x), (float) edgey.get(y, x)); else gp.lineTo((float) edgex.get(y, x), (float) edgey.get(y, x)); } g.draw(gp); } }
Example 11
Source File: CoverageRenderer.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void drawGridHoriz(java.awt.Graphics2D g, GeoReferencedArray geo) { CoverageCoordSys csData = geo.getCoordSysForData(); HorizCoordSys hcs = csData.getHorizCoordSys(); if (!hcs.isLatLon2D()) { drawGridHorizRegular(g, geo); return; } // 2D case Array data = geo.getData(); data = data.reduce(); if (data.getRank() != 2) throw new IllegalArgumentException("must be 2D"); Index ima = data.getIndex(); LatLonAxis2D xaxis2D = hcs.getLonAxis2D(); LatLonAxis2D yaxis2D = hcs.getLatAxis2D(); /* * String stag = geocs.getHorizStaggerType(); * if (stag != null && stag.equals(CDM.ARAKAWA_E)) { * drawGridHorizRotated(g, data, xaxis2D, yaxis2D); * return; * } */ ArrayDouble.D2 edgex = (ArrayDouble.D2) xaxis2D.getCoordBoundsAsArray(); ArrayDouble.D2 edgey = (ArrayDouble.D2) yaxis2D.getCoordBoundsAsArray(); GeneralPath gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 5); int[] shape = xaxis2D.getShape(); // should both be the same int ny = shape[0]; int nx = shape[1]; for (int y = 0; y < ny; y++) { for (int x = 0; x < nx; x++) { gp.reset(); gp.moveTo((float) edgex.get(y, x), (float) edgey.get(y, x)); gp.lineTo((float) edgex.get(y, x + 1), (float) edgey.get(y, x + 1)); gp.lineTo((float) edgex.get(y + 1, x + 1), (float) edgey.get(y + 1, x + 1)); gp.lineTo((float) edgex.get(y + 1, x), (float) edgey.get(y + 1, x)); double val = data.getDouble(ima.set(y, x)); // ordering LOOK int colorIndex = colorScale.getIndexFromValue(val); g.setColor(colorScale.getColor(colorIndex)); g.fill(gp); } } }
Example 12
Source File: CoverageRenderer.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void drawGridLines(java.awt.Graphics2D g, GeoReferencedArray geo) { CoverageCoordSys geocs = geo.getCoordSysForData(); LatLonAxis2D lataxis = geocs.getHorizCoordSys().getLatAxis2D(); LatLonAxis2D lonaxis = geocs.getHorizCoordSys().getLonAxis2D(); if (lataxis == null || lonaxis == null) return; ArrayDouble.D2 edgex = (ArrayDouble.D2) lonaxis.getCoordBoundsAsArray(); ArrayDouble.D2 edgey = (ArrayDouble.D2) lataxis.getCoordBoundsAsArray(); GeneralPath gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 5); g.setColor(Color.BLACK); int[] shape = lataxis.getShape(); // should both be the same int ny = shape[0]; int nx = shape[1]; for (int y = 0; y < ny + 1; y += 10) { gp.reset(); for (int x = 0; x < nx + 1; x++) { if (x == 0) gp.moveTo((float) edgex.get(y, x), (float) edgey.get(y, x)); else gp.lineTo((float) edgex.get(y, x), (float) edgey.get(y, x)); } g.draw(gp); } for (int x = 0; x < nx + 1; x += 10) { gp.reset(); for (int y = 0; y < ny + 1; y++) { if (y == 0) gp.moveTo((float) edgex.get(y, x), (float) edgey.get(y, x)); else gp.lineTo((float) edgex.get(y, x), (float) edgey.get(y, x)); } g.draw(gp); } }
Example 13
Source File: SpaceComponent.java From pumpernickel with MIT License | 4 votes |
/** * Paints the visual elements of a SpaceComponent. * * @param g * the Graphics to draw to * @param lightBorder * whether the border should be light or dark. * @param drawArrows * whether arrows should be painted * @param w * the width to paint * @param h * the height to paint */ protected static void paintSpace(Graphics g, boolean lightBorder, boolean drawArrows, int w, int h) { Graphics2D g2 = (Graphics2D) g; if (lightBorder) { g2.setColor(new Color(255, 255, 255, 80)); } else { g2.setColor(new Color(0, 0, 0, 80)); } g2.setStroke(new BasicStroke(1)); g2.drawRect(0, 0, w - 1, h - 1); GeneralPath path = new GeneralPath(); if (drawArrows) { g2.setColor(new Color(0, 0, 0, 180)); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); path.reset(); path.moveTo(0, h / 2 + .5f); path.lineTo(6, h / 2 - 2); path.lineTo(6, h / 2 + 3); path.lineTo(0, h / 2 + .5f); g2.fill(path); path.reset(); path.moveTo(w - 1, h / 2 + .5f); path.lineTo(w - 7, h / 2 - 2); path.lineTo(w - 7, h / 2 + 3); path.lineTo(w - 1, h / 2 + .5f); g2.fill(path); g2.setStroke(new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10, new float[] { 1, 2 }, 0)); path.reset(); path.moveTo(7, h / 2); path.lineTo(w - 8, h / 2); g2.draw(path); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); } }