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