< prev index next >

test/javax/swing/plaf/basic/BasicGraphicsUtils/8132119/bug8132119.java

Print this page




  24 import java.awt.Color;
  25 import java.awt.Font;
  26 import java.awt.FontMetrics;
  27 import java.awt.Graphics2D;
  28 import java.awt.GraphicsEnvironment;
  29 import java.awt.font.FontRenderContext;
  30 import java.awt.font.NumericShaper;
  31 import java.awt.font.TextAttribute;
  32 import java.awt.font.TextLayout;
  33 import java.awt.image.BufferedImage;
  34 import java.util.HashMap;
  35 import javax.swing.JComponent;
  36 import javax.swing.JLabel;
  37 import javax.swing.SwingUtilities;
  38 import javax.swing.UIManager;
  39 import javax.swing.plaf.basic.BasicGraphicsUtils;
  40 import javax.swing.plaf.metal.MetalLookAndFeel;
  41 
  42 /**
  43  * @test
  44  * @bug 8132119 8168992
  45  * @author Alexandr Scherbatiy
  46  * @summary Provide public API for text related methods in SwingBasicGraphicsUtils2
  47  */
  48 public class bug8132119 {
  49 
  50     private static final int WIDTH = 50;
  51     private static final int HEIGHT = 50;
  52     private static final Color DRAW_COLOR = Color.RED;
  53     private static final Color BACKGROUND_COLOR = Color.GREEN;
  54     private static final NumericShaper NUMERIC_SHAPER = NumericShaper.getShaper(
  55             NumericShaper.ARABIC);
  56 
  57     public static void main(String[] args) throws Exception {
  58         SwingUtilities.invokeAndWait(bug8132119::testStringMethods);
  59     }
  60 
  61     private static void testStringMethods() {
  62         setMetalLAF();
  63         testStringWidth();
  64         testStringClip();


 263         try {
 264             UIManager.setLookAndFeel(new MetalLookAndFeel());
 265         } catch (Exception e) {
 266             throw new RuntimeException(e);
 267         }
 268     }
 269 
 270     private static JComponent createComponent(String str) {
 271         JComponent comp = new JLabel(str);
 272         comp.setSize(WIDTH, HEIGHT);
 273         comp.putClientProperty(TextAttribute.NUMERIC_SHAPING, NUMERIC_SHAPER);
 274         comp.setFont(getFont());
 275         return comp;
 276     }
 277 
 278     private static Font getFont() {
 279         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
 280         String[] fontNames = ge.getAvailableFontFamilyNames();
 281         String fontName = fontNames[0];
 282         for (String name : fontNames) {
 283             if ("Arial".equals(name)) {
 284                 fontName = name;
 285                 break;
 286             }
 287         }
 288         return new Font(fontName, Font.PLAIN, 28);
 289     }
 290 
 291     private static float getLayoutWidth(String text, Font font, NumericShaper shaper) {
 292         HashMap map = new HashMap();
 293         map.put(TextAttribute.FONT, font);
 294         map.put(TextAttribute.NUMERIC_SHAPING, shaper);
 295         FontRenderContext frc = new FontRenderContext(null, false, false);
 296         TextLayout layout = new TextLayout(text, map, frc);
 297         return layout.getAdvance();
 298     }
 299 
 300     private static void checkImageIsEmpty(BufferedImage buffImage) {
 301         int background = BACKGROUND_COLOR.getRGB();
 302 
 303         for (int i = 0; i < buffImage.getWidth(); i++) {




  24 import java.awt.Color;
  25 import java.awt.Font;
  26 import java.awt.FontMetrics;
  27 import java.awt.Graphics2D;
  28 import java.awt.GraphicsEnvironment;
  29 import java.awt.font.FontRenderContext;
  30 import java.awt.font.NumericShaper;
  31 import java.awt.font.TextAttribute;
  32 import java.awt.font.TextLayout;
  33 import java.awt.image.BufferedImage;
  34 import java.util.HashMap;
  35 import javax.swing.JComponent;
  36 import javax.swing.JLabel;
  37 import javax.swing.SwingUtilities;
  38 import javax.swing.UIManager;
  39 import javax.swing.plaf.basic.BasicGraphicsUtils;
  40 import javax.swing.plaf.metal.MetalLookAndFeel;
  41 
  42 /**
  43  * @test
  44  * @bug 8132119 8168992 8169897
  45  * @author Alexandr Scherbatiy
  46  * @summary Provide public API for text related methods in SwingBasicGraphicsUtils2
  47  */
  48 public class bug8132119 {
  49 
  50     private static final int WIDTH = 50;
  51     private static final int HEIGHT = 50;
  52     private static final Color DRAW_COLOR = Color.RED;
  53     private static final Color BACKGROUND_COLOR = Color.GREEN;
  54     private static final NumericShaper NUMERIC_SHAPER = NumericShaper.getShaper(
  55             NumericShaper.ARABIC);
  56 
  57     public static void main(String[] args) throws Exception {
  58         SwingUtilities.invokeAndWait(bug8132119::testStringMethods);
  59     }
  60 
  61     private static void testStringMethods() {
  62         setMetalLAF();
  63         testStringWidth();
  64         testStringClip();


 263         try {
 264             UIManager.setLookAndFeel(new MetalLookAndFeel());
 265         } catch (Exception e) {
 266             throw new RuntimeException(e);
 267         }
 268     }
 269 
 270     private static JComponent createComponent(String str) {
 271         JComponent comp = new JLabel(str);
 272         comp.setSize(WIDTH, HEIGHT);
 273         comp.putClientProperty(TextAttribute.NUMERIC_SHAPING, NUMERIC_SHAPER);
 274         comp.setFont(getFont());
 275         return comp;
 276     }
 277 
 278     private static Font getFont() {
 279         GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
 280         String[] fontNames = ge.getAvailableFontFamilyNames();
 281         String fontName = fontNames[0];
 282         for (String name : fontNames) {
 283             if ("Serif".equals(name)) {
 284                 fontName = name;
 285                 break;
 286             }
 287         }
 288         return new Font(fontName, Font.PLAIN, 28);
 289     }
 290 
 291     private static float getLayoutWidth(String text, Font font, NumericShaper shaper) {
 292         HashMap map = new HashMap();
 293         map.put(TextAttribute.FONT, font);
 294         map.put(TextAttribute.NUMERIC_SHAPING, shaper);
 295         FontRenderContext frc = new FontRenderContext(null, false, false);
 296         TextLayout layout = new TextLayout(text, map, frc);
 297         return layout.getAdvance();
 298     }
 299 
 300     private static void checkImageIsEmpty(BufferedImage buffImage) {
 301         int background = BACKGROUND_COLOR.getRGB();
 302 
 303         for (int i = 0; i < buffImage.getWidth(); i++) {


< prev index next >