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