< prev index next >

src/java.desktop/macosx/classes/sun/lwawt/LWTextFieldPeer.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


 105     }
 106 
 107     /**
 108      * Restoring native behavior. We should sets the selection range to zero,
 109      * when component lost its focus.
 110      *
 111      * @param e the focus event
 112      */
 113     @Override
 114     void handleJavaFocusEvent(final FocusEvent e) {
 115         if (e.getID() == FocusEvent.FOCUS_LOST) {
 116             // In order to de-select the selection
 117             setCaretPosition(0);
 118         }
 119         super.handleJavaFocusEvent(e);
 120     }
 121 
 122     @SuppressWarnings("serial")// Safe: outer class is non-serializable.
 123     private final class JPasswordFieldDelegate extends JPasswordField {
 124 
 125         // Empty non private constructor was added because access to this
 126         // class shouldn't be emulated by a synthetic accessor method.
 127         JPasswordFieldDelegate() {
 128             super();
 129         }
 130 
 131         @Override
 132         public void replaceSelection(String content) {
 133             getDocument().removeDocumentListener(LWTextFieldPeer.this);
 134             super.replaceSelection(content);
 135             // post only one text event in this case
 136             postTextEvent();
 137             getDocument().addDocumentListener(LWTextFieldPeer.this);
 138         }
 139 
 140         @Override
 141         public boolean hasFocus() {
 142             return getTarget().hasFocus();
 143         }
 144 
 145         @Override
 146         public Point getLocationOnScreen() {
 147             return LWTextFieldPeer.this.getLocationOnScreen();
 148         }
 149     }
 150 }
   1 /*
   2  * Copyright (c) 2011, 2018, 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


 105     }
 106 
 107     /**
 108      * Restoring native behavior. We should sets the selection range to zero,
 109      * when component lost its focus.
 110      *
 111      * @param e the focus event
 112      */
 113     @Override
 114     void handleJavaFocusEvent(final FocusEvent e) {
 115         if (e.getID() == FocusEvent.FOCUS_LOST) {
 116             // In order to de-select the selection
 117             setCaretPosition(0);
 118         }
 119         super.handleJavaFocusEvent(e);
 120     }
 121 
 122     @SuppressWarnings("serial")// Safe: outer class is non-serializable.
 123     private final class JPasswordFieldDelegate extends JPasswordField {
 124 






 125         @Override
 126         public void replaceSelection(String content) {
 127             getDocument().removeDocumentListener(LWTextFieldPeer.this);
 128             super.replaceSelection(content);
 129             // post only one text event in this case
 130             postTextEvent();
 131             getDocument().addDocumentListener(LWTextFieldPeer.this);
 132         }
 133 
 134         @Override
 135         public boolean hasFocus() {
 136             return getTarget().hasFocus();
 137         }
 138 
 139         @Override
 140         public Point getLocationOnScreen() {
 141             return LWTextFieldPeer.this.getLocationOnScreen();
 142         }
 143     }
 144 }
< prev index next >