List of usage examples for java.awt Graphics2D fill
public abstract void fill(Shape s);
From source file:TexturePaintFill.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; // a round rectangle. RoundRectangle2D r = new RoundRectangle2D.Float(25, 35, 150, 150, 25, 25); // a texture rectangle the same size as the texture image. Rectangle2D tr = new Rectangle2D.Double(0, 0, mImage.getWidth(), mImage.getHeight()); // the TexturePaint. TexturePaint tp = new TexturePaint(mImage, tr); // Now fill the round rectangle. g2.setPaint(tp);/*from w w w. j a va2s. co m*/ g2.fill(r); }
From source file:TexturePaintDemo.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; BufferedImage bi = new BufferedImage(5, 5, BufferedImage.TYPE_INT_RGB); Graphics2D big = bi.createGraphics(); big.setColor(Color.blue);//from w w w . j a va 2 s . c om big.fillRect(0, 0, 5, 5); big.setColor(Color.lightGray); big.fillOval(0, 0, 5, 5); Rectangle r = new Rectangle(0, 0, 5, 5); g2.setPaint(new TexturePaint(bi, r)); Rectangle rect = new Rectangle(5, 5, 200, 200); g2.fill(rect); }
From source file:edu.umd.cfar.lamp.chronicle.ChronicleRuler.java
/** * {@inheritDoc}//ww w. ja v a 2 s . co m */ public void paint(PPaintContext paintContext) { if (this.backgroundColor != null) { Graphics2D graph = paintContext.getGraphics(); graph.setPaint(backgroundColor); graph.fill(getBoundsReference()); } if (this.viewer.model != null && this.viewer.model.getFocus() != null) { resetMinWidth(paintContext, viewer.getScrollViews().columnHeader); int maxWidthRule = findChronicleWidthsApproximation(end); maxWidthRule -= 1; int i = (int) ((firstVisibleFrame + ChronicleRuler.widths[minWidth] - 1) / ChronicleRuler.widths[minWidth]); int firstI = i; int end = (int) (lastVisibleFrame / ChronicleRuler.widths[minWidth]); boolean[] found = new boolean[1 + end - i]; int toAvoid = -1; if (minWidth % 3 == 1) { toAvoid = minWidth + 1; } for (int width = maxWidthRule; width >= minWidth; width--) { if (width != toAvoid) { int diff = (int) (ChronicleRuler.widths[width] / ChronicleRuler.widths[minWidth]); i = (int) ((firstVisibleFrame + ChronicleRuler.widths[width] - 1) / ChronicleRuler.widths[width]); end = (int) (lastVisibleFrame / ChronicleRuler.widths[width]); while (i <= end) { long frameNum = i * ChronicleRuler.widths[width]; int borderNum = i * diff - firstI; if (!found[borderNum]) { drawHashForFrame((int) frameNum, paintContext, minWidth, maxWidthRule, width); found[borderNum] = true; } i++; } } else { // want to draw 5 rules on a 2 width box. // So draw all the fives that aren't divisible // by two i = (int) ((firstVisibleFrame + ChronicleRuler.widths[width] - 1) / ChronicleRuler.widths[width]); end = (int) (lastVisibleFrame / ChronicleRuler.widths[width]); while (i <= end) { long frameNum = i * ChronicleRuler.widths[width]; int fiveMultiple = (int) (frameNum / ChronicleRuler.widths[width - 2]); // widths[width] == 5 * widths[width-2] if ((fiveMultiple & 1) == 1) { drawHashForFrame((int) frameNum, paintContext, minWidth, maxWidthRule, width); } i++; } } } boolean startsWithTwo = (minFrameLabellingDistance % 3) == 1; long fLabelDist = ChronicleRuler.widths[minFrameLabellingDistance]; if (startsWithTwo) { Set already = paintFrameLabelsAtDistanceExcept(paintContext, fLabelDist, null); fLabelDist = ChronicleRuler.widths[minFrameLabellingDistance + 1]; paintFrameLabelsAtDistanceExcept(paintContext, fLabelDist, already); } else { paintFrameLabelsAtDistanceExcept(paintContext, fLabelDist, null); } } }
From source file:AlgorithmAnimation.java
public synchronized void paintComponent(Graphics g) // Called on the event dispatch thread { if (values == null) return;/* ww w .j av a 2 s. c o m*/ Graphics2D g2 = (Graphics2D) g; int width = getWidth() / values.length; for (int i = 0; i < values.length; i++) { double height = values[i] * getHeight(); Rectangle2D bar = new Rectangle2D.Double(width * i, 0, width, height); if (values[i] == marked1 || values[i] == marked2) g2.fill(bar); else g2.draw(bar); } }
From source file:ShapeTest.java
public void paintComponent(Graphics g) { if (points == null) return;/*w w w.j ava 2s . c om*/ Graphics2D g2 = (Graphics2D) g; for (int i = 0; i < points.length; i++) { double x = points[i].getX() - SIZE / 2; double y = points[i].getY() - SIZE / 2; g2.fill(new Rectangle2D.Double(x, y, SIZE, SIZE)); } g2.draw(shapeMaker.makeShape(points)); }
From source file:Bouncer.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; setAntialiasing(g2);// w ww. j av a2s .c om setClip(g2); setTransform(g2); Shape shape = createShape(); setPaint(g2); g2.fill(shape); if (mOutline) { setStroke(g2); g2.setPaint(Color.blue); g2.draw(shape); } drawAxes(g2); }
From source file:MainClass.java
public void paintToPDF(JTextPane ta) { try {//from w w w . j ava 2 s .c om 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:lu.lippmann.cdb.common.gui.DragAndDroppablePieChartPanel.java
/** * {@inheritDoc}//from w w w . j a v a2s . co m */ @Override public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; if (!released && source != null) { final PiePlot plot = ((PiePlot) getChart().getPlot()); final Comparable<?> key = plot.getDataset().getKey(source.getSectionIndex()); final Color color = (Color) plot.getSectionPaint(key); g2d.translate(tx, ty); g2d.setColor(color); g2d.fill(source.getArea()); } }
From source file:org.jfree.experimental.chart.plot.dial.DialBackground.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). *//* w w w .j a v a 2s .co m*/ public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) { Paint p = this.paint; if (p instanceof GradientPaint) { p = this.gradientPaintTransformer.transform((GradientPaint) p, view); } g2.setPaint(p); g2.fill(view); }
From source file:org.fhcrc.cpl.toolbox.gui.chart.ChartMouseAndMotionListener.java
/** * Draws zoom rectangle (if present).//from w w w .j av a 2s. c o 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 selectedRegion * @param stroke * @param fillColor */ protected void drawSelectedRegion(Rectangle2D selectedRegion, Stroke stroke, Color fillColor, boolean xorMode, Graphics2D g2) { // Set XOR mode to draw the zoom rectangle if (g2 == null) return; Paint origColor = g2.getPaint(); if (selectedRegion != null) { if (xorMode) { g2.setXORMode(fillColor); } else g2.setPaint(fillColor); g2.fill(selectedRegion); g2.setPaint(Color.black); g2.setStroke(stroke); if (xorMode) g2.setPaint(Color.white); else g2.setPaint(Color.black); g2.draw(selectedRegion); g2.setPaintMode(); g2.setPaint(origColor); } }