jdk/src/java.desktop/unix/classes/sun/awt/X11/XTextFieldPeer.java
author martin
Thu, 30 Oct 2014 07:31:41 -0700
changeset 28059 e576535359cc
parent 25859 3317bb8137f4
child 28236 610561ed1847
permissions -rw-r--r--
8067377: My hobby: caning, then then canning, the the can-can Summary: Fix ALL the stutters! Reviewed-by: rriggs, mchung, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23647
41d22f2dbeb5 8033712: Fix more serial lint warnings in sun.awt
darcy
parents: 20469
diff changeset
     2
 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.peer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.event.ActionEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.event.ActionListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.event.TextEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.event.DocumentListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.event.DocumentEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.swing.plaf.ComponentUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.swing.InputMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import javax.swing.JPasswordField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.swing.SwingUtilities;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.swing.TransferHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.awt.event.MouseEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.awt.event.FocusEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.awt.event.KeyEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.swing.plaf.UIResource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.swing.UIDefaults;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import javax.swing.JTextField;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import javax.swing.JComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import javax.swing.border.Border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import com.sun.java.swing.plaf.motif.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.awt.im.InputMethodRequests;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
    55
import sun.util.logging.PlatformLogger;
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
    56
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import sun.awt.CausedFocusEvent;
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 3938
diff changeset
    58
import sun.awt.AWTAccessor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
20435
543c1c7dd21a 7150100: [macosx] "0123456789" is selected in the TextField
serb
parents: 18178
diff changeset
    60
final class XTextFieldPeer extends XComponentPeer implements TextFieldPeer {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
    61
    private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XTextField");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
20435
543c1c7dd21a 7150100: [macosx] "0123456789" is selected in the TextField
serb
parents: 18178
diff changeset
    63
    private String text;
543c1c7dd21a 7150100: [macosx] "0123456789" is selected in the TextField
serb
parents: 18178
diff changeset
    64
    private final XAWTTextField xtext;
543c1c7dd21a 7150100: [macosx] "0123456789" is selected in the TextField
serb
parents: 18178
diff changeset
    65
    private final boolean firstChangeSkipped;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
20435
543c1c7dd21a 7150100: [macosx] "0123456789" is selected in the TextField
serb
parents: 18178
diff changeset
    67
    XTextFieldPeer(TextField target) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        super(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        text = target.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        xtext = new XAWTTextField(text,this, target.getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        xtext.getDocument().addDocumentListener(xtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        xtext.setCursor(target.getCursor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        XToolkit.specialPeerMap.put(xtext,this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        initTextField();
20435
543c1c7dd21a 7150100: [macosx] "0123456789" is selected in the TextField
serb
parents: 18178
diff changeset
    76
        setText(target.getText());
543c1c7dd21a 7150100: [macosx] "0123456789" is selected in the TextField
serb
parents: 18178
diff changeset
    77
        if (target.echoCharIsSet()) {
543c1c7dd21a 7150100: [macosx] "0123456789" is selected in the TextField
serb
parents: 18178
diff changeset
    78
            setEchoChar(target.getEchoChar());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        else setEchoChar((char)0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
20435
543c1c7dd21a 7150100: [macosx] "0123456789" is selected in the TextField
serb
parents: 18178
diff changeset
    82
        int start = target.getSelectionStart();
543c1c7dd21a 7150100: [macosx] "0123456789" is selected in the TextField
serb
parents: 18178
diff changeset
    83
        int end = target.getSelectionEnd();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        // Fix for 5100200
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        // Restoring Motif behaviour
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        // Since the end position of the selected text can be greater then the length of the text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        // so we should set caret to max position of the text
20435
543c1c7dd21a 7150100: [macosx] "0123456789" is selected in the TextField
serb
parents: 18178
diff changeset
    88
        setCaretPosition(Math.min(end, text.length()));
543c1c7dd21a 7150100: [macosx] "0123456789" is selected in the TextField
serb
parents: 18178
diff changeset
    89
        if (end > start) {
543c1c7dd21a 7150100: [macosx] "0123456789" is selected in the TextField
serb
parents: 18178
diff changeset
    90
            // Should be called after setText() and setCaretPosition()
543c1c7dd21a 7150100: [macosx] "0123456789" is selected in the TextField
serb
parents: 18178
diff changeset
    91
            select(start, end);
543c1c7dd21a 7150100: [macosx] "0123456789" is selected in the TextField
serb
parents: 18178
diff changeset
    92
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
20435
543c1c7dd21a 7150100: [macosx] "0123456789" is selected in the TextField
serb
parents: 18178
diff changeset
    94
        setEditable(target.isEditable());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        // After this line we should not change the component's text
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        firstChangeSkipped = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   100
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        XToolkit.specialPeerMap.remove(xtext);
12285
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents: 11979
diff changeset
   103
        // visible caret has a timer thread which must be stopped
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents: 11979
diff changeset
   104
        xtext.getCaret().setVisible(false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        xtext.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        super.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    void initTextField() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        setVisible(target.isVisible());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        setBounds(x, y, width, height, SET_BOUNDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 3938
diff changeset
   114
        AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 3938
diff changeset
   115
        foreground = compAccessor.getForeground(target);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        if (foreground == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            foreground = SystemColor.textText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        setForeground(foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 3938
diff changeset
   121
        background = compAccessor.getBackground(target);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        if (background == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            if (((TextField)target).isEditable()) background = SystemColor.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            else background = SystemColor.control;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        setBackground(background);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        if (!target.isBackgroundSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            // This is a way to set the background color of the TextArea
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 3938
diff changeset
   130
            // without calling setBackground - go through accessor
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 3938
diff changeset
   131
            compAccessor.setBackground(target, background);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        if (!target.isForegroundSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            target.setForeground(SystemColor.textText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        setFont(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     */
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   143
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    public void setEditable(boolean editable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        if (xtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            xtext.setEditable(editable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            xtext.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @see java.awt.peer.ComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   154
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public void setEnabled(boolean enabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        super.setEnabled(enabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        if (xtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            xtext.setEnabled(enabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            xtext.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     */
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   166
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public InputMethodRequests getInputMethodRequests() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        if (xtext != null) return xtext.getInputMethodRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        else  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   173
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    void handleJavaInputMethodEvent(InputMethodEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        if (xtext != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            xtext.processInputMethodEventImpl(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @see java.awt.peer.TextFieldPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     */
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   182
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public void setEchoChar(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if (xtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            xtext.setEchoChar(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            xtext.putClientProperty("JPasswordField.cutCopyAllowed",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                    xtext.echoCharIsSet() ? Boolean.FALSE : Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   194
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public int getSelectionStart() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        return xtext.getSelectionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   202
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public int getSelectionEnd() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        return xtext.getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   210
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    public String getText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        return xtext.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     */
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   218
    @Override
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   219
    public void setText(String text) {
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   220
        setXAWTTextField(text);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   224
    private void setXAWTTextField(String txt) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        text = txt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        if (xtext != null)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            // JTextField.setText() posts two different events (remove & insert).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            // Since we make no differences between text events,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            // the document listener has to be disabled while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            // JTextField.setText() is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            xtext.getDocument().removeDocumentListener(xtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            xtext.setText(txt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            if (firstChangeSkipped) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                postEvent(new TextEvent(target, TextEvent.TEXT_VALUE_CHANGED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            xtext.getDocument().addDocumentListener(xtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            xtext.setCaretPosition(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * to be implemented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   245
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public void setCaretPosition(int position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if (xtext != null) xtext.setCaretPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    void repaintText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        xtext.repaintNow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   254
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    public void setBackground(Color c) {
18178
ee71c923891d 8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents: 16839
diff changeset
   256
        if (log.isLoggable(PlatformLogger.Level.FINE)) {
16839
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   257
            log.fine("target="+ target + ", old=" + background + ", new=" + c);
d0f2e97b7359 8010297: Missing isLoggable() checks in logging code
anthony
parents: 13604
diff changeset
   258
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        background = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        if (xtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            xtext.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            xtext.setSelectedTextColor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        repaintText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   267
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        foreground = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        if (xtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            xtext.setForeground(foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            xtext.setSelectionColor(foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            xtext.setCaretColor(foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        repaintText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   278
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        synchronized (getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            font = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            if (xtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                xtext.setFont(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        xtext.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /**
28059
e576535359cc 8067377: My hobby: caning, then then canning, the the can-can
martin
parents: 25859
diff changeset
   290
     * Deselects the highlighted text.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    public void deselect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        int selStart=xtext.getSelectionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        int selEnd=xtext.getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        if (selStart != selEnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            xtext.select(selStart,selStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * to be implemented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     */
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   304
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    public int getCaretPosition() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        return xtext.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     */
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   312
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    public void select(int s, int e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        xtext.select(s,e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        // Fixed 5100806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        // We must take care that Swing components repainted correctly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        xtext.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   320
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        return xtext.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   325
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        return xtext.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   330
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    public Dimension getPreferredSize(int cols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        return getMinimumSize(cols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    private static final int PADDING = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   337
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    public Dimension getMinimumSize(int cols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        Font f = xtext.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        FontMetrics fm = xtext.getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        return new Dimension(fm.charWidth('0') * cols + 10,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                             fm.getMaxDescent() + fm.getMaxAscent() + PADDING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   345
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    public boolean isFocusable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    // NOTE: This method is called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    public void action(final long when, final int modifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        postEvent(new ActionEvent(target, ActionEvent.ACTION_PERFORMED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                                  text, when,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                                  modifiers));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    protected void disposeImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   361
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    public void repaint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        if (xtext  != null) xtext.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    }
10096
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
   365
    @Override
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
   366
    void paintPeer(final Graphics g) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        if (xtext  != null) xtext.paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   370
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    public void print(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        if (xtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            xtext.print(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   377
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        super.focusLost(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        xtext.forwardFocusLost(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   383
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        super.focusGained(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        xtext.forwardFocusGained(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   389
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    void handleJavaKeyEvent(KeyEvent e) {
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 3938
diff changeset
   391
        AWTAccessor.getComponentAccessor().processEvent(xtext,e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   395
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    public void handleJavaMouseEvent( MouseEvent mouseEvent ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        super.handleJavaMouseEvent(mouseEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        if (xtext != null)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            mouseEvent.setSource(xtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            int id = mouseEvent.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            if (id == MouseEvent.MOUSE_DRAGGED || id == MouseEvent.MOUSE_MOVED)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                xtext.processMouseMotionEventImpl(mouseEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                xtext.processMouseEventImpl(mouseEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * DEPRECATED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     */
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   411
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    public Dimension minimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        return getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   416
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    public void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        super.setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        if (xtext != null) xtext.setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   422
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    public void setBounds(int x, int y, int width, int height, int op) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        super.setBounds(x, y, width, height, op);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        if (xtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
             * Fixed 6277332, 6198290:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
             * the coordinates is coming (to peer): relatively to closest HW parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
             * the coordinates is setting (to textField): relatively to closest ANY parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
             * the parent of peer is target.getParent()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
             * the parent of textField is the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
             * see 6277332, 6198290 for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            int childX = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            int childY = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            Component parent = target.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            // we up to heavyweight parent in order to be sure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            // that the coordinates of the text pane is relatively to closest parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            while (parent.isLightweight()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                childX -= parent.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                childY -= parent.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                parent = parent.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            xtext.setBounds(childX,childY,width,height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            xtext.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   449
    final class AWTTextFieldUI extends MotifPasswordFieldUI {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   451
        private JTextField jtf;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   453
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        protected String getPropertyPrefix() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            JTextComponent comp = getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            if (comp instanceof JPasswordField && ((JPasswordField)comp).echoCharIsSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                return "PasswordField";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                return "TextField";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   463
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        public void installUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            super.installUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            jtf = (JTextField) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            JTextField editor = jtf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            UIDefaults uidefaults = XToolkit.getUIDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            String prefix = getPropertyPrefix();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            Font f = editor.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            if ((f == null) || (f instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                editor.setFont(uidefaults.getFont(prefix + ".font"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            Color bg = editor.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            if ((bg == null) || (bg instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                editor.setBackground(uidefaults.getColor(prefix + ".background"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            Color fg = editor.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            if ((fg == null) || (fg instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                editor.setForeground(uidefaults.getColor(prefix + ".foreground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            Color color = editor.getCaretColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            if ((color == null) || (color instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                editor.setCaretColor(uidefaults.getColor(prefix + ".caretForeground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            Color s = editor.getSelectionColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            if ((s == null) || (s instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                editor.setSelectionColor(uidefaults.getColor(prefix + ".selectionBackground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            Color sfg = editor.getSelectedTextColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            if ((sfg == null) || (sfg instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                editor.setSelectedTextColor(uidefaults.getColor(prefix + ".selectionForeground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            Color dfg = editor.getDisabledTextColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            if ((dfg == null) || (dfg instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                editor.setDisabledTextColor(uidefaults.getColor(prefix + ".inactiveForeground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            Border b = editor.getBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            if ((b == null) || (b instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                editor.setBorder(uidefaults.getBorder(prefix + ".border"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            Insets margin = editor.getMargin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            if (margin == null || margin instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                editor.setMargin(uidefaults.getInsets(prefix + ".margin"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   520
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        protected void installKeyboardActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            super.installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            JTextComponent comp = getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            UIDefaults uidefaults = XToolkit.getUIDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            String prefix = getPropertyPrefix();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            if (map != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                                                 map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   538
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        protected Caret createCaret() {
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents: 12285
diff changeset
   540
            return new XTextAreaPeer.XAWTCaret();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
23647
41d22f2dbeb5 8033712: Fix more serial lint warnings in sun.awt
darcy
parents: 20469
diff changeset
   544
    @SuppressWarnings("serial") // JDK-implementation class
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   545
    final class XAWTTextField extends JPasswordField
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   546
            implements ActionListener, DocumentListener {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   548
        private boolean isFocused = false;
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   549
        private final XComponentPeer peer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   551
        XAWTTextField(String text, XComponentPeer peer, Container parent) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            super(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            this.peer = peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            setDoubleBuffered(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            setFocusable(false);
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 3938
diff changeset
   556
            AWTAccessor.getComponentAccessor().setParent(this,parent);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            setBackground(peer.getPeerBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            setForeground(peer.getPeerForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            setFont(peer.getPeerFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            setCaretPosition(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   566
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        public void actionPerformed( ActionEvent actionEvent ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            peer.postEvent(new ActionEvent(peer.target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                                           ActionEvent.ACTION_PERFORMED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                                           getText(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                                           actionEvent.getWhen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                                           actionEvent.getModifiers()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   576
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        public void insertUpdate(DocumentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                peer.postEvent(new TextEvent(peer.target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                                             TextEvent.TEXT_VALUE_CHANGED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   584
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        public void removeUpdate(DocumentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                peer.postEvent(new TextEvent(peer.target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                                             TextEvent.TEXT_VALUE_CHANGED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   592
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        public void changedUpdate(DocumentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                peer.postEvent(new TextEvent(peer.target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                                             TextEvent.TEXT_VALUE_CHANGED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   600
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        public ComponentPeer getPeer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            return (ComponentPeer) peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        public void repaintNow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            paintImmediately(getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   609
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        public Graphics getGraphics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            return peer.getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   614
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            ComponentUI ui = new AWTTextFieldUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        void forwardFocusGained( FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            isFocused = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            FocusEvent fe = CausedFocusEvent.retarget(e, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            super.processFocusEvent(fe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        void forwardFocusLost( FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            isFocused = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            FocusEvent fe = CausedFocusEvent.retarget(e, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            super.processFocusEvent(fe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   633
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        public boolean hasFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            return isFocused;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        public void processInputMethodEventImpl(InputMethodEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            processInputMethodEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        public void processMouseEventImpl(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            processMouseEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        public void processMouseMotionEventImpl(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            processMouseMotionEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        // Fix for 4915454 - override the default implementation to avoid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        // loading SystemFlavorMap and associated classes.
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   652
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        public void setTransferHandler(TransferHandler newHandler) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            TransferHandler oldHandler = (TransferHandler)
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 12523
diff changeset
   655
                getClientProperty(AWTAccessor.getClientPropertyKeyAccessor()
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 12523
diff changeset
   656
                                      .getJComponent_TRANSFER_HANDLER());
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 12523
diff changeset
   657
            putClientProperty(AWTAccessor.getClientPropertyKeyAccessor()
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 12523
diff changeset
   658
                                  .getJComponent_TRANSFER_HANDLER(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                              newHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            firePropertyChange("transferHandler", oldHandler, newHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
20469
47a792bd7dbf 8025603: Unused methods in the awt text peers should be removed
serb
parents: 20435
diff changeset
   664
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        public void setEchoChar(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            super.setEchoChar(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            ((AWTTextFieldUI)ui).installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
}