List of usage examples for java.awt Graphics2D setPaint
public abstract void setPaint(Paint paint);
From source file:org.apache.fop.render.bitmap.AbstractBitmapDocumentHandler.java
/** {@inheritDoc} */ public IFPainter startPageContent() throws IFException { int bitmapWidth; int bitmapHeight; double scale; Point2D offset = null;// www . ja va 2 s. c om if (targetBitmapSize != null) { //Fit the generated page proportionally into the given rectangle (in pixels) double scale2w = 1000 * targetBitmapSize.width / this.currentPageDimensions.getWidth(); double scale2h = 1000 * targetBitmapSize.height / this.currentPageDimensions.getHeight(); bitmapWidth = targetBitmapSize.width; bitmapHeight = targetBitmapSize.height; //Centering the page in the given bitmap offset = new Point2D.Double(); if (scale2w < scale2h) { scale = scale2w; double h = this.currentPageDimensions.height * scale / 1000; offset.setLocation(0, (bitmapHeight - h) / 2.0); } else { scale = scale2h; double w = this.currentPageDimensions.width * scale / 1000; offset.setLocation((bitmapWidth - w) / 2.0, 0); } } else { //Normal case: just scale according to the target resolution scale = scaleFactor * getUserAgent().getTargetResolution() / FopFactoryConfigurator.DEFAULT_TARGET_RESOLUTION; bitmapWidth = (int) ((this.currentPageDimensions.width * scale / 1000f) + 0.5f); bitmapHeight = (int) ((this.currentPageDimensions.height * scale / 1000f) + 0.5f); } //Set up bitmap to paint on this.currentImage = createBufferedImage(bitmapWidth, bitmapHeight); Graphics2D graphics2D = this.currentImage.createGraphics(); // draw page background if (!getSettings().hasTransparentPageBackground()) { graphics2D.setBackground(getSettings().getPageBackgroundColor()); graphics2D.setPaint(getSettings().getPageBackgroundColor()); graphics2D.fillRect(0, 0, bitmapWidth, bitmapHeight); } //Set rendering hints graphics2D.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); if (getSettings().isAntiAliasingEnabled() && this.currentImage.getColorModel().getPixelSize() > 1) { graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); } else { graphics2D.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF); graphics2D.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); } if (getSettings().isQualityRenderingEnabled()) { graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); } else { graphics2D.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); } graphics2D.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); //Set up initial coordinate system for the page if (offset != null) { graphics2D.translate(offset.getX(), offset.getY()); } graphics2D.scale(scale / 1000f, scale / 1000f); return new Java2DPainter(graphics2D, getContext(), getFontInfo()); }
From source file:figs.treeVisualization.gui.TimeAxisTree2DPanel.java
/** * */// w w w . j ava2 s . co m protected void drawDateAxis(Graphics2D g2, double cursor, Rectangle2D plotArea) { g2.setPaint(this.getBackgroundColor()); g2.setStroke(this.getCladeBranchStroke()); /** * The interpretation of cursor depends on what edge is passed in. * RectangleEdge.RIGHT uses the cursor as the x position. * <code>PhyloDataAxis.draw()</code> uses <code>RectangleEdge.RIGHT</code> * * See <code>org.jfree.chart.axis.ValueAxis.drawAxisLine</code>. */ fDateAxis.draw(g2, cursor, plotArea); }
From source file:Diva.java
@Override public void paint(Graphics g, JComponent c) { Graphics2D g2 = (Graphics2D) g.create(); // Paint the view. super.paint(g2, c); if (mActive) { // Create a radial gradient, transparent in the middle. java.awt.geom.Point2D center = new java.awt.geom.Point2D.Float(mX, mY); float radius = 72; float[] dist = { 0.0f, 1.0f }; Color[] colors = { new Color(0.0f, 0.0f, 0.0f, 0.0f), Color.BLACK }; RadialGradientPaint p = new RadialGradientPaint(center, radius, dist, colors); g2.setPaint(p); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .6f)); g2.fillRect(0, 0, c.getWidth(), c.getHeight()); }/*from ww w .j a v a 2 s . c om*/ g2.dispose(); }
From source file:org.esa.s2tbx.dataio.s2.l1b.L1bSceneDescription.java
public BufferedImage createTilePicture(int width) { Color[] colors = new Color[] { Color.GREEN, Color.RED, Color.BLUE, Color.YELLOW }; double scale = width / sceneRectangle.getWidth(); int height = (int) Math.round(sceneRectangle.getHeight() * scale); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); Graphics2D graphics = image.createGraphics(); graphics.scale(scale, scale);//from w w w . jav a 2 s.c om graphics.translate(-sceneRectangle.getX(), -sceneRectangle.getY()); graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); graphics.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); graphics.setPaint(Color.WHITE); graphics.fill(sceneRectangle); graphics.setStroke(new BasicStroke(100F)); graphics.setFont(new Font("Arial", Font.PLAIN, 800)); for (int i = 0; i < tileInfos.length; i++) { Rectangle rect = tileInfos[i].rectangle; graphics.setPaint(addAlpha(colors[i % colors.length].brighter(), 100)); graphics.fill(rect); } for (int i = 0; i < tileInfos.length; i++) { Rectangle rect = tileInfos[i].rectangle; graphics.setPaint(addAlpha(colors[i % colors.length].darker(), 100)); graphics.draw(rect); graphics.setPaint(colors[i % colors.length].darker().darker()); graphics.drawString("Tile " + (i + 1) + ": " + tileInfos[i].id, rect.x + 1200F, rect.y + 2200F); } return image; }
From source file:org.tsho.dmc2.core.chart.DmcLyapunovPlot.java
public boolean renderVsTime(Graphics2D g2, Rectangle2D dataArea) { final int imageWidth = (int) dataArea.getWidth(); g2.setPaint(Color.red); final int timeStep; if (Math.abs(upper - lower) >= imageWidth) { timeStep = ((int) upper - (int) lower) / imageWidth; } else {/*www . j a va2s.c o m*/ timeStep = 1; } CoreStatusEvent statusEv = new CoreStatusEvent(this); int prevX[] = new int[model.getNVar()]; int prevY[] = new int[model.getNVar()]; int ratio = (int) upper / 100; for (int i = (int) lower; i < (int) upper; i += timeStep) { double[] result; int transX, transY; result = Lua.evaluateLyapunovExponents(model, parameters, initialPoint, i); for (int j = 0; j < result.length; j++) { transX = (int) this.domainAxis.valueToJava2D(i, dataArea, RectangleEdge.BOTTOM); transY = (int) this.rangeAxis.valueToJava2D(result[j], dataArea, RectangleEdge.LEFT); // System.out.println("time: " + i); // System.out.println("ly[" + j + "] = " + result[j]); // System.out.println("x: " + transX + " y: " + transY); g2.setPaint(paintSequence[j]); //g2.fillRect(transX, transY, 1, 1); if (bigDots) { g2.fillRect(transX - 1, transY - 1, 3, 3); } else { g2.fillRect(transX, transY, 1, 1); } if (connectWithLines) { if (i > (int) lower) { g2.drawLine(transX, transY, prevX[j], prevY[j]); } prevX[j] = transX; prevY[j] = transY; } } if (stopped == true) { return false; } else if (ratio > 0) { statusEv.setPercent(i / ratio); statusEv.setType(CoreStatusEvent.COUNT | CoreStatusEvent.PERCENT); notifyCoreStatusListeners(statusEv); } } return true; }
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;/* www. j a v a 2 s .co 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:org.tsho.dmc2.core.chart.DmcLyapunovPlot.java
public boolean renderVsParameter(Graphics2D g2, Rectangle2D dataArea) { final int imageWidth = (int) dataArea.getWidth(); g2.setPaint(Color.red); final double parStep; parStep = Math.abs(upper - lower) / imageWidth; CoreStatusEvent statusEv = new CoreStatusEvent(this); //int ratio = upper / 100; int prevX[] = new int[model.getNVar()]; int prevY[] = new int[model.getNVar()]; for (double i = lower; i < upper; i += parStep) { double[] result; int transX, transY; parameters.put(firstParLabel, i); try {//from w ww. j a v a 2 s.c om result = Lua.evaluateLyapunovExponents(model, parameters, initialPoint, iterations); } catch (ModelException e) { String mess = "Exception while:\n" + dumpVariableDoubles(parameters) + dumpVariableDoubles(initialPoint); throw new ModelException(mess, e); } for (int j = 0; j < result.length; j++) { transX = (int) this.domainAxis.valueToJava2D(i, dataArea, RectangleEdge.BOTTOM); transY = (int) this.rangeAxis.valueToJava2D(result[j], dataArea, RectangleEdge.LEFT); // System.out.println("ly[" + j + "] = " + result[j]); // System.out.println("x: " + transX + " y: " + transY); g2.setPaint(paintSequence[j]); //g2.fillRect(transX, transY, 1, 1); if (bigDots) { g2.fillRect(transX - 1, transY - 1, 3, 3); } else { g2.fillRect(transX, transY, 1, 1); } if (connectWithLines) { if (i != lower) { g2.drawLine(transX, transY, prevX[j], prevY[j]); } prevX[j] = transX; prevY[j] = transY; } } if (stopped == true) { return false; } //else if (ratio > 0 && i % ratio == 0) { statusEv.setPercent(0); statusEv.setType(CoreStatusEvent.COUNT | CoreStatusEvent.PERCENT); notifyCoreStatusListeners(statusEv); //} } return true; }
From source file:dataminning2.KmeanGraphplot.java
protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int w = getWidth(); int h = getHeight(); // Draw ordinate. g2.draw(new Line2D.Double(PAD, PAD, PAD, h - PAD)); // Draw abcissa. g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD, h - PAD)); double xInc = (double) (w - 2 * PAD) / (data.length - 1); double scale = (double) (h - 2 * PAD) / 88; // Mark data points. g2.setPaint(Color.red); for (int i = 0; i < cluster0.length; i++) { double x = PAD + i * dataX[i]; double y = h - PAD - scale * dataY[i]; g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4)); }/*from w ww .ja v a2s .c om*/ g2.setPaint(Color.BLUE); for (int i = 0; i < cluster1.length; i++) { double x = PAD + i * dataX[i]; double y = h - PAD - scale * dataY[i]; g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4)); } g2.setPaint(Color.YELLOW); for (int i = 0; i < cluster2.length; i++) { double x = PAD + i * dataX[i]; double y = h - PAD - scale * dataY[i]; g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4)); } }
From source file:com.od.jtimeseries.ui.visualizer.chart.creator.EfficientXYLineAndShapeRenderer.java
private void drawLine(XYItemRendererState state, Graphics2D g2, XYPlot plot, double transX0, double transY0, double transX1, double transY1, Stroke s, Paint p) { PlotOrientation orientation = plot.getOrientation(); if (orientation == PlotOrientation.HORIZONTAL) { state.workingLine.setLine(transY0, transX0, transY1, transX1); } else if (orientation == PlotOrientation.VERTICAL) { state.workingLine.setLine(transX0, transY0, transX1, transY1); }/*from w ww .ja v a2 s. c o m*/ g2.setStroke(s); g2.setPaint(p); g2.draw(state.workingLine); }
From source file:org.jfree.experimental.chart.plot.dial.DialTextAnnotation.java
/** * Draws the background to the specified graphics device. If the dial * frame specifies a window, the clipping region will already have been * set to this window before this method is called. * * @param g2 the graphics device (<code>null</code> not permitted). * @param plot the plot (ignored here). * @param frame the dial frame (ignored here). * @param view the view rectangle (<code>null</code> not permitted). *//*from ww w . ja va2s . c o m*/ public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { // work out the anchor point Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, this.radius); Arc2D arc = new Arc2D.Double(f, this.angle, 0.0, Arc2D.OPEN); Point2D pt = arc.getStartPoint(); g2.setPaint(this.paint); g2.setFont(this.font); TextUtilities.drawAlignedString(this.label, g2, (float) pt.getX(), (float) pt.getY(), this.anchor); }