src/share/classes/java/awt/Component.java

Print this page
rev 1379 : [mq]: fontmanager.patch


  57 import java.awt.dnd.DropTarget;
  58 import java.lang.reflect.InvocationTargetException;
  59 import java.lang.reflect.Method;
  60 import java.security.AccessController;
  61 import java.security.PrivilegedAction;
  62 import javax.accessibility.*;
  63 import java.util.logging.*;
  64 import java.applet.Applet;
  65 
  66 import sun.security.action.GetPropertyAction;
  67 import sun.awt.AppContext;
  68 import sun.awt.AWTAccessor;
  69 import sun.awt.ConstrainableGraphics;
  70 import sun.awt.SubRegionShowable;
  71 import sun.awt.SunToolkit;
  72 import sun.awt.WindowClosingListener;
  73 import sun.awt.CausedFocusEvent;
  74 import sun.awt.EmbeddedFrame;
  75 import sun.awt.dnd.SunDropTargetEvent;
  76 import sun.awt.im.CompositionArea;



  77 import sun.java2d.SunGraphics2D;
  78 import sun.java2d.pipe.Region;
  79 import sun.awt.image.VSyncedBSManager;
  80 import sun.java2d.pipe.hw.ExtendedBufferCapabilities;
  81 import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
  82 import sun.awt.RequestFocusController;
  83 import sun.java2d.SunGraphicsEnvironment;
  84 
  85 /**
  86  * A <em>component</em> is an object having a graphical representation
  87  * that can be displayed on the screen and that can interact with the
  88  * user. Examples of components are the buttons, checkboxes, and scrollbars
  89  * of a typical graphical user interface. <p>
  90  * The <code>Component</code> class is the abstract superclass of
  91  * the nonmenu-related Abstract Window Toolkit components. Class
  92  * <code>Component</code> can also be extended directly to create a
  93  * lightweight component. A lightweight component is a component that is
  94  * not associated with a native opaque window.
  95  * <p>
  96  * <h3>Serialization</h3>


2833     /**
2834      * Gets the font metrics for the specified font.
2835      * Warning: Since Font metrics are affected by the
2836      * {@link java.awt.font.FontRenderContext FontRenderContext} and
2837      * this method does not provide one, it can return only metrics for
2838      * the default render context which may not match that used when
2839      * rendering on the Component if {@link Graphics2D} functionality is being
2840      * used. Instead metrics can be obtained at rendering time by calling
2841      * {@link Graphics#getFontMetrics()} or text measurement APIs on the
2842      * {@link Font Font} class.
2843      * @param font the font for which font metrics is to be
2844      *          obtained
2845      * @return the font metrics for <code>font</code>
2846      * @see       #getFont
2847      * @see       #getPeer
2848      * @see       java.awt.peer.ComponentPeer#getFontMetrics(Font)
2849      * @see       Toolkit#getFontMetrics(Font)
2850      * @since     JDK1.0
2851      */
2852     public FontMetrics getFontMetrics(Font font) {
2853         // REMIND: PlatformFont flag should be obsolete soon...
2854         if (sun.font.FontManager.usePlatformFontMetrics()) {




2855             if (peer != null &&
2856                 !(peer instanceof LightweightPeer)) {
2857                 return peer.getFontMetrics(font);
2858             }
2859         }
2860         return sun.font.FontDesignMetrics.getMetrics(font);
2861     }
2862 
2863     /**
2864      * Sets the cursor image to the specified cursor.  This cursor
2865      * image is displayed when the <code>contains</code> method for
2866      * this component returns true for the current cursor location, and
2867      * this Component is visible, displayable, and enabled. Setting the
2868      * cursor of a <code>Container</code> causes that cursor to be displayed
2869      * within all of the container's subcomponents, except for those
2870      * that have a non-<code>null</code> cursor.
2871      * <p>
2872      * The method may have no visual effect if the Java platform
2873      * implementation and/or the native system do not support
2874      * changing the mouse cursor shape.




  57 import java.awt.dnd.DropTarget;
  58 import java.lang.reflect.InvocationTargetException;
  59 import java.lang.reflect.Method;
  60 import java.security.AccessController;
  61 import java.security.PrivilegedAction;
  62 import javax.accessibility.*;
  63 import java.util.logging.*;
  64 import java.applet.Applet;
  65 
  66 import sun.security.action.GetPropertyAction;
  67 import sun.awt.AppContext;
  68 import sun.awt.AWTAccessor;
  69 import sun.awt.ConstrainableGraphics;
  70 import sun.awt.SubRegionShowable;
  71 import sun.awt.SunToolkit;
  72 import sun.awt.WindowClosingListener;
  73 import sun.awt.CausedFocusEvent;
  74 import sun.awt.EmbeddedFrame;
  75 import sun.awt.dnd.SunDropTargetEvent;
  76 import sun.awt.im.CompositionArea;
  77 import sun.font.FontManager;
  78 import sun.font.FontManagerFactory;
  79 import sun.font.SunFontManager;
  80 import sun.java2d.SunGraphics2D;
  81 import sun.java2d.pipe.Region;
  82 import sun.awt.image.VSyncedBSManager;
  83 import sun.java2d.pipe.hw.ExtendedBufferCapabilities;
  84 import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
  85 import sun.awt.RequestFocusController;
  86 import sun.java2d.SunGraphicsEnvironment;
  87 
  88 /**
  89  * A <em>component</em> is an object having a graphical representation
  90  * that can be displayed on the screen and that can interact with the
  91  * user. Examples of components are the buttons, checkboxes, and scrollbars
  92  * of a typical graphical user interface. <p>
  93  * The <code>Component</code> class is the abstract superclass of
  94  * the nonmenu-related Abstract Window Toolkit components. Class
  95  * <code>Component</code> can also be extended directly to create a
  96  * lightweight component. A lightweight component is a component that is
  97  * not associated with a native opaque window.
  98  * <p>
  99  * <h3>Serialization</h3>


2836     /**
2837      * Gets the font metrics for the specified font.
2838      * Warning: Since Font metrics are affected by the
2839      * {@link java.awt.font.FontRenderContext FontRenderContext} and
2840      * this method does not provide one, it can return only metrics for
2841      * the default render context which may not match that used when
2842      * rendering on the Component if {@link Graphics2D} functionality is being
2843      * used. Instead metrics can be obtained at rendering time by calling
2844      * {@link Graphics#getFontMetrics()} or text measurement APIs on the
2845      * {@link Font Font} class.
2846      * @param font the font for which font metrics is to be
2847      *          obtained
2848      * @return the font metrics for <code>font</code>
2849      * @see       #getFont
2850      * @see       #getPeer
2851      * @see       java.awt.peer.ComponentPeer#getFontMetrics(Font)
2852      * @see       Toolkit#getFontMetrics(Font)
2853      * @since     JDK1.0
2854      */
2855     public FontMetrics getFontMetrics(Font font) {
2856         // This is an unsupported hack, but left in for a customer.
2857         // Do not remove.
2858         FontManager fm = FontManagerFactory.getInstance();
2859         if (fm instanceof SunFontManager
2860             && ((SunFontManager) fm).usePlatformFontMetrics()) {
2861 
2862             if (peer != null &&
2863                 !(peer instanceof LightweightPeer)) {
2864                 return peer.getFontMetrics(font);
2865             }
2866         }
2867         return sun.font.FontDesignMetrics.getMetrics(font);
2868     }
2869 
2870     /**
2871      * Sets the cursor image to the specified cursor.  This cursor
2872      * image is displayed when the <code>contains</code> method for
2873      * this component returns true for the current cursor location, and
2874      * this Component is visible, displayable, and enabled. Setting the
2875      * cursor of a <code>Container</code> causes that cursor to be displayed
2876      * within all of the container's subcomponents, except for those
2877      * that have a non-<code>null</code> cursor.
2878      * <p>
2879      * The method may have no visual effect if the Java platform
2880      * implementation and/or the native system do not support
2881      * changing the mouse cursor shape.