List of usage examples for java.awt Graphics2D setPaint
public abstract void setPaint(Paint paint);
From source file:TexturedPanel.java
/** * Paints this component with its textured background. */// w ww .java2s. c om protected void paintComponent(Graphics g) { super.paintComponent(g); if (ourPainter != null) { int w = getWidth(); int h = getHeight(); Insets in = getInsets(); int x = in.left; int y = in.top; w = w - in.left - in.right; h = h - in.top - in.bottom; if (w >= 0 && h >= 0) { Graphics2D g2 = (Graphics2D) g; Paint pt = g2.getPaint(); g2.setPaint(ourPainter); g2.fillRect(x, y, w, h); g2.setPaint(pt); } } }
From source file:edu.umd.cfar.lamp.chronicle.ChronicleRuler.java
/** * {@inheritDoc}//from w w w. j a va 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:MainClass.java
public void paint(Graphics g) { Graphics2D g2D = (Graphics2D) g; Point2D.Float p1 = new Point2D.Float(150.f, 75.f); Point2D.Float p2 = new Point2D.Float(250.f, 75.f); float width = 300; float height = 50; GradientPaint g1 = new GradientPaint(p1, Color.WHITE, p2, Color.DARK_GRAY, true); Rectangle2D.Float rect1 = new Rectangle2D.Float(p1.x - 100, p1.y - 25, width, height); g2D.setPaint(g1); g2D.fill(rect1);/*from w w w .ja va2s . co m*/ g2D.setPaint(Color.BLACK); g2D.draw(rect1); g2D.draw(new Line2D.Float(p1, p2)); g2D.drawString("Cyclic Gradient Paint", p1.x - 100, p1.y - 50); g2D.drawString("p1", p1.x - 20, p1.y); g2D.drawString("p2", p2.x + 10, p2.y); p1.setLocation(150, 200); p2.setLocation(250, 200); GradientPaint g2 = new GradientPaint(p1, Color.WHITE, p2, Color.DARK_GRAY, false); rect1.setRect(p1.x - 100, p1.y - 25, width, height); g2D.setPaint(g2); g2D.fill(rect1); g2D.setPaint(Color.BLACK); g2D.draw(rect1); g2D.draw(new Line2D.Float(p1, p2)); g2D.drawString("Acyclic Gradient Paint", p1.x - 100, p1.y - 50); g2D.drawString("p1", p1.x - 20, p1.y); g2D.drawString("p2", p2.x + 10, p2.y); }
From source file:com.bdb.weather.display.day.ItemRenderer.java
/** * Plots the data for a given series./*from ww w . j a v a 2 s.c o m*/ * * @param g2 the drawing surface. * @param dataArea the data area. * @param info collects plot rendering info. * @param plot the plot. * @param dataset the dataset. * @param seriesIndex the series index. */ @Override public void drawSeries(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info, PolarPlot plot, XYDataset dataset, int seriesIndex) { Shape point = new Rectangle2D.Double(-2, -2, 4, 4); int numPoints = dataset.getItemCount(seriesIndex); g2.setPaint(lookupSeriesPaint(seriesIndex)); g2.setStroke(lookupSeriesStroke(seriesIndex)); for (int i = 0; i < numPoints; i++) { double theta = dataset.getXValue(seriesIndex, i); double radius = dataset.getYValue(seriesIndex, i); Point p = plot.translateToJava2D(theta, radius, plot.getAxis(), dataArea); Shape shape = ShapeUtilities.createTranslatedShape(point, p.getX(), p.getY()); g2.fill(shape); } }
From source file:TransformTranslation.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; // Use antialiasing. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Move the origin to 75, 75. AffineTransform at = AffineTransform.getTranslateInstance(75, 75); g2.transform(at);/*from ww w. j ava2s . com*/ // Draw the shapes in their original locations. g2.setPaint(Color.black); g2.draw(axes); g2.draw(shape); // Transform the Graphics2D. g2.transform(AffineTransform.getTranslateInstance(150, 0)); // Draw the "new" shapes in dashed. Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 }, 0); g2.setStroke(stroke); g2.draw(axes); g2.draw(shape); }
From source file:TransformersRotation.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; // Use antialiasing. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Move the origin to 75, 75. AffineTransform at = AffineTransform.getTranslateInstance(75, 75); g2.transform(at);/*from w ww. jav a 2 s . com*/ // Draw the shapes in their original locations. g2.setPaint(Color.black); g2.draw(axes); g2.draw(shape); // Transform the Graphics2D. g2.transform(AffineTransform.getRotateInstance(-Math.PI / 6)); // Draw the "new" shapes in dashed. Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 }, 0); g2.setStroke(stroke); g2.draw(axes); g2.draw(shape); }
From source file:TransformTranslatedRotation.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; // Use antialiasing. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Move the origin to 75, 75. AffineTransform at = AffineTransform.getTranslateInstance(75, 75); g2.transform(at);/* www .j ava 2 s . c o m*/ // Draw the shapes in their original locations. g2.setPaint(Color.black); g2.draw(axes); g2.draw(shape); // Transform the Graphics2D. float cm = 72 / 2.54f; g2.transform(AffineTransform.getRotateInstance(-Math.PI / 6, 3 * cm, 2 * cm)); // Draw the "new" shapes in dashed. Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 }, 0); g2.setStroke(stroke); g2.draw(axes); g2.draw(shape); }
From source file:edu.umd.cfar.lamp.chronicle.ChronicleRuler.java
private void drawLine(int x1, int y1, int x2, int y2, Paint p, Stroke stroke, PPaintContext paintContext) { Graphics2D g2 = paintContext.getGraphics(); Paint old = g2.getPaint();/*from w w w. ja v a 2 s .c o m*/ Stroke oldS = g2.getStroke(); g2.setPaint(p); g2.setStroke(stroke); g2.drawLine(x1, y1, x2, y2); g2.setPaint(old); g2.setStroke(oldS); }
From source file:TransformScale.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; // Use antialiasing. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Move the origin to 75, 75. AffineTransform at = AffineTransform.getTranslateInstance(75, 75); g2.transform(at);//w w w .j av a 2 s . c o m // Draw the shapes in their original locations. g2.setPaint(Color.black); g2.draw(axes); g2.draw(shape); // Transform the Graphics2D. g2.transform(AffineTransform.getScaleInstance(3, 3)); // Draw the "new" shapes in dashed. g2.transform(AffineTransform.getTranslateInstance(75, 75)); Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 }, 0); g2.setStroke(stroke); g2.draw(axes); g2.draw(shape); }
From source file:TextBouncer.java
protected void drawAxes(Graphics2D g2) { if (mAxes == false) return;//w w w. j a v a 2 s . c o m g2.setPaint(getForeground()); g2.setStroke(new BasicStroke()); Dimension d = getSize(); int side = 20; int arrow = 4; int w = d.width / 2, h = d.height / 2; g2.drawLine(w - side, h, w + side, h); g2.drawLine(w + side - arrow, h - arrow, w + side, h); g2.drawLine(w, h - side, w, h + side); g2.drawLine(w + arrow, h + side - arrow, w, h + side); }