jdk/src/solaris/classes/sun/awt/X11/XTextFieldPeer.java
author ant
Fri, 22 Feb 2013 15:13:13 +0400
changeset 15983 26a673dec5b2
parent 13604 31089af1a447
child 16839 d0f2e97b7359
permissions -rw-r--r--
8006406: lightweight embedding in other Java UI toolkits Reviewed-by: serb, anthony, art
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4371
diff changeset
     2
 * Copyright (c) 2003, 2007, 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
public 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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    String text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    XAWTTextField xtext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    boolean firstChangeSkipped;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    public XTextFieldPeer(TextField target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        super(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        int start, end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        firstChangeSkipped = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        text = target.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        xtext = new XAWTTextField(text,this, target.getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        xtext.getDocument().addDocumentListener(xtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        xtext.setCursor(target.getCursor());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        XToolkit.specialPeerMap.put(xtext,this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        TextField txt = (TextField) target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        initTextField();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        setText(txt.getText());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        if (txt.echoCharIsSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            setEchoChar(txt.getEchoChar());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        else setEchoChar((char)0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        start = txt.getSelectionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        end = txt.getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        if (end > start) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
            select(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        // Fix for 5100200
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        // Restoring Motif behaviour
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        // Since the end position of the selected text can be greater then the length of the text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        // so we should set caret to max position of the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        int caretPosition = Math.min(end, text.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        setCaretPosition(caretPosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        setEditable(txt.isEditable());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        // After this line we should not change the component's text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        firstChangeSkipped = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        XToolkit.specialPeerMap.remove(xtext);
12285
37f0c586ba99 7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents: 11979
diff changeset
   107
        // 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
   108
        xtext.getCaret().setVisible(false);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        xtext.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        super.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    void initTextField() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        setVisible(target.isVisible());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        setBounds(x, y, width, height, SET_BOUNDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 3938
diff changeset
   118
        AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 3938
diff changeset
   119
        foreground = compAccessor.getForeground(target);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (foreground == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            foreground = SystemColor.textText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        setForeground(foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 3938
diff changeset
   125
        background = compAccessor.getBackground(target);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        if (background == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            if (((TextField)target).isEditable()) background = SystemColor.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            else background = SystemColor.control;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        setBackground(background);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if (!target.isBackgroundSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            // 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
   134
            // without calling setBackground - go through accessor
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 3938
diff changeset
   135
            compAccessor.setBackground(target, background);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (!target.isForegroundSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            target.setForeground(SystemColor.textText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        setFont(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    public void setEditable(boolean editable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        if (xtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            xtext.setEditable(editable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            xtext.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @see java.awt.peer.ComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public void setEnabled(boolean enabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        super.setEnabled(enabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (xtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            xtext.setEnabled(enabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            xtext.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    public InputMethodRequests getInputMethodRequests() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        if (xtext != null) return xtext.getInputMethodRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        else  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    void handleJavaInputMethodEvent(InputMethodEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (xtext != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            xtext.processInputMethodEventImpl(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @see java.awt.peer.TextFieldPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public void setEchoChar(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        if (xtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            xtext.setEchoChar(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            xtext.putClientProperty("JPasswordField.cutCopyAllowed",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                    xtext.echoCharIsSet() ? Boolean.FALSE : Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    public int getSelectionStart() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        return xtext.getSelectionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
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
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public String getText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        return xtext.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public void setText(String txt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        setXAWTTextField(txt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    protected boolean setXAWTTextField(String txt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        text = txt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if (xtext != null)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            // JTextField.setText() posts two different events (remove & insert).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            // Since we make no differences between text events,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            // the document listener has to be disabled while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            // JTextField.setText() is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            xtext.getDocument().removeDocumentListener(xtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            xtext.setText(txt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            if (firstChangeSkipped) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                postEvent(new TextEvent(target, TextEvent.TEXT_VALUE_CHANGED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            xtext.getDocument().addDocumentListener(xtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            xtext.setCaretPosition(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        return true;
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
     * to be implemented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    public void setCaretPosition(int position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        if (xtext != null) xtext.setCaretPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * DEPRECATED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @see java.awt.peer.TextFieldPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    public void setEchoCharacter(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        setEchoChar(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    void repaintText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        xtext.repaintNow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    public void setBackground(Color c) {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2
diff changeset
   261
        if (log.isLoggable(PlatformLogger.FINE)) log.fine("target="+ target + ", old=" + background + ", new=" + c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        background = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if (xtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            xtext.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            xtext.setSelectedTextColor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        repaintText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        foreground = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        if (xtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            xtext.setForeground(foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            xtext.setSelectionColor(foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            xtext.setCaretColor(foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        repaintText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        synchronized (getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            font = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            if (xtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                xtext.setFont(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        xtext.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * DEPRECATED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @see java.awt.peer.TextFieldPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    public Dimension preferredSize(int cols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        return getPreferredSize(cols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * Deselects the the highlighted text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public void deselect() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        int selStart=xtext.getSelectionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        int selEnd=xtext.getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        if (selStart != selEnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            xtext.select(selStart,selStart);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * to be implemented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    public int getCaretPosition() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        return xtext.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    public void select(int s, int e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        xtext.select(s,e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        // Fixed 5100806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        // We must take care that Swing components repainted correctly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        xtext.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        return xtext.getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        return xtext.getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    public Dimension getPreferredSize(int cols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        return getMinimumSize(cols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    private static final int PADDING = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    public Dimension getMinimumSize(int cols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        Font f = xtext.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        FontMetrics fm = xtext.getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        return new Dimension(fm.charWidth('0') * cols + 10,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                             fm.getMaxDescent() + fm.getMaxAscent() + PADDING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    public boolean isFocusable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    // NOTE: This method is called by privileged threads.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    public void action(final long when, final int modifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        postEvent(new ActionEvent(target, ActionEvent.ACTION_PERFORMED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                                  text, when,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                                  modifiers));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    protected void disposeImpl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    public void repaint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        if (xtext  != null) xtext.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
10096
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
   373
    @Override
f9ac9a52952d 6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents: 5506
diff changeset
   374
    void paintPeer(final Graphics g) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        if (xtext  != null) xtext.paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    public void print(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        if (xtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            xtext.print(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        super.focusLost(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        xtext.forwardFocusLost(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        super.focusGained(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        xtext.forwardFocusGained(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    void handleJavaKeyEvent(KeyEvent e) {
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 3938
diff changeset
   395
        AWTAccessor.getComponentAccessor().processEvent(xtext,e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    public void handleJavaMouseEvent( MouseEvent mouseEvent ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        super.handleJavaMouseEvent(mouseEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        if (xtext != null)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            mouseEvent.setSource(xtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            int id = mouseEvent.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            if (id == MouseEvent.MOUSE_DRAGGED || id == MouseEvent.MOUSE_MOVED)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                xtext.processMouseMotionEventImpl(mouseEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                xtext.processMouseEventImpl(mouseEvent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * DEPRECATED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    public Dimension minimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        return getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * DEPRECATED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    public Dimension minimumSize(int cols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        return getMinimumSize(cols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    public void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        super.setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        if (xtext != null) xtext.setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    public void setBounds(int x, int y, int width, int height, int op) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        super.setBounds(x, y, width, height, op);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        if (xtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
             * Fixed 6277332, 6198290:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
             * the coordinates is coming (to peer): relatively to closest HW parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
             * the coordinates is setting (to textField): relatively to closest ANY parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
             * the parent of peer is target.getParent()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
             * the parent of textField is the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
             * see 6277332, 6198290 for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
            int childX = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            int childY = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            Component parent = target.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            // we up to heavyweight parent in order to be sure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            // that the coordinates of the text pane is relatively to closest parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            while (parent.isLightweight()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                childX -= parent.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                childY -= parent.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                parent = parent.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            xtext.setBounds(childX,childY,width,height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            xtext.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    // Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    // stub functions: to be fully implemented in a future release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    public int getIndexAtPoint(int x, int y) { return -1; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    public Rectangle getCharacterBounds(int i) { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    public long filterEvents(long mask) { return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    /*  To be fully implemented in a future release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        int oldSelectionStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        int oldSelectionEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        public native int getIndexAtPoint(int x, int y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        public native Rectangle getCharacterBounds(int i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        public native long filterEvents(long mask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
         * Handle a change in the text selection endpoints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
         * (Note: could be simply a change in the caret location)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
         public void selectionValuesChanged(int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
         return;  // Need to write implemetation of this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
         }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    class  AWTTextFieldUI extends MotifPasswordFieldUI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
         * Creates a UI for a JTextField.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
         * @param c the text field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
         * @return the UI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        JTextField jtf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        protected String getPropertyPrefix() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            JTextComponent comp = getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            if (comp instanceof JPasswordField && ((JPasswordField)comp).echoCharIsSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                return "PasswordField";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                return "TextField";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        public void installUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            super.installUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            jtf = (JTextField) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            JTextField editor = jtf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            UIDefaults uidefaults = XToolkit.getUIDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            String prefix = getPropertyPrefix();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            Font f = editor.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            if ((f == null) || (f instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                editor.setFont(uidefaults.getFont(prefix + ".font"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            Color bg = editor.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            if ((bg == null) || (bg instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                editor.setBackground(uidefaults.getColor(prefix + ".background"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            Color fg = editor.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            if ((fg == null) || (fg instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                editor.setForeground(uidefaults.getColor(prefix + ".foreground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            Color color = editor.getCaretColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            if ((color == null) || (color instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                editor.setCaretColor(uidefaults.getColor(prefix + ".caretForeground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            Color s = editor.getSelectionColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            if ((s == null) || (s instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                editor.setSelectionColor(uidefaults.getColor(prefix + ".selectionBackground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            Color sfg = editor.getSelectedTextColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            if ((sfg == null) || (sfg instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                editor.setSelectedTextColor(uidefaults.getColor(prefix + ".selectionForeground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            Color dfg = editor.getDisabledTextColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            if ((dfg == null) || (dfg instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                editor.setDisabledTextColor(uidefaults.getColor(prefix + ".inactiveForeground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            Border b = editor.getBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            if ((b == null) || (b instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                editor.setBorder(uidefaults.getBorder(prefix + ".border"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            Insets margin = editor.getMargin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            if (margin == null || margin instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                editor.setMargin(uidefaults.getInsets(prefix + ".margin"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        protected void installKeyboardActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            super.installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            JTextComponent comp = getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            UIDefaults uidefaults = XToolkit.getUIDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            String prefix = getPropertyPrefix();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            if (map != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                                                 map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        protected Caret createCaret() {
12523
a3c0565476da 7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents: 12285
diff changeset
   581
            return new XTextAreaPeer.XAWTCaret();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    class XAWTTextField extends JPasswordField
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        implements ActionListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                   DocumentListener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        boolean isFocused = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        XComponentPeer peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        public XAWTTextField(String text, XComponentPeer peer, Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            super(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            this.peer = peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            setDoubleBuffered(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            setFocusable(false);
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 3938
diff changeset
   599
            AWTAccessor.getComponentAccessor().setParent(this,parent);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            setBackground(peer.getPeerBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            setForeground(peer.getPeerForeground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            setFont(peer.getPeerFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            setCaretPosition(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            addActionListener(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        public void actionPerformed( ActionEvent actionEvent ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            peer.postEvent(new ActionEvent(peer.target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                                           ActionEvent.ACTION_PERFORMED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                                           getText(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                                           actionEvent.getWhen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                                           actionEvent.getModifiers()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        public void insertUpdate(DocumentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                peer.postEvent(new TextEvent(peer.target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                                             TextEvent.TEXT_VALUE_CHANGED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        public void removeUpdate(DocumentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                peer.postEvent(new TextEvent(peer.target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                                             TextEvent.TEXT_VALUE_CHANGED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        public void changedUpdate(DocumentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                peer.postEvent(new TextEvent(peer.target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                                             TextEvent.TEXT_VALUE_CHANGED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        public ComponentPeer getPeer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            return (ComponentPeer) peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        public void repaintNow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            paintImmediately(getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        public Graphics getGraphics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            return peer.getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            ComponentUI ui = new AWTTextFieldUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        void forwardFocusGained( FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
            isFocused = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            FocusEvent fe = CausedFocusEvent.retarget(e, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            super.processFocusEvent(fe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        void forwardFocusLost( FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            isFocused = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            FocusEvent fe = CausedFocusEvent.retarget(e, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            super.processFocusEvent(fe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        public boolean hasFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
            return isFocused;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        public void processInputMethodEventImpl(InputMethodEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            processInputMethodEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
        public void processMouseEventImpl(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            processMouseEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        public void processMouseMotionEventImpl(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
            processMouseMotionEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        // Fix for 4915454 - override the default implementation to avoid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        // loading SystemFlavorMap and associated classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        public void setTransferHandler(TransferHandler newHandler) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            TransferHandler oldHandler = (TransferHandler)
13604
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 12523
diff changeset
   694
                getClientProperty(AWTAccessor.getClientPropertyKeyAccessor()
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 12523
diff changeset
   695
                                      .getJComponent_TRANSFER_HANDLER());
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 12523
diff changeset
   696
            putClientProperty(AWTAccessor.getClientPropertyKeyAccessor()
31089af1a447 7163201: Simplify toolkit internals references
bagiras
parents: 12523
diff changeset
   697
                                  .getJComponent_TRANSFER_HANDLER(),
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                              newHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            firePropertyChange("transferHandler", oldHandler, newHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        public void setEchoChar(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            super.setEchoChar(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            ((AWTTextFieldUI)ui).installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
}