List of usage examples for java.awt Graphics2D setTransform
public abstract void setTransform(AffineTransform Tx);
From source file:Main.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); int[] x = { 0, 100, 100, 0, 0, 75, 75, 125, 25, 50 }; int[] y = { 0, 10, 10, 100, 25, 125, 75, 75, 510, 50 }; Graphics2D g2d = (Graphics2D) g; AffineTransform at0 = g2d.getTransform(); g2d.scale(size / 100, size / 100);//from w ww . jav a 2s . co m g.drawPolyline(x, y, x.length); g2d.setTransform(at0); }
From source file:Scale.java
public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; g2d.setColor(new Color(150, 150, 150)); g2d.fillRect(0, 0, 80, 50);/*from w ww . j av a2s .c o m*/ AffineTransform tx1 = new AffineTransform(); tx1.translate(110, 20); tx1.scale(0.5, 0.5); g2d.setTransform(tx1); g2d.fillRect(0, 0, 80, 50); AffineTransform tx2 = new AffineTransform(); tx2.translate(200, 20); tx2.scale(1.5, 1.5); g2d.setTransform(tx2); g2d.fillRect(0, 0, 80, 50); }
From source file:Main.java
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g.create(); String text = "I don't see the problem"; FontMetrics fm = g2d.getFontMetrics(); int x = (getWidth() - fm.stringWidth(text)) / 2; int y = ((getHeight() - fm.getHeight()) / 2) + fm.getDescent(); g2d.setTransform(AffineTransform.getRotateInstance(Math.toRadians(45), getWidth() / 2, getHeight() / 2)); g2d.drawString(text, x, y);// ww w . java 2 s . c om g2d.dispose(); }
From source file:ArrowIcon.java
protected Image getArrowImage() { if (arrowImage == null) { arrowImage = createTranslucentImage(size, size); AffineTransform atx = direction != SOUTH ? new AffineTransform() : null; switch (direction) { case NORTH: atx.setToRotation(Math.PI, size / 2, size / 2); break; case EAST: atx.setToRotation(-(Math.PI / 2), size / 2, size / 2); break; case WEST: atx.setToRotation(Math.PI / 2, size / 2, size / 2); case SOUTH: default: { /* no xform*/ } }/*from ww w.j a v a2s .c o m*/ Graphics2D ig = (Graphics2D) arrowImage.getGraphics(); if (atx != null) { ig.setTransform(atx); } int width = size; int height = size / 2 + 1; int xx = (size - width) / 2; int yy = (size - height + 1) / 2; Color base = color != null ? color : UIManager.getColor("controlDkShadow").darker(); paintArrow(ig, base, xx, yy); paintArrowBevel(ig, base, xx, yy); paintArrowBevel(ig, deriveColorHSB(base, 0f, 0f, .20f), xx, yy + 1); } return arrowImage; }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(Color.black);/*from w w w. j a va2 s . c om*/ g2.draw(new Rectangle2D.Float(10, 20, 30, 40)); AffineTransform at = AffineTransform.getTranslateInstance(75, 75); g2.setTransform(at); g2.setPaint(Color.red); g2.draw(new Rectangle2D.Float(10, 20, 30, 40)); }
From source file:com.igormaznitsa.jhexed.renders.svg.SVGImage.java
public BufferedImage rasterize(final int width, final int height, final int imageType) throws IOException { final BufferedImage result = new BufferedImage(width, height, imageType); final float xfactor = (float) width / getSVGWidth(); final float yfactor = (float) height / getSVGHeight(); final Graphics2D g = result.createGraphics(); processAntialias(this.quality, g); g.setTransform(AffineTransform.getScaleInstance(xfactor, yfactor)); this.svgGraphicsNode.primitivePaint(g); g.dispose();/* www. j a v a 2s.c om*/ return result; }
From source file:Main.java
@Override public void paintComponent(Graphics gr) { Color c = gr.getColor();//from w w w. ja v a 2 s .c om setForeground(new Color(0, 0, 0, 0)); super.paintComponent(gr); setForeground(c); gr.setColor(c); Graphics2D g = (Graphics2D) gr; g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); double pw = this.getPreferredSize().width; double ph = this.getPreferredSize().height; double w = this.getSize().width; double h = this.getSize().height; g.setColor(this.getForeground()); AffineTransform stretch = AffineTransform.getScaleInstance(w / pw, h / ph); g.setTransform(stretch); g.drawString(getText(), 0, this.getFont().getSize()); }
From source file:juicebox.track.EigenvectorTrack.java
private void drawRotatedString(Graphics2D g2, String string, float x, float y) { AffineTransform orig = g2.getTransform(); g2.rotate(0);/*w w w . j ava 2s . c o m*/ g2.setColor(Color.BLUE); g2.translate(x, 0); g2.scale(-1, 1); g2.translate(-x, 0); g2.drawString(string, x, y); g2.setTransform(orig); }
From source file:Main.java
public void paint(Graphics g, JComponent c) { JLabel label = (JLabel) c; String text = label.getText(); Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon(); if ((icon == null) && (text == null)) { return;/*from ww w. j av a 2s .c om*/ } FontMetrics fm = g.getFontMetrics(); paintViewInsets = c.getInsets(paintViewInsets); paintViewR.x = paintViewInsets.left; paintViewR.y = paintViewInsets.top; // Use inverted height & width paintViewR.height = c.getWidth() - (paintViewInsets.left + paintViewInsets.right); paintViewR.width = c.getHeight() - (paintViewInsets.top + paintViewInsets.bottom); paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0; paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0; String clippedText = layoutCL(label, fm, text, icon, paintViewR, paintIconR, paintTextR); Graphics2D g2 = (Graphics2D) g; AffineTransform tr = g2.getTransform(); if (clockwise) { g2.rotate(Math.PI / 2); g2.translate(0, -c.getWidth()); } else { g2.rotate(-Math.PI / 2); g2.translate(-c.getHeight(), 0); } if (icon != null) { icon.paintIcon(c, g, paintIconR.x, paintIconR.y); } if (text != null) { int textX = paintTextR.x; int textY = paintTextR.y + fm.getAscent(); if (label.isEnabled()) { paintEnabledText(label, g, clippedText, textX, textY); } else { paintDisabledText(label, g, clippedText, textX, textY); } } g2.setTransform(tr); }
From source file:TextRendering.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Dimension d = getSize();/*www. j a v a 2 s . com*/ AffineTransform ct = AffineTransform.getTranslateInstance(d.width / 2, d.height * 3 / 4); g2.transform(ct); String s = "www.java2s.com"; Font f = new Font("Serif", Font.PLAIN, 128); g2.setFont(f); int count = 6; for (int i = 1; i <= count; i++) { AffineTransform oldTransform = g2.getTransform(); float ratio = (float) i / (float) count; g2.transform(AffineTransform.getRotateInstance(Math.PI * (ratio - 1.0f))); float alpha = ((i == count) ? 1.0f : ratio / 3); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha)); g2.drawString(s, 0, 0); g2.setTransform(oldTransform); } }