jdk/src/solaris/classes/sun/awt/motif/MTextAreaPeer.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
permissions -rw-r--r--
Initial load
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 1995-2003 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.motif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.peer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.event.TextEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.event.MouseEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.awt.event.MouseWheelEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.awt.datatransfer.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.BufferedReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.io.StringReader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.awt.im.InputMethodRequests;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
public class MTextAreaPeer extends MComponentPeer implements TextAreaPeer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    native void pCreate(MComponentPeer parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private boolean firstChangeSkipped;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * Initialize JNI field and method IDs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    private static native void initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        initIDs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    void create(MComponentPeer parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        firstChangeSkipped = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        pCreate(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    void initialize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        int start, end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        TextArea txt = (TextArea)target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        String  text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        if ((text = txt.getText()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            setText(text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        start = txt.getSelectionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        end = txt.getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        if (end > start) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            select(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            setCaretPosition(start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        super.pSetScrollbarBackground(getParent_NoClientCode(target).getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        if (!target.isBackgroundSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            // This is a way to set the background color of the TextArea
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            // without calling setBackground - go through native C code
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            setTargetBackground(SystemColor.text);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        if (!target.isForegroundSet()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            target.setForeground(SystemColor.textText);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        setEditable(txt.isEditable());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
//      oldSelectionStart = -1; // accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
//      oldSelectionEnd = -1;   // accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        super.initialize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public MTextAreaPeer(TextArea target) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        super(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public void setEditable(boolean editable) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        pSetEditable(editable);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        /* 4136955 - Calling setBackground() here works around an Xt
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
         * bug by forcing Xt to flush an internal widget cache
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        setBackground(target.getBackground());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public void setBackground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        setTextBackground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    public void setForeground(Color c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        pSetInnerForeground(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    native int getExtraWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    native int getExtraHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public native void setTextBackground(Color c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public native void pSetEditable(boolean e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public native void select(int selStart, int selEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public native int getSelectionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    public native int getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public native void setText(String txt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    public native String getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public native void insert(String txt, int pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    public native void replaceRange(String txt, int start, int end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    public native void setFont(Font f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public native void setCaretPosition(int pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public native int getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    public native void pSetCursor(Cursor c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    native void pShow2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    native void pMakeCursorVisible();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public Dimension getMinimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return getMinimumSize(10, 60);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public Dimension getPreferredSize(int rows, int cols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        return getMinimumSize(rows, cols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public Dimension getMinimumSize(int rows, int cols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        FontMetrics fm = getFontMetrics(target.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        /* Calculate proper size for text area plus scrollbars.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
         *   - Motif allows NO leading in its text areas ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
         *   - extra width and height counts everything outside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
         *     usable text space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
         * (bug 4103248, 4120310):
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
         *   - Motif uses maxAscent + maxDescent, not ascent + descent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        int colWidth = fm.charWidth('0');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        int rowHeight = fm.getMaxAscent() + fm.getMaxDescent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        return new Dimension(cols * colWidth + getExtraWidth(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                             rows * rowHeight + getExtraHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    public boolean isFocusable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    // Called from native widget when paste key is pressed and we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    // already own the selection (prevents Motif from hanging while
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    // waiting for the selection)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public void pasteFromClipboard() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        Clipboard clipboard = target.getToolkit().getSystemClipboard();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        Transferable content = clipboard.getContents(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if (content != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                String data = (String)(content.getTransferData(DataFlavor.stringFlavor));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                // fix for 4401853: to clear TextArea selection if null is pasted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                data = (data == null ? "" : data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                replaceRange(data, getSelectionStart(), getSelectionEnd());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * Print the native component by rendering the Motif look ourselves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * ToDo(aim): needs to query native motif for more accurate size and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * color information, the top/left text offsets, and selected text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    static final int MARGIN = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    static final int BORDER = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    static final int SCROLLBAR = 16;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    int fontHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    int fontAscent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    int fontLeading;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    int topLine = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    int numLines = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    int textLength = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    Vector lines;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    int selStart = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    int selEnd = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    int movedRight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    // the following vars are assigned in print() method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    transient boolean hscrollbar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    transient boolean vscrollbar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public void print(Graphics g) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        TextArea area = (TextArea)target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        Dimension d = area.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        Color bg = area.getBackground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        Color fg = area.getForeground();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        FontMetrics fm = getFontMetrics(area.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        int vmin, vmax, vval, vvis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        int hmin, hmax, hval, hvis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        int max = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
          Doesn't work right yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        selStart = area.getSelectionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        selEnd = area.getSelectionEnd();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        // Figure out number of lines and max line length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        String text = area.getText();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        textLength = text.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        BufferedReader is = new BufferedReader(new StringReader(text));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        String line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        int pos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        lines = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        int sv = ((TextArea)target).getScrollbarVisibility();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        vscrollbar = (sv == TextArea.SCROLLBARS_BOTH ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                sv == TextArea.SCROLLBARS_VERTICAL_ONLY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        hscrollbar = (sv == TextArea.SCROLLBARS_BOTH ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                sv == TextArea.SCROLLBARS_HORIZONTAL_ONLY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        boolean wrap = !hscrollbar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        int w = d.width - (vscrollbar ? SCROLLBAR : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        int h = d.height - (hscrollbar ? SCROLLBAR : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            numLines = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            while((line = is.readLine()) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                int len = fm.stringWidth(line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                if (len > w && wrap) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                   // need to do line wrapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                   int start = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                   int end = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                   int string_length = line.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                   while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                       int line_width = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                       end = start + 1; // at least one character per line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                       while (end < string_length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                               char c = line.charAt(end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                               int cw = fm.charWidth(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                               if (line_width + cw + 10 > w) // +10?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                                       break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                               line_width += cw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                               end++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                       // form a line from start to end (not including end)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                       String substr = line.substring(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                       // System.out.println("wrap line: " + substr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                       TextLine tline = new TextLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                       tline.text = substr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                       tline.pos = pos + start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                       lines.addElement(tline);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                       start = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                       max = Math.max(max, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                       numLines ++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                       if (end == string_length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                           // we have processed the whole string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                           pos += line.length() + 1; // +1 for the ending \n ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                           break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                       }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                TextLine tline = new TextLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                tline.text = line;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                tline.pos = pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                lines.addElement(tline);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                pos += line.length() + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                max = Math.max(max, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                numLines++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            is.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        fontHeight = fm.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        fontAscent = fm.getAscent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        fontLeading = fm.getLeading();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        hmin = vmin = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        vvis = linesInWindow(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        vmax = Math.max(numLines - vvis, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        vval = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        hvis = w - (2 * MARGIN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        hmax = Math.max(max - hvis, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        hval = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        g.setColor(bg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        g.fillRect(BORDER, BORDER, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        if (vscrollbar)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            int sbh = d.height - (hscrollbar ? SCROLLBAR : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            g.fillRect(d.width - SCROLLBAR - 3, 1, SCROLLBAR - 3, sbh - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            Graphics ng = g.create();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                ng.translate(d.width - (SCROLLBAR - 2), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                drawScrollbar(ng, bg, SCROLLBAR - 2, sbh,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                              vmin, vmax, vval, vvis, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                ng.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        if (hscrollbar)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            int sbw = d.width - (vscrollbar ? SCROLLBAR : 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            g.fillRect(1, d.height - SCROLLBAR - 3, sbw - 1, SCROLLBAR - 3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            Graphics ng = g.create();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                ng.translate(0, d.height - (SCROLLBAR - 2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                drawScrollbar(ng, bg, SCROLLBAR - 2, sbw,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                              hmin, hmax, hval, hvis, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                ng.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        draw3DRect(g, bg, 0, 0, w - 1, h - 1, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        if (text != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            int l = linesInWindow(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            h = d.height - ((2 * MARGIN) + SCROLLBAR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            int e = Math.min(numLines - 1, (topLine + l) - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            paintLines(g, bg, fg, topLine, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        target.print(g);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    int linesInWindow(boolean horizScrollbar) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        Dimension d = target.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        int htotal = d.height - ((2 * MARGIN) + (horizScrollbar? SCROLLBAR : 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        return htotal / fontHeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    void paintLines(Graphics g, Color bg, Color fg, int s, int e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        Dimension d = target.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        int w = d.width - ((2 * BORDER) + (vscrollbar ? SCROLLBAR : 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        int h = d.height - ((2 * BORDER) + (hscrollbar ? SCROLLBAR : 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        int lm = linesInWindow(true) + topLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        s = Math.max(topLine, s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        e = Math.min(e, lm - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        Graphics ng = g.create();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            ng.clipRect(BORDER + MARGIN, MARGIN + BORDER, w - (2*MARGIN),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                        h - (2*MARGIN));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            ng.setFont(target.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            for (int i = s ; i <= e; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                paintLine(ng, bg, fg, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            ng.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    void paintLine(Graphics g, Color bg, Color fg, int lnr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        Dimension d = target.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        int l = linesInWindow(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        if((lnr < topLine) || (lnr >= l + topLine)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        int w = d.width - ((2 * BORDER) + (hscrollbar ? SCROLLBAR : 0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        int y = MARGIN + fontLeading + ((lnr - topLine) * fontHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        String text = ((TextLine)lines.elementAt(lnr)).text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        int len = text.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        if (lnr > numLines - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            g.setColor(bg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            g.fillRect(BORDER, y - fontLeading, w, fontHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        int s = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        int e = (lnr < numLines - 1) ? len : textLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        int xs = pos2x(selStart) - movedRight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        int xe = pos2x(selEnd) - movedRight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        Color highlight = bg.brighter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        if ((selStart < s) && (selEnd > e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            g.fillRect(BORDER, y - fontLeading, w, fontHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            g.setColor(bg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            g.fillRect(BORDER, y - fontLeading, w, fontHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            if ((selStart >= s) && (selStart <= e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                if (selEnd > e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                    g.fillRect(xs, y - fontLeading, (w + BORDER) - xs, fontHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                } else if (selStart == selEnd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                  //g.fillRect(xs, y - fontLeading, 1, fontHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                    g.fillRect(xs, y - fontLeading, xe - xs, fontHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            } else if ((selEnd >= s) && (selEnd <= e)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                g.setColor(highlight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                g.fillRect(BORDER, y - fontLeading, xe - BORDER, fontHeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        g.setColor(fg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        g.drawString(text, MARGIN - movedRight, y + fontAscent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    int pos2x(int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        FontMetrics fm = getFontMetrics(target.getFont());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        int widths[] = fm.getWidths();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        TextLine tl1 = (TextLine)lines.elementAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        TextLine tl2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        int l = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        for (int i = 0; i < lines.size() - 1; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            tl2 = (TextLine)lines.elementAt(i+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            if (pos >= tl1.pos && pos < tl2.pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                l = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            tl1 = tl2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        int x = MARGIN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        for (int i = 0 ; i < (pos - tl1.pos - 1) ; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            x += widths[tl1.text.charAt(i)];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * DEPRECATED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    public void insertText(String txt, int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        insert(txt, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * DEPRECATED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    public void replaceText(String txt, int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        replaceRange(txt, start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * DEPRECATED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    public Dimension minimumSize() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        return getMinimumSize();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * DEPRECATED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    public Dimension preferredSize(int rows, int cols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        return getPreferredSize(rows, cols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * DEPRECATED
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    public Dimension minimumSize(int rows, int cols) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        return getMinimumSize(rows, cols);
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
     * Post a new TextEvent when the value of a text component changes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    public void valueChanged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        postEvent(new TextEvent(target, TextEvent.TEXT_VALUE_CHANGED));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
    void pShow(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
      pShow2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
      notifyTextComponentChange(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    void pHide(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
      notifyTextComponentChange(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
      super.pHide();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    void pDispose(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
      notifyTextComponentChange(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
      super.pDispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    public boolean handlesWheelScrolling() {return true;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    public void handleEvent(AWTEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        if (e.getID() == MouseEvent.MOUSE_WHEEL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            MouseWheelEvent mwe = (MouseWheelEvent)e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            nativeHandleMouseWheel(mwe.getScrollType(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                                   mwe.getScrollAmount(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                                   mwe.getWheelRotation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            super.handleEvent(e);
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
     public InputMethodRequests getInputMethodRequests() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
      }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    native void nativeHandleMouseWheel(int scrollType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                                       int scrollAmount,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                                       int wheelRotation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    // Accessibility support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    // stub functions: to be fully implemented in a future release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    public int getIndexAtPoint(int x, int y) { return -1; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    public Rectangle getCharacterBounds(int i) { return null; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    public long filterEvents(long mask) { return 0; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
/*  To be fully implemented in a future release
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    int oldSelectionStart;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
    int oldSelectionEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    public native int getIndexAtPoint(int x, int y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    public native Rectangle getCharacterBounds(int i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    public native long filterEvents(long mask);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * Handle a change in the text selection endpoints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * (Note: could be simply a change in the caret location)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    public void selectionValuesChanged(int start, int end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        return;  // Need to write implementation of this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
class TextLine {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    String text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    int pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
}