List of usage examples for java.awt Graphics2D translate
public abstract void translate(double tx, double ty);
From source file:org.dishevelled.piccolo.sprite.statemachine.AbstractStateMachineSprite.java
@Override public final void paint(final PPaintContext paintContext) { if (currentAnimation != null) { Graphics2D g = paintContext.getGraphics(); Image currentFrame = currentAnimation.getCurrentFrame(); PBounds bounds = getBoundsReference(); double w = currentFrame.getWidth(null); double h = currentFrame.getHeight(null); g.translate(bounds.getX(), bounds.getY()); g.scale(bounds.getWidth() / w, bounds.getHeight() / h); g.drawImage(currentFrame, 0, 0, null); g.scale(w / bounds.getWidth(), h / bounds.getHeight()); g.translate(-1 * bounds.getX(), -1 * bounds.getY()); }// ww w.jav a 2s.c o m }
From source file:CustomStrokes.java
/** Draw the example */ public void paint(Graphics g1) { Graphics2D g = (Graphics2D) g1; // Get a shape to work with. Here we'll use the letter B Font f = new Font("Serif", Font.BOLD, 200); GlyphVector gv = f.createGlyphVector(g.getFontRenderContext(), "B"); Shape shape = gv.getOutline(); // Set drawing attributes and starting position g.setColor(Color.black);//www . j av a2 s. c o m g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.translate(10, 175); // Draw the shape once with each stroke for (int i = 0; i < strokes.length; i++) { g.setStroke(strokes[i]); // set the stroke g.draw(shape); // draw the shape g.translate(140, 0); // move to the right } }
From source file:org.pentaho.reporting.libraries.pixie.wmf.WmfFile.java
public synchronized void draw(final Graphics2D graphics, final Rectangle2D bounds) { // this adjusts imageWidth and imageHeight scaleToFit((float) bounds.getWidth(), (float) bounds.getHeight()); // adjust translation if needed ... graphics.translate(bounds.getX(), bounds.getY()); // adjust to the image origin graphics.translate(-imageX, -imageY); this.graphics = graphics; for (int i = 0; i < records.size(); i++) { try {/*from w w w .j av a 2s . c o m*/ final MfCmd command = (MfCmd) records.get(i); command.setScale((float) imageWidth / (float) maxWidth, (float) imageHeight / (float) maxHeight); command.replay(this); } catch (Exception e) { logger.warn("Error while processing image record #" + i, e); } } resetStates(); }
From source file:gui.GraphsPanel.java
/** open PrinterDialog(). * //from www . ja va 2 s.co m */ public void print() { class VVP implements Printable { VisualizationViewer<TreeNode, TreeNode> vv; public VVP(VisualizationViewer<TreeNode, TreeNode> vv) { this.vv = vv; } public int print(Graphics g, PageFormat pf, int pageIndex) { if (pageIndex > 0) { return Printable.NO_SUCH_PAGE; } else { Graphics2D g2d = (Graphics2D) g; vv.setDoubleBuffered(false); g2d.translate(pf.getImageableX(), pf.getImageableX()); vv.paint(g2d); vv.setDoubleBuffered(true); return (Printable.PAGE_EXISTS); } } } Printable[] toPrint = { new VVP(vv) }; new PrinterDialog(toPrint); }
From source file:Main.java
@Override public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { Graphics2D g2 = (Graphics2D) g; int bottomLineY = height - thickness - shadowPad; RoundRectangle2D.Double bubble = new RoundRectangle2D.Double(0 + strokePad, 0 + strokePad, width - thickness - shadowPad, bottomLineY, radius, radius); Area area = new Area(bubble); g2.setRenderingHints(hints);//from w w w .ja v a 2 s . c o m g2.setColor(color); g2.setStroke(stroke); g2.draw(area); Area shadowArea = new Area(new Rectangle(0, 0, width, height)); shadowArea.subtract(area); g.setClip(shadowArea); Color shadow = new Color(color.getRed(), color.getGreen(), color.getBlue(), 128); g2.setColor(shadow); g2.translate(shadowPad, shadowPad); g2.draw(area); }
From source file:ImageOps.java
/** Draw the example */ public void paint(Graphics g1) { Graphics2D g = (Graphics2D) g1; // Create a BufferedImage big enough to hold the Image loaded // in the constructor. Then copy that image into the new // BufferedImage object so that we can process it. BufferedImage bimage = new BufferedImage(image.getWidth(this), image.getHeight(this), BufferedImage.TYPE_INT_RGB); Graphics2D ig = bimage.createGraphics(); ig.drawImage(image, 0, 0, this); // copy the image // Set some default graphics attributes g.setFont(new Font("SansSerif", Font.BOLD, 12)); // 12pt bold text g.setColor(Color.green); // Draw in green g.translate(10, 10); // Set some margins // Loop through the filters for (int i = 0; i < filters.length; i++) { // If the filter is null, draw the original image, otherwise, // draw the image as processed by the filter if (filters[i] == null) g.drawImage(bimage, 0, 0, this); else/*from w w w . j av a 2s . c om*/ g.drawImage(filters[i].filter(bimage, null), 0, 0, this); g.drawString(filterNames[i], 0, 205); // Label the image g.translate(137, 0); // Move over if (i % 4 == 3) g.translate(-137 * 4, 215); // Move down after 4 } }
From source file:no.met.jtimeseries.chart.XYWindArrowRenderer.java
/** * Draws the visual representation of a single wind arrow. *///from ww w . j a v a2 s .c om @Override public void drawItem(Graphics2D g2d, XYItemRendererState state, Rectangle2D plotArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) { resizeArrowByPlotHeight((int) plotArea.getHeight()); // Needs a new graphics object to use translate() and rotate() Graphics2D g2 = (Graphics2D) g2d.create(); g2.setRenderingHints(renderHints); RectangleEdge domainAxisLocation = plot.getDomainAxisEdge(); double middleY = plotArea.getCenterY(); WindDataset windData = (WindDataset) dataset; Number x = windData.getX(series, item); Number windDir = windData.getWindDirection(series, item); Number wforce = windData.getWindForce(series, item); double middleX = domainAxis.valueToJava2D(x.doubleValue(), plotArea, domainAxisLocation); g2.translate((int) middleX, (int) middleY); g2.setColor(Color.BLACK); if (wforce.doubleValue() <= zeroWindLimit) { drawCircle(g2); } else { g2.rotate(Math.toRadians(windDir.doubleValue() - 180)); drawArrow(g2, wforce.doubleValue()); if (useArrowHead) { g2.fill(getPolygonHead(arrowHeadSize, arrowHeight)); } else { g2.draw(getCircleHead(arrowHeadSize, arrowHeight)); } } }
From source file:org.apache.fop.render.pcl.PCLPainter.java
private void drawTextAsBitmap(final int x, final int y, final int letterSpacing, final int wordSpacing, final int[] dx, final String text, FontTriplet triplet) throws IFException { //Use Java2D to paint different fonts via bitmap final Font font = parent.getFontInfo().getFontInstance(triplet, state.getFontSize()); //for cursive fonts, so the text isn't clipped final FontMetricsMapper mapper = (FontMetricsMapper) parent.getFontInfo().getMetricsFor(font.getFontName()); final int maxAscent = mapper.getMaxAscent(font.getFontSize()) / 1000; final int ascent = mapper.getAscender(font.getFontSize()) / 1000; final int descent = mapper.getDescender(font.getFontSize()) / 1000; int safetyMargin = (int) (SAFETY_MARGIN_FACTOR * font.getFontSize()); final int baselineOffset = maxAscent + safetyMargin; final Rectangle boundingBox = getTextBoundingBox(x, y, letterSpacing, wordSpacing, dx, text, font, mapper); final Dimension dim = boundingBox.getSize(); Graphics2DImagePainter painter = new Graphics2DImagePainter() { public void paint(Graphics2D g2d, Rectangle2D area) { if (DEBUG) { g2d.setBackground(Color.LIGHT_GRAY); g2d.clearRect(0, 0, (int) area.getWidth(), (int) area.getHeight()); }/*from www . ja va 2 s.com*/ g2d.translate(-x, -y + baselineOffset); if (DEBUG) { Rectangle rect = new Rectangle(x, y - maxAscent, 3000, maxAscent); g2d.draw(rect); rect = new Rectangle(x, y - ascent, 2000, ascent); g2d.draw(rect); rect = new Rectangle(x, y, 1000, -descent); g2d.draw(rect); } Java2DPainter painter = new Java2DPainter(g2d, getContext(), parent.getFontInfo(), state); try { painter.drawText(x, y, letterSpacing, wordSpacing, dx, text); } catch (IFException e) { //This should never happen with the Java2DPainter throw new RuntimeException("Unexpected error while painting text", e); } } public Dimension getImageSize() { return dim.getSize(); } }; paintMarksAsBitmap(painter, boundingBox); }
From source file:coolmap.canvas.datarenderer.renderer.impl.NumberComposite.java
private void updateLegend() { try {//w ww . jav a 2s. c om ArrayList<Image> legends = new ArrayList<Image>(4); if (singleRenderer != null && singleRenderer.getLegend() != null) { legends.add(singleRenderer.getLegend()); } if (rowGroupRenderer != null && rowGroupRenderer.getLegend() != null) { legends.add(rowGroupRenderer.getLegend()); } if (columnGroupRenderer != null && columnGroupRenderer.getLegend() != null) { legends.add(columnGroupRenderer.getLegend()); } if (rowColumnGroupRenderer != null && rowColumnGroupRenderer.getLegend() != null) { legends.add(rowColumnGroupRenderer.getLegend()); } if (!legends.isEmpty()) { int margin = 5; int imageWidth = 0; int imageHeight = 0; for (Image l : legends) { imageHeight += margin * 2 + l.getHeight(null); if (imageWidth < l.getWidth(null)) { imageWidth = l.getWidth(null); } } imageWidth += margin * 2; if (imageWidth > 0 && imageHeight > 0) { legend = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration() .createCompatibleImage(imageWidth, imageHeight, Transparency.TRANSLUCENT); Graphics2D g2D = legend.createGraphics(); g2D.translate(margin, 0); for (Image l : legends) { g2D.translate(0, margin); g2D.drawImage(l, 0, 0, null); g2D.translate(0, margin + l.getHeight(null)); } g2D.dispose(); } } } catch (Exception e) { } }
From source file:userInterface.EnergySourceBoardSupervisor.ManageEnergyConsumptionsJPanel.java
private void saveBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveBtnActionPerformed JTableHeader tableHeaderComp = applianceTable.getTableHeader(); int totalWidth = tableHeaderComp.getWidth() + applianceTable.getWidth(); int totalHeight = tableHeaderComp.getHeight() + applianceTable.getHeight(); BufferedImage tableImage = new BufferedImage(totalWidth, totalHeight, BufferedImage.TYPE_INT_RGB); Graphics2D g2D = (Graphics2D) tableImage.getGraphics(); tableHeaderComp.paint(g2D);/*from w w w . j av a 2 s . c om*/ g2D.translate(0, tableHeaderComp.getHeight()); applianceTable.paint(g2D); String name = fileNameTxt.getText(); try { if (!name.equals("")) { ImageIO.write(tableImage, "png", new File("C:\\Users\\Reshmi\\Documents\\NetBeansProjects\\FinalProject\\Saved Files\\" + name + ".png")); JOptionPane.showMessageDialog(null, "image saved as " + name + ".png", "Saved", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(null, "enter name to be saved", "No image name", JOptionPane.ERROR_MESSAGE); } } catch (Exception e) { System.out.println(e.getMessage()); } }