50 import java.beans.PropertyChangeListener;
51 import java.beans.PropertyChangeSupport;
52 import java.beans.Transient;
53 import java.awt.im.InputContext;
54 import java.awt.im.InputMethodRequests;
55 import java.awt.dnd.DropTarget;
56 import java.lang.reflect.InvocationTargetException;
57 import java.lang.reflect.Method;
58 import java.security.AccessController;
59 import java.security.PrivilegedAction;
60 import java.security.AccessControlContext;
61 import javax.accessibility.*;
62 import java.applet.Applet;
63
64 import sun.security.action.GetPropertyAction;
65 import sun.awt.AppContext;
66 import sun.awt.AWTAccessor;
67 import sun.awt.ConstrainableGraphics;
68 import sun.awt.SubRegionShowable;
69 import sun.awt.SunToolkit;
70 import sun.awt.WindowClosingListener;
71 import sun.awt.CausedFocusEvent;
72 import sun.awt.EmbeddedFrame;
73 import sun.awt.dnd.SunDropTargetEvent;
74 import sun.awt.im.CompositionArea;
75 import sun.font.FontManager;
76 import sun.font.FontManagerFactory;
77 import sun.font.SunFontManager;
78 import sun.java2d.SunGraphics2D;
79 import sun.java2d.pipe.Region;
80 import sun.awt.image.VSyncedBSManager;
81 import sun.java2d.pipe.hw.ExtendedBufferCapabilities;
82 import static sun.java2d.pipe.hw.ExtendedBufferCapabilities.VSyncType.*;
83 import sun.awt.RequestFocusController;
84 import sun.java2d.SunGraphicsEnvironment;
85 import sun.util.logging.PlatformLogger;
86
87 /**
88 * A <em>component</em> is an object having a graphical representation
89 * that can be displayed on the screen and that can interact with the
90 * user. Examples of components are the buttons, checkboxes, and scrollbars
4849 switch(id) {
4850 // Handling of the PAINT and UPDATE events is now done in the
4851 // peer's handleEvent() method so the background can be cleared
4852 // selectively for non-native components on Windows only.
4853 // - Fred.Ecks@Eng.sun.com, 5-8-98
4854
4855 case KeyEvent.KEY_PRESSED:
4856 case KeyEvent.KEY_RELEASED:
4857 Container p = (Container)((this instanceof Container) ? this : parent);
4858 if (p != null) {
4859 p.preProcessKeyEvent((KeyEvent)e);
4860 if (e.isConsumed()) {
4861 if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
4862 focusLog.finest("Pre-process consumed event");
4863 }
4864 return;
4865 }
4866 }
4867 break;
4868
4869 case WindowEvent.WINDOW_CLOSING:
4870 if (toolkit instanceof WindowClosingListener) {
4871 windowClosingException = ((WindowClosingListener)
4872 toolkit).windowClosingNotify((WindowEvent)e);
4873 if (checkWindowClosingException()) {
4874 return;
4875 }
4876 }
4877 break;
4878
4879 default:
4880 break;
4881 }
4882
4883 /*
4884 * 6. Deliver event for normal processing
4885 */
4886 if (newEventsOnly) {
4887 // Filtering needs to really be moved to happen at a lower
4888 // level in order to get maximum performance gain; it is
4889 // here temporarily to ensure the API spec is honored.
4890 //
4891 if (eventEnabled(e)) {
4892 processEvent(e);
4893 }
4894 } else if (id == MouseEvent.MOUSE_WHEEL) {
4895 // newEventsOnly will be false for a listenerless ScrollPane, but
4896 // MouseWheelEvents still need to be dispatched to it so scrolling
4897 // can be done.
4898 autoProcessMouseWheel((MouseWheelEvent)e);
4914 //
4915 switch(olde.id) {
4916 case Event.KEY_PRESS:
4917 case Event.KEY_RELEASE:
4918 case Event.KEY_ACTION:
4919 case Event.KEY_ACTION_RELEASE:
4920 if (olde.key != key) {
4921 ((KeyEvent)e).setKeyChar(olde.getKeyEventChar());
4922 }
4923 if (olde.modifiers != modifiers) {
4924 ((KeyEvent)e).setModifiers(olde.modifiers);
4925 }
4926 break;
4927 default:
4928 break;
4929 }
4930 }
4931 }
4932
4933 /*
4934 * 8. Special handling for 4061116 : Hook for browser to close modal
4935 * dialogs.
4936 */
4937 if (id == WindowEvent.WINDOW_CLOSING && !e.isConsumed()) {
4938 if (toolkit instanceof WindowClosingListener) {
4939 windowClosingException =
4940 ((WindowClosingListener)toolkit).
4941 windowClosingDelivered((WindowEvent)e);
4942 if (checkWindowClosingException()) {
4943 return;
4944 }
4945 }
4946 }
4947
4948 /*
4949 * 9. Allow the peer to process the event.
4950 * Except KeyEvents, they will be processed by peer after
4951 * all KeyEventPostProcessors
4952 * (see DefaultKeyboardFocusManager.dispatchKeyEvent())
4953 */
4954 if (!(e instanceof KeyEvent)) {
4955 ComponentPeer tpeer = peer;
4956 if (e instanceof FocusEvent && (tpeer == null || tpeer instanceof LightweightPeer)) {
4957 // if focus owner is lightweight then its native container
4958 // processes event
4959 Component source = (Component)e.getSource();
4960 if (source != null) {
4961 Container target = source.getNativeContainer();
4962 if (target != null) {
4963 tpeer = target.getPeer();
4964 }
4965 }
4966 }
4967 if (tpeer != null) {
4968 tpeer.handleEvent(e);
5035 e.getScrollType(),
5036 e.getScrollAmount(),
5037 e.getWheelRotation(),
5038 e.getPreciseWheelRotation());
5039 ((AWTEvent)e).copyPrivateDataInto(newMWE);
5040 // When dispatching a wheel event to
5041 // ancestor, there is no need trying to find descendant
5042 // lightweights to dispatch event to.
5043 // If we dispatch the event to toplevel ancestor,
5044 // this could encolse the loop: 6480024.
5045 anc.dispatchEventToSelf(newMWE);
5046 if (newMWE.isConsumed()) {
5047 e.consume();
5048 }
5049 return true;
5050 }
5051 }
5052 return false;
5053 }
5054
5055 boolean checkWindowClosingException() {
5056 if (windowClosingException != null) {
5057 if (this instanceof Dialog) {
5058 ((Dialog)this).interruptBlocking();
5059 } else {
5060 windowClosingException.fillInStackTrace();
5061 windowClosingException.printStackTrace();
5062 windowClosingException = null;
5063 }
5064 return true;
5065 }
5066 return false;
5067 }
5068
5069 boolean areInputMethodsEnabled() {
5070 // in 1.2, we assume input method support is required for all
5071 // components that handle key events, but components can turn off
5072 // input methods by calling enableInputMethods(false).
5073 return ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) &&
5074 ((eventMask & AWTEvent.KEY_EVENT_MASK) != 0 || keyListener != null);
5075 }
5076
5077 // REMIND: remove when filtering is handled at lower level
5078 boolean eventEnabled(AWTEvent e) {
5079 return eventTypeEnabled(e.id);
5080 }
5081
5082 boolean eventTypeEnabled(int type) {
5083 switch(type) {
5084 case ComponentEvent.COMPONENT_MOVED:
5085 case ComponentEvent.COMPONENT_RESIZED:
5086 case ComponentEvent.COMPONENT_SHOWN:
5087 case ComponentEvent.COMPONENT_HIDDEN:
5088 if ((eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
|
50 import java.beans.PropertyChangeListener;
51 import java.beans.PropertyChangeSupport;
52 import java.beans.Transient;
53 import java.awt.im.InputContext;
54 import java.awt.im.InputMethodRequests;
55 import java.awt.dnd.DropTarget;
56 import java.lang.reflect.InvocationTargetException;
57 import java.lang.reflect.Method;
58 import java.security.AccessController;
59 import java.security.PrivilegedAction;
60 import java.security.AccessControlContext;
61 import javax.accessibility.*;
62 import java.applet.Applet;
63
64 import sun.security.action.GetPropertyAction;
65 import sun.awt.AppContext;
66 import sun.awt.AWTAccessor;
67 import sun.awt.ConstrainableGraphics;
68 import sun.awt.SubRegionShowable;
69 import sun.awt.SunToolkit;
70 import sun.awt.CausedFocusEvent;
71 import sun.awt.EmbeddedFrame;
72 import sun.awt.dnd.SunDropTargetEvent;
73 import sun.awt.im.CompositionArea;
74 import sun.font.FontManager;
75 import sun.font.FontManagerFactory;
76 import sun.font.SunFontManager;
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 import sun.util.logging.PlatformLogger;
85
86 /**
87 * A <em>component</em> is an object having a graphical representation
88 * that can be displayed on the screen and that can interact with the
89 * user. Examples of components are the buttons, checkboxes, and scrollbars
4848 switch(id) {
4849 // Handling of the PAINT and UPDATE events is now done in the
4850 // peer's handleEvent() method so the background can be cleared
4851 // selectively for non-native components on Windows only.
4852 // - Fred.Ecks@Eng.sun.com, 5-8-98
4853
4854 case KeyEvent.KEY_PRESSED:
4855 case KeyEvent.KEY_RELEASED:
4856 Container p = (Container)((this instanceof Container) ? this : parent);
4857 if (p != null) {
4858 p.preProcessKeyEvent((KeyEvent)e);
4859 if (e.isConsumed()) {
4860 if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
4861 focusLog.finest("Pre-process consumed event");
4862 }
4863 return;
4864 }
4865 }
4866 break;
4867
4868 default:
4869 break;
4870 }
4871
4872 /*
4873 * 6. Deliver event for normal processing
4874 */
4875 if (newEventsOnly) {
4876 // Filtering needs to really be moved to happen at a lower
4877 // level in order to get maximum performance gain; it is
4878 // here temporarily to ensure the API spec is honored.
4879 //
4880 if (eventEnabled(e)) {
4881 processEvent(e);
4882 }
4883 } else if (id == MouseEvent.MOUSE_WHEEL) {
4884 // newEventsOnly will be false for a listenerless ScrollPane, but
4885 // MouseWheelEvents still need to be dispatched to it so scrolling
4886 // can be done.
4887 autoProcessMouseWheel((MouseWheelEvent)e);
4903 //
4904 switch(olde.id) {
4905 case Event.KEY_PRESS:
4906 case Event.KEY_RELEASE:
4907 case Event.KEY_ACTION:
4908 case Event.KEY_ACTION_RELEASE:
4909 if (olde.key != key) {
4910 ((KeyEvent)e).setKeyChar(olde.getKeyEventChar());
4911 }
4912 if (olde.modifiers != modifiers) {
4913 ((KeyEvent)e).setModifiers(olde.modifiers);
4914 }
4915 break;
4916 default:
4917 break;
4918 }
4919 }
4920 }
4921
4922 /*
4923 * 9. Allow the peer to process the event.
4924 * Except KeyEvents, they will be processed by peer after
4925 * all KeyEventPostProcessors
4926 * (see DefaultKeyboardFocusManager.dispatchKeyEvent())
4927 */
4928 if (!(e instanceof KeyEvent)) {
4929 ComponentPeer tpeer = peer;
4930 if (e instanceof FocusEvent && (tpeer == null || tpeer instanceof LightweightPeer)) {
4931 // if focus owner is lightweight then its native container
4932 // processes event
4933 Component source = (Component)e.getSource();
4934 if (source != null) {
4935 Container target = source.getNativeContainer();
4936 if (target != null) {
4937 tpeer = target.getPeer();
4938 }
4939 }
4940 }
4941 if (tpeer != null) {
4942 tpeer.handleEvent(e);
5009 e.getScrollType(),
5010 e.getScrollAmount(),
5011 e.getWheelRotation(),
5012 e.getPreciseWheelRotation());
5013 ((AWTEvent)e).copyPrivateDataInto(newMWE);
5014 // When dispatching a wheel event to
5015 // ancestor, there is no need trying to find descendant
5016 // lightweights to dispatch event to.
5017 // If we dispatch the event to toplevel ancestor,
5018 // this could encolse the loop: 6480024.
5019 anc.dispatchEventToSelf(newMWE);
5020 if (newMWE.isConsumed()) {
5021 e.consume();
5022 }
5023 return true;
5024 }
5025 }
5026 return false;
5027 }
5028
5029 boolean areInputMethodsEnabled() {
5030 // in 1.2, we assume input method support is required for all
5031 // components that handle key events, but components can turn off
5032 // input methods by calling enableInputMethods(false).
5033 return ((eventMask & AWTEvent.INPUT_METHODS_ENABLED_MASK) != 0) &&
5034 ((eventMask & AWTEvent.KEY_EVENT_MASK) != 0 || keyListener != null);
5035 }
5036
5037 // REMIND: remove when filtering is handled at lower level
5038 boolean eventEnabled(AWTEvent e) {
5039 return eventTypeEnabled(e.id);
5040 }
5041
5042 boolean eventTypeEnabled(int type) {
5043 switch(type) {
5044 case ComponentEvent.COMPONENT_MOVED:
5045 case ComponentEvent.COMPONENT_RESIZED:
5046 case ComponentEvent.COMPONENT_SHOWN:
5047 case ComponentEvent.COMPONENT_HIDDEN:
5048 if ((eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
|