List of usage examples for java.awt Graphics2D draw
public abstract void draw(Shape s);
From source file:com.projity.pm.graphic.graph.GraphInteractor.java
protected void drawLinkSelectionBarShadow(GraphicNode node) { if (node == null) return;/* ww w. j a v a 2 s . co m*/ Graphics2D g = initGraphics(); Rectangle2D selectionRectangle = getLinkSelectionShadowBounds(node); if (selectionRectangle == null) return; g.setStroke(new BasicStroke(3)); g.draw(selectionRectangle); }
From source file:MainClass.java
public void paintToPDF(JTextPane ta) { try {// w ww.jav a 2 s .co m ta.setBounds(0, 0, (int) convertToPixels(612 - 58), (int) convertToPixels(792 - 60)); Document document = new Document(); FileOutputStream fos = new FileOutputStream("2.pdf"); PdfWriter writer = PdfWriter.getInstance(document, fos); document.setPageSize(new com.lowagie.text.Rectangle(612, 792)); document.open(); PdfContentByte cb = writer.getDirectContent(); cb.saveState(); cb.concatCTM(1, 0, 0, 1, 0, 0); DefaultFontMapper mapper = new DefaultFontMapper(); mapper.insertDirectory("c:/windows/fonts"); Graphics2D g2 = cb.createGraphics(612, 792, mapper, true, .95f); AffineTransform at = new AffineTransform(); at.translate(convertToPixels(20), convertToPixels(20)); at.scale(pixelToPoint, pixelToPoint); g2.transform(at); g2.setColor(Color.WHITE); g2.fill(ta.getBounds()); Rectangle alloc = getVisibleEditorRect(ta); ta.getUI().getRootView(ta).paint(g2, alloc); g2.setColor(Color.BLACK); g2.draw(ta.getBounds()); g2.dispose(); cb.restoreState(); document.close(); fos.flush(); fos.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.openfaces.component.chart.impl.renderers.LineFillRenderer.java
private void drawPrimaryLine(Graphics2D g2, Collection<Line2D> lines, int row, int item) { g2.setPaint(getItemPaint(row, item)); g2.setStroke(getItemStroke(row, item)); for (Line2D line : lines) { g2.draw(line); }// w ww. j a v a 2 s . c om }
From source file:JavaWorldPrintExample1.java
/** * Method: print//from ww w .j a va 2 s .co m * <p> * * This class is responsible for rendering a page using the provided * parameters. The result will be a grid where each cell will be half an * inch by half an inch. * * @param g * a value of type Graphics * @param pageFormat * a value of type PageFormat * @param page * a value of type int * @return a value of type int */ public int print(Graphics g, PageFormat pageFormat, int page) { int i; Graphics2D g2d; Line2D.Double line = new Line2D.Double(); //--- Validate the page number, we only print the first page if (page == 0) { //--- Create a graphic2D object a set the default parameters g2d = (Graphics2D) g; g2d.setColor(Color.black); //--- Translate the origin to be (0,0) g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); //--- Print the vertical lines for (i = 0; i < pageFormat.getWidth(); i += INCH / 2) { line.setLine(i, 0, i, pageFormat.getHeight()); g2d.draw(line); } //--- Print the horizontal lines for (i = 0; i < pageFormat.getHeight(); i += INCH / 2) { line.setLine(0, i, pageFormat.getWidth(), i); g2d.draw(line); } return (PAGE_EXISTS); } else return (NO_SUCH_PAGE); }
From source file:org.fhcrc.cpl.viewer.mrm.utilities.MRMerMouseListener.java
/** * Draws zoom rectangle (if present)./*from w w w.j a v a 2 s . co m*/ * The drawing is performed in XOR mode, therefore * when this method is called twice in a row, * the second call will completely restore the state * of the canvas. * * @param g2 the graphics device. */ private void drawCoElutionRegion(Graphics2D g2) { // Set XOR mode to draw the zoom rectangle if (g2 == null) return; Paint origColor = g2.getPaint(); // g2.setXORMode(Color.gray); g2.setXORMode(new Color(30, 10, 30, 5)); if (this.coElutionRegion != null) { g2.fill(this.coElutionRegion); g2.setPaint(Color.white); g2.setStroke(new BasicStroke(3.0f)); g2.draw(this.coElutionRegion); } g2.setPaintMode(); g2.setPaint(origColor); }
From source file:io.github.dsheirer.spectrum.SpectrumPanel.java
/** * Draws the current fft spectrum with a line and a gradient fill. *///w ww .j a v a2 s. co m private void drawSpectrum(Graphics2D graphics) { Dimension size = getSize(); //Draw the background Rectangle background = new Rectangle(0, 0, size.width, size.height); graphics.setColor(mColorSpectrumBackground); graphics.draw(background); graphics.fill(background); //Define the gradient GradientPaint gradient = new GradientPaint(0, (getSize().height - mSpectrumInset) / 2, mColorSpectrumGradientTop, 0, getSize().height, mColorSpectrumGradientBottom); graphics.setBackground(mColorSpectrumBackground); GeneralPath spectrumShape = new GeneralPath(); //Start at the lower right inset point spectrumShape.moveTo(size.getWidth(), size.getHeight() - mSpectrumInset); //Draw to the lower left spectrumShape.lineTo(0, size.getHeight() - mSpectrumInset); float[] bins = getBins(); //If we have FFT data to display ... if (bins != null) { float insideHeight = size.height - mSpectrumInset; float scalor = insideHeight / -mDBScale; /* Calculate based on bin size - 1, since bin 0 is rendered at zero * and the last bin is rendered at the width */ float binSize = (float) size.width / ((float) (bins.length)); for (int x = 0; x < bins.length; x++) { float height; height = bins[x] * scalor; if (height > insideHeight) { height = insideHeight; } if (height < 0) { height = 0; } float xAxis = (float) x * binSize; spectrumShape.lineTo(xAxis, height); } } //Otherwise show an empty spectrum else { //Draw Left Size graphics.setPaint(gradient); spectrumShape.lineTo(0, size.getHeight() - mSpectrumInset); //Draw Middle spectrumShape.lineTo(size.getWidth(), size.getHeight() - mSpectrumInset); } //Draw Right Side spectrumShape.lineTo(size.getWidth(), size.getHeight() - mSpectrumInset); graphics.setPaint(gradient); graphics.draw(spectrumShape); graphics.fill(spectrumShape); graphics.setPaint(mColorSpectrumLine); //Draw the bottom line under the spectrum graphics.draw(new Line2D.Float(0, size.height - mSpectrumInset, size.width, size.height - mSpectrumInset)); }
From source file:org.jax.maanova.plot.MaanovaChartPanel.java
/** * Render the selection rectangle/*from ww w . j ava2 s . c o m*/ * @param graphics2D * the graphics context to render to */ protected synchronized void renderDragRectangle(Graphics2D graphics2D) { Rectangle2D nonNegativeSelectionRectangle = MaanovaChartPanel .toNonNegativeWidthHeightRectangle(this.dragRectangle); graphics2D.setColor(this.getSelectionRectangleFillColor()); graphics2D.fill(nonNegativeSelectionRectangle); graphics2D.setColor(this.getSelectionRectangleColor()); graphics2D.draw(nonNegativeSelectionRectangle); }
From source file:org.jfree.experimental.chart.plot.dial.DialCap.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 w ww. j av a 2s . c om*/ public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { g2.setPaint(this.fillPaint); Rectangle2D f = DialPlot.rectangleByRadius(frame, this.radius, this.radius); Ellipse2D e = new Ellipse2D.Double(f.getX(), f.getY(), f.getWidth(), f.getHeight()); g2.fill(e); g2.setPaint(this.outlinePaint); g2.setStroke(this.outlineStroke); g2.draw(e); }
From source file:de.dakror.villagedefense.game.entity.struct.Struct.java
@Override public void draw(Graphics2D g) { g.drawImage(getImage(), (int) x, (int) y, Game.w); if (getAttackArea().getBounds().width > 0 && (clicked || hovered)) { Color oldColor = g.getColor(); g.setColor(Color.darkGray); g.draw(getAttackArea()); g.setColor(oldColor);/* ww w . j a v a2 s. c om*/ } // TODO: DEBUG // for (Vector p : structPoints.entries) // { // Vector v = p.clone(); // v.mul(Tile.SIZE); // v.add(new Vector(x, y)); // // Color old = g.getColor(); // g.setColor(Color.green); // g.fillRect((int) v.x, (int) v.y, 4, 4); // g.setColor(old); // } }
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 ww . j av 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); }