jdk/src/solaris/classes/sun/awt/X11/XTextAreaPeer.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8133 c7e4a02e928e
child 10095 daec42746ec0
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8133
diff changeset
     2
 * Copyright (c) 2003, 2011, 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.ComponentPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.peer.TextAreaPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.event.DocumentListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.event.DocumentEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.JTextArea;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.swing.JComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.swing.JScrollPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import javax.swing.JScrollBar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.swing.plaf.ComponentUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import com.sun.java.swing.plaf.motif.MotifTextAreaUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import javax.swing.plaf.UIResource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import javax.swing.UIDefaults;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import javax.swing.border.Border;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import javax.swing.border.EmptyBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import javax.swing.border.CompoundBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import javax.swing.border.AbstractBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import javax.swing.JButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.swing.JViewport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.swing.InputMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import javax.swing.SwingUtilities;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import javax.swing.TransferHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import javax.swing.plaf.basic.BasicArrowButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import javax.swing.plaf.basic.BasicScrollBarUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import javax.swing.plaf.basic.BasicScrollPaneUI;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.beans.PropertyChangeEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import java.beans.PropertyChangeListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import javax.swing.text.Caret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import javax.swing.text.DefaultCaret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import javax.swing.text.JTextComponent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import javax.swing.plaf.BorderUIResource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import java.awt.im.InputMethodRequests;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import sun.awt.CausedFocusEvent;
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 2
diff changeset
    63
import sun.awt.AWTAccessor;
6826
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
    64
import sun.awt.SunToolkit;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
class XTextAreaPeer extends XComponentPeer implements TextAreaPeer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    boolean editable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    AWTTextPane textPane;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    AWTTextArea jtext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    boolean firstChangeSkipped;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    private final JavaMouseEventHandler javaMouseEventHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        = new JavaMouseEventHandler( this );
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /* FIXME  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    public long filterEvents(long mask) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        Thread.dumpStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /* FIXME   */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public Rectangle getCharacterBounds(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        Thread.dumpStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    public int getIndexAtPoint(int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        Thread.dumpStack();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Create a Text area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    XTextAreaPeer(TextArea target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        super( target  );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        // some initializations require that target be set even
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        // though init(target) has not been called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        this.target = target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        //ComponentAccessor.enableEvents(target,AWTEvent.MOUSE_WHEEL_EVENT_MASK);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        target.enableInputMethods(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        firstChangeSkipped = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        String text = ((TextArea)target).getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        jtext = new AWTTextArea(text, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        jtext.setWrapStyleWord(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        jtext.getDocument().addDocumentListener(jtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        XToolkit.specialPeerMap.put(jtext,this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        jtext.enableInputMethods(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        textPane = new AWTTextPane(jtext,this, target.getParent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        setBounds(x, y, width, height, SET_BOUNDS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        textPane.setVisible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        textPane.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 2
diff changeset
   123
        AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor();
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 2
diff changeset
   124
        foreground = compAccessor.getForeground(target);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        if (foreground == null)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            foreground = SystemColor.textText;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        setForeground(foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 2
diff changeset
   130
        background = compAccessor.getBackground(target);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        if (background == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            if (target.isEditable()) background = SystemColor.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            else background = SystemColor.control;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        setBackground(background);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (!target.isBackgroundSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            // This is a way to set the background color of the TextArea
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 2
diff changeset
   139
            // without calling setBackground - go through accessor
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 2
diff changeset
   140
            compAccessor.setBackground(target, background);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        if (!target.isForegroundSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            target.setForeground(SystemColor.textText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        setFont(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        int start = target.getSelectionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        int end = target.getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        if (end > start) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            select(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        // Fix for 5100200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        // Restoring Motif behaviour
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        // Since the end position of the selected text can be greater then the length of the text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        // so we should set caret to max position of the text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        int caretPosition = Math.min(end, text.length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        setCaretPosition(caretPosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        setEditable(target.isEditable());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        setScrollBarVisibility();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        // set the text of this object to the text of its target
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        setTextImpl(target.getText());  //?? should this be setText
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        // After this line we should not change the component's text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        firstChangeSkipped = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public void dispose() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        XToolkit.specialPeerMap.remove(jtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        jtext.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        textPane.removeNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        super.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
8133
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   178
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   179
    /*
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   180
     * The method overrides one from XComponentPeer
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   181
     * If ignoreSubComponents=={@code true} it calls super.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   182
     * If ignoreSubComponents=={@code false} it uses the XTextArea machinery
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   183
     * to change cursor appropriately. In particular it changes the cursor to
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   184
     * default if over scrollbars.
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   185
     */
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   186
    @Override
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   187
    public void pSetCursor(Cursor cursor, boolean ignoreSubComponents) {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   188
        Point onScreen = getLocationOnScreen();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   189
        if (ignoreSubComponents ||
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   190
            javaMouseEventHandler == null ||
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   191
            onScreen == null)
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   192
        {
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   193
            super.pSetCursor(cursor, true);
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   194
            return;
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   195
        }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   196
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   197
        Point cursorPos = new Point();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   198
        ((XGlobalCursorManager)XGlobalCursorManager.getCursorManager()).getCursorPos(cursorPos);
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   199
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   200
        Point localPoint = new Point(cursorPos.x - onScreen.x, cursorPos.y - onScreen.y );
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   201
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   202
        javaMouseEventHandler.setPointerToUnderPoint(localPoint);
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   203
        javaMouseEventHandler.setCursor();
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   204
    }
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
   205
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    void setScrollBarVisibility() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        int visibility = ((TextArea)target).getScrollbarVisibility();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        jtext.setLineWrap(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (visibility == TextArea.SCROLLBARS_NONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            textPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            textPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            jtext.setLineWrap(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        else if (visibility == TextArea.SCROLLBARS_BOTH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            textPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            textPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        else if (visibility == TextArea.SCROLLBARS_VERTICAL_ONLY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            textPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            textPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            jtext.setLineWrap(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        else if (visibility == TextArea.SCROLLBARS_HORIZONTAL_ONLY) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            textPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            textPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Compute minimum size.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        return getMinimumSize(10, 60);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public Dimension getPreferredSize(int rows, int cols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        return getMinimumSize(rows, cols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @see java.awt.peer.TextAreaPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public Dimension getMinimumSize(int rows, int cols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        /*    Dimension d = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
              if (jtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
              d = jtext.getMinimumSize(rows,cols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
              }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
              return d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        int vsbwidth=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        int hsbheight=0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        JScrollBar vsb = textPane.getVerticalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        if (vsb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            vsbwidth = vsb.getMinimumSize().width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        JScrollBar hsb = textPane.getHorizontalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if (hsb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            hsbheight = hsb.getMinimumSize().height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        Font f = jtext.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        FontMetrics fm = jtext.getFontMetrics(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        return new Dimension(fm.charWidth('0') * cols + /*2*XMARGIN +*/ vsbwidth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                             fm.getHeight() * rows + /*2*YMARGIN +*/ hsbheight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    public boolean isFocusable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    public void setVisible(boolean b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        super.setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        if (textPane != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            textPane.setVisible(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    void repaintText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        jtext.repaintNow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        super.focusGained(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        jtext.forwardFocusGained(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        super.focusLost(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        jtext.forwardFocusLost(e);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * Paint the component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * this method is called when the repaint instruction has been used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    public void repaint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        if (textPane  != null)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            //textPane.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            textPane.repaint();
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
    public void paint(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        if (textPane  != null)  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            textPane.paint(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public void setBounds(int x, int y, int width, int height, int op) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        super.setBounds(x, y, width, height, op);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        if (textPane != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
             * Fixed 6277332, 6198290:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
             * the coordinates is coming (to peer): relatively to closest HW parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
             * the coordinates is setting (to textPane): relatively to closest ANY parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
             * the parent of peer is target.getParent()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
             * the parent of textPane is the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
             * see 6277332, 6198290 for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            int childX = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            int childY = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            Component parent = target.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            // we up to heavyweight parent in order to be sure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            // that the coordinates of the text pane is relatively to closest parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            while (parent.isLightweight()){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                childX -= parent.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                childY -= parent.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                parent = parent.getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            textPane.setBounds(childX,childY,width,height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            textPane.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    void handleJavaKeyEvent(KeyEvent e) {
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 2
diff changeset
   344
        AWTAccessor.getComponentAccessor().processEvent(jtext,e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    public boolean handlesWheelScrolling() { return true; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    void handleJavaMouseWheelEvent(MouseWheelEvent e) {
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 2
diff changeset
   350
        AWTAccessor.getComponentAccessor().processEvent(textPane,e);
2
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 void handleJavaMouseEvent( MouseEvent e ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        super.handleJavaMouseEvent( e );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        javaMouseEventHandler.handle( e );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    void handleJavaInputMethodEvent(InputMethodEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        if (jtext != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            jtext.processInputMethodEventPublic((InputMethodEvent)e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    public void select(int s, int e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        jtext.select(s,e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        // Fixed 5100806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        // We must take care that Swing components repainted correctly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        jtext.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        super.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
//          synchronized (getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
//              background = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
//          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        if (jtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            jtext.setBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            jtext.setSelectedTextColor(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
//          repaintText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        super.setForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
//          synchronized (getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
//              foreground = c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
//          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        if (jtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            jtext.setForeground(foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            jtext.setSelectionColor(foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            jtext.setCaretColor(foreground);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
//          repaintText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    public void setFont(Font f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        super.setFont(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
//          synchronized (getStateLock()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
//              font = f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
//          }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        if (jtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            jtext.setFont(font);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        textPane.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    }
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
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public void setEditable(boolean editable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        this.editable = editable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        if (jtext != null) jtext.setEditable(editable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        repaintText();
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
     * @see java.awt.peer.ComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    public void setEnabled(boolean enabled) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        super.setEnabled(enabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        if (jtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            jtext.setEnabled(enabled);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            jtext.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    public InputMethodRequests getInputMethodRequests() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        if (jtext != null) return jtext.getInputMethodRequests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        else  return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    public int getSelectionStart() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        return jtext.getSelectionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    public int getSelectionEnd() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        return jtext.getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    public String getText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        return jtext.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    public void setText(String txt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        setTextImpl(txt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        repaintText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    protected boolean setTextImpl(String txt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        if (jtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            // Please note that we do not want to post an event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            // if setText() replaces an empty text by an empty text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            // that is, if component's text remains unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            if (jtext.getDocument().getLength() == 0 && txt.length() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            // JTextArea.setText() posts two different events (remove & insert).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            // Since we make no differences between text events,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            // the document listener has to be disabled while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            // JTextArea.setText() is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            jtext.getDocument().removeDocumentListener(jtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            jtext.setText(txt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            if (firstChangeSkipped) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                postEvent(new TextEvent(target, TextEvent.TEXT_VALUE_CHANGED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            jtext.getDocument().addDocumentListener(jtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * insert the text "txt on position "pos" in the array lines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * @see java.awt.peer.TextAreaPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    public void insert(String txt, int p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        if (jtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            boolean doScroll = (p >= jtext.getDocument().getLength() && jtext.getDocument().getLength() != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            jtext.insert(txt,p);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            textPane.validate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            if (doScroll) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                JScrollBar bar = textPane.getVerticalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                if (bar != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                    bar.setValue(bar.getMaximum()-bar.getVisibleAmount());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                }
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * replace the text between the position "s" and "e" with "txt"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * @see java.awt.peer.TextAreaPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    public void replaceRange(String txt, int s, int e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        if (jtext != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            // JTextArea.replaceRange() posts two different events.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            // Since we make no differences between text events,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            // the document listener has to be disabled while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            // JTextArea.replaceRange() is called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            jtext.getDocument().removeDocumentListener(jtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            jtext.replaceRange(txt, s, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            postEvent(new TextEvent(target, TextEvent.TEXT_VALUE_CHANGED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            jtext.getDocument().addDocumentListener(jtext);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * to be implemented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    public void setCaretPosition(int position) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        jtext.setCaretPosition(position);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * to be implemented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * @see java.awt.peer.TextComponentPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    public int getCaretPosition() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        return jtext.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * DEPRECATED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * @see java.awt.peer.TextAreaPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    public void insertText(String txt, int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        insert(txt, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * DEPRECATED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * @see java.awt.peer.TextAreaPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    public void replaceText(String txt, int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        replaceRange(txt, start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     * DEPRECATED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * @see java.awt.peer.TextAreaPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    public Dimension minimumSize(int rows, int cols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        return getMinimumSize(rows, cols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * DEPRECATED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * @see java.awt.peer.TextAreaPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    public Dimension preferredSize(int rows, int cols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        return getPreferredSize(rows, cols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    class  AWTTextAreaUI extends MotifTextAreaUI {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
         * Creates a UI for a JTextArea.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
         * @param c the text field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
         * @return the UI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        JTextArea jta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        protected String getPropertyPrefix() { return "TextArea"; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        public void installUI(JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            super.installUI(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            jta = (JTextArea) c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            JTextArea editor = jta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            UIDefaults uidefaults = XToolkit.getUIDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            String prefix = getPropertyPrefix();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            Font f = editor.getFont();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            if ((f == null) || (f instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                editor.setFont(uidefaults.getFont(prefix + ".font"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            Color bg = editor.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            if ((bg == null) || (bg instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                editor.setBackground(uidefaults.getColor(prefix + ".background"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            Color fg = editor.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            if ((fg == null) || (fg instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                editor.setForeground(uidefaults.getColor(prefix + ".foreground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            Color color = editor.getCaretColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            if ((color == null) || (color instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                editor.setCaretColor(uidefaults.getColor(prefix + ".caretForeground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            Color s = editor.getSelectionColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            if ((s == null) || (s instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                editor.setSelectionColor(uidefaults.getColor(prefix + ".selectionBackground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            Color sfg = editor.getSelectedTextColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            if ((sfg == null) || (sfg instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                editor.setSelectedTextColor(uidefaults.getColor(prefix + ".selectionForeground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            Color dfg = editor.getDisabledTextColor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            if ((dfg == null) || (dfg instanceof UIResource)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                editor.setDisabledTextColor(uidefaults.getColor(prefix + ".inactiveForeground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            Border b = new BevelBorder(false,SystemColor.controlDkShadow,SystemColor.controlLtHighlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            editor.setBorder(new BorderUIResource.CompoundBorderUIResource(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                b,new EmptyBorder(2, 2, 2, 2)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            Insets margin = editor.getMargin();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            if (margin == null || margin instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                editor.setMargin(uidefaults.getInsets(prefix + ".margin"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        protected void installKeyboardActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            super.installKeyboardActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
            JTextComponent comp = getComponent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            UIDefaults uidefaults = XToolkit.getUIDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            String prefix = getPropertyPrefix();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            if (map != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
                SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                                                 map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        protected Caret createCaret() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            return new XAWTCaret();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    // TODO : fix this duplicate code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    class XAWTCaret extends DefaultCaret {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            super.focusGained(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
            getComponent().repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
            super.focusLost(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            getComponent().repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
        // Fix for 5100950: textarea.getSelectedText() returns the de-selected text, on XToolkit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
        // Restoring Motif behaviour
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        // If the text is unhighlighted then we should sets the selection range to zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
        public void setSelectionVisible(boolean vis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
            if (vis){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                super.setSelectionVisible(vis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
            }else{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                // In order to de-select the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                setDot(getDot());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    class XAWTScrollBarButton extends BasicArrowButton
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        UIDefaults uidefaults = XToolkit.getUIDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        private Color darkShadow = SystemColor.controlShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
        private Color lightShadow = SystemColor.controlLtHighlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        private Color buttonBack = uidefaults.getColor("ScrollBar.track");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        public XAWTScrollBarButton(int direction)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            super(direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            switch (direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            case NORTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            case SOUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
            case EAST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
            case WEST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                this.direction = direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                throw new IllegalArgumentException("invalid direction");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
            setRequestFocusEnabled(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            setOpaque(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
            setBackground(uidefaults.getColor("ScrollBar.thumb"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
            setForeground(uidefaults.getColor("ScrollBar.foreground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        public Dimension getPreferredSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            switch (direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            case NORTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            case SOUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
                return new Dimension(11, 12);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            case EAST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            case WEST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                return new Dimension(12, 11);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            return getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        public Dimension getMaximumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            return getPreferredSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        public boolean isFocusTraversable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        public void paint(Graphics g)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            int w = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
            int h = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            if (isOpaque()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                g.setColor(buttonBack);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                g.fillRect(0, 0, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            boolean isPressed = getModel().isPressed();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            Color lead = (isPressed) ? darkShadow : lightShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            Color trail = (isPressed) ? lightShadow : darkShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            Color fill = getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            int cx = w / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            int cy = h / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            int s = Math.min(w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            switch (direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            case NORTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
                g.setColor(lead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                g.drawLine(cx, 0, cx, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
                for (int x = cx - 1, y = 1, dx = 1; y <= s - 2; y += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
                    g.setColor(lead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
                    g.drawLine(x, y, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
                    if (y >= (s - 2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                        g.drawLine(x, y + 1, x, y + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                    g.setColor(fill);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
                    g.drawLine(x + 1, y, x + dx, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                    if (y < (s - 2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
                        g.drawLine(x, y + 1, x + dx + 1, y + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
                    g.setColor(trail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                    g.drawLine(x + dx + 1, y, x + dx + 1, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
                    if (y >= (s - 2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                        g.drawLine(x + 1, y + 1, x + dx + 1, y + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                    dx += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                    x -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            case SOUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                g.setColor(trail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                g.drawLine(cx, s, cx, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                for (int x = cx - 1, y = s - 1, dx = 1; y >= 1; y -= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                    g.setColor(lead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                    g.drawLine(x, y, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                    if (y <= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                        g.drawLine(x, y - 1, x + dx + 1, y - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                    g.setColor(fill);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
                    g.drawLine(x + 1, y, x + dx, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                    if (y > 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
                        g.drawLine(x, y - 1, x + dx + 1, y - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
                    g.setColor(trail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
                    g.drawLine(x + dx + 1, y, x + dx + 1, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
                    dx += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
                    x -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            case EAST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                g.setColor(lead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
                g.drawLine(s, cy, s, cy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                for (int y = cy - 1, x = s - 1, dy = 1; x >= 1; x -= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
                    g.setColor(lead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                    g.drawLine(x, y, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
                    if (x <= 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                        g.drawLine(x - 1, y, x - 1, y + dy + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                    g.setColor(fill);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
                    g.drawLine(x, y + 1, x, y + dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
                    if (x > 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
                        g.drawLine(x - 1, y, x - 1, y + dy + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
                    g.setColor(trail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
                    g.drawLine(x, y + dy + 1, x, y + dy + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                    dy += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
                    y -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            case WEST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                g.setColor(trail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
                g.drawLine(0, cy, 0, cy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                for (int y = cy - 1, x = 1, dy = 1; x <= s - 2; x += 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
                    g.setColor(lead);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                    g.drawLine(x, y, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
                    if (x >= (s - 2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                        g.drawLine(x + 1, y, x + 1, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                    g.setColor(fill);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
                    g.drawLine(x, y + 1, x, y + dy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                    if (x < (s - 2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
                        g.drawLine(x + 1, y, x + 1, y + dy + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
                    g.setColor(trail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
                    g.drawLine(x, y + dy + 1, x, y + dy + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
                    if (x >= (s - 2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
                        g.drawLine(x + 1, y + 1, x + 1, y + dy + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
                    dy += 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
                    y -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
    class XAWTScrollBarUI extends BasicScrollBarUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        public XAWTScrollBarUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
            super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
        protected void installDefaults()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            super.installDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            scrollbar.setBorder(new BevelBorder(false,SystemColor.controlDkShadow,SystemColor.controlLtHighlight) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        protected void configureScrollBarColors() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
            UIDefaults uidefaults = XToolkit.getUIDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
            Color bg = scrollbar.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            if (bg == null || bg instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                scrollbar.setBackground(uidefaults.getColor("ScrollBar.background"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
            Color fg = scrollbar.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
            if (fg == null || fg instanceof UIResource) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                scrollbar.setForeground(uidefaults.getColor("ScrollBar.foreground"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
            thumbHighlightColor = uidefaults.getColor("ScrollBar.thumbHighlight");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            thumbLightShadowColor = uidefaults.getColor("ScrollBar.thumbShadow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
            thumbDarkShadowColor = uidefaults.getColor("ScrollBar.thumbDarkShadow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            thumbColor = uidefaults.getColor("ScrollBar.thumb");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
            trackColor = uidefaults.getColor("ScrollBar.track");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            trackHighlightColor = uidefaults.getColor("ScrollBar.trackHighlight");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        protected JButton createDecreaseButton(int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            JButton b = new XAWTScrollBarButton(orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        protected JButton createIncreaseButton(int orientation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            JButton b = new XAWTScrollBarButton(orientation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            return b;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        public JButton getDecreaseButton(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            return decrButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        public JButton getIncreaseButton(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            return incrButton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            paintTrack(g, c, getTrackBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            Rectangle thumbBounds = getThumbBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            paintThumb(g, c, thumbBounds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        public void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            if(!scrollbar.isEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            if (thumbBounds.isEmpty())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                thumbBounds = getTrackBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            int w = thumbBounds.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
            int h = thumbBounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            g.translate(thumbBounds.x, thumbBounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            g.setColor(thumbColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            g.fillRect(0, 0, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            g.setColor(thumbHighlightColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            g.drawLine(0, 0, 0, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            g.drawLine(1, 0, w-1, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            g.setColor(thumbLightShadowColor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            g.drawLine(1, h-1, w-1, h-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
            g.drawLine(w-1, 1, w-1, h-2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            g.translate(-thumbBounds.x, -thumbBounds.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    class AWTTextArea extends JTextArea implements DocumentListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        boolean isFocused = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        XTextAreaPeer peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
        public AWTTextArea(String text, XTextAreaPeer peer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            super(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
            setFocusable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
            this.peer = peer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        public void insertUpdate(DocumentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                peer.postEvent(new TextEvent(peer.target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                                             TextEvent.TEXT_VALUE_CHANGED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        public void removeUpdate(DocumentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                peer.postEvent(new TextEvent(peer.target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                                             TextEvent.TEXT_VALUE_CHANGED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        public void changedUpdate(DocumentEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            if (peer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                peer.postEvent(new TextEvent(peer.target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                                             TextEvent.TEXT_VALUE_CHANGED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        void forwardFocusGained( FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
            isFocused = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            FocusEvent fe = CausedFocusEvent.retarget(e, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            super.processFocusEvent(fe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
        void forwardFocusLost( FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            isFocused = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            FocusEvent fe = CausedFocusEvent.retarget(e, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
            super.processFocusEvent(fe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        public boolean hasFocus() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            return isFocused;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        public void repaintNow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            paintImmediately(getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        public void processMouseEventPublic(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
            processMouseEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        public void processMouseMotionEventPublic(MouseEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            processMouseMotionEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
        public void processInputMethodEventPublic(InputMethodEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            processInputMethodEvent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            ComponentUI ui = new AWTTextAreaUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
            setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        // Fix for 4915454 - override the default implementation to avoid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
        // loading SystemFlavorMap and associated classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        public void setTransferHandler(TransferHandler newHandler) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            TransferHandler oldHandler = (TransferHandler)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
                getClientProperty(XTextTransferHelper.getTransferHandlerKey());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            putClientProperty(XTextTransferHelper.getTransferHandlerKey(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                              newHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
            firePropertyChange("transferHandler", oldHandler, newHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
    class XAWTScrollPaneUI extends BasicScrollPaneUI
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        private final Border vsbMarginBorderR = new EmptyBorder(0, 2, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        private final Border vsbMarginBorderL = new EmptyBorder(0, 0, 0, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        private final Border hsbMarginBorder = new EmptyBorder(2, 0, 0, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        private Border vsbBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        private Border hsbBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        private PropertyChangeListener propertyChangeHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        protected void installListeners(JScrollPane scrollPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            super.installListeners(scrollPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
            propertyChangeHandler = createPropertyChangeHandler();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            scrollPane.addPropertyChangeListener(propertyChangeHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        public void paint(Graphics g, JComponent c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            Border vpBorder = scrollpane.getViewportBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            if (vpBorder != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                Rectangle r = scrollpane.getViewportBorderBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                vpBorder.paintBorder(scrollpane, g, r.x, r.y, r.width, r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        protected void uninstallListeners(JScrollPane scrollPane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
            super.uninstallListeners(scrollPane);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            scrollPane.removePropertyChangeListener(propertyChangeHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        private PropertyChangeListener createPropertyChangeHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            return new PropertyChangeListener() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                    public void propertyChange(PropertyChangeEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                        String propertyName = e.getPropertyName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                        if (propertyName.equals("componentOrientation")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                            JScrollPane pane = (JScrollPane)e.getSource();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                            JScrollBar vsb = pane.getVerticalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                            if (vsb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                                if (isLeftToRight(pane)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                                    vsbBorder = new CompoundBorder(new EmptyBorder(0, 4, 0, -4),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                                                                   vsb.getBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                                    vsbBorder = new CompoundBorder(new EmptyBorder(0, -4, 0, 4),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                                                                   vsb.getBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                                vsb.setBorder(vsbBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                    }};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        boolean isLeftToRight( Component c ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            return c.getComponentOrientation().isLeftToRight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        protected void installDefaults(JScrollPane scrollpane) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
            Border b = scrollpane.getBorder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            UIDefaults uidefaults = XToolkit.getUIDefaults();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            scrollpane.setBorder(uidefaults.getBorder("ScrollPane.border"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
            scrollpane.setBackground(uidefaults.getColor("ScrollPane.background"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            scrollpane.setViewportBorder(uidefaults.getBorder("TextField.border"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
            JScrollBar vsb = scrollpane.getVerticalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            if (vsb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                if (isLeftToRight(scrollpane)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                    vsbBorder = new CompoundBorder(vsbMarginBorderR,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                                                   vsb.getBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                    vsbBorder = new CompoundBorder(vsbMarginBorderL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                                                   vsb.getBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                vsb.setBorder(vsbBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
            JScrollBar hsb = scrollpane.getHorizontalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            if (hsb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                hsbBorder = new CompoundBorder(hsbMarginBorder, hsb.getBorder());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                hsb.setBorder(hsbBorder);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        protected void uninstallDefaults(JScrollPane c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            super.uninstallDefaults(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            JScrollBar vsb = scrollpane.getVerticalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
            if (vsb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                if (vsb.getBorder() == vsbBorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                    vsb.setBorder(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                vsbBorder = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            JScrollBar hsb = scrollpane.getHorizontalScrollBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
            if (hsb != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                if (hsb.getBorder() == hsbBorder) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                    hsb.setBorder(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                hsbBorder = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
    private class AWTTextPane extends JScrollPane implements FocusListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        JTextArea jtext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        XWindow xwin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        Color control = SystemColor.control;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        Color focus = SystemColor.activeCaptionBorder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        public AWTTextPane(JTextArea jt, XWindow xwin, Container parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
            super(jt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
            this.xwin = xwin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            setDoubleBuffered(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            jt.addFocusListener(this);
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 2
diff changeset
  1144
            AWTAccessor.getComponentAccessor().setParent(this,parent);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
            setViewportBorder(new BevelBorder(false,SystemColor.controlDkShadow,SystemColor.controlLtHighlight) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            this.jtext = jt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            setFocusable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            addNotify();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        public void focusGained(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            Graphics g = getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            Rectangle r = getViewportBorderBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
            g.setColor(focus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
            g.drawRect(r.x,r.y,r.width,r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
            g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        public void focusLost(FocusEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
            Graphics g = getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            Rectangle r = getViewportBorderBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            g.setColor(control);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
            g.drawRect(r.x,r.y,r.width,r.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            g.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        public Window getRealParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            return (Window) xwin.target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        public ComponentPeer getPeer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
            return (ComponentPeer) (xwin);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
        public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            ComponentUI ui = new XAWTScrollPaneUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        public JScrollBar createVerticalScrollBar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
            return new XAWTScrollBar(JScrollBar.VERTICAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        public JScrollBar createHorizontalScrollBar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
            return new XAWTScrollBar(JScrollBar.HORIZONTAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        public JTextArea getTextArea () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
            return this.jtext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
        public Graphics getGraphics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
            return xwin.getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        class XAWTScrollBar extends ScrollBar {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
            public XAWTScrollBar(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                super(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                setFocusable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
            public void updateUI() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
                ComponentUI ui = new XAWTScrollBarUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
                setUI(ui);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
    static class BevelBorder extends AbstractBorder implements UIResource {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        private Color darkShadow = SystemColor.controlDkShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        private Color lightShadow = SystemColor.controlLtHighlight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        private Color control = SystemColor.controlShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        private boolean isRaised;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        public BevelBorder(boolean isRaised, Color darkShadow, Color lightShadow) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            this.isRaised = isRaised;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            this.darkShadow = darkShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
            this.lightShadow = lightShadow;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            g.setColor((isRaised) ? lightShadow : darkShadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
            g.drawLine(x, y, x+w-1, y);           // top
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
            g.drawLine(x, y+h-1, x, y+1);         // left
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
            g.setColor(control);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
            g.drawLine(x+1, y+1, x+w-2, y+1);           // top
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
            g.drawLine(x+1, y+h-1, x+1, y+1);         // left
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
            g.setColor((isRaised) ? darkShadow : lightShadow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
            g.drawLine(x+1, y+h-1, x+w-1, y+h-1); // bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
            g.drawLine(x+w-1, y+h-1, x+w-1, y+1); // right
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
            g.setColor(control);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
            g.drawLine(x+1, y+h-2, x+w-2, y+h-2); // bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
            g.drawLine(x+w-2, y+h-2, x+w-2, y+1); // right
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        public Insets getBorderInsets(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
            return getBorderInsets(c, new Insets(0,0,0,0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        public Insets getBorderInsets(Component c, Insets insets) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            insets.top = insets.left = insets.bottom = insets.right = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
            return insets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        public boolean isOpaque(Component c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
    // This class dispatches 'MouseEvent's to 'XTextAreaPeer''s (hidden)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
    // subcomponents, and overrides mouse cursor, e.g. for scrollbars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
    // However, current dispatching is a kind of fake, and is tuned to do only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
    // what is necessary/possible. E.g. no additional mouse-exited/entered
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
    // events are generated, when mouse exits scrollbar and enters viewport
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
    // with JTextArea inside. Actually, no events are ever generated here (for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
    // now). They are only dispatched as correctly as possible/neccessary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
    // In future, it would be better to replace fake-emulation of grab-detection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    // and event-dispatching here, by reusing some common implementation of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
    // functionality. Mouse-cursor setting should also be freed of hacked
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    // overloading here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
    private static final class JavaMouseEventHandler {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        private final XTextAreaPeer outer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        private final Pointer current = new Pointer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        private boolean grabbed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
        JavaMouseEventHandler( XTextAreaPeer outer ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
            this.outer = outer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
        // 1. We can make grab-tracking emulation here more robust to variations in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        //    in mouse-events order and consistence. E.g. by using such code:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        //    if( grabbed && event.getID()==MouseEvent.MOUSE_MOVED ) grabbed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        //    Or we can also use 'assert'ions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
        // 2. WARNING: Currently, while grab-detection mechanism _here_ says, that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        //    grab is in progress, we do not update 'current'.  In case 'current'
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        //    is set to a scrollbar or to a scroll-button, then references to their
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        //    'Component'-instances are "remembered". And events are dispatched to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        //    these remembered components, without checking, if XTextAreaPeer has
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        //    replaced these instances with another ones. This also aplies to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
        //    mouse-drags-from-outside (see comment in 'grabbed_update' method).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
        void handle( MouseEvent event ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
            if ( ! grabbed ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                // dispatch() needs up-to-date pointer in ungrabbed case.
8133
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
  1295
                setPointerToUnderPoint( event.getPoint() );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
            dispatch( event );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
            boolean wasGrabbed = grabbed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
            grabbed_update( event );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
            if ( wasGrabbed && ! grabbed ) {
8133
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
  1301
                setPointerToUnderPoint( event.getPoint() );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
            setCursor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
        // Following is internally private:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
        // Here dispatching is performed, of 'MouseEvent's to (some)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        // 'XTextAreaPeer''s (hidden) subcomponents.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
        private void dispatch( MouseEvent event ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            switch( current.getType() )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                case TEXT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                    Point point = toViewportChildLocalSpace(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                        outer.textPane.getViewport(), event.getPoint() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
                    XTextAreaPeer.AWTTextArea jtext = outer.jtext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
                    MouseEvent newEvent = newMouseEvent( jtext, point, event );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
                    int id = newEvent.getID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                    if ( id==MouseEvent.MOUSE_MOVED || id==MouseEvent.MOUSE_DRAGGED ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                        jtext.processMouseMotionEventPublic( newEvent );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                        jtext.processMouseEventPublic( newEvent );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
                // We perform (additional) dispatching of events to buttons of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
                // scrollbar, instead of leaving it to JScrollbar. This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
                // required, because of different listeners in Swing and AWT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
                // which trigger scrolling (ArrowButtonListener vs. TrackListener,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                // accordingly). So we dispatch events to scroll-buttons, to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
                // invoke a correct Swing button listener.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
                // See CR 6175401 for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
                case BAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
                case BUTTON:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
                    Component c = current.getBar();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
                    Point p = toLocalSpace( c, event.getPoint() );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                    if ( current.getType()==Pointer.Type.BUTTON ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
                        c = current.getButton();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
                        p = toLocalSpace( c, p );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                    }
4371
dc9dcb8b0ae7 6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents: 2
diff changeset
  1341
                    AWTAccessor.getComponentAccessor().processEvent( c, newMouseEvent( c, p, event ) );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        private static MouseEvent newMouseEvent(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
            Component source, Point point, MouseEvent template )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
            MouseEvent e = template;
6826
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
  1350
            MouseEvent nme = new MouseEvent(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
                source,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
                e.getID(), e.getWhen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
                e.getModifiersEx() | e.getModifiers(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
                point.x, point.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
                e.getXOnScreen(), e.getYOnScreen(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
                e.getClickCount(), e.isPopupTrigger(), e.getButton() );
6826
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
  1357
            // Because these MouseEvents are dispatched directly to
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
  1358
            // their target, we need to mark them as being
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
  1359
            // system-generated here
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
  1360
            SunToolkit.setSystemGenerated(nme);
1fc6a05552f2 6991992: Need to forward-port AWT's part of the fix for 6691674
dcherepanov
parents: 5506
diff changeset
  1361
            return nme;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        private void setCursor() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
            if ( current.getType()==Pointer.Type.TEXT ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
                // 'target.getCursor()' is also applied from elsewhere
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
                // (at least now), but only when mouse "entered", and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                // before 'XTextAreaPeer.handleJavaMouseEvent' is invoked.
8133
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
  1369
                outer.pSetCursor( outer.target.getCursor(), true );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
                // We can write here a more intelligent cursor selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
                // mechanism, like getting cursor from 'current' component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
                // However, I see no point in doing so now. But if you feel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
                // like implementing it, you'll probably need to introduce
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
                // 'Pointer.Type.PANEL'.
8133
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
  1377
                outer.pSetCursor( outer.textPane.getCursor(), true );
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
        // Current way of grab-detection causes interesting (but harmless)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        // side-effect. If mouse is draged from outside to inside of TextArea,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        // we will then (in some cases) be asked to dispatch mouse-entered/exited
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        // events. But, as at least one mouse-button is down, we will detect
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        // grab-mode is on (though the grab isn't ours).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        // Thus, we will not update 'current' (see 'handle' method), and will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        // dispatch events to the last subcomponent, the 'current' was set to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
        // As always, we set cursor in this case also. But, all this seems
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
        // harmless, because mouse entered/exited events seem to have no effect
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
        // here, and cursor setting is ignored in case of drags from outside.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
        // Grab-detection can be further improved, e.g. by taking into account
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
        // current event-ID, but I see not point in doing it now.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
        private void grabbed_update( MouseEvent event ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
            final int allButtonsMask
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
                = MouseEvent.BUTTON1_DOWN_MASK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                | MouseEvent.BUTTON2_DOWN_MASK
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
                | MouseEvent.BUTTON3_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
            grabbed = ( (event.getModifiersEx() & allButtonsMask) != 0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
        // 'toLocalSpace' and 'toViewportChildLocalSpace' can be "optimized" to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
        // 'return' 'void' and use 'Point' input-argument also as output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
        private static Point toLocalSpace( Component local, Point inParentSpace )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
            Point p = inParentSpace;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
            Point l = local.getLocation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
            return new Point( p.x - l.x, p.y - l.y );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
        private static Point toViewportChildLocalSpace( JViewport v, Point inViewportParentSpace )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
            Point l = toLocalSpace(v, inViewportParentSpace);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
            Point p = v.getViewPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
            l.x += p.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
            l.y += p.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
            return l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
8133
c7e4a02e928e 6431076: Cursor gets reset to text cursor in xawt TextArea when autoscrolling on append
dav
parents: 7668
diff changeset
  1422
        private void setPointerToUnderPoint( Point point ) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
            if ( outer.textPane.getViewport().getBounds().contains( point ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
                current.setText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
            else if ( ! setPointerIfPointOverScrollbar(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
                outer.textPane.getVerticalScrollBar(), point ) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
                if ( ! setPointerIfPointOverScrollbar(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
                    outer.textPane.getHorizontalScrollBar(), point ) )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
                    current.setNone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
        private boolean setPointerIfPointOverScrollbar( JScrollBar bar, Point point ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
            if ( ! bar.getBounds().contains( point ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
            current.setBar( bar );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
            Point local = toLocalSpace( bar, point );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
            XTextAreaPeer.XAWTScrollBarUI ui =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
                (XTextAreaPeer.XAWTScrollBarUI) bar.getUI();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
            if ( ! setPointerIfPointOverButton( ui.getIncreaseButton(), local ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
                setPointerIfPointOverButton( ui.getDecreaseButton(), local );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
        private boolean setPointerIfPointOverButton( JButton button, Point point ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
            if ( ! button.getBounds().contains( point ) ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
            current.setButton( button );
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        private static final class Pointer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
            static enum Type {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
                NONE, TEXT, BAR, BUTTON  // , PANEL
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
            Type getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
                return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
            boolean isNone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
                return type==Type.NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
            JScrollBar getBar() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
                boolean ok = type==Type.BAR || type==Type.BUTTON;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
                assert ok;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
                return ok ? bar : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
            JButton getButton() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
                boolean ok = type==Type.BUTTON;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
                assert ok;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
                return ok ? button : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
            void setNone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
                type = Type.NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
            void setText() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
                type = Type.TEXT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
            void setBar( JScrollBar bar ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
                this.bar=bar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
                type=Type.BAR;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
            void setButton( JButton button ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
                this.button=button;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                type=Type.BUTTON;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
            private Type type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
            private JScrollBar bar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
            private JButton button;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
}