List of usage examples for java.awt Graphics2D draw
public abstract void draw(Shape s);
From source file:org.apache.fop.render.pcl.PCLRenderer.java
/** * Paints the text decoration marks.//from ww w . j av a2s . c o m * @param g2d Graphics2D instance to paint to * @param fm Current typeface * @param fontsize Current font size * @param inline inline area to paint the marks for * @param baseline position of the baseline * @param startx start IPD */ private static void renderTextDecoration(Graphics2D g2d, FontMetrics fm, int fontsize, InlineArea inline, int baseline, int startx) { boolean hasTextDeco = inline.hasUnderline() || inline.hasOverline() || inline.hasLineThrough(); if (hasTextDeco) { float descender = fm.getDescender(fontsize) / 1000f; float capHeight = fm.getCapHeight(fontsize) / 1000f; float lineWidth = (descender / -4f) / 1000f; float endx = (startx + inline.getIPD()) / 1000f; if (inline.hasUnderline()) { Color ct = (Color) inline.getTrait(Trait.UNDERLINE_COLOR); g2d.setColor(ct); float y = baseline - descender / 2f; g2d.setStroke(new BasicStroke(lineWidth)); g2d.draw(new Line2D.Float(startx / 1000f, y / 1000f, endx, y / 1000f)); } if (inline.hasOverline()) { Color ct = (Color) inline.getTrait(Trait.OVERLINE_COLOR); g2d.setColor(ct); float y = (float) (baseline - (1.1 * capHeight)); g2d.setStroke(new BasicStroke(lineWidth)); g2d.draw(new Line2D.Float(startx / 1000f, y / 1000f, endx, y / 1000f)); } if (inline.hasLineThrough()) { Color ct = (Color) inline.getTrait(Trait.LINETHROUGH_COLOR); g2d.setColor(ct); float y = (float) (baseline - (0.45 * capHeight)); g2d.setStroke(new BasicStroke(lineWidth)); g2d.draw(new Line2D.Float(startx / 1000f, y / 1000f, endx, y / 1000f)); } } }
From source file:business.ImageManager.java
private void doDrawPath(Graphics2D big, Point ori, Point dest, Color color) { //setup para os rastros big.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); big.setStroke(new BasicStroke(0.75f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1f, new float[] { 3f, 5f, 7f, 5f, 11f, 5f, 15f, 5f, 21f, 5f, 27f, 5f, 33f, 5f }, 0f)); big.setColor(color);/*from www. ja va 2s . c o m*/ //draw path Path2D.Double path = new Path2D.Double(); path.moveTo(ori.getX(), ori.getY()); path.lineTo(dest.getX(), dest.getY()); //draw on graph big.draw(path); }
From source file:StrokeChooserPanel.java
/** * Draws a line using the sample stroke. * * @param g the graphics device.// w w w . j a va 2s. c o m */ public void paintComponent(final Graphics g) { final Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); final Dimension size = getSize(); final Insets insets = getInsets(); final double xx = insets.left; final double yy = insets.top; final double ww = size.getWidth() - insets.left - insets.right; final double hh = size.getHeight() - insets.top - insets.bottom; // calculate point one final Point2D one = new Point2D.Double(xx + 6, yy + hh / 2); // calculate point two final Point2D two = new Point2D.Double(xx + ww - 6, yy + hh / 2); // draw a circle at point one final Ellipse2D circle1 = new Ellipse2D.Double(one.getX() - 5, one.getY() - 5, 10, 10); final Ellipse2D circle2 = new Ellipse2D.Double(two.getX() - 6, two.getY() - 5, 10, 10); // draw a circle at point two g2.draw(circle1); g2.fill(circle1); g2.draw(circle2); g2.fill(circle2); // draw a line connecting the points final Line2D line = new Line2D.Double(one, two); if (this.stroke != null) { g2.setStroke(this.stroke); g2.draw(line); } }
From source file:com.rapidminer.gui.plotter.charts.RapidBarPainter.java
/** * Paints a single bar instance.//from w ww . j a v a 2 s .co m * * @param g2 * the graphics target. * @param renderer * the renderer. * @param row * the row index. * @param column * the column index. * @param bar * the bar * @param base * indicates which side of the rectangle is the base of the bar. */ @Override public void paintBar(final Graphics2D g2, final BarRenderer renderer, final int row, final int column, final RectangularShape bar, final RectangleEdge base) { Paint itemPaint = renderer.getItemPaint(row, column); Color c0 = null; if (itemPaint instanceof Color) { c0 = (Color) itemPaint; } else { c0 = SwingTools.DARK_BLUE; } // as a special case, if the bar color has alpha == 0, we draw // nothing. if (c0.getAlpha() == 0) { return; } g2.setPaint(c0); g2.fill(new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), bar.getWidth(), bar.getHeight())); // draw the outline... if (renderer.isDrawBarOutline()) { Stroke stroke = renderer.getItemOutlineStroke(row, column); Paint paint = renderer.getItemOutlinePaint(row, column); if (stroke != null && paint != null) { g2.setStroke(stroke); g2.setPaint(paint); g2.draw(bar); } } }
From source file:org.eurocarbdb.application.glycoworkbench.plugin.PeakListChartPanel.java
public void mouseDragged(MouseEvent e) { if (mouse_start_point != null && theDocument.size() > 0) { if (is_moving) { // moving double mz_delta = screenToDataX(mouse_start_point.getX() - e.getPoint().getX()); if (mz_delta > 0.) { double old_upper_bound = thePlot.getDomainAxis().getUpperBound(); double old_lower_bound = thePlot.getDomainAxis().getLowerBound(); double new_upper_bound = Math.min(old_upper_bound + mz_delta, theDocument.getMaxMZ()); double new_lower_bound = old_lower_bound + new_upper_bound - old_upper_bound; thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound)); } else { double old_upper_bound = thePlot.getDomainAxis().getUpperBound(); double old_lower_bound = thePlot.getDomainAxis().getLowerBound(); double new_lower_bound = Math.max(old_lower_bound + mz_delta, theDocument.getMinMZ()); double new_upper_bound = old_upper_bound + new_lower_bound - old_lower_bound; thePlot.getDomainAxis().setRange(new Range(new_lower_bound, new_upper_bound)); }/*from w w w . ja va 2 s .co m*/ mouse_start_point = e.getPoint(); } else { // zooming Graphics2D g2 = (Graphics2D) theChartPanel.getGraphics(); g2.setXORMode(java.awt.Color.gray); // delete old rectangle if (zoom_rectangle != null) g2.draw(zoom_rectangle); // create new rectangle double start_x = Math.min(e.getX(), mouse_start_point.getX()); double end_x = Math.max(e.getX(), mouse_start_point.getX()); Rectangle2D data_area = theChartPanel.getScreenDataArea((int) start_x, (int) mouse_start_point.getY()); double xmax = Math.min(end_x, data_area.getMaxX()); zoom_rectangle = new Rectangle2D.Double(start_x, data_area.getMinY(), xmax - start_x, data_area.getHeight()); // draw new rectangle g2.draw(zoom_rectangle); g2.dispose(); } } }
From source file:org.squidy.designer.model.PipeShape.java
@Override protected void paintShape(PPaintContext paintContext) { super.paintShape(paintContext); Graphics2D g = paintContext.getGraphics(); boolean processing = getPipe().getSource().isProcessing(); boolean hasFailure = getSource().hasFailure(); if (selected) { g.setColor(hasFailure ? COLOR_FAILURE_SELECTED : (processing ? COLOR_PROCESSING_SELECTED : COLOR_NORMAL_SELECTED)); } else {//from w w w .ja v a2 s . c o m g.setColor(hasFailure ? COLOR_FAILURE : (processing ? COLOR_PROCESSING : COLOR_NORMAL)); } for (int i = 0; i < 3; i++) { g.setStroke(STROKE_SHAPE[i]); g.draw(shape); } }
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);// w w w .j ava 2 s .co m 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:de.berlios.statcvs.xml.chart.SymbolicNameAnnotation.java
/** * @see org.jfree.chart.annotations.XYAnnotation#draw(java.awt.Graphics2D, org.jfree.chart.plot.XYPlot, java.awt.geom.Rectangle2D, org.jfree.chart.axis.ValueAxis, org.jfree.chart.axis.ValueAxis) *///from ww w . j a v a2 s . co m public void draw(Graphics2D g2d, XYPlot xyPlot, Rectangle2D dataArea, ValueAxis domainAxis, ValueAxis rangeAxis) { PlotOrientation orientation = xyPlot.getOrientation(); // don't draw the annotation if symbolic names date is out of axis' bounds. if (domainAxis.getUpperBound() < symbolicName.getDate().getTime() || domainAxis.getLowerBound() > symbolicName.getDate().getTime()) { return; } RectangleEdge domainEdge = Plot.resolveDomainAxisLocation(xyPlot.getDomainAxisLocation(), orientation); RectangleEdge rangeEdge = Plot.resolveRangeAxisLocation(xyPlot.getRangeAxisLocation(), orientation); float x = (float) domainAxis.translateValueToJava2D(symbolicName.getDate().getTime(), dataArea, domainEdge); float y1 = (float) rangeAxis.translateValueToJava2D(rangeAxis.getUpperBound(), dataArea, rangeEdge); float y2 = (float) rangeAxis.translateValueToJava2D(rangeAxis.getLowerBound(), dataArea, rangeEdge); g2d.setPaint(linePaint); g2d.setStroke(stroke); Line2D line = new Line2D.Float(x, y1, x, y2); g2d.draw(line); float anchorX = x; float anchorY = y1 + 2; g2d.setFont(font); g2d.setPaint(textPaint); /*g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);*/ RefineryUtilities.drawRotatedString(symbolicName.getName(), g2d, anchorX, anchorY, TextAnchor.BOTTOM_RIGHT, TextAnchor.BOTTOM_RIGHT, -Math.PI / 2); }
From source file:org.tros.logo.swing.LogoPanel.java
@Override public void forward(final double distance) { Drawable command = new Drawable() { @Override//w ww . ja va 2 s.com public void draw(Graphics2D g2, TurtleState turtleState) { double newx = turtleState.penX + (distance * Math.cos(turtleState.angle)); double newy = turtleState.penY + (distance * Math.sin(turtleState.angle)); if (!turtleState.penup) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.draw(new Line2D.Double(turtleState.penX, turtleState.penY, newx, newy)); } turtleState.penX = newx; turtleState.penY = newy; } @Override public void addListener(DrawListener listener) { } @Override public void removeListener(DrawListener listener) { } @Override public Drawable cloneDrawable() { return this; } }; submitCommand(command); }
From source file:org.tros.logo.swing.LogoPanel.java
@Override public void backward(final double distance) { Drawable command = new Drawable() { @Override/*w w w .ja v a 2 s.com*/ public void draw(Graphics2D g2, TurtleState turtleState) { double newx = turtleState.penX - (distance * Math.cos(turtleState.angle)); double newy = turtleState.penY - (distance * Math.sin(turtleState.angle)); if (!turtleState.penup) { g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.draw(new Line2D.Double(turtleState.penX, turtleState.penY, newx, newy)); } turtleState.penX = newx; turtleState.penY = newy; } @Override public void addListener(DrawListener listener) { } @Override public void removeListener(DrawListener listener) { } @Override public Drawable cloneDrawable() { return this; } }; submitCommand(command); }