jdk/src/macosx/classes/sun/lwawt/LWTextAreaPeer.java
author serb
Mon, 24 Sep 2012 21:33:41 +0400
changeset 13993 8b3fe3d8badb
parent 13357 6a75209a8aeb
child 20153 d5bf90bfcb6d
permissions -rw-r--r--
7160627: [macosx] TextArea has wrong initial size 7124213: [macosx] pack() does ignore size of a component; doesn't on the other platforms Reviewed-by: anthony, art
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     1
/*
13993
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
     2
 * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     4
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    10
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    15
 * accompanied this code).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    16
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    20
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    23
 * questions.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    24
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    25
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    26
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
package sun.lwawt;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    28
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    29
import java.awt.Component;
12396
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12047
diff changeset
    30
import java.awt.Cursor;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    31
import java.awt.Dimension;
13993
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
    32
import java.awt.Insets;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    33
import java.awt.Point;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    34
import java.awt.TextArea;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    35
import java.awt.event.TextEvent;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    36
import java.awt.peer.TextAreaPeer;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    37
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    38
import javax.swing.JScrollBar;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
import javax.swing.JScrollPane;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
import javax.swing.JTextArea;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    41
import javax.swing.ScrollPaneConstants;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    42
import javax.swing.text.Document;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    43
import javax.swing.text.JTextComponent;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    44
13993
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
    45
/**
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
    46
 * Lightweight implementation of {@link TextAreaPeer}. Delegates most of the
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
    47
 * work to the {@link JTextArea} inside JScrollPane.
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
    48
 */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    49
final class LWTextAreaPeer
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    50
        extends LWTextComponentPeer<TextArea, LWTextAreaPeer.ScrollableJTextArea>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    51
        implements TextAreaPeer {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    52
13993
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
    53
    /**
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
    54
     * The default number of visible columns.
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
    55
     */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    56
    private static final int DEFAULT_COLUMNS = 60;
13993
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
    57
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
    58
    /**
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
    59
     * The default number of visible rows.
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
    60
     */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    61
    private static final int DEFAULT_ROWS = 10;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    62
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    63
    LWTextAreaPeer(final TextArea target,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    64
                   final PlatformComponent platformComponent) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    65
        super(target, platformComponent);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    67
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    68
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    69
    protected ScrollableJTextArea createDelegate() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    70
        return new ScrollableJTextArea();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    71
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    72
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    73
    @Override
13143
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12531
diff changeset
    74
    void initializeImpl() {
31c70a66a053 7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents: 12531
diff changeset
    75
        super.initializeImpl();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    76
        final int visibility = getTarget().getScrollbarVisibility();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    77
        synchronized (getDelegateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
            setScrollBarVisibility(visibility);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    79
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    81
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    82
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
    JTextComponent getTextComponent() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    84
        return getDelegate().getView();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    85
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    86
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    87
    @Override
12396
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12047
diff changeset
    88
    protected Cursor getCursor(final Point p) {
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12047
diff changeset
    89
        final boolean isContains;
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12047
diff changeset
    90
        synchronized (getDelegateLock()) {
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12047
diff changeset
    91
            isContains = getDelegate().getViewport().getBounds().contains(p);
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12047
diff changeset
    92
        }
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12047
diff changeset
    93
        return isContains ? super.getCursor(p) : null;
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12047
diff changeset
    94
    }
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12047
diff changeset
    95
79c64c6eb61e 7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents: 12047
diff changeset
    96
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    97
    protected Component getDelegateFocusOwner() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    98
        return getTextComponent();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    99
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   100
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   101
    @Override
13993
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   102
    public Dimension getPreferredSize() {
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   103
        return getMinimumSize();
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   104
    }
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   105
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   106
    @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   107
    public Dimension getMinimumSize() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   108
        return getMinimumSize(DEFAULT_ROWS, DEFAULT_COLUMNS);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   109
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   110
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   111
    @Override
13993
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   112
    public Dimension getPreferredSize(final int rows, final int columns) {
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   113
        return getMinimumSize(rows, columns);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   114
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   115
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   116
    @Override
13993
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   117
    public Dimension getMinimumSize(final int rows, final int columns) {
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   118
        final Dimension size = super.getMinimumSize(rows, columns);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   119
        synchronized (getDelegateLock()) {
13993
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   120
            // JScrollPane insets
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   121
            final Insets pi = getDelegate().getInsets();
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   122
            size.width += pi.left + pi.right;
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   123
            size.height += pi.top + pi.bottom;
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   124
            // Take scrollbars into account.
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   125
            final int vsbPolicy = getDelegate().getVerticalScrollBarPolicy();
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   126
            if (vsbPolicy == ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS) {
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   127
                final JScrollBar vbar = getDelegate().getVerticalScrollBar();
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   128
                size.width += vbar != null ? vbar.getMinimumSize().width : 0;
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   129
            }
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   130
            final int hsbPolicy = getDelegate().getHorizontalScrollBarPolicy();
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   131
            if (hsbPolicy == ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS) {
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   132
                final JScrollBar hbar = getDelegate().getHorizontalScrollBar();
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   133
                size.height += hbar != null ? hbar.getMinimumSize().height : 0;
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   134
            }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   135
        }
13993
8b3fe3d8badb 7160627: [macosx] TextArea has wrong initial size
serb
parents: 13357
diff changeset
   136
        return size;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   137
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   138
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   139
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   140
    public void insert(final String text, final int pos) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   141
        final ScrollableJTextArea pane = getDelegate();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   142
        synchronized (getDelegateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   143
            final JTextArea area = pane.getView();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   144
            final boolean doScroll = pos >= area.getDocument().getLength()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   145
                                     && area.getDocument().getLength() != 0;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   146
            area.insert(text, pos);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   147
            revalidate();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   148
            if (doScroll) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   149
                final JScrollBar vbar = pane.getVerticalScrollBar();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   150
                if (vbar != null) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   151
                    vbar.setValue(vbar.getMaximum() - vbar.getVisibleAmount());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   152
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   153
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   154
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   155
        repaintPeer();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   156
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   157
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   158
    @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   159
    public void replaceRange(final String text, final int start,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   160
                             final int end) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   161
        synchronized (getDelegateLock()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   162
            // JTextArea.replaceRange() posts two different events.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   163
            // Since we make no differences between text events,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   164
            // the document listener has to be disabled while
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   165
            // JTextArea.replaceRange() is called.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   166
            final Document document = getTextComponent().getDocument();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   167
            document.removeDocumentListener(this);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   168
            getDelegate().getView().replaceRange(text, start, end);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   169
            revalidate();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   170
            postEvent(new TextEvent(getTarget(), TextEvent.TEXT_VALUE_CHANGED));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   171
            document.addDocumentListener(this);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   172
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   173
        repaintPeer();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   174
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   175
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   176
    private void setScrollBarVisibility(final int visibility) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   177
        final ScrollableJTextArea pane = getDelegate();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   178
        final JTextArea view = pane.getView();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   179
        view.setLineWrap(false);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   180
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   181
        switch (visibility) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   182
            case TextArea.SCROLLBARS_NONE:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   183
                pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   184
                pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   185
                view.setLineWrap(true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   186
                break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   187
            case TextArea.SCROLLBARS_VERTICAL_ONLY:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   188
                pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   189
                pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   190
                view.setLineWrap(true);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   191
                break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   192
            case TextArea.SCROLLBARS_HORIZONTAL_ONLY:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   193
                pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   194
                pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   195
                break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   196
            default:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   197
                pane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
                pane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   199
                break;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   200
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   201
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   202
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   203
    @SuppressWarnings("serial")
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   204
    final class ScrollableJTextArea extends JScrollPane {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   205
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   206
        ScrollableJTextArea() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   207
            super();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   208
            getViewport().setView(new JTextAreaDelegate());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   209
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   210
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   211
        public JTextArea getView() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   212
            return (JTextArea) getViewport().getView();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   213
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   214
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   215
        @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   216
        public void setEnabled(final boolean enabled) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   217
            getViewport().getView().setEnabled(enabled);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   218
            super.setEnabled(enabled);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   219
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   220
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   221
        @SuppressWarnings("serial")
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   222
        private final class JTextAreaDelegate extends JTextArea {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   223
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   224
            // Empty non private constructor was added because access to this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   225
            // class shouldn't be emulated by a synthetic accessor method.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   226
            JTextAreaDelegate() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   227
                super();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   228
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   229
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   230
            @Override
12531
42a9335fd8b3 7124210: [macosx] Replacing text in a TextField does generate an extra TextEvent
alexp
parents: 12396
diff changeset
   231
            public void replaceSelection(String content) {
42a9335fd8b3 7124210: [macosx] Replacing text in a TextField does generate an extra TextEvent
alexp
parents: 12396
diff changeset
   232
                getDocument().removeDocumentListener(LWTextAreaPeer.this);
42a9335fd8b3 7124210: [macosx] Replacing text in a TextField does generate an extra TextEvent
alexp
parents: 12396
diff changeset
   233
                super.replaceSelection(content);
42a9335fd8b3 7124210: [macosx] Replacing text in a TextField does generate an extra TextEvent
alexp
parents: 12396
diff changeset
   234
                // post only one text event in this case
42a9335fd8b3 7124210: [macosx] Replacing text in a TextField does generate an extra TextEvent
alexp
parents: 12396
diff changeset
   235
                postTextEvent();
42a9335fd8b3 7124210: [macosx] Replacing text in a TextField does generate an extra TextEvent
alexp
parents: 12396
diff changeset
   236
                getDocument().addDocumentListener(LWTextAreaPeer.this);
42a9335fd8b3 7124210: [macosx] Replacing text in a TextField does generate an extra TextEvent
alexp
parents: 12396
diff changeset
   237
            }
42a9335fd8b3 7124210: [macosx] Replacing text in a TextField does generate an extra TextEvent
alexp
parents: 12396
diff changeset
   238
42a9335fd8b3 7124210: [macosx] Replacing text in a TextField does generate an extra TextEvent
alexp
parents: 12396
diff changeset
   239
            @Override
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   240
            public boolean hasFocus() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   241
                return getTarget().hasFocus();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   242
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   243
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   244
            @Override
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   245
            public Point getLocationOnScreen() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   246
                return LWTextAreaPeer.this.getLocationOnScreen();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   247
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   248
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   249
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   250
}