List of usage examples for java.awt.geom GeneralPath GeneralPath
public GeneralPath(int rule, int initialCapacity)
From source file:FilledGeneralPath.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int x = 5;/*from w w w . jav a 2 s . c o m*/ int y = 7; // fill and stroke GeneralPath int xPoints[] = { x, 200, x, 200 }; int yPoints[] = { y, 200, 200, y }; GeneralPath filledPolygon = new GeneralPath(GeneralPath.WIND_EVEN_ODD, xPoints.length); filledPolygon.moveTo(xPoints[0], yPoints[0]); for (int index = 1; index < xPoints.length; index++) { filledPolygon.lineTo(xPoints[index], yPoints[index]); } filledPolygon.closePath(); g2.setPaint(Color.red); g2.fill(filledPolygon); g2.setPaint(Color.black); g2.draw(filledPolygon); g2.drawString("Filled and Stroked GeneralPath", x, 250); }
From source file:GeneralPathDemo2D.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(Color.gray);/*from w w w . java 2 s. c om*/ int x = 5; int y = 7; // draw GeneralPath (polygon) int xPoints[] = { x, 200, x, 200 }; int yPoints[] = { y, 200, 200, y }; GeneralPath polygon = new GeneralPath(GeneralPath.WIND_EVEN_ODD, xPoints.length); polygon.moveTo(xPoints[0], yPoints[0]); for (int index = 1; index < xPoints.length; index++) { polygon.lineTo(xPoints[index], yPoints[index]); } polygon.closePath(); g2.draw(polygon); g2.drawString("GeneralPath", x, 250); }
From source file:GeneralPathOpenDemo2D.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(Color.gray);//from w ww . j av a2 s.c o m int x = 5; int y = 7; // draw GeneralPath (polyline) int xPoints[] = { x, 200, x, 200 }; int yPoints[] = { y, 200, 200, y }; GeneralPath polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, xPoints.length); polyline.moveTo(xPoints[0], yPoints[0]); for (int index = 1; index < xPoints.length; index++) { polyline.lineTo(xPoints[index], yPoints[index]); } g2.draw(polyline); g2.drawString("GeneralPath (open)", x, 250); }
From source file:ExtendedGeneralPath.java
/** * Constructs a new <code>ExtendedGeneralPath</code> object with * the specified winding rule and the specified initial capacity * to store path coordinates./*w w w . j a v a 2 s . c om*/ */ public ExtendedGeneralPath(int rule, int initialCapacity) { path = new GeneralPath(rule, initialCapacity); }
From source file:Bouncer.java
protected Shape createShape() { GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD, mPoints.length); path.moveTo(mPoints[0], mPoints[1]); for (int i = 2; i < mN; i += 6) path.curveTo(mPoints[i], mPoints[i + 1], mPoints[i + 2], mPoints[i + 3], mPoints[i + 4], mPoints[i + 5]);// w w w .j a v a2 s . co m path.closePath(); return path; }
From source file:net.sf.maltcms.chromaui.annotations.XYSelectableShapeAnnotation.java
/** * * @param x//from w w w. j av a 2s . c o m * @param y * @param w * @param h * @return */ public static Shape getCrosshairShape(double x, double y, double w, double h) { // draw GeneralPath (polyline) //we draw two lines, one from //x-5,y to x+5,y and one from //x,y-5 to x,y+5 double x2Points[] = { x - w, x + w, x, x }; double y2Points[] = { y, y, y - h, y + h }; GeneralPath crosshair = new GeneralPath(GeneralPath.WIND_EVEN_ODD, x2Points.length); crosshair.moveTo(x2Points[0], y2Points[0]); crosshair.lineTo(x2Points[1], y2Points[1]); crosshair.moveTo(x2Points[2], y2Points[2]); crosshair.lineTo(x2Points[3], y2Points[3]); return crosshair; }
From source file:net.sf.maltcms.chromaui.charts.events.XYAnnotationAdder.java
/** * * @param x// www . j a v a 2 s . c om * @param y * @param w * @param h * @return */ public Shape getCrosshairShape(double x, double y, double w, double h) { // draw GeneralPath (polyline) //we draw two lines, one from //x-5,y to x+5,y and one from //x,y-5 to x,y+5 double x2Points[] = { x - w, x + w, x, x }; double y2Points[] = { y, y, y - h, y + h }; GeneralPath crosshair = new GeneralPath(GeneralPath.WIND_EVEN_ODD, x2Points.length); crosshair.moveTo(x2Points[0], y2Points[0]); crosshair.lineTo(x2Points[1], y2Points[1]); crosshair.moveTo(x2Points[2], y2Points[2]); crosshair.lineTo(x2Points[3], y2Points[3]); return crosshair; }
From source file:net.sourceforge.processdash.ui.web.reports.RadarPlot.java
protected void drawRadar(Graphics2D g2, Rectangle2D plotArea, PlotRenderingInfo info, int pieIndex, PieDataset data) {//from w ww.ja va 2 s . c o m // adjust the plot area by the interior spacing value double gapHorizontal = plotArea.getWidth() * this.interiorGap; double gapVertical = plotArea.getHeight() * this.interiorGap; double radarX = plotArea.getX() + gapHorizontal / 2; double radarY = plotArea.getY() + gapVertical / 2; double radarW = plotArea.getWidth() - gapHorizontal; double radarH = plotArea.getHeight() - gapVertical; // make the radar area a square if the radar chart is to be circular... // NOTE that non-circular radar charts are not currently supported. if (true) { //circular) { double min = Math.min(radarW, radarH) / 2; radarX = (radarX + radarX + radarW) / 2 - min; radarY = (radarY + radarY + radarH) / 2 - min; radarW = 2 * min; radarH = 2 * min; } double radius = radarW / 2; double centerX = radarX + radarW / 2; double centerY = radarY + radarH / 2; Rectangle2D radarArea = new Rectangle2D.Double(radarX, radarY, radarW, radarH); // plot the data (unless the dataset is null)... if ((data != null) && (data.getKeys().size() > 0)) { // get a list of categories... List keys = data.getKeys(); int numAxes = keys.size(); // draw each of the axes on the radar chart, and register // the shape of the radar line. double multiplier = 1.0; GeneralPath lineShape = new GeneralPath(GeneralPath.WIND_NON_ZERO, numAxes + 1); GeneralPath gridShape = new GeneralPath(GeneralPath.WIND_NON_ZERO, numAxes + 1); int axisNumber = -1; Iterator iterator = keys.iterator(); while (iterator.hasNext()) { Comparable currentKey = (Comparable) iterator.next(); axisNumber++; Number dataValue = data.getValue(currentKey); double value = (dataValue != null ? dataValue.doubleValue() : 0); if (value > 1 || Double.isNaN(value) || Double.isInfinite(value)) value = 1.0; if (value < 0) value = 0.0; multiplier *= value; double angle = 2 * Math.PI * axisNumber / numAxes; double deltaX = Math.sin(angle) * radius; double deltaY = -Math.cos(angle) * radius; // draw the spoke g2.setPaint(axisPaint); g2.setStroke(axisStroke); Line2D line = new Line2D.Double(centerX, centerY, centerX + deltaX, centerY + deltaY); g2.draw(line); // register the grid line and the shape line if (axisNumber == 0) { gridShape.moveTo((float) deltaX, (float) deltaY); lineShape.moveTo((float) (deltaX * value), (float) (deltaY * value)); } else { gridShape.lineTo((float) deltaX, (float) deltaY); lineShape.lineTo((float) (deltaX * value), (float) (deltaY * value)); } if (showAxisLabels) { // draw the label double labelX = centerX + deltaX * (1 + axisLabelGap); double labelY = centerY + deltaY * (1 + axisLabelGap); String label = currentKey.toString(); drawLabel(g2, radarArea, label, axisNumber, labelX, labelY); } } gridShape.closePath(); lineShape.closePath(); // draw five gray concentric gridlines g2.translate(centerX, centerY); g2.setPaint(gridLinePaint); g2.setStroke(gridLineStroke); for (int i = 5; i > 0; i--) { Shape scaledGrid = gridShape .createTransformedShape(AffineTransform.getScaleInstance(i / 5.0, i / 5.0)); g2.draw(scaledGrid); } // get the color for the plot shape. Paint dataPaint = plotLinePaint; if (dataPaint == ADAPTIVE_COLORING) { //multiplier = Math.exp(Math.log(multiplier) * 2 / numAxes); dataPaint = getMultiplierColor((float) multiplier); } // compute a slightly transparent version of the plot color for // the fill. Paint dataFill = null; if (dataPaint instanceof Color && getForegroundAlpha() != 1.0) dataFill = new Color(((Color) dataPaint).getRed() / 255f, ((Color) dataPaint).getGreen() / 255f, ((Color) dataPaint).getBlue() / 255f, getForegroundAlpha()); else dataFill = dataPaint; // draw the plot shape. First fill with a parially // transparent color, then stroke with the opaque color. g2.setPaint(dataFill); g2.fill(lineShape); g2.setPaint(dataPaint); g2.setStroke(plotLineStroke); g2.draw(lineShape); // cleanup the graphics context. g2.translate(-centerX, -centerY); } }
From source file:org.esa.snap.graphbuilder.gpf.ui.worldmap.NestWorldMapPane.java
public static ArrayList<GeneralPath> assemblePathList(GeoPos[] geoPoints) { final GeneralPath path = new GeneralPath(GeneralPath.WIND_NON_ZERO, geoPoints.length + 8); final ArrayList<GeneralPath> pathList = new ArrayList<>(16); if (geoPoints.length > 1) { double lon, lat; double minLon = 0, maxLon = 0; boolean first = true; for (GeoPos gp : geoPoints) { lon = gp.getLon();/*from www .j ava 2 s . c o m*/ lat = gp.getLat(); if (first) { minLon = lon; maxLon = lon; path.moveTo(lon, lat); first = false; } if (lon < minLon) { minLon = lon; } if (lon > maxLon) { maxLon = lon; } path.lineTo(lon, lat); } path.closePath(); int runIndexMin = (int) Math.floor((minLon + 180) / 360); int runIndexMax = (int) Math.floor((maxLon + 180) / 360); if (runIndexMin == 0 && runIndexMax == 0) { // the path is completely within [-180, 180] longitude pathList.add(path); return pathList; } final Area pathArea = new Area(path); final GeneralPath pixelPath = new GeneralPath(GeneralPath.WIND_NON_ZERO); for (int k = runIndexMin; k <= runIndexMax; k++) { final Area currentArea = new Area( new Rectangle2D.Float(k * 360.0f - 180.0f, -90.0f, 360.0f, 180.0f)); currentArea.intersect(pathArea); if (!currentArea.isEmpty()) { pathList.add(areaToPath(currentArea, -k * 360.0, pixelPath)); } } } return pathList; }
From source file:org.jcurl.math.helpers.CurveShape.java
public static Shape approximateLinear(final CurveGhost c, final double[] sections) throws FunctionEvaluationException { final double[] x_1 = { c.getC(0, 0, sections[0]), c.getC(1, 0, sections[0]) }; final double[] x_2 = { 0, 0 }; final GeneralPath gp = new GeneralPath(GeneralPath.WIND_NON_ZERO, sections.length + 1); gp.moveTo((float) x_1[0], (float) x_1[1]); for (int i = 1; i < sections.length; i++) { x_2[0] = c.getC(0, 0, sections[i]); x_2[1] = c.getC(1, 0, sections[i]); gp.lineTo((float) x_2[0], (float) x_2[1]); x_1[0] = x_2[0];/*from ww w. j a v a 2 s . c om*/ x_1[1] = x_2[1]; } return gp; }