public void init(Graphics2D g, float scale, int width, int height) { if (this.METRICS == null) { AffineTransform transform = g.getTransform(); if (Double.compare(transform.getScaleX(), 1) != 0 || Double.compare(transform.getScaleY(), 1) != 0) { throw new IllegalStateException("Illegal Transform"); } this.METRICS = new FontMetrics[FONTS.length]; Font defaultFont = g.getFont(); for (int i = 0; i < FONTS.length; i++) { g.setFont(FONTS[i]); this.METRICS[i] = g.getFontMetrics(); } g.setFont(defaultFont); } this.g = g; this.scale = scale; this.screen.width = width; this.screen.height = height; this.lapList.clear(); this.fixedLabelMap.clear(); this.r = (int) (2 / this.scale + 0.5); this.r2 = (int) (4 / this.scale + 0.5); }
public void drawConditionalSequenceFlowIndicator(Line2D.Double line) { int horizontal = (int) (CONDITIONAL_INDICATOR_WIDTH * 0.7); int halfOfHorizontal = horizontal / 2; int halfOfVertical = CONDITIONAL_INDICATOR_WIDTH / 2; Polygon conditionalIndicator = new Polygon(); conditionalIndicator.addPoint(0, 0); conditionalIndicator.addPoint(-halfOfHorizontal, halfOfVertical); conditionalIndicator.addPoint(0, CONDITIONAL_INDICATOR_WIDTH); conditionalIndicator.addPoint(halfOfHorizontal, halfOfVertical); AffineTransform transformation = new AffineTransform(); transformation.setToIdentity(); double angle = Math.atan2(line.y2 - line.y1, line.x2 - line.x1); transformation.translate(line.x1, line.y1); transformation.rotate((angle - Math.PI / 2d)); AffineTransform originalTransformation = g.getTransform(); g.setTransform(transformation); g.draw(conditionalIndicator); Paint originalPaint = g.getPaint(); g.setPaint(CONDITIONAL_INDICATOR_COLOR); g.fill(conditionalIndicator); g.setPaint(originalPaint); g.setTransform(originalTransformation); }
@Override public synchronized void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D gfx = (Graphics2D) g; Rectangle vbounds = _panel.getViewBounds(); gfx.translate( (getWidth() - vbounds.width / 16) / 2 - vbounds.x / 16, (getHeight() - vbounds.height / 16) / 2 - vbounds.y / 16); AffineTransform xform = gfx.getTransform(); gfx.scale(0.25, 0.25); // draw our block glyphs for (BlockGlyph blockGlyph : _blocks.values()) { blockGlyph.paint(gfx); } // draw the view bounds gfx.scale(0.25, 0.25); gfx.draw(vbounds); gfx.setColor(Color.red); gfx.draw(_panel.getInfluentialBounds()); gfx.setTransform(xform); }
/** * Render the View to the given graphic context. This implementation render the interior first, * then the outline. */ public void paint(Graphics2D g, Rectangle2D a) { if (!a.intersects(getBounds())) return; if (image != null) { // paint bitmap g.drawImage(image, text2ModelTr, null); // debug: g.setPaint(Color.red); g.draw(this.bounds); super.paint(g, a); // possibly paint framebox if non-null } else { // paint textlayout super.paint(g, a); // possibly paint framebox if non-null AffineTransform oldAT = g.getTransform(); // paint text in black g.setPaint(Color.black); // from now on, we work in Y-direct (<0) coordinates to avoid inextricable problems with font // being mirrored... g.transform(text2ModelTr); // also include rotation textLayout.draw(g, 0.0f, 0.0f); // [pending] ajouter un cadre si areDimensionsComputed (wysiwyg du pauvre) // get back to previous transform g.setTransform(oldAT); if (DEBUG) { g.setPaint(Color.red); g.draw(bounds); } } }
@Override public void drawTextAxis( Graphics2D g2d, Dimension dim, boolean isHorizontal, String text, double coordinate) { if (!this.showAxisFonts) return; g2d.setFont(this.axisFont); int width = g2d.getFontMetrics().stringWidth(text) + this.axisFontMargin; int height = g2d.getFontMetrics().getHeight(); /*if (isHorizontal) g2d.fillRect(0, (int) dim.getHeight()-width, (int) dim.getWidth(), (int) dim.getHeight()); else g2d.fillRect(0, 0, width, (int) dim.getHeight());*/ g2d.setFont(axisFont); AffineTransform orig = g2d.getTransform(); double angle = Math.toRadians(90); if (this.showAxisFonts) if (!isHorizontal) { g2d.setColor(this.axisBackgroundColor); g2d.fillRect(axisFontMargin, (int) coordinate - height, width, height); g2d.setColor(this.axisFontColor); g2d.drawString(text, this.axisFontMargin, (int) coordinate - axisFontMargin); } else { g2d.rotate( -angle, (int) coordinate - this.axisFontMargin, (int) dim.getHeight() - axisFontMargin); g2d.setColor(this.axisBackgroundColor); g2d.fillRect( (int) coordinate - this.axisFontMargin, (int) dim.getHeight() - height, width, height); g2d.setColor(this.axisFontColor); g2d.drawString( text, (int) coordinate - this.axisFontMargin, (int) dim.getHeight() - axisFontMargin); g2d.setTransform(orig); } }
private void drawSliders(Graphics2D g2d) { g2d.translate(sliderBaseLineRect.x, sliderBaseLineRect.y); g2d.setStroke(STROKE_1); for (int i = 0; i < getSliderCount(); i++) { if (isSliderVisible(i)) { double sliderPos = getRelativeSliderPos(getSliderSample(i)); g2d.translate(sliderPos, 0.0); final Color sliderColor = getSliderColor(i); g2d.setPaint(sliderColor); g2d.fill(sliderShape); int gray = (sliderColor.getRed() + sliderColor.getGreen() + sliderColor.getBlue()) / 3; g2d.setColor(gray < 128 ? Color.white : Color.black); g2d.draw(sliderShape); String text = getFormattedValue(getSliderSample(i)); g2d.setColor(Color.black); // save the old transformation final AffineTransform oldTransform = g2d.getTransform(); g2d.transform(AffineTransform.getRotateInstance(Math.PI / 2)); g2d.drawString(text, 3 + 0.5f * SLIDER_HEIGHT, 0.35f * FONT_SIZE); // restore the old transformation g2d.setTransform(oldTransform); g2d.translate(-sliderPos, 0.0); } } g2d.translate(-sliderBaseLineRect.x, -sliderBaseLineRect.y); }
private void drawYLabel(Graphics g) { g.setFont(fontBold); // # radians to rotate. double theta = -Math.PI / 2; Rectangle plotRect = getPlotRect(); /* The y axis laabel. */ String yLabel = "True Positive Fraction"; int stringWidth = fm.stringWidth(yLabel); // where to begin drawing (the rotated image) Point translate = new Point(fm.getAscent(), plotRect.y + (plotRect.height / 2 + stringWidth / 2)); Graphics2D g2 = (Graphics2D) g; AffineTransform save = g2.getTransform(); g2.translate(translate.x, translate.y); g2.rotate(theta); g2.setColor(boundaryColor); g2.drawString(yLabel, 0, 0); g2.setTransform(save); }
@Override public synchronized void draw(Graphics g, Transform t) { Graphics2D g2d = (Graphics2D) g; AffineTransform ord = g2d.getTransform(); g2d.setTransform(t.getAffineTransform()); float y1 = -length; // * t.scaling.y; float y2 = 0; if (reverse) { float tmp = y1; y1 = y2; y2 = tmp; } // Vec2 p1 = Vec2.add(t.position, new Vec2(0,y1)); // Vec2 p2 = Vec2.add(t.position, new Vec2(width * t.scaling.x / 2, y2));//Vec2.mul(offset2, // t.scaling)); // Vec2 p3 = Vec2.add(t.position, new Vec2(-width * t.scaling.x / 2, y2));//Vec2.mul(offset3, // t.scaling)); Vec2 p1 = new Vec2(0, y1); Vec2 p2 = new Vec2(width / 2, y2); Vec2 p3 = new Vec2(-width / 2, y2); int[] xPoints = new int[] {(int) p1.x, (int) p2.x, (int) p3.x}; int[] yPoints = new int[] {(int) p1.y, (int) p2.y, (int) p3.y}; g2d.drawPolygon(xPoints, yPoints, 3); g2d.setTransform(ord); }
/** {@inheritDoc} */ @Override protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) { BufferedImage decImg = decBtnMousePressed ? SCROLL_DEC_PRESSED : decBtnMouseOver ? SCROLL_DEC_OVER : SCROLL_DEC_NORMAL; BufferedImage incImg = incBtnMousePressed ? SCROLL_INC_PRESSED : incBtnMouseOver ? SCROLL_INC_OVER : SCROLL_INC_NORMAL; Graphics2D g2 = (Graphics2D) g; AffineTransform origTransform = g2.getTransform(); int scrollWidth = scrollbar.getWidth(); if (scrollbar.getOrientation() == JScrollBar.VERTICAL) { scrollWidth = scrollbar.getHeight(); g2.scale(1, -1); g2.rotate(-Math.PI / 2, 0, 0); } // draw track & bottons if (scrollbar.isEnabled()) { g.drawImage(decImg, 0, 0, scrollbar); // g.drawImage(BACKGROUND_ENABLED, 15, 0, scrollWidth - 15, 15, 0, 0, 1, 15, scrollbar); g.drawImage(incImg, scrollWidth - 15, 0, scrollbar); } else { // g.drawImage(BACKGROUND_DISABLED, 0, 0, scrollWidth, 15, 0, 0, 1, 15, scrollbar); } // undo any transform g2.setTransform(origTransform); }
/** * A static method for drawing an image (adapted from my first assignment) * * @param x horizontal position * @param y vertical position * @param w the scaled image width * @param h the scaled image height * @param angle the angle of rotation of the image * @param hflip whether or not to flip the image horizontally * @param vflip whether or not to flip the image vertically * @param canvas the image to draw * @param screen the destination to render to */ public static void drawImage( double x, double y, double w, double h, double angle, boolean hflip, boolean vflip, BufferedImage canvas, Graphics2D screen) { AffineTransform oldTransform = screen.getTransform(); double widthRatio = (double) w / (double) canvas.getWidth(); double heightRatio = (double) h / (double) canvas.getHeight(); AffineTransform affine = new AffineTransform(); affine.translate(x, y); affine.scale(widthRatio, heightRatio); affine.scale((hflip ? -1 : 1) * 1.0, (vflip ? -1 : 1) * 1.0); affine.rotate(angle); affine.translate((double) -canvas.getWidth() / 2.0, (double) -canvas.getHeight() / 2.0); screen.transform(affine); screen.drawImage(canvas, 0, 0, null); screen.setTransform(oldTransform); }
public void render(Vehicle vehicle) { Vector adjustedPosition = vehicle.position().add(viewPoint); int x = (int) adjustedPosition.x(); int y = (int) adjustedPosition.y(); Vector tip = new Vector(x + vehicle.boundingRadius(), y); Vector left = new Vector(x - 5, y - 5); Vector right = new Vector(x - 5, y + 5); int[] xPos = {(int) tip.x(), (int) left.x(), (int) right.x()}; int[] yPos = {(int) tip.y(), (int) left.y(), (int) right.y()}; AffineTransform orig = graphics.getTransform(); AffineTransform rot = AffineTransform.getRotateInstance(vehicle.heading().x(), vehicle.heading().y(), x, y); graphics.transform(rot); graphics.drawPolygon(xPos, yPos, 3); graphics.setTransform(orig); if (showFeelers) { Vector[] feelers = createFeelersFor(vehicle); for (Vector feeler : feelers) { graphics.drawLine(x, y, (int) feeler.x(), (int) feeler.y()); } } renderHealthBar(vehicle, x, y); renderEnergyBar(vehicle, x, y); }
/** This method is invoked before the rendered image of the figure is composited. */ public void drawFigure(Graphics2D g) { AffineTransform savedTransform = null; if (get(TRANSFORM) != null) { savedTransform = g.getTransform(); g.transform(get(TRANSFORM)); } if (get(FILL_STYLE) != ODGConstants.FillStyle.NONE) { Paint paint = ODGAttributeKeys.getFillPaint(this); if (paint != null) { g.setPaint(paint); drawFill(g); } } if (get(STROKE_STYLE) != ODGConstants.StrokeStyle.NONE) { Paint paint = ODGAttributeKeys.getStrokePaint(this); if (paint != null) { g.setPaint(paint); g.setStroke(ODGAttributeKeys.getStroke(this)); drawStroke(g); } } if (get(TRANSFORM) != null) { g.setTransform(savedTransform); } }
/** * Renders an image on the device * * @param tx the image location on the screen, x coordinate * @param ty the image location on the screen, y coordinate * @param img the image * @param rotation the image rotatation */ private static void renderImage( Graphics2D graphics, double x, double y, Image image, double rotation, float opacity) { AffineTransform temp = graphics.getTransform(); AffineTransform markAT = new AffineTransform(); Point2D mapCentre = new java.awt.geom.Point2D.Double(x, y); Point2D graphicCentre = new java.awt.geom.Point2D.Double(); temp.transform(mapCentre, graphicCentre); markAT.translate(graphicCentre.getX(), graphicCentre.getY()); double shearY = temp.getShearY(); double scaleY = temp.getScaleY(); double originalRotation = Math.atan(shearY / scaleY); markAT.rotate(rotation); graphics.setTransform(markAT); graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity)); // we moved the origin to the centre of the image. graphics.drawImage(image, -image.getWidth(null) / 2, -image.getHeight(null) / 2, null); graphics.setTransform(temp); return; }
/** * Prints the page at the specified index into the specified {@link Graphics} context in the * specified format. * * @param g the context into which the page is drawn * @param pageFormat the size and orientation of the page being drawn * @param pageIndex the zero based index of the page to be drawn * @return PAGE_EXISTS if the page is rendered successfully or NO_SUCH_PAGE if {@code pageIndex} * specifies a non-existent page. * @exception java.awt.print.PrinterException thrown when the print job is terminated. */ public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException { if (pageIndex > 0) { return Printable.NO_SUCH_PAGE; } Graphics2D graphics = (Graphics2D) g; AffineTransform txOld = graphics.getTransform(); graphics.scale(MM_PER_PX, MM_PER_PX); Rectangle2D boundsOld = getDrawable().getBounds(); Rectangle2D pageBounds = new Rectangle2D.Double( pageFormat.getImageableX() / MM_PER_PX, pageFormat.getImageableY() / MM_PER_PX, pageFormat.getImageableWidth() / MM_PER_PX, pageFormat.getImageableHeight() / MM_PER_PX); // Set size // TODO Keep Drawable's aspect ratio when scaling getDrawable().setBounds(pageBounds); // TODO Assure to temporarily turn off anti-aliasing before printing try { getDrawable().draw(new DrawingContext(graphics)); } finally { getDrawable().setBounds(boundsOld); } graphics.setTransform(txOld); return Printable.PAGE_EXISTS; }
@Override public void paint( final Graphics2D g, final Rectangle srcRect, final double magnification, final boolean active, final int channels, final Layer active_layer, final List<Layer> layers) { AffineTransform gt = null; Stroke stroke = null; AffineTransform aff = this.at; // remove graphics transform if (!"true".equals(getProject().getProperty("dissector_zoom"))) { gt = g.getTransform(); g.setTransform(new AffineTransform()); // identity stroke = g.getStroke(); g.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); aff = new AffineTransform(gt); aff.concatenate(this.at); } for (final Item item : al_items) { item.paint(g, aff, active_layer); } // restore if (null != gt) g.setTransform(gt); if (null != stroke) g.setStroke(stroke); }
private void drawShape(Shuttle shuttle) { Graphics2D g = shuttle.g; Shape oldclip = shuttle.g.getClip(); g.setClip(shuttle.clip); Composite oldcomposite = g.getComposite(); if (shuttle.opacity != 1f) { g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, shuttle.opacity)); } AffineTransform oldtr = g.getTransform(); g.setTransform(shuttle.transform); Stroke oldStroke = g.getStroke(); Stroke newStroke = new BasicStroke(shuttle.strokeWidth, shuttle.linecap.stroke(), shuttle.linejoin.stroke()); g.setStroke(newStroke); if (shuttle.fill != null) { g.setPaint(shuttle.fill); g.fill(shuttle.shape); } if (shuttle.stroke != null) { g.setPaint(shuttle.stroke); g.draw(shuttle.shape); } g.setClip(oldclip); g.setStroke(oldStroke); g.setTransform(oldtr); g.setComposite(oldcomposite); }
/** * paintComponent which paints the component. Flips if Status is normalRotation. * * @param _graphics the graphics which are painted. */ @Override public final void paintComponent(final Graphics _graphics) { // initialize values Graphics2D g2d = (Graphics2D) _graphics; AffineTransform origXform = g2d.getTransform(); AffineTransform newXform = (AffineTransform) origXform.clone(); // center of rotation is center of the panel int xRot = this.getWidth() / 2; int yRot = this.getHeight() / 2; // fetch rotation from Status double rotation = 0; // if not normal rotation if (!State.isNormalRotation()) { final int filpRotation = 180; rotation = filpRotation; } // rotate the image and draw the image to panel newXform.rotate(Math.toRadians(rotation), xRot, yRot); g2d.setTransform(newXform); super.paintComponent(g2d); g2d.setTransform(origXform); }
@Override public void drawParticlesWireframe( Vec2[] centers, float radius, ParticleColor[] colors, int count) { Graphics2D g = getGraphics(); saveState(g); transformGraphics(g, zero); g.setStroke(stroke); for (int i = 0; i < count; i++) { Vec2 center = centers[i]; Color color; // No alpha channel, it slows everything down way too much. if (colors == null) { color = pcolor; } else { ParticleColor c = colors[i]; color = new Color(c.r * 1f / 127, c.g * 1f / 127, c.b * 1f / 127, 1); } AffineTransform old = g.getTransform(); g.translate(center.x, center.y); g.scale(radius, radius); g.setColor(color); g.draw(circle); g.setTransform(old); } restoreState(g); }
@Override public void DesenhaSe(Graphics2D dbg, int XMundo, int YMundo) { // TODO Auto-generated method stub if (selecionado) { dbg.setColor(Color.white); } else { dbg.setColor(Color.lightGray); } if (ativo) { dbg.setColor(Color.green); } dbg.fillRect((int) X, (int) Y, sizeX, sizeY); AffineTransform trans = dbg.getTransform(); // dbg.scale(1.4, 1.4); dbg.drawImage( AnimeSet, null, (int) getX() + getSizeX() / 2 - AnimeSet.getWidth() / 2, (int) getY() + getSizeY() / 2 - AnimeSet.getHeight() / 2 + 3); dbg.setTransform(trans); DesenhaSeLayerDois(dbg, XMundo, YMundo); }
/** * Draw a string with given reference point and rotation angle. (0.5, 0.5) is center, (0, 0) is * lower left, (1, 0) is upper left, etc. The angle of rotation is in radians. The logical are * proportional to the base coordinates. */ public void drawTextBaseRatio( String label, double horizontalReference, double verticalReference, double rotation, double[] coord) { int[] sc = projection.screenProjectionBaseRatio(coord); int x = sc[0]; int y = sc[1]; AffineTransform transform = g2d.getTransform(); // Corner offset adjustment : Text Offset is used Here FontRenderContext frc = g2d.getFontRenderContext(); Font font = g2d.getFont(); double w = font.getStringBounds(label, frc).getWidth(); double h = font.getSize2D(); if (rotation != 0) { g2d.rotate(rotation, x, y); } x -= (int) (w * horizontalReference); y += (int) (h * verticalReference); g2d.drawString(label, x, y); g2d.setTransform(transform); }
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(); int pointSize = Math.max(Math.min(w, h) / 80, 4); double xInc = (double) (w - 2 * PAD) / (MAX_X - 1); double scale = (double) (h - 2 * PAD) / MAX_Y; // Draw abcissa. int tickInc = MAX_X / 10; for (int i = 0; i <= MAX_X; i += tickInc) { int x = PAD + (int) (i * xInc); int y = h - PAD; g.drawString(Integer.toString(i), x - 5, y + 20); g2.draw(new Line2D.Double(x, y - 5, x, y + 5)); } g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD / 2, h - PAD)); AffineTransform orig = g2.getTransform(); g2.rotate(-Math.PI / 2); g2.setColor(Color.black); g2.drawString("Number of comparisons", -((h + PAD) / 2), PAD / 3); g2.setTransform(orig); // Draw ordinate. tickInc = (h - PAD) / 10; for (int i = tickInc; i < h - PAD; i += tickInc) { int x = PAD; int closest_10 = ((int) (i / scale) / 10) * 10; int y = h - PAD - (int) (closest_10 * scale); if (y < PAD) break; String tickMark = Integer.toString(closest_10); int stringLen = (int) g2.getFontMetrics().getStringBounds(tickMark, g2).getWidth(); g.drawString(tickMark, x - stringLen - 8, y + 5); g2.draw(new Line2D.Double(x - 5, y, x + 5, y)); } g2.draw(new Line2D.Double(PAD, PAD / 2, PAD, h - PAD)); g.drawString("Array Size", (w - PAD) / 2, h - PAD + 40); for (int index = 0; index < plot_data.size(); index++) { int[] data = plot_data.get(index); // Mark data points. g2.setPaint(plot_colors.get(index)); for (int i = 0; i < data.length; i++) { double x = PAD + i * xInc; double y = h - PAD - scale * data[i]; g2.fill(new Ellipse2D.Double(x - pointSize / 2, y - pointSize / 2, pointSize, pointSize)); } g2.setFont(textFont); int stringHeight = (int) g2.getFontMetrics().getStringBounds(plot_names.get(index), g2).getHeight(); g.drawString(plot_names.get(index), PAD + 20, PAD + (index + 1) * stringHeight); } }
public void overlay(Graphics g) { if (!firstOverlayInvocation) { if (cachedBounds != null) { g.setColor(Color.black); Rectangle2D tmp = graph.toScreen((Rectangle2D) cachedBounds.clone()); g.drawRect( (int) tmp.getX(), (int) tmp.getY(), (int) tmp.getWidth() - 2, (int) tmp.getHeight() - 2); } else if (!initialBounds.equals(vertex.getBounds())) { Graphics2D g2 = (Graphics2D) g; AffineTransform oldTransform = g2.getTransform(); g2.scale(graph.getScale(), graph.getScale()); graph.getUI().paintCell(g, vertex, vertex.getBounds(), true); if (contextViews != null) { for (int i = 0; i < contextViews.length; i++) { graph.getUI().paintCell(g, contextViews[i], contextViews[i].getBounds(), true); } } if (!graph.isPortsScaled()) g2.setTransform(oldTransform); if (portViews != null && graph.isPortsVisible()) graph.getUI().paintPorts(g, portViews); g2.setTransform(oldTransform); } } firstOverlayInvocation = false; }
/** * Iterates through the Page's Boxes, drawing to the provided Graphics object * * @see java.awt.print.Printable#print(java.awt.Graphics, java.awt.print.PageFormat, int) */ public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException { if (pageIndex >= 1) { return Printable.NO_SUCH_PAGE; } Graphics2D graphics2d = (Graphics2D) graphics; AffineTransform at = graphics2d.getTransform(); double dpi = at.getScaleX() * 72; if (PrintingPlugin.isDebugging(TRACE_PRINTING)) { PrintingPlugin.log("Printing page " + pageIndex, null); // $NON-NLS-1$ System.out.println("PageFormat: " + pageFormat); // $NON-NLS-1$ System.out.println("PageFormat height: " + pageFormat.getHeight()); // $NON-NLS-1$ System.out.println("PageFormat width: " + pageFormat.getWidth()); // $NON-NLS-1$ System.out.println( "PageFormat imageableX,Y " + pageFormat.getImageableX() + ", " + pageFormat.getImageableY()); // $NON-NLS-1$ //$NON-NLS-2$ System.out.println( "PageFormat imageable height: " + pageFormat.getImageableHeight()); // $NON-NLS-1$ System.out.println( "PageFormat imageable width: " + pageFormat.getImageableWidth()); // $NON-NLS-1$ System.out.println( "PageFormat orientation (LANDSCAPE=" + PageFormat.LANDSCAPE + ", PORTRAIT=" + PageFormat.PORTRAIT + "): " + pageFormat.getOrientation()); // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ System.out.println("Graphics: clip bounds: " + graphics2d.getClipBounds()); // $NON-NLS-1$ System.out.println("Transform: scaleX: " + at.getScaleX()); // $NON-NLS-1$ System.out.println("Transform: scaleY: " + at.getScaleY()); // $NON-NLS-1$ System.out.println("DPI?? : " + dpi); // $NON-NLS-1$ } graphics2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); Iterator<Box> iter = diagram.getBoxes().iterator(); while (iter.hasNext()) { Box box = iter.next(); graphics2d = (Graphics2D) graphics.create( box.getLocation().x, box.getLocation().y, box.getSize().width, box.getSize().height); box.getBoxPrinter().draw(graphics2d, monitor); } return Printable.PAGE_EXISTS; }
public void drawRegion( Image img, int x_src, int y_src, int width, int height, int transform, int x_dst, int y_dst) { AffineTransform savedT = g2d.getTransform(); g2d.translate(x_dst, y_dst); transform(transform, width, height); g2d.drawImage(img, 0, 0, width, height, x_src, y_src, x_src + width, y_src + height, null); g2d.setTransform(savedT); }
public void paint(Graphics2D g2d) { AffineTransform old = g2d.getTransform(); g2d.rotate(this.getDirection().getRotation()); super.paint(g2d); g2d.setTransform(old); }
private void renderGraphicsStroke( Graphics2D graphics, double x, double y, Style2D style, double rotation, float opacity) { if (LOGGER.isLoggable(Level.FINEST)) { LOGGER.finest("drawing GraphicsStroke@" + x + "," + y); } graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, opacity)); if (style instanceof GraphicStyle2D) { BufferedImage image = ((GraphicStyle2D) style).getImage(); renderImage(graphics, x, y, image, rotation, opacity); } else if (style instanceof MarkStyle2D) { // almost like the code in the main paint method, but // here we don't use the mark composite MarkStyle2D ms2d = (MarkStyle2D) style; Shape transformedShape = ms2d.getTransformedShape((float) x, (float) y, (float) rotation); if (transformedShape != null) { if (ms2d.getFill() != null) { graphics.setPaint(ms2d.getFill()); graphics.fill(transformedShape); } if (ms2d.getContour() != null) { graphics.setPaint(ms2d.getContour()); graphics.setStroke(ms2d.getStroke()); graphics.draw(transformedShape); } } } else if (style instanceof IconStyle2D) { IconStyle2D icons = (IconStyle2D) style; Icon icon = icons.getIcon(); AffineTransform markAT = new AffineTransform(graphics.getTransform()); markAT.translate(x, y); markAT.rotate(rotation); markAT.translate(-icon.getIconWidth() / 2.0, -icon.getIconHeight() / 2.0); AffineTransform temp = graphics.getTransform(); try { graphics.setTransform(markAT); icon.paintIcon(null, graphics, 0, 0); } finally { graphics.setTransform(temp); } } }
public void pushMatrix() { if (transformCount == transformStack.length) { throw new RuntimeException( "pushMatrix() cannot use push more than " + transformStack.length + " times"); } transformStack[transformCount] = g2.getTransform(); transformCount++; }
protected void renderGraph(Graphics2D g2d) { if (renderContext.getGraphicsContext() == null) { renderContext.setGraphicsContext(new GraphicsDecorator(g2d)); } else { renderContext.getGraphicsContext().setDelegate(g2d); } renderContext.setScreenDevice(this); Layout<V, E> layout = model.getGraphLayout(); g2d.setRenderingHints(renderingHints); // the size of the VisualizationViewer Dimension d = getSize(); // clear the offscreen image g2d.setColor(getBackground()); g2d.fillRect(0, 0, d.width, d.height); AffineTransform oldXform = g2d.getTransform(); AffineTransform newXform = new AffineTransform(oldXform); // AffineTransform newXform = new AffineTransform(); newXform.concatenate( renderContext.getMultiLayerTransformer().getTransformer(Layer.VIEW).getTransform()); // viewTransformer.getTransform()); g2d.setTransform(newXform); // if there are preRenderers set, paint them for (Paintable paintable : preRenderers) { if (paintable.useTransform()) { paintable.paint(g2d); } else { g2d.setTransform(oldXform); paintable.paint(g2d); g2d.setTransform(newXform); } } if (layout instanceof Caching) { ((Caching) layout).clear(); } renderer.render(renderContext, layout); // if there are postRenderers set, do it for (Paintable paintable : postRenderers) { if (paintable.useTransform()) { paintable.paint(g2d); } else { g2d.setTransform(oldXform); paintable.paint(g2d); g2d.setTransform(newXform); } } g2d.setTransform(oldXform); }
public void draw(Graphics2D g) { update(); double rotationRequired = Math.toRadians(rotation); AffineTransform orig = g.getTransform(); g.translate(missilestartx, missilestarty); g.rotate(rotationRequired); g.drawImage(missile, 0, -1, 25, 2, null); g.setTransform(orig); }
public void initGraphic(final Graphics2D graphics) { this.graphics = graphics; this.renderingHints = graphics.getRenderingHints(); this.displayToDevice = (graphics != null) ? graphics.getTransform() : null; this.objectiveToDevice = (displayToDevice != null) ? new AffineTransform(displayToDevice) : new AffineTransform(); this.objectiveToDevice.concatenate(objectiveToDisplay); this.current = DISPLAY_TRS; }