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