List of usage examples for java.awt.geom GeneralPath moveTo
public abstract void moveTo(double x, double y);
From source file:LineStyles.java
/** This method draws the example figure */ public void paint(Graphics g1) { Graphics2D g = (Graphics2D) g1; // Use anti-aliasing to avoid "jaggies" in the lines g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Define the shape to draw GeneralPath shape = new GeneralPath(); shape.moveTo(xpoints[0], ypoints[0]); // start at point 0 shape.lineTo(xpoints[1], ypoints[1]); // draw a line to point 1 shape.lineTo(xpoints[2], ypoints[2]); // and then on to point 2 // Move the origin to the right and down, creating a margin g.translate(20, 40);/* w w w .j a v a 2 s.co m*/ // Now loop, drawing our shape with the three different line styles for (int i = 0; i < linestyles.length; i++) { g.setColor(Color.gray); // Draw a gray line g.setStroke(linestyles[i]); // Select the line style to use g.draw(shape); // Draw the shape g.setColor(Color.black); // Now use black g.setStroke(thindashed); // And the thin dashed line g.draw(shape); // And draw the shape again. // Highlight the location of the vertexes of the shape // This accentuates the cap and join styles we're demonstrating for (int j = 0; j < xpoints.length; j++) g.fillRect(xpoints[j] - 2, ypoints[j] - 2, 5, 5); g.drawString(capNames[i], 5, 105); // Label the cap style g.drawString(joinNames[i], 5, 120); // Label the join style g.translate(150, 0); // Move over to the right before looping again } }
From source file:AttributesApp.java
public AttributesApp() { setBackground(Color.lightGray); setSize(500, 200);/* www . jav a 2 s . c o m*/ attribString = new AttributedString(text); GeneralPath star = new GeneralPath(); star.moveTo(0, 0); star.lineTo(10, 30); star.lineTo(-10, 10); star.lineTo(10, 10); star.lineTo(-10, 30); star.closePath(); GraphicAttribute starShapeAttr = new ShapeGraphicAttribute(star, GraphicAttribute.TOP_ALIGNMENT, false); attribString.addAttribute(TextAttribute.CHAR_REPLACEMENT, starShapeAttr, 0, 1); attribString.addAttribute(TextAttribute.FOREGROUND, new Color(255, 255, 0), 0, 1); int index = text.indexOf("Java Source"); attribString.addAttribute(TextAttribute.FOREGROUND, Color.blue, index, index + 7); Font font = new Font("sanserif", Font.ITALIC, 40); attribString.addAttribute(TextAttribute.FONT, font, index, index + 7); loadImage(); BufferedImage bimage = new BufferedImage(image.getWidth(this), image.getHeight(this), BufferedImage.TYPE_INT_ARGB); Graphics2D big = bimage.createGraphics(); big.drawImage(image, null, this); GraphicAttribute javaImageAttr = new ImageGraphicAttribute(bimage, GraphicAttribute.TOP_ALIGNMENT, 0, 0); index = text.indexOf("Java"); attribString.addAttribute(TextAttribute.CHAR_REPLACEMENT, javaImageAttr, index - 1, index); font = new Font("serif", Font.BOLD, 60); attribString.addAttribute(TextAttribute.FONT, font, index, index + 4); attribString.addAttribute(TextAttribute.FOREGROUND, new Color(243, 63, 163), index, index + 4); // Start and end indexes. index = text.indexOf("source"); attribString.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, index, index + 2); index = text.indexOf("and support"); font = new Font("sanserif", Font.ITALIC, 40); attribString.addAttribute(TextAttribute.FONT, font, index, index + 10); attribString.addAttribute(TextAttribute.FOREGROUND, Color.white, index, index + 2); // Start and end indexes. attribString.addAttribute(TextAttribute.FOREGROUND, Color.blue, index + 3, index + 10); // Start and end indexes. }
From source file:TransformersRotationTranslation.java
protected Shape createAxes() { GeneralPath path = new GeneralPath(); // Axes.//from w ww. j av a 2 s. c om path.moveTo(-length, 0); path.lineTo(length, 0); path.moveTo(0, -length); path.lineTo(0, length); // Arrows. path.moveTo(length - arrowLength, -arrowLength); path.lineTo(length, 0); path.lineTo(length - arrowLength, arrowLength); path.moveTo(-arrowLength, length - arrowLength); path.lineTo(0, length); path.lineTo(arrowLength, length - arrowLength); // Half-centimeter tick marks float cm = 72 / 2.54f; float lengthCentimeter = length / cm; for (float i = 0.5f; i < lengthCentimeter; i += 1.0f) { float tick = i * cm; path.moveTo(tick, -tickSize / 2); path.lineTo(tick, tickSize / 2); path.moveTo(-tick, -tickSize / 2); path.lineTo(-tick, tickSize / 2); path.moveTo(-tickSize / 2, tick); path.lineTo(tickSize / 2, tick); path.moveTo(-tickSize / 2, -tick); path.lineTo(tickSize / 2, -tick); } // Full-centimeter tick marks for (float i = 1.0f; i < lengthCentimeter; i += 1.0f) { float tick = i * cm; path.moveTo(tick, -tickSize); path.lineTo(tick, tickSize); path.moveTo(-tick, -tickSize); path.lineTo(-tick, tickSize); path.moveTo(-tickSize, tick); path.lineTo(tickSize, tick); path.moveTo(-tickSize, -tick); path.lineTo(tickSize, -tick); } return path; }
From source file:com.bdb.weather.display.current.WindDirPointer.java
/** * Draws the pointer.//ww w . j ava 2 s . c o m * * @param g2 The graphics target. * @param plot The plot. * @param frame The dial's reference frame. * @param view The dial's view. */ @Override public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { g2.setPaint(Color.blue); g2.setStroke(new BasicStroke(1.0f)); DialScale scale = plot.getScaleForDataset(getDatasetIndex()); double value = plot.getValue(getDatasetIndex()); double angle = scale.valueToAngle(value % 360.0); Rectangle2D outerRect = DialPlot.rectangleByRadius(frame, outerRadius, outerRadius); Rectangle2D innerRect = DialPlot.rectangleByRadius(frame, outerRadius - innerOffset, outerRadius - innerOffset); g2.setPaint(getOutlinePaint()); Arc2D arc1 = new Arc2D.Double(outerRect, angle - (ARC_LENGTH / 2), ARC_LENGTH, Arc2D.OPEN); g2.draw(arc1); Arc2D arc2 = new Arc2D.Double(innerRect, angle, 0.0, Arc2D.OPEN); GeneralPath gp = new GeneralPath(); gp.moveTo(arc1.getStartPoint().getX(), arc1.getStartPoint().getY()); gp.lineTo(arc2.getStartPoint().getX(), arc2.getStartPoint().getY()); gp.lineTo(arc1.getEndPoint().getX(), arc1.getEndPoint().getY()); g2.draw(gp); if (fill) { g2.setPaint(getFillPaint()); g2.fill(gp); } }
From source file:net.sourceforge.processdash.ev.ui.chart.TooltipLineXYLineAndShapeRenderer.java
/** * Creates and returns a polygon that has the same shape as the line passed * as a parameter, but ticker so it can be used as a mouse-over tooltip area *//* w w w .j av a2 s . c o m*/ private Shape getTooltipArea(Line2D line, int series) { GeneralPath area = new GeneralPath(); float areaWidth = getAreaWidth(series); area.moveTo((float) line.getX1(), (float) (line.getY1() + areaWidth / 2)); area.lineTo((float) line.getX2(), (float) (line.getY2() + areaWidth / 2)); area.lineTo((float) line.getX2(), (float) (line.getY2() - areaWidth / 2)); area.lineTo((float) line.getX1(), (float) (line.getY1() - areaWidth / 2)); area.closePath(); return area; }
From source file:CustomStrokes.java
/** Add a small square centered at (x,y) to the specified path */ void markPoint(GeneralPath path, float x, float y) { path.moveTo(x - radius, y - radius); // Begin a new sub-path path.lineTo(x + radius, y - radius); // Add a line segment to it path.lineTo(x + radius, y + radius); // Add a second line segment path.lineTo(x - radius, y + radius); // And a third path.closePath(); // Go back to last moveTo position }
From source file:org.jfree.chart.demo.TimeSeriesDemo9.java
/** * A demonstration application showing how to create a simple time series chart. This * example uses monthly data./*from w w w.ja va 2 s . co m*/ * * @param title the frame title. */ public TimeSeriesDemo9(final String title) { super(title); // create a title... final String chartTitle = "Test"; final XYDataset dataset = createDataset(); final JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, "Date", "Price Per Unit", dataset, true, true, false); // final StandardLegend sl = (StandardLegend) chart.getLegend(); // sl.setDisplaySeriesShapes(true); final XYPlot plot = chart.getXYPlot(); final XYItemRenderer r = plot.getRenderer(); if (r instanceof StandardXYItemRenderer) { final StandardXYItemRenderer renderer = (StandardXYItemRenderer) r; renderer.setPlotShapes(true); renderer.setShapesFilled(true); renderer.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0)); renderer.setSeriesShape(1, new Rectangle2D.Double(-3.0, -3.0, 6.0, 6.0)); final GeneralPath s2 = new GeneralPath(); s2.moveTo(0.0f, -3.0f); s2.lineTo(3.0f, 3.0f); s2.lineTo(-3.0f, 3.0f); s2.closePath(); renderer.setSeriesShape(2, s2); final GeneralPath s3 = new GeneralPath(); s3.moveTo(-1.0f, -3.0f); s3.lineTo(1.0f, -3.0f); s3.lineTo(1.0f, -1.0f); s3.lineTo(3.0f, -1.0f); s3.lineTo(3.0f, 1.0f); s3.lineTo(1.0f, 1.0f); s3.lineTo(1.0f, 3.0f); s3.lineTo(-1.0f, 3.0f); s3.lineTo(-1.0f, 1.0f); s3.lineTo(-3.0f, 1.0f); s3.lineTo(-3.0f, -1.0f); s3.lineTo(-1.0f, -1.0f); s3.closePath(); renderer.setSeriesShape(3, s3); } plot.getDomainAxis().setVisible(false); plot.getRangeAxis().setVisible(false); final ChartPanel chartPanel = new ChartPanel(chart); chartPanel.setPreferredSize(new java.awt.Dimension(500, 270)); setContentPane(chartPanel); }
From source file:StrokeTest.java
public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; GeneralPath path = new GeneralPath(); path.moveTo((float) points[0].getX(), (float) points[0].getY()); for (int i = 1; i < points.length; i++) path.lineTo((float) points[i].getX(), (float) points[i].getY()); BasicStroke stroke;/*from w ww .j a va 2 s. com*/ if (dash) { float miterLimit = 10.0F; float[] dashPattern = { 10F, 10F, 10F, 10F, 10F, 10F, 30F, 10F, 30F, 10F, 30F, 10F, 10F, 10F, 10F, 10F, 10F, 30F }; float dashPhase = 0; stroke = new BasicStroke(width, cap, join, miterLimit, dashPattern, dashPhase); } else stroke = new BasicStroke(width, cap, join); g2.setStroke(stroke); g2.draw(path); }
From source file:chiliad.parser.pdf.extractor.vectorgraphics.operator.Invoke.java
/** * process : Do : Paint the specified XObject (section 4.7). * * @param operator The operator that is being executed. * @param arguments List/*ww w. jav a 2s.c om*/ * @throws IOException If there is an error invoking the sub object. */ @Override public void process(PDFOperator operator, List<COSBase> arguments) throws IOException { VectorGraphicsExtractor extractor = (VectorGraphicsExtractor) context; PDPage page = extractor.getPage(); COSName objectName = (COSName) arguments.get(0); Map<String, PDXObject> xobjects = extractor.getResources().getXObjects(); PDXObject xobject = (PDXObject) xobjects.get(objectName.getName()); if (xobject == null) { LOG.warn("Can't find the XObject for '" + objectName.getName() + "'"); } else if (xobject instanceof PDXObjectImage) { PDXObjectImage image = (PDXObjectImage) xobject; try { if (image.getImageMask()) { // set the current non stroking colorstate, so that it can // be used to create a stencil masked image image.setStencilColor(extractor.getGraphicsState().getNonStrokingColor()); } BufferedImage awtImage = image.getRGBImage(); if (awtImage == null) { LOG.warn("getRGBImage returned NULL"); return;//TODO PKOCH } int imageWidth = awtImage.getWidth(); int imageHeight = awtImage.getHeight(); double pageHeight = extractor.getPageSize().getHeight(); LOG.debug("imageWidth: " + imageWidth + "\t\timageHeight: " + imageHeight); Matrix ctm = extractor.getGraphicsState().getCurrentTransformationMatrix(); float yScaling = ctm.getYScale(); float angle = (float) Math.acos(ctm.getValue(0, 0) / ctm.getXScale()); if (ctm.getValue(0, 1) < 0 && ctm.getValue(1, 0) > 0) { angle = (-1) * angle; } ctm.setValue(2, 1, (float) (pageHeight - ctm.getYPosition() - Math.cos(angle) * yScaling)); ctm.setValue(2, 0, (float) (ctm.getXPosition() - Math.sin(angle) * yScaling)); // because of the moved 0,0-reference, we have to shear in the opposite direction ctm.setValue(0, 1, (-1) * ctm.getValue(0, 1)); ctm.setValue(1, 0, (-1) * ctm.getValue(1, 0)); AffineTransform ctmAT = ctm.createAffineTransform(); ctmAT.scale(1f / imageWidth, 1f / imageHeight); extractor.drawImage(awtImage, ctmAT); } catch (Exception e) { LOG.error(e, e); } } else if (xobject instanceof PDXObjectForm) { // save the graphics state context.getGraphicsStack().push((PDGraphicsState) context.getGraphicsState().clone()); PDXObjectForm form = (PDXObjectForm) xobject; COSStream formContentstream = form.getCOSStream(); // find some optional resources, instead of using the current resources PDResources pdResources = form.getResources(); // if there is an optional form matrix, we have to map the form space to the user space Matrix matrix = form.getMatrix(); if (matrix != null) { Matrix xobjectCTM = matrix.multiply(context.getGraphicsState().getCurrentTransformationMatrix()); context.getGraphicsState().setCurrentTransformationMatrix(xobjectCTM); } if (form.getBBox() != null) { PDGraphicsState graphicsState = context.getGraphicsState(); PDRectangle bBox = form.getBBox(); float x1 = bBox.getLowerLeftX(); float y1 = bBox.getLowerLeftY(); float x2 = bBox.getUpperRightX(); float y2 = bBox.getUpperRightY(); Point2D p0 = extractor.transformedPoint(x1, y1); Point2D p1 = extractor.transformedPoint(x2, y1); Point2D p2 = extractor.transformedPoint(x2, y2); Point2D p3 = extractor.transformedPoint(x1, y2); GeneralPath bboxPath = new GeneralPath(); bboxPath.moveTo((float) p0.getX(), (float) p0.getY()); bboxPath.lineTo((float) p1.getX(), (float) p1.getY()); bboxPath.lineTo((float) p2.getX(), (float) p2.getY()); bboxPath.lineTo((float) p3.getX(), (float) p3.getY()); bboxPath.closePath(); Area resultClippingArea = new Area(graphicsState.getCurrentClippingPath()); Area newArea = new Area(bboxPath); resultClippingArea.intersect(newArea); graphicsState.setCurrentClippingPath(resultClippingArea); } getContext().processSubStream(page, pdResources, formContentstream); // restore the graphics state context.setGraphicsState((PDGraphicsState) context.getGraphicsStack().pop()); } }
From source file:de.iteratec.iteraplan.presentation.dialog.GraphicalReporting.Line.JFreeChartSvgRenderer.java
byte[] renderJFreeChart(JFreeChart chart, float width, float height, boolean naked, Date fromDate, Date toDate) throws IOException { String svgNamespaceUri = SVGDOMImplementation.SVG_NAMESPACE_URI; Document doc = SVGDOMImplementation.getDOMImplementation().createDocument(svgNamespaceUri, "svg", null); String generatedText = "Generated " + DateUtils.formatAsStringToLong(new Date(), UserContext.getCurrentLocale()) + " by " + MessageAccess.getStringOrNull("global.applicationname", UserContext.getCurrentLocale()) + " " + properties.getBuildId();/*w w w . j a va2 s .c om*/ String drawingInfo = MessageAccess.getStringOrNull("graphicalExport.timeline.drawInfo", UserContext.getCurrentLocale()) + ": " + DateUtils.formatAsString(fromDate, UserContext.getCurrentLocale()) + " -> " + DateUtils.formatAsString(toDate, UserContext.getCurrentLocale()); SVGGeneratorContext ctx = SVGGeneratorContext.createDefault(doc); ctx.setComment(generatedText); SVGGraphics2D svgGraphics = new SVGGraphics2D(ctx, false); if (!naked) { //Render the chart to the SVG graphics object chart.draw(svgGraphics, new Rectangle(20, 20, Math.round(width - MARGIN), Math.round(height - MARGIN))); //Add logo and generated text int widthIntForLogo = Math.round(width + 40 - MARGIN); int heightIntForLogo = Math.round(height - MARGIN + 20); int xLogoUpperRightCorner[] = { widthIntForLogo - 40, widthIntForLogo, widthIntForLogo, widthIntForLogo - 8, widthIntForLogo - 8, widthIntForLogo - 40 }; int yLogoUpperRightCorner[] = { MARGIN_TOP, MARGIN_TOP, MARGIN_TOP + 40, MARGIN_TOP + 40, MARGIN_TOP + 8, MARGIN_TOP + 8 }; GeneralPath logoUpperRightCorner = new GeneralPath(); logoUpperRightCorner.moveTo(xLogoUpperRightCorner[0], yLogoUpperRightCorner[0]); for (int i = 1; i < xLogoUpperRightCorner.length; i++) { logoUpperRightCorner.lineTo(xLogoUpperRightCorner[i], yLogoUpperRightCorner[i]); } logoUpperRightCorner.closePath(); svgGraphics.setColor(Color.decode(COLOR_LOGO)); svgGraphics.fill(logoUpperRightCorner); svgGraphics.draw(logoUpperRightCorner); int xLogoLowerLeftCorner[] = { MARGIN_LEFT, MARGIN_LEFT + 8, MARGIN_LEFT + 8, MARGIN_LEFT + 40, MARGIN_LEFT + 40, MARGIN_LEFT }; int yLogoLowerLeftCorner[] = { heightIntForLogo, heightIntForLogo, heightIntForLogo + 32, heightIntForLogo + 32, heightIntForLogo + 40, heightIntForLogo + 40 }; GeneralPath logoLowerLeftCorner = new GeneralPath(); logoLowerLeftCorner.moveTo(xLogoLowerLeftCorner[0], yLogoLowerLeftCorner[0]); for (int i = 1; i < xLogoLowerLeftCorner.length; i++) { logoLowerLeftCorner.lineTo(xLogoLowerLeftCorner[i], yLogoLowerLeftCorner[i]); } logoLowerLeftCorner.closePath(); svgGraphics.setColor(Color.BLACK); svgGraphics.fill(logoLowerLeftCorner); svgGraphics.draw(logoLowerLeftCorner); Font f = new Font(null, Font.ITALIC, 12); svgGraphics.setFont(f); FontMetrics fontMetrics = svgGraphics.getFontMetrics(f); int charsWidthInfo = fontMetrics.stringWidth(drawingInfo); svgGraphics.drawString(drawingInfo, width - MARGIN - charsWidthInfo, height - MARGIN + MARGIN_DOWN_GENERATED_TEXT); int charsWidth = fontMetrics.stringWidth(generatedText); svgGraphics.drawString(generatedText, width - MARGIN - charsWidth, height - MARGIN + MARGIN_DOWN_GENERATED_TEXT + 20); } else { chart.draw(svgGraphics, new Rectangle(20, 20, Math.round(JFreeChartLineGraphicCreator.DEFAULT_HEIGHT - NAKED_MARGIN), Math.round(JFreeChartLineGraphicCreator.DEFAULT_HEIGHT - NAKED_MARGIN))); } svgGraphics.setSVGCanvasSize(new Dimension((int) width, (int) height)); //Convert the SVGGraphics2D object to SVG XML ByteArrayOutputStream baos = new ByteArrayOutputStream(); Writer out = new OutputStreamWriter(baos, "UTF-8"); svgGraphics.stream(out, true); byte[] originalSvgXml = baos.toByteArray(); // return originalSvgXml; return addAdditionalAttributes(originalSvgXml); }