< prev index next >

src/java.desktop/macosx/classes/sun/lwawt/LWComponentPeer.java

Print this page


   1 /*
   2  * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 886             size.width = fm.charWidth(WIDE_CHAR);
 887             size.height = fm.getHeight();
 888         }
 889         return size;
 890     }
 891 
 892     @Override
 893     public void updateCursorImmediately() {
 894         getLWToolkit().getCursorManager().updateCursor();
 895     }
 896 
 897     @Override
 898     public boolean isFocusable() {
 899         // Overridden in focusable subclasses like buttons
 900         return false;
 901     }
 902 
 903     @Override
 904     public boolean requestFocus(Component lightweightChild, boolean temporary,
 905                                 boolean focusedWindowChangeAllowed, long time,
 906                                 CausedFocusEvent.Cause cause)
 907     {
 908         if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
 909             focusLog.finest("lightweightChild=" + lightweightChild + ", temporary=" + temporary +
 910                             ", focusedWindowChangeAllowed=" + focusedWindowChangeAllowed +
 911                             ", time= " + time + ", cause=" + cause);
 912         }
 913         if (LWKeyboardFocusManagerPeer.processSynchronousLightweightTransfer(
 914                 getTarget(), lightweightChild, temporary,
 915                 focusedWindowChangeAllowed, time)) {
 916             return true;
 917         }
 918 
 919         int result = LWKeyboardFocusManagerPeer.shouldNativelyFocusHeavyweight(
 920                 getTarget(), lightweightChild, temporary,
 921                 focusedWindowChangeAllowed, time, cause);
 922         switch (result) {
 923             case LWKeyboardFocusManagerPeer.SNFH_FAILURE:
 924                 return false;
 925             case LWKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED:
 926                 Window parentWindow = SunToolkit.getContainingWindow(getTarget());


1261             }
1262             delegateEvent = SwingUtilities.convertMouseEvent(getTarget(), me, eventTarget);
1263         } else if (e instanceof KeyEvent) {
1264             KeyEvent ke = (KeyEvent) e;
1265             delegateEvent = new KeyEvent(getDelegateFocusOwner(), ke.getID(), ke.getWhen(),
1266                     ke.getModifiers(), ke.getKeyCode(), ke.getKeyChar(), ke.getKeyLocation());
1267             AWTAccessor.getKeyEventAccessor().setExtendedKeyCode((KeyEvent) delegateEvent,
1268                     ke.getExtendedKeyCode());
1269         } else if (e instanceof FocusEvent) {
1270             FocusEvent fe = (FocusEvent) e;
1271             delegateEvent = new FocusEvent(getDelegateFocusOwner(), fe.getID(), fe.isTemporary());
1272         }
1273         return delegateEvent;
1274     }
1275 
1276     protected void handleJavaMouseEvent(MouseEvent e) {
1277         Component target = getTarget();
1278         assert (e.getSource() == target);
1279 
1280         if (!target.isFocusOwner() && LWKeyboardFocusManagerPeer.shouldFocusOnClick(target)) {
1281             LWKeyboardFocusManagerPeer.requestFocusFor(target, CausedFocusEvent.Cause.MOUSE_EVENT);
1282         }
1283     }
1284 
1285     /**
1286      * Handler for FocusEvents.
1287      */
1288     void handleJavaFocusEvent(final FocusEvent e) {
1289         // Note that the peer receives all the FocusEvents from
1290         // its lightweight children as well
1291         KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
1292         kfmPeer.setCurrentFocusOwner(e.getID() == FocusEvent.FOCUS_GAINED ? getTarget() : null);
1293     }
1294 
1295     /**
1296      * All peers should clear background before paint.
1297      *
1298      * @return false on components that DO NOT require a clearRect() before
1299      *         painting.
1300      */
1301     protected final boolean shouldClearRectBeforePaint() {


   1 /*
   2  * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 886             size.width = fm.charWidth(WIDE_CHAR);
 887             size.height = fm.getHeight();
 888         }
 889         return size;
 890     }
 891 
 892     @Override
 893     public void updateCursorImmediately() {
 894         getLWToolkit().getCursorManager().updateCursor();
 895     }
 896 
 897     @Override
 898     public boolean isFocusable() {
 899         // Overridden in focusable subclasses like buttons
 900         return false;
 901     }
 902 
 903     @Override
 904     public boolean requestFocus(Component lightweightChild, boolean temporary,
 905                                 boolean focusedWindowChangeAllowed, long time,
 906                                 FocusEvent.Cause cause)
 907     {
 908         if (focusLog.isLoggable(PlatformLogger.Level.FINEST)) {
 909             focusLog.finest("lightweightChild=" + lightweightChild + ", temporary=" + temporary +
 910                             ", focusedWindowChangeAllowed=" + focusedWindowChangeAllowed +
 911                             ", time= " + time + ", cause=" + cause);
 912         }
 913         if (LWKeyboardFocusManagerPeer.processSynchronousLightweightTransfer(
 914                 getTarget(), lightweightChild, temporary,
 915                 focusedWindowChangeAllowed, time)) {
 916             return true;
 917         }
 918 
 919         int result = LWKeyboardFocusManagerPeer.shouldNativelyFocusHeavyweight(
 920                 getTarget(), lightweightChild, temporary,
 921                 focusedWindowChangeAllowed, time, cause);
 922         switch (result) {
 923             case LWKeyboardFocusManagerPeer.SNFH_FAILURE:
 924                 return false;
 925             case LWKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED:
 926                 Window parentWindow = SunToolkit.getContainingWindow(getTarget());


1261             }
1262             delegateEvent = SwingUtilities.convertMouseEvent(getTarget(), me, eventTarget);
1263         } else if (e instanceof KeyEvent) {
1264             KeyEvent ke = (KeyEvent) e;
1265             delegateEvent = new KeyEvent(getDelegateFocusOwner(), ke.getID(), ke.getWhen(),
1266                     ke.getModifiers(), ke.getKeyCode(), ke.getKeyChar(), ke.getKeyLocation());
1267             AWTAccessor.getKeyEventAccessor().setExtendedKeyCode((KeyEvent) delegateEvent,
1268                     ke.getExtendedKeyCode());
1269         } else if (e instanceof FocusEvent) {
1270             FocusEvent fe = (FocusEvent) e;
1271             delegateEvent = new FocusEvent(getDelegateFocusOwner(), fe.getID(), fe.isTemporary());
1272         }
1273         return delegateEvent;
1274     }
1275 
1276     protected void handleJavaMouseEvent(MouseEvent e) {
1277         Component target = getTarget();
1278         assert (e.getSource() == target);
1279 
1280         if (!target.isFocusOwner() && LWKeyboardFocusManagerPeer.shouldFocusOnClick(target)) {
1281             LWKeyboardFocusManagerPeer.requestFocusFor(target, FocusEvent.Cause.MOUSE_EVENT);
1282         }
1283     }
1284 
1285     /**
1286      * Handler for FocusEvents.
1287      */
1288     void handleJavaFocusEvent(final FocusEvent e) {
1289         // Note that the peer receives all the FocusEvents from
1290         // its lightweight children as well
1291         KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance();
1292         kfmPeer.setCurrentFocusOwner(e.getID() == FocusEvent.FOCUS_GAINED ? getTarget() : null);
1293     }
1294 
1295     /**
1296      * All peers should clear background before paint.
1297      *
1298      * @return false on components that DO NOT require a clearRect() before
1299      *         painting.
1300      */
1301     protected final boolean shouldClearRectBeforePaint() {


< prev index next >