public void centrage(Graphics g) { Graphics2D g2; g2 = (Graphics2D) g; int largeurAffichage = physics.getLignes() * pixel_size, hauteurAffichage = physics.getColonnes() * pixel_size; double diffX = this.getWidth() / (double) largeurAffichage, diffY = this.getHeight() / (double) hauteurAffichage; if (diffY > diffX) { g2.translate( 0, Math.max( hauteurAffichage * diffX - this.getHeight(), this.getHeight() - hauteurAffichage * diffX) / 2); g2.scale(diffX, diffX); // transform = (AffineTransform) g2.getTransform(); } else { g2.translate( Math.max( largeurAffichage * diffY - this.getWidth(), this.getWidth() - largeurAffichage * diffY) / 2, 0); g2.scale(diffY, diffY); // transform = (AffineTransform) g2.getTransform(); } }
@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); }
public void paintMiniature(Graphics2D g2d, Dimension miniatureSize, boolean mouseOver) { Image feedIcon = document.getIcon(); if (feedIcon != null) { int iconWidth = feedIcon.getWidth(this); int iconHeight = feedIcon.getHeight(this); double scale = (double) miniatureSize.width / (double) iconWidth; if (scale > 1) { scale = 1.0; } g2d.scale(scale, scale); int x = (miniatureSize.width - iconWidth) / 2; if (x < 0) { x = 0; } int y = (miniatureSize.height - iconHeight) / 2; if (y < 0) { y = 0; } g2d.setRenderingHint( RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g2d.drawImage(feedIcon, x, y, this); // reset scale g2d.scale(1 / scale, 1 / scale); } else { double scale = 0.8; g2d.scale(scale, scale); feedTable.paint(g2d); // reset scale g2d.scale(1 / scale, 1 / scale); } }
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); }
public void transform(int transform, int width, int height) { switch (transform) { case TRANS_ROT90: { g2d.translate(height, 0); g2d.rotate(ANGLE_90); break; } case TRANS_ROT180: { g2d.translate(width, height); g2d.rotate(Math.PI); break; } case TRANS_ROT270: { g2d.translate(0, width); g2d.rotate(ANGLE_270); break; } case TRANS_MIRROR: { g2d.translate(width, 0); g2d.scale(-1, 1); break; } case TRANS_MIRROR_ROT90: { g2d.translate(height, 0); g2d.rotate(ANGLE_90); g2d.translate(width, 0); g2d.scale(-1, 1); break; } case TRANS_MIRROR_ROT180: { g2d.translate(width, 0); g2d.scale(-1, 1); g2d.translate(width, height); g2d.rotate(Math.PI); break; } case TRANS_MIRROR_ROT270: { g2d.rotate(ANGLE_270); g2d.scale(-1, 1); break; } } }
@Override public int print(Graphics g, PageFormat pf, int page) throws PrinterException { if (page > 0) { /* We have only one page, and 'page' is zero-based */ return NO_SUCH_PAGE; } /* 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 */ Graphics2D g2d = (Graphics2D) g; Paper paper = new Paper(); paper.setImageableArea(0, 0, 560, 540); paper.setSize(560, 540); // PageFormat format = new PageFormat(); pf.setOrientation(PageFormat.LANDSCAPE); Dimension dimension = this.getSize(); double compWidth = dimension.width; double compHeight = dimension.height; double pageWidth = pf.getImageableWidth(); double pageHeight = pf.getImageableHeight(); double scaleWidth = pageWidth / compWidth; double scaleHeight = pageHeight / compHeight; pf.setPaper(paper); g2d.scale(scaleWidth, scaleHeight); g2d.translate(pf.getImageableX(), pf.getImageableY()); print(g2d); /* Now we perform our rendering */ /* tell the caller that this page is part of the printed document */ return PAGE_EXISTS; }
private boolean paintSimpleRobot(Dimension d, Graphics2D g2d) { if (null == jointvals || jointvals.length < SimulatedKinematicsSimple.NUM_JOINTS) { return true; } maxSimpleJv0 = Math.max(maxSimpleJv0, jointvals[0]); double sfactor = Math.min(d.width / 2.0, d.height / 2.0) / (Math.abs(maxSimpleJv0) + SimulatedKinematicsSimple.DEFAULT_SEGLENGTHS[0]); g2d.scale(sfactor, -1.0 * sfactor); g2d.setColor(Color.gray); g2d.fill(j1circle); l0rect.width = jointvals[0]; g2d.rotate(Math.toRadians(jointvals[2])); g2d.setColor(Color.yellow); g2d.fill(l0rect); g2d.translate(l0rect.width, 0.0); g2d.setColor(Color.gray); g2d.fill(j1circle); l1rect.width = Math.cos(Math.toRadians(jointvals[5] - jointvals[2])) * SimulatedKinematicsSimple.DEFAULT_SEGLENGTHS[0]; g2d.rotate(Math.toRadians(jointvals[4] - jointvals[2])); g2d.setColor(Color.yellow); g2d.fill(l1rect); return false; }
public static void doRendering(Graphics gee, JPanel p, Game game) { Graphics2D g = (Graphics2D) gee; g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int pwidth = p.getWidth(); int pheight = p.getHeight(); int width = RESOLUTION.width; int height = RESOLUTION.height; g.scale(pwidth / RESOLUTION.getWidth(), pheight / RESOLUTION.getHeight()); g.setColor(Color.black); g.fillRect(0, 0, RESOLUTION.width, RESOLUTION.height); if (gui != null) { // gui = new GameGuiStart(); gui.draw(g, width, height); } else { System.out.println("Warning, Game gui is null"); } g.setColor(new Color(0, 0, 0, 100)); g.fillRect(0, 0, 200, 20); g.setColor(new Color(255, 255, 255, 100)); fpsUpdateTimer--; if (fpsUpdateTimer <= 0) { fpsUpdateTimer = fpsUpdateTimerMax; fpsPercent = ((int) ((TickUtil.getFps() / 60) * 100)); fps = (int) (TickUtil.getFps()); } g.setFont(GameGuiStart.createCinderFont(0, 10)); g.drawString("Speed: " + fpsPercent + "% - FPS: " + fps, 1, 12); }
@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); }
/** {@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); }
/** * Override the pain method do draw the axis lines * * @param g The graphics to paint to */ public void paint(Graphics g) { Rectangle b = getBounds(); g.setColor(canvasBg); g.fillRect(0, 0, b.width, b.height); paintGrid(g); Point center = getCenter(); if (g instanceof Graphics2D) { ((Graphics2D) g).translate(center.x, center.y); } super.paint(g); if (g instanceof Graphics2D) { ((Graphics2D) g).scale(1.0, 1.0); } g.setColor(Color.gray); g.drawLine(0, -10 * b.height, 0, 10 * b.height); g.drawLine(-10 * b.width, 0, 10 * b.width, 0); MetSymbol tmp = highlightedMetSymbol; if (tmp != null) { Rectangle tb = tmp.getBounds(); g.setColor(Color.red); g.drawRect(tb.x - 2, tb.y - 2, tb.width + 4, tb.height + 4); } }
@Override public BufferedImage getView() { if (img == null) { return img; } Graphics2D gpcs = (Graphics2D) img.getGraphics(); gpcs.scale( windowSize.getWidth() / canvasSize.getWidth(), windowSize.getHeight() / canvasSize.getHeight()); gpcs.setColor(Color.WHITE); gpcs.fillRect(0, 0, (int) canvasSize.getWidth(), (int) canvasSize.getHeight()); for (Edge e : graph.edgeSet()) { if (e.isEnabled()) { gpcs.setColor(e.getStrokeColor()); gpcs.draw(e); } } for (Vertex v : graph.vertexSet()) { if (v.isEnabled()) { gpcs.setColor(v.getStrokeColor()); gpcs.draw(v); gpcs.setColor(v.getFillColor()); gpcs.fill(v); } } return img; }
@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 printImage(Graphics2D g2d, PageFormat pageFormat) { if (g2d == null) { return; } System.gc(); g2d.drawImage(ImageHelper.getRecordSheet(aero), 18, 18, 558, 738, Color.BLACK, null); printAeroImage(g2d, ImageHelper.getFluffImage(aero, ImageHelper.imageAero)); printAeroData(g2d); printArmor(g2d); printWeaponsNEquipment(g2d); printHeatSinks(g2d); // Armor Pips printFrontArmor(g2d, aero.getOArmor(Aero.LOC_NOSE)); printLeftArmor(g2d, aero.getOArmor(Aero.LOC_LWING)); printRightArmor(g2d, aero.getOArmor(Aero.LOC_RWING)); printRearArmor(g2d, aero.getOArmor(Aero.LOC_AFT)); // Internal Pips printStruct(g2d, aero.get0SI()); g2d.scale(pageFormat.getImageableWidth(), pageFormat.getImageableHeight()); }
public int print(Graphics g, PageFormat format, int page_index) throws PrinterException { if (page_index > 0) { return Printable.NO_SUCH_PAGE; } // get the bounds of the component Dimension dim = comp.getSize(); double cHeight = dim.getHeight(); double cWidth = dim.getWidth(); // get the bounds of the printable area double pHeight = format.getImageableHeight(); double pWidth = format.getImageableWidth(); double pXStart = format.getImageableX(); double pYStart = format.getImageableY(); double xRatio = pWidth / cWidth; double yRatio = pHeight / cHeight; Graphics2D g2 = (Graphics2D) g; g2.translate(pXStart, pYStart); g2.scale(xRatio, yRatio); comp.paint(g2); return Printable.PAGE_EXISTS; }
/** * Adds the componentType buttons to the Panel of Main Window. * * @param pkg_name whose componentType buttons will be added * @param a needed for the addition of the ActionListener of respective buttons and calling method * of Pad_Draw */ public void add_componentType_buttons(package_cls pkg_name, final counts a) { int i; JLabel pkg_hdng = new JLabel(pkg_name.getName()); panel.add(pkg_hdng); for (i = 0; i < pkg_name.getComponentType_list().size(); i++) { final componentType cmp_Types = pkg_name.getComponentType_list().get(i); int btnHeight, btnWidth; double scale = 0.5; btnWidth = (int) (scale * (double) cmp_Types.getWidth()); btnHeight = (int) (scale * (double) cmp_Types.getHeight()); ImageIcon myIcon = new ImageIcon(cmp_Types.getType_Img()); BufferedImage bi = new BufferedImage(btnWidth, btnHeight, BufferedImage.TYPE_INT_ARGB); Graphics2D g = bi.createGraphics(); g.scale(scale, scale); myIcon.paintIcon(null, g, 0, 0); g.dispose(); JButton strctButton = new JButton(new ImageIcon(bi)); strctButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { drawPad.add_componentType(cmp_Types, a); taskbar.setText("Click to add a component"); } }); panel.add(strctButton); } panel.validate(); // Updates the Panel }
public void printImage(Graphics2D g2d, PageFormat pageFormat) { if (g2d == null) { return; } System.gc(); // g2d.drawImage(ImageHelper.getRecordSheet(smallCraft), 18, 18, 558, // 738, Color.BLACK, null); try { ImageHelper.loadSVGImage(new File("data/images/recordsheets/SpheroidSmallScraftTemplate.svg")) .render(g2d); } catch (SVGException e) { e.printStackTrace(); } g2d.setColor(Color.BLACK); printSmallCraftSpheroidImage(g2d, ImageHelper.getFluffImage(smallCraft, ImageHelper.imageAero)); printSmallCraftSpheroidData(g2d); printArmor(g2d); printWeaponsNEquipment(g2d); printHeatSinks(g2d); // Armor Pips printFrontArmor(g2d, smallCraft.getOArmor(Aero.LOC_NOSE)); printLeftArmor(g2d, smallCraft.getOArmor(Aero.LOC_LWING)); printRightArmor(g2d, smallCraft.getOArmor(Aero.LOC_RWING)); printRearArmor(g2d, smallCraft.getOArmor(Aero.LOC_AFT)); // Internal Pips printStruct(g2d, smallCraft.get0SI()); g2d.scale(pageFormat.getImageableWidth(), pageFormat.getImageableHeight()); }
/** * Gets (creates if necessary) disabled icon based on the passed one. * * @return <code>ImageIcon</code> constructed from disabled image of passed icon. */ @Nullable public static Icon getDisabledIcon(Icon icon) { if (icon instanceof LazyIcon) icon = ((LazyIcon) icon).getOrComputeIcon(); if (icon == null) return null; Icon disabledIcon = ourIcon2DisabledIcon.get(icon); if (disabledIcon == null) { if (!isGoodSize(icon)) { LOG.error(icon); // # 22481 return EMPTY_ICON; } final int scale = UIUtil.isRetina() ? 2 : 1; @SuppressWarnings("UndesirableClassUsage") BufferedImage image = new BufferedImage( scale * icon.getIconWidth(), scale * icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); final Graphics2D graphics = image.createGraphics(); graphics.setColor(UIUtil.TRANSPARENT_COLOR); graphics.fillRect(0, 0, icon.getIconWidth(), icon.getIconHeight()); graphics.scale(scale, scale); icon.paintIcon(LabelHolder.ourFakeComponent, graphics, 0, 0); graphics.dispose(); Image img = ImageUtil.filter(image, UIUtil.getGrayFilter()); if (UIUtil.isRetina()) img = RetinaImage.createFrom(img, 2, ImageLoader.ourComponent); disabledIcon = new JBImageIcon(img); ourIcon2DisabledIcon.put(icon, disabledIcon); } return disabledIcon; }
/* (non-Javadoc) * @see org.jdesktop.swingx.painter.Painter#paint(java.awt.Graphics2D, java.lang.Object, int, int) */ @Override public void paint(Graphics2D g, JXPanel c, int width, int height) { Color c1 = getActiveColor(); Graphics2D g2 = (Graphics2D) g.create(); RoundRectangle2D rect = new RoundRectangle2D.Double(0, 0, 10, 10, 0, 0); g2.setColor(new Color(0, 0, 0, 0)); g2.fill(rect); g2.setColor(c1); // g2.scale(CONV_MILIMETER_2_PIXELS, CONV_MILIMETER_2_PIXELS); g2.scale(width / 10, height / 10); // g.translate(width/2, height/2); g2.setStroke(new BasicStroke(0.3f)); GeneralPath sp = new GeneralPath(); sp.moveTo(0, 4); sp.lineTo(4, 4); sp.lineTo(4, 0); sp.moveTo(0, 6); sp.lineTo(4, 6); sp.lineTo(4, 10); sp.moveTo(6, 0); sp.lineTo(6, 4); sp.lineTo(10, 4); sp.moveTo(6, 10); sp.lineTo(6, 6); sp.lineTo(10, 6); g2.draw(sp); // NeptusLog.pub().info("<###> .... "+width+" by "+height); }
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(); }
public void paint(java.awt.Graphics g) { int w = m_bi.getWidth(this); int h = m_bi.getHeight(this); // int ww= (int)(w*(percentSize/100)); // int hh=(int)(h*(percentSize/100)); g.setColor(java.awt.Color.white); g.fillRect(0, 0, this.getWidth(), this.getHeight()); java.awt.Graphics2D g2d = (java.awt.Graphics2D) g; g2d.scale(percentSize / 100.0, percentSize / 100.0); int ml = (this.getWidth() / 2) - (w / 2); int mh = (this.getHeight() / 2) - (h / 2); if (m_bi != null) { g2d.drawImage(m_bi, ml, mh, this); } }
/* * Draws gnomon with base at bottom. Again, coordinate system is translated to commonly used coordinate system. */ public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D img = (Graphics2D) g; img.translate(0, this.getHeight()); img.drawString("Gnomon angle", 20, -5); img.scale(1.0, -1.0); double x, y; // baseLine is the bottom, hLine is the height of the gnomon, angleLine is the style (diagonal // portion) Line2D baseLine, hLine, angleLine; if (gnomonAngle < Math.atan( this.getHeight() / (this.getWidth() / 2))) { // style will extend to center of image y = Math.tan(gnomonAngle) * (this.getWidth() / 2); baseLine = new Line2D.Double(0, 0, this.getWidth() / 2, 0); hLine = new Line2D.Double(this.getWidth() / 2, 0, this.getWidth() / 2, y); angleLine = new Line2D.Double(0, 0, this.getWidth() / 2, y); } else { // style needs to be closer to maintain the angle x = this.getHeight() / Math.tan(gnomonAngle); baseLine = new Line2D.Double(0, 0, x, 0); hLine = new Line2D.Double(x, 0, x, this.getHeight()); angleLine = new Line2D.Double(0, 0, x, this.getHeight()); } img.draw(baseLine); img.draw(hLine); img.draw(angleLine); }
/** Creates a graphic instance for rendering an image. */ protected final Graphics2D createImageGraphics( double x, double y, double w, double h, boolean flipH, boolean flipV) { Graphics2D g2 = state.g; if (flipH || flipV) { g2 = (Graphics2D) g2.create(); if (flipV && flipH) { g2.rotate(Math.toRadians(180), x + w / 2, y + h / 2); } else { int sx = 1; int sy = 1; int dx = 0; int dy = 0; if (flipH) { sx = -1; dx = (int) (-w - 2 * x); } if (flipV) { sy = -1; dy = (int) (-h - 2 * y); } g2.scale(sx, sy); g2.translate(dx, dy); } } return g2; }
/** paints the DrawComponent into the Graphics of the BufferedImage */ protected void paintDrawComponent() { long startTime = 0; if (debugPaint) startTime = System.currentTimeMillis(); if (bufferedImage != null) { Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics(); g2d.setRenderingHints(renderingHintsManager.getRenderingHints()); g2d.setBackground(bgColor); g2d.setPaint(bgColor); g2d.translate(-bufferBounds.x, -bufferBounds.y); g2d.setClip(bufferBounds); g2d.fillRect(bufferBounds.x, bufferBounds.y, bufferBounds.width, bufferBounds.height); if (debugPaint) { drawRealRectangle(g2d); drawBufferRectangle(g2d); drawViewRectangle(g2d); } g2d.scale(scale, scale); DrawComponentPaintable.paintDrawComponent(dc, g2d); } if (debugPaint) { long endTime = System.currentTimeMillis() - startTime; logger.debug("paintDrawComponent took " + endTime + " ms!"); // $NON-NLS-1$ //$NON-NLS-2$ } }
public static void main(String[] args) throws Exception { BufferedImage image = new BufferedImage(200, 200, BufferedImage.TYPE_INT_RGB); Graphics2D g = image.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setPaint(Color.WHITE); g.fill(new Rectangle(image.getWidth(), image.getHeight())); g.scale(.9, .9); g.setPaint(Color.BLACK); g.setStroke(new BasicStroke(0.5f)); g.draw(new Ellipse2D.Double(25, 25, 150, 150)); // To visually check it // ImageIO.write(image, "PNG", new File(args[0])); boolean nonWhitePixelFound = false; for (int x = 100; x < 200; ++x) { if (image.getRGB(x, 90) != Color.WHITE.getRGB()) { nonWhitePixelFound = true; break; } } if (!nonWhitePixelFound) { throw new RuntimeException("A circle is rendered like a 'C' shape."); } }
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; }
/** * 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; }
// renders a page to the given graphics private void renderPage( PDPage page, Graphics2D graphics, int width, int height, float scaleX, float scaleY) throws IOException { graphics.clearRect(0, 0, width, height); graphics.scale(scaleX, scaleY); // TODO should we be passing the scale to PageDrawer rather than messing with Graphics? PDRectangle cropBox = page.getCropBox(); int rotationAngle = page.getRotation(); if (rotationAngle != 0) { float translateX = 0; float translateY = 0; switch (rotationAngle) { case 90: translateX = cropBox.getHeight(); break; case 270: translateY = cropBox.getWidth(); break; case 180: translateX = cropBox.getWidth(); translateY = cropBox.getHeight(); break; } graphics.translate(translateX, translateY); graphics.rotate((float) Math.toRadians(rotationAngle)); } // the end-user may provide a custom PageDrawer PageDrawerParameters parameters = new PageDrawerParameters(this, page); PageDrawer drawer = createPageDrawer(parameters); drawer.drawPage(graphics, cropBox); }