List of usage examples for java.awt Graphics2D setRenderingHint
public abstract void setRenderingHint(Key hintKey, Object hintValue);
From source file:MouseMoveScale.java
public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D) g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2d.setColor(new Color(0, 0, 200)); g2d.fill(myRect);//from w ww . j ava 2 s .co m }
From source file:net.rptools.maptool.util.PersistenceUtil.java
public static void saveToken(Token token, File file, boolean doWait) throws IOException { // Thumbnail// ww w .ja v a 2 s . c o m BufferedImage image = null; if (doWait) image = ImageManager.getImageAndWait(token.getImageAssetId()); else image = ImageManager.getImage(token.getImageAssetId()); Dimension sz = new Dimension(image.getWidth(), image.getHeight()); SwingUtil.constrainTo(sz, 50); BufferedImage thumb = new BufferedImage(sz.width, sz.height, BufferedImage.TRANSLUCENT); Graphics2D g = thumb.createGraphics(); g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); g.drawImage(image, 0, 0, sz.width, sz.height, null); g.dispose(); PackedFile pakFile = null; try { pakFile = new PackedFile(file); saveAssets(token.getAllImageAssets(), pakFile); pakFile.putFile(Token.FILE_THUMBNAIL, ImageUtil.imageToBytes(thumb, "png")); pakFile.setContent(token); pakFile.setProperty(PROP_VERSION, MapTool.getVersion()); pakFile.save(); } finally { if (pakFile != null) pakFile.close(); } }
From source file:Highlights.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON); String s = "Drag the text to highlight Java Source and Support."; Font font = new Font("Serif", Font.PLAIN, 32); if (textLayout == null) { FontRenderContext frc = g2.getFontRenderContext(); textLayout = new TextLayout(s, font, frc); }//from w w w .ja v a 2 s .co m // Draw the highlight. if (firstHit != null && secondHit != null) { Shape base = textLayout.getLogicalHighlightShape(firstHit.getInsertionIndex(), secondHit.getInsertionIndex()); AffineTransform at = AffineTransform.getTranslateInstance(x, y); Shape highlight = at.createTransformedShape(base); g2.setPaint(Color.white); g2.fill(highlight); } g2.setPaint(Color.black); textLayout.draw(g2, x, y); }
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; String s = "\"www.java2s.com,\" www.java2s.com"; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Font plainFont = new Font("Times New Roman", Font.PLAIN, 24); AttributedString as = new AttributedString(s); as.addAttribute(TextAttribute.FONT, plainFont); as.addAttribute(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON, 18, 22); g2.drawString(as.getIterator(), 24, 70); }
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; String s = "\"www.java2s.com,\" www.java2s.com"; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Font plainFont = new Font("Times New Roman", Font.PLAIN, 24); AttributedString as = new AttributedString(s); as.addAttribute(TextAttribute.FONT, plainFont); as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON, 1, 11); g2.drawString(as.getIterator(), 24, 70); }
From source file:MainClass.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; String s = "\"www.java2s.com,\" www.java2s.com"; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Font plainFont = new Font("Times New Roman", Font.PLAIN, 24); AttributedString as = new AttributedString(s); as.addAttribute(TextAttribute.FONT, plainFont); g2.drawString(as.getIterator(), 24, 70); }
From source file:CombiningShapes.java
public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); String option = (String) mOptions.getSelectedItem(); if (option.equals("outline")) { // draw the outlines and return. g2.draw(mShapeOne);/*from w ww . ja v a2 s.c o m*/ g2.draw(mShapeTwo); return; } // Create Areas from the shapes. Area areaOne = new Area(mShapeOne); Area areaTwo = new Area(mShapeTwo); // Combine the Areas according to the selected option. if (option.equals("add")) areaOne.add(areaTwo); else if (option.equals("intersection")) areaOne.intersect(areaTwo); else if (option.equals("subtract")) areaOne.subtract(areaTwo); else if (option.equals("exclusive or")) areaOne.exclusiveOr(areaTwo); // Fill the resulting Area. g2.setPaint(Color.orange); g2.fill(areaOne); // Draw the outline of the resulting Area. g2.setPaint(Color.black); g2.draw(areaOne); }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); int cx = getSize().width / 2; int cy = getSize().height / 2; g2.translate(cx, cy);/*from w ww .jav a 2 s . co m*/ g2.rotate(theta * Math.PI / 180); Shape oldClip = g2.getClip(); Shape e = new Ellipse2D.Float(-cx, -cy, cx * 2, cy * 2); g2.clip(e); Shape c = new Ellipse2D.Float(-cx, -cy, cx * 3 / 4, cy * 2); g2.setPaint(new GradientPaint(40, 40, Color.blue, 60, 50, Color.white, true)); g2.fill(c); g2.setPaint(Color.yellow); g2.fillOval(cx / 4, 0, cx, cy); g2.setClip(oldClip); g2.setFont(new Font("Times New Roman", Font.PLAIN, 64)); g2.setPaint(new GradientPaint(-cx, 0, Color.red, cx, 0, Color.black, false)); g2.drawString("Hello, 2D!", -cx * 3 / 4, cy / 4); AlphaComposite ac = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) .75); g2.setComposite(ac); Shape r = new RoundRectangle2D.Float(0, -cy * 3 / 4, cx * 3 / 4, cy * 3 / 4, 20, 20); g2.setStroke(new BasicStroke(4)); g2.setPaint(Color.magenta); g2.fill(r); g2.setPaint(Color.green); g2.draw(r); g2.drawImage(image, -cx / 2, -cy / 2, this); }
From source file:dataminning2.Graphplot.java
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(); // Draw ordinate. g2.draw(new Line2D.Double(PAD, PAD, PAD, h - PAD)); // Draw abcissa. g2.draw(new Line2D.Double(PAD, h - PAD, w - PAD, h - PAD)); double xInc = (double) (w - 2 * PAD) / (data.length - 1); double scale = (double) (h - 2 * PAD) / 88; // Mark data points. g2.setPaint(Color.red);// w w w . j av a 2 s.co m int length1 = 0; int length2 = data.length / 3; for (int i = 0; i < length2; i++) { double x = PAD + i * dataX[i]; double y = h - PAD - scale * dataY[i]; g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4)); } g2.setPaint(Color.BLUE); int lengthnew = length1 + length2; length2 = length2 + lengthnew; for (int i = lengthnew; i < length2; i++) { double x = PAD + i * dataX[i]; double y = h - PAD - scale * dataY[i]; g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4)); } g2.setPaint(Color.YELLOW); lengthnew = lengthnew + lengthnew; for (int i = length2; i < data.length; i++) { double x = PAD + i * dataX[i]; double y = h - PAD - scale * dataY[i]; g2.fill(new Ellipse2D.Double(x - 2, y - 2, 4, 4)); } }
From source file:TexturedText.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setPaint(tp);// w ww . ja v a2s .c o m g2.setFont(myFont); g2.drawString(mesg, 20, 100); }