public void drawCircle(int xpos, int ypos, double rot, double xscale, double yscale, int width) { g.translate(xpos, ypos); g.rotate(rot * Math.PI / 180.0); g.scale(xscale, yscale); g.fillOval(-width / 2, -width / 2, width, width); g.scale(1.0 / xscale, 1.0 / yscale); g.rotate(-rot * Math.PI / 180.0); g.translate(-xpos, -ypos); }
public void drawStar(int xpos, int ypos, double rot, double xscale, double yscale) { g.translate(xpos, ypos); g.rotate(rot * Math.PI / 180.0); g.scale(xscale, yscale); g.fillOval(-10, -10, 20, 20); g.scale(1.0 / xscale, 1.0 / yscale); g.rotate(-rot * Math.PI / 180.0); g.translate(-xpos, -ypos); }
public void drawRocket( Image image, int xpos, int ypos, double rot, double xscale, double yscale) { int width = rocketImage.getWidth(this); int height = rocketImage.getHeight(this); g.translate(xpos, ypos); g.rotate(rot * Math.PI / 180.0); g.scale(xscale, yscale); g.drawImage(image, -width / 2, -height / 2, width, height, this); g.scale(1.0 / xscale, 1.0 / yscale); g.rotate(-rot * Math.PI / 180.0); g.translate(-xpos, -ypos); }
protected void drawString(Graphics2D g2, double x, double y, double theta) { // Transform to the requested location. g2.translate(x, y); // Rotate by the requested angle. g2.rotate(theta); // Draw the first part of the string. String first = mMessage.substring(0, mSplit); float width = drawBoxedString(g2, first, Color.white, Color.red, 0); // Draw the second part of the string. String second = mMessage.substring(mSplit); drawBoxedString(g2, second, Color.blue, Color.white, width); // Undo the transformations. g2.rotate(-theta); g2.translate(-x, -y); }
public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D) g; if (!text.equals("")) { g2.translate(0, getSize().getHeight()); g2.rotate(-Math.PI / 2); g2.setColor(Color.black); g2.drawString(text, 20, 14); g2.translate(0, -getSize().getHeight()); g2.transform(AffineTransform.getQuadrantRotateInstance(1)); } }
public void paint(Graphics g) { gRef = (Graphics2D) g; // change size of font gRef.setFont(gRef.getFont().deriveFont(9.0f)); fmRef = g.getFontMetrics(); // Clear background if (Preferences.monochrome) { gRef.setColor(Preferences.whiteColor); } else { gRef.setColor(Preferences.backgroundColor); } gRef.fillRect(0, 0, getWidth(), getHeight()); // set colour to correct drawing colour if (Preferences.monochrome) { gRef.setColor(Preferences.blackColor); } else { gRef.setColor(Preferences.penColor); } gRef.translate(0, margin); // Call c code to draw tree gRef.scale(scale, scale); nativeDrawTree(); }
@Override public int print(Graphics g, PageFormat pf, int page) throws PrinterException { if (page > 0) { return NO_SUCH_PAGE; } int i = pf.getOrientation(); // get the size of the page double pageWidth = pf.getImageableWidth(); double pageHeight = pf.getImageableHeight(); double myWidth = this.getWidth(); // - borderWidth * 2; double myHeight = this.getHeight(); // - borderWidth * 2; double scaleX = pageWidth / myWidth; double scaleY = pageHeight / myHeight; double minScale = Math.min(scaleX, scaleY); Graphics2D g2d = (Graphics2D) g; g2d.translate(pf.getImageableX(), pf.getImageableY()); g2d.scale(minScale, minScale); drawPlot(g); return PAGE_EXISTS; }
public void paint(Graphics g) { if (loadflag && (!runflag)) { g.clearRect(0, 0, 530, 330); Graphics2D g2D = (Graphics2D) g; g2D.translate(0, 50); // 设置图像左上角为当前点 g.drawImage(iImage, 0, 0, null); // 画输入图 } }
public int print(Graphics g,PageFormat pf,int pageIndex) { if (pageIndex == 0) { Graphics2D g2d= (Graphics2D)g; g2d.translate(pf.getImageableX(), pf.getImageableY()); g2d.setColor(Color.black); g2d.drawString("example string", 250, 250); g2d.fillRect(0, 0, 200, 200); return Printable.PAGE_EXISTS; } else { return Printable.NO_SUCH_PAGE; } }
public void draw(Graphics2D g) { if (AttributeKeys.FILL_COLOR.get(this) != null) { g.setColor(AttributeKeys.FILL_COLOR.get(this)); drawFill(g); } if (STROKE_COLOR.get(this) != null && STROKE_WIDTH.get(this) > 0d) { g.setStroke(AttributeKeys.getStroke(this)); g.setColor(STROKE_COLOR.get(this)); drawStroke(g); } if (TEXT_COLOR.get(this) != null) { if (TEXT_SHADOW_COLOR.get(this) != null && TEXT_SHADOW_OFFSET.get(this) != null) { Dimension2DDouble d = TEXT_SHADOW_OFFSET.get(this); g.translate(d.width, d.height); g.setColor(TEXT_SHADOW_COLOR.get(this)); drawText(g); g.translate(-d.width, -d.height); } g.setColor(TEXT_COLOR.get(this)); drawText(g); } }
/** [Internal] */ public int print(Graphics g, PageFormat pf, int pi) throws PrinterException { if (pi >= 1) { return Printable.NO_SUCH_PAGE; } RepaintManager currentManager = RepaintManager.currentManager(this); currentManager.setDoubleBufferingEnabled(false); Graphics2D g2 = (Graphics2D) g; initState(g2, true); g2.translate((int) (pf.getImageableX() + 1), (int) (pf.getImageableY() + 1)); g2.scale(printScale, printScale); doBuffer(g2, true, null); currentManager.setDoubleBufferingEnabled(true); return Printable.PAGE_EXISTS; }
@Override public void paintIcon(Component c, Graphics g, int x, int y) { Graphics2D g2 = (Graphics2D) g.create(); g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.translate(x, y); g2.setStroke(new BasicStroke(BORDER_WIDTH)); g2.setPaint(LINE_COLOR); g2.draw(BORDER); g2.setStroke(new BasicStroke(SLIT_WIDTH)); g2.setColor(UIManager.getColor("Panel.background")); int n = SLIT_NUM + 1; int v = ICON_SIZE / n; int m = n * v; for (int i = 1; i < n; i++) { int a = i * v; g2.drawLine(a, 0, a, m); g2.drawLine(0, a, m, a); } // g2.drawLine(1 * v, 0 * v, 1 * v, 4 * v); // g2.drawLine(2 * v, 0 * v, 2 * v, 4 * v); // g2.drawLine(3 * v, 0 * v, 3 * v, 4 * v); // g2.drawLine(0 * v, 1 * v, 4 * v, 1 * v); // g2.drawLine(0 * v, 2 * v, 4 * v, 2 * v); // g2.drawLine(0 * v, 3 * v, 4 * v, 3 * v); g2.setPaint(LINE_COLOR); Rectangle2D b = ARROW.getBounds(); Point2D p = new Point2D.Double(b.getX() + b.getWidth() / 2d, b.getY() + b.getHeight() / 2d); AffineTransform toCenterAT = AffineTransform.getTranslateInstance(ICON_SIZE / 2d - p.getX(), ICON_SIZE / 2d - p.getY()); g2.fill(toCenterAT.createTransformedShape(ARROW)); g2.dispose(); }
public BufferedImage composeImageForSector( Sector sector, int imageWidth, int imageHeight, int levelNumber, String mimeType, boolean abortOnError, BufferedImage image) { if (sector == null) { String message = Logging.getMessage("nullValue.SectorIsNull"); Logging.logger().severe(message); throw new IllegalStateException(message); } if (levelNumber < 0) { levelNumber = this.levels.getLastLevel().getLevelNumber(); } else if (levelNumber > this.levels.getLastLevel().getLevelNumber()) { Logging.logger() .warning( Logging.getMessage( "generic.LevelRequestedGreaterThanMaxLevel", levelNumber, this.levels.getLastLevel().getLevelNumber())); levelNumber = this.levels.getLastLevel().getLevelNumber(); } MercatorTextureTile[][] tiles = this.getTilesInSector(sector, levelNumber); if (tiles.length == 0 || tiles[0].length == 0) { Logging.logger().severe(Logging.getMessage("layers.TiledImageLayer.NoImagesAvailable")); return null; } if (image == null) image = new BufferedImage(imageWidth, imageHeight, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); for (MercatorTextureTile[] row : tiles) { for (MercatorTextureTile tile : row) { if (tile == null) continue; BufferedImage tileImage; try { tileImage = this.getImage(tile, mimeType); double sh = ((double) imageHeight / (double) tileImage.getHeight()) * (tile.getSector().getDeltaLat().divide(sector.getDeltaLat())); double sw = ((double) imageWidth / (double) tileImage.getWidth()) * (tile.getSector().getDeltaLon().divide(sector.getDeltaLon())); double dh = imageHeight * (-tile.getSector().getMaxLatitude().subtract(sector.getMaxLatitude()).degrees / sector.getDeltaLat().degrees); double dw = imageWidth * (tile.getSector().getMinLongitude().subtract(sector.getMinLongitude()).degrees / sector.getDeltaLon().degrees); AffineTransform txf = g.getTransform(); g.translate(dw, dh); g.scale(sw, sh); g.drawImage(tileImage, 0, 0, null); g.setTransform(txf); } catch (Exception e) { if (abortOnError) throw new RuntimeException(e); String message = Logging.getMessage("generic.ExceptionWhileRequestingImage", tile.getPath()); Logging.logger().log(java.util.logging.Level.WARNING, message, e); } } } return image; }
/** * The printing interface. * * @param g the graphic context. * @param pf the page format. * @param page the page number. * @return PAGE_EXISTS if the page has to be printed. * @throws PrinterException if a printing error occurs. */ public int print(Graphics g, PageFormat pf, int page) throws PrinterException { int npages = 0; // This might be explained as follows: // 1 - The Java printing system normally works with an internal // resolution which is 72 dpi (probably inspired by Postscript). // 2 - To have a sufficient resolution, this is increased by 16 times, // by using the scale method of the graphic object associated to the // printer. This gives a 72 dpi * 16=1152 dpi resolution. // 3 - The 0.127 mm pitch used in FidoCadJ corresponds to a 200 dpi // resolution. Calculating 1152 dpi / 200 dpi gives the 5.76 constant double xscale = 1.0 / 16; // Set 1152 logical units for an inch double yscale = 1.0 / 16; // as the standard resolution is 72 double zoom = 5.76; // act in a 1152 dpi resolution as 1:1 Graphics2D g2d = (Graphics2D) g; // User (0,0) is typically outside the imageable area, so we must // translate by the X and Y values in the PageFormat to avoid clipping if (printMirror) { g2d.translate(pf.getImageableX() + pf.getImageableWidth(), pf.getImageableY()); g2d.scale(-xscale, yscale); } else { g2d.translate(pf.getImageableX(), pf.getImageableY()); g2d.scale(xscale, yscale); } int printerWidth = (int) pf.getImageableWidth() * 16; // Perform an adjustement if we need to fit the drawing to the page. if (printFitToPage) { MapCoordinates zoomm = DrawingSize.calculateZoomToFit( cc.dmp, (int) pf.getImageableWidth() * 16, (int) pf.getImageableHeight() * 16, false); zoom = zoomm.getXMagnitude(); } MapCoordinates m = new MapCoordinates(); m.setMagnitudes(zoom, zoom); PointG o = new PointG(0, 0); int imageWidth = DrawingSize.getImageSize(cc.dmp, zoom, false, o).width; npages = (int) Math.floor((imageWidth - 1) / (double) printerWidth); // Check if we need more than one page if (printerWidth < imageWidth) { g2d.translate(-(printerWidth * page), 0); } // Check if printing is finished. if (page > npages) { return NO_SUCH_PAGE; } // Now we perform our rendering cc.drawingAgent.draw(new Graphics2DSwing(g2d), m); /* tell the caller that this page is part of the printed document */ return PAGE_EXISTS; }
// also clip, transform, composite, // public boolean isOpaque(){return false;}//theOpaque!=null&&theOpaque;} // --------------------------------------------------------- private void doPaint(Graphics2D g, int s, Object o) { // process an operation from the buffer // System.out.println(s); Object o1 = null, o2 = null, o3 = null, o4 = null, o5 = null, o6 = null, o7 = null, o8 = null, o9 = null, o10 = null, o11 = null; if (o instanceof Object[]) { Object[] a = (Object[]) o; if (a.length > 0) o1 = a[0]; if (a.length > 1) o2 = a[1]; if (a.length > 2) o3 = a[2]; if (a.length > 3) o4 = a[3]; if (a.length > 4) o5 = a[4]; if (a.length > 5) o6 = a[5]; if (a.length > 6) o7 = a[6]; if (a.length > 7) o8 = a[7]; if (a.length > 8) o9 = a[8]; if (a.length > 9) o10 = a[9]; if (a.length > 10) o11 = a[10]; } switch (s) { case clear: paintBackground(g, theBackground); break; // public void addRenderingHints(Map<?,?> hints) // {toBuffer("addRenderingHints",hints );} case addRenderingHints: g.addRenderingHints((Map<?, ?>) o); break; case clip1: g.clip((Shape) o); break; case draw1: g.draw((Shape) o); break; case draw3DRect: g.draw3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5); break; case drawGlyphVector: g.drawGlyphVector((GlyphVector) o1, (Float) o2, (Float) o3); break; case drawImage1: g.drawImage((BufferedImage) o1, (BufferedImageOp) o2, (Integer) o3, (Integer) o4); break; case drawImage2: g.drawImage((Image) o1, (AffineTransform) o2, (ImageObserver) o3); break; case drawRenderableImage: g.drawRenderableImage((RenderableImage) o1, (AffineTransform) o2); break; case drawRenderedImage: g.drawRenderedImage((RenderedImage) o1, (AffineTransform) o2); break; case drawString1: g.drawString((AttributedCharacterIterator) o1, (Float) o2, (Float) o3); break; case drawString2: g.drawString((AttributedCharacterIterator) o1, (Integer) o2, (Integer) o3); break; case drawString3: g.drawString((String) o1, (Float) o2, (Float) o3); break; case drawString4: g.drawString((String) o1, (Integer) o2, (Integer) o3); break; case fill: g.fill((Shape) o); break; case fill3DRect: g.fill3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5); break; case rotate1: g.rotate((Double) o); break; case rotate2: g.rotate((Double) o1, (Double) o2, (Double) o3); break; case scale1: g.scale((Double) o1, (Double) o2); break; case setBackground: g.setBackground( (Color) o); // paintBackground(g,(Color)o); /*super.setBackground((Color)o) ;*/ break; case setComposite: g.setComposite((Composite) o); break; case setPaint: g.setPaint((Paint) o); break; case setRenderingHint: g.setRenderingHint((RenderingHints.Key) o1, o2); break; case setRenderingHints: g.setRenderingHints((Map<?, ?>) o); break; case setStroke: g.setStroke((Stroke) o); break; case setTransform: g.setTransform(makeTransform(o)); break; case shear: g.shear((Double) o1, (Double) o2); break; case transform1: g.transform(makeTransform(o)); break; case translate1: g.translate((Double) o1, (Double) o2); break; case translate2: g.translate((Integer) o1, (Integer) o2); break; case clearRect: g.clearRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case copyArea: g.copyArea( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case drawArc: g.drawArc( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case drawBytes: g.drawBytes((byte[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5); break; case drawChars: g.drawChars((char[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5); break; case drawImage4: g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (Color) o4, (ImageObserver) o5); break; case drawImage5: g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (ImageObserver) o4); break; case drawImage6: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Color) o6, (ImageObserver) o7); break; case drawImage7: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (ImageObserver) o6); break; case drawImage8: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6, (Integer) o7, (Integer) o8, (Integer) o9, (Color) o10, (ImageObserver) o11); break; case drawImage9: g.drawImage( (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6, (Integer) o7, (Integer) o8, (Integer) o9, (ImageObserver) o10); break; case drawLine: g.drawLine((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case drawOval: g.drawOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case drawPolygon1: g.drawPolygon((int[]) o1, (int[]) o2, (Integer) o3); break; case drawPolygon2: g.drawPolygon((Polygon) o); break; case drawPolyline: g.drawPolyline((int[]) o1, (int[]) o2, (Integer) o3); break; case drawRect: g.drawRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case drawRoundRect: g.drawRoundRect( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case fillArc: g.fillArc( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case fillOval: g.fillOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; // {toBuffer("fillPolygon",mkArg(xPoints, yPoints, nPoints) );} case fillPolygon1: g.fillPolygon((int[]) o1, (int[]) o2, (Integer) o3); break; case fillPolygon2: g.fillPolygon((Polygon) o); break; case fillRect: g.fillRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4); break; case fillRoundRect: g.fillRoundRect( (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6); break; case setClip1: g.setClip((Shape) o); break; case setColor: g.setColor((Color) o); break; case setFont: g.setFont((Font) o); break; case setPaintMode: g.setPaintMode(); break; case setXORMode: g.setXORMode((Color) o); break; case opaque: super.setOpaque((Boolean) o); break; case drawOutline: // g.drawString((String)o1, (Integer)o2, (Integer)o3) ;break; { FontRenderContext frc = g.getFontRenderContext(); TextLayout tl = new TextLayout((String) o1, g.getFont(), frc); Shape s1 = tl.getOutline(null); AffineTransform af = g.getTransform(); g.translate((Integer) o2, (Integer) o3); g.draw(s1); g.setTransform(af); } ; break; default: System.out.println("Unknown image operation " + s); } }