jdk/src/share/classes/javax/swing/text/DefaultEditorKit.java
author ohair
Tue, 28 Dec 2010 15:53:50 -0800
changeset 7668 d4a77089c587
parent 5506 202f599c92aa
child 12418 f749f1ed92ca
permissions -rw-r--r--
6962318: Update copyright year Reviewed-by: xdono
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 5506
diff changeset
     2
 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4968
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4968
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4968
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4968
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4968
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.event.ActionEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.Action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.KeyStroke;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import javax.swing.SwingConstants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.UIManager;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * This is the set of things needed by a text component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * to be a reasonably functioning editor for some <em>type</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * of text document.  This implementation provides a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * implementation which treats text as plain text and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * provides a minimal set of actions for a simple editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <dt><b><font size=+1>Newlines</font></b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * There are two properties which deal with newlines.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * system property, <code>line.separator</code>, is defined to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * platform-dependent, either "\n", "\r", or "\r\n".  There is also
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * a property defined in <code>DefaultEditorKit</code>, called
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <a href=#EndOfLineStringProperty><code>EndOfLineStringProperty</code></a>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * which is defined automatically when a document is loaded, to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * the first occurrence of any of the newline characters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * When a document is loaded, <code>EndOfLineStringProperty</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * is set appropriately, and when the document is written back out, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <code>EndOfLineStringProperty</code> is used.  But while the document
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * is in memory, the "\n" character is used to define a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * newline, regardless of how the newline is defined when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * the document is on disk.  Therefore, for searching purposes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * "\n" should always be used.  When a new document is created,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * and the <code>EndOfLineStringProperty</code> has not been defined,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * it will use the System property when writing out the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <p>Note that <code>EndOfLineStringProperty</code> is set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * on the <code>Document</code> using the <code>get/putProperty</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * methods.  Subclasses may override this behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * </dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
public class DefaultEditorKit extends EditorKit {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * default constructor for DefaultEditorKit
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    public DefaultEditorKit() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * Gets the MIME type of the data that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * kit represents support for.  The default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * is <code>text/plain</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @return the type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public String getContentType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        return "text/plain";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Fetches a factory that is suitable for producing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * views of any models that are produced by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * kit.  The default is to have the UI produce the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * factory, so this method has no implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @return the view factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public ViewFactory getViewFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Fetches the set of commands that can be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * on a text component that is using a model and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * view produced by this kit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @return the command list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    public Action[] getActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        return defaultActions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * Fetches a caret that can navigate through views
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * produced by the associated ViewFactory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @return the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public Caret createCaret() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Creates an uninitialized text storage model (PlainDocument)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * that is appropriate for this type of editor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @return the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    public Document createDefaultDocument() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        return new PlainDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * Inserts content from the given stream which is expected
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * to be in a format appropriate for this kind of content
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * @param in  The stream to read from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @param doc The destination for the insertion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @param pos The location in the document to place the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *   content >= 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @exception IOException on any I/O error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @exception BadLocationException if pos represents an invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *   location within the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public void read(InputStream in, Document doc, int pos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        throws IOException, BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        read(new InputStreamReader(in), doc, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Writes content from a document to the given stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * in a format appropriate for this kind of content handler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @param out The stream to write to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @param doc The source for the write.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * @param pos The location in the document to fetch the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *   content >= 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @param len The amount to write out >= 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * @exception IOException on any I/O error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @exception BadLocationException if pos represents an invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *   location within the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public void write(OutputStream out, Document doc, int pos, int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        throws IOException, BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        OutputStreamWriter osw = new OutputStreamWriter(out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        write(osw, doc, pos, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        osw.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * Gets the input attributes for the pane. This method exists for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * the benefit of StyledEditorKit so that the read method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * pick up the correct attributes to apply to inserted text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * This class's implementation simply returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @return null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    MutableAttributeSet getInputAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * Inserts content from the given stream, which will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * treated as plain text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @param in  The stream to read from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * @param doc The destination for the insertion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * @param pos The location in the document to place the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *   content >= 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @exception IOException on any I/O error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @exception BadLocationException if pos represents an invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *   location within the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public void read(Reader in, Document doc, int pos)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        throws IOException, BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        char[] buff = new char[4096];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        int nch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        boolean lastWasCR = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        boolean isCRLF = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        boolean isCR = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        int last;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        boolean wasEmpty = (doc.getLength() == 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        AttributeSet attr = getInputAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        // Read in a block at a time, mapping \r\n to \n, as well as single
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        // \r's to \n's. If a \r\n is encountered, \r\n will be set as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        // newline string for the document, if \r is encountered it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        // be set as the newline character, otherwise the newline property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        // for the document will be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        while ((nch = in.read(buff, 0, buff.length)) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            last = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            for(int counter = 0; counter < nch; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                switch(buff[counter]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                case '\r':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                    if (lastWasCR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                        isCR = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                        if (counter == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                            doc.insertString(pos, "\n", attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                            pos++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                            buff[counter - 1] = '\n';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                        lastWasCR = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                case '\n':
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                    if (lastWasCR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                        if (counter > (last + 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                            doc.insertString(pos, new String(buff, last,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                                            counter - last - 1), attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                            pos += (counter - last - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                        // else nothing to do, can skip \r, next write will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                        // write \n
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                        lastWasCR = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                        last = counter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                        isCRLF = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    if (lastWasCR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                        isCR = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                        if (counter == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                            doc.insertString(pos, "\n", attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                            pos++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                            buff[counter - 1] = '\n';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                        lastWasCR = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            if (last < nch) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                if(lastWasCR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                    if (last < (nch - 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                        doc.insertString(pos, new String(buff, last,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                                         nch - last - 1), attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                        pos += (nch - last - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                    doc.insertString(pos, new String(buff, last,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                                     nch - last), attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                    pos += (nch - last);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        if (lastWasCR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            doc.insertString(pos, "\n", attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            isCR = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        if (wasEmpty) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            if (isCRLF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                doc.putProperty(EndOfLineStringProperty, "\r\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            else if (isCR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                doc.putProperty(EndOfLineStringProperty, "\r");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                doc.putProperty(EndOfLineStringProperty, "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * Writes content from a document to the given stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * as plain text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @param out  The stream to write to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @param doc The source for the write.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @param pos The location in the document to fetch the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *   content from >= 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @param len The amount to write out >= 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @exception IOException on any I/O error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @exception BadLocationException if pos is not within 0 and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *   the length of the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    public void write(Writer out, Document doc, int pos, int len)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        throws IOException, BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        if ((pos < 0) || ((pos + len) > doc.getLength())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            throw new BadLocationException("DefaultEditorKit.write", pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        Segment data = new Segment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        int nleft = len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        int offs = pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        Object endOfLineProperty = doc.getProperty(EndOfLineStringProperty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        if (endOfLineProperty == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                endOfLineProperty = System.getProperty("line.separator");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            } catch (SecurityException se) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        String endOfLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        if (endOfLineProperty instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            endOfLine = (String)endOfLineProperty;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            endOfLine = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        if (endOfLineProperty != null && !endOfLine.equals("\n")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            // There is an end of line string that isn't \n, have to iterate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            // through and find all \n's and translate to end of line string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            while (nleft > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                int n = Math.min(nleft, 4096);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                doc.getText(offs, n, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                int last = data.offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                char[] array = data.array;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                int maxCounter = last + data.count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                for (int counter = last; counter < maxCounter; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                    if (array[counter] == '\n') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                        if (counter > last) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                            out.write(array, last, counter - last);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                        out.write(endOfLine);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                        last = counter + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                if (maxCounter > last) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                    out.write(array, last, maxCounter - last);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                offs += n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                nleft -= n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            // Just write out text, will already have \n, no mapping to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            // do.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            while (nleft > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                int n = Math.min(nleft, 4096);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                doc.getText(offs, n, data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                out.write(data.array, data.offset, data.count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                offs += n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                nleft -= n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * When reading a document if a CRLF is encountered a property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * with this name is added and the value will be "\r\n".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    public static final String EndOfLineStringProperty = "__EndOfLine__";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    // --- names of well-known actions ---------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * Name of the action to place content into the associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * document.  If there is a selection, it is removed before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * the new content is added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    public static final String insertContentAction = "insert-content";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * Name of the action to place a line/paragraph break into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * the document.  If there is a selection, it is removed before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * the break is added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    public static final String insertBreakAction = "insert-break";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * Name of the action to place a tab character into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * the document.  If there is a selection, it is removed before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * the tab is added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    public static final String insertTabAction = "insert-tab";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * Name of the action to delete the character of content that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * precedes the current caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    public static final String deletePrevCharAction = "delete-previous";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * Name of the action to delete the character of content that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * follows the current caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public static final String deleteNextCharAction = "delete-next";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * Name of the action to delete the word that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * follows the beginning of the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @see JTextComponent#getSelectionStart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    public static final String deleteNextWordAction = "delete-next-word";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * Name of the action to delete the word that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * precedes the beginning of the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @see JTextComponent#getSelectionStart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    public static final String deletePrevWordAction = "delete-previous-word";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * Name of the action to set the editor into read-only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    public static final String readOnlyAction = "set-read-only";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * Name of the action to set the editor into writeable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    public static final String writableAction = "set-writable";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * Name of the action to cut the selected region
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * and place the contents into the system clipboard.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @see JTextComponent#cut
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    public static final String cutAction = "cut-to-clipboard";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * Name of the action to copy the selected region
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * and place the contents into the system clipboard.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @see JTextComponent#copy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    public static final String copyAction = "copy-to-clipboard";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * Name of the action to paste the contents of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * system clipboard into the selected region, or before the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * caret if nothing is selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * @see JTextComponent#paste
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    public static final String pasteAction = "paste-from-clipboard";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * Name of the action to create a beep.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    public static final String beepAction = "beep";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * Name of the action to page up vertically.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    public static final String pageUpAction = "page-up";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * Name of the action to page down vertically.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    public static final String pageDownAction = "page-down";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * Name of the action to page up vertically, and move the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    /*public*/ static final String selectionPageUpAction = "selection-page-up";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * Name of the action to page down vertically, and move the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
    /*public*/ static final String selectionPageDownAction = "selection-page-down";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * Name of the action to page left horizontally, and move the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    /*public*/ static final String selectionPageLeftAction = "selection-page-left";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * Name of the action to page right horizontally, and move the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    /*public*/ static final String selectionPageRightAction = "selection-page-right";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * Name of the Action for moving the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * logically forward one position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    public static final String forwardAction = "caret-forward";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * Name of the Action for moving the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * logically backward one position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    public static final String backwardAction = "caret-backward";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * Name of the Action for extending the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * by moving the caret logically forward one position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    public static final String selectionForwardAction = "selection-forward";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * Name of the Action for extending the selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * by moving the caret logically backward one position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    public static final String selectionBackwardAction = "selection-backward";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * Name of the Action for moving the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * logically upward one position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    public static final String upAction = "caret-up";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * Name of the Action for moving the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * logically downward one position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    public static final String downAction = "caret-down";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * Name of the Action for moving the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * logically upward one position, extending the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    public static final String selectionUpAction = "selection-up";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * Name of the Action for moving the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * logically downward one position, extending the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    public static final String selectionDownAction = "selection-down";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * Name of the <code>Action</code> for moving the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * to the beginning of a word.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    public static final String beginWordAction = "caret-begin-word";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * Name of the Action for moving the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * to the end of a word.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
    public static final String endWordAction = "caret-end-word";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * Name of the <code>Action</code> for moving the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * to the beginning of a word, extending the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
    public static final String selectionBeginWordAction = "selection-begin-word";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * Name of the Action for moving the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * to the end of a word, extending the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    public static final String selectionEndWordAction = "selection-end-word";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * Name of the <code>Action</code> for moving the caret to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * beginning of the previous word.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    public static final String previousWordAction = "caret-previous-word";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * Name of the <code>Action</code> for moving the caret to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * beginning of the next word.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    public static final String nextWordAction = "caret-next-word";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * Name of the <code>Action</code> for moving the selection to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * beginning of the previous word, extending the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    public static final String selectionPreviousWordAction = "selection-previous-word";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * Name of the <code>Action</code> for moving the selection to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * beginning of the next word, extending the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    public static final String selectionNextWordAction = "selection-next-word";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * Name of the <code>Action</code> for moving the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * to the beginning of a line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    public static final String beginLineAction = "caret-begin-line";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     * Name of the <code>Action</code> for moving the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     * to the end of a line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    public static final String endLineAction = "caret-end-line";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * Name of the <code>Action</code> for moving the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * to the beginning of a line, extending the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
    public static final String selectionBeginLineAction = "selection-begin-line";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * Name of the <code>Action</code> for moving the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * to the end of a line, extending the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
    public static final String selectionEndLineAction = "selection-end-line";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * Name of the <code>Action</code> for moving the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * to the beginning of a paragraph.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
    public static final String beginParagraphAction = "caret-begin-paragraph";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * Name of the <code>Action</code> for moving the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * to the end of a paragraph.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    public static final String endParagraphAction = "caret-end-paragraph";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * Name of the <code>Action</code> for moving the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * to the beginning of a paragraph, extending the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
    public static final String selectionBeginParagraphAction = "selection-begin-paragraph";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * Name of the <code>Action</code> for moving the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * to the end of a paragraph, extending the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    public static final String selectionEndParagraphAction = "selection-end-paragraph";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * Name of the <code>Action</code> for moving the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * to the beginning of the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    public static final String beginAction = "caret-begin";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * Name of the <code>Action</code> for moving the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * to the end of the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    public static final String endAction = "caret-end";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     * Name of the <code>Action</code> for moving the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * to the beginning of the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    public static final String selectionBeginAction = "selection-begin";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * Name of the Action for moving the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * to the end of the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    public static final String selectionEndAction = "selection-end";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * Name of the Action for selecting a word around the caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    public static final String selectWordAction = "select-word";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * Name of the Action for selecting a line around the caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    public static final String selectLineAction = "select-line";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * Name of the Action for selecting a paragraph around the caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    public static final String selectParagraphAction = "select-paragraph";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * Name of the Action for selecting the entire document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    public static final String selectAllAction = "select-all";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * Name of the Action for removing selection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    /*public*/ static final String unselectAction = "unselect";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * Name of the Action for toggling the component's orientation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    /*public*/ static final String toggleComponentOrientationAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        = "toggle-componentOrientation";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * Name of the action that is executed by default if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * a <em>key typed event</em> is received and there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * is no keymap entry.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * @see #getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
    public static final String defaultKeyTypedAction = "default-typed";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    // --- Action implementations ---------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    private static final Action[] defaultActions = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        new InsertContentAction(), new DeletePrevCharAction(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        new DeleteNextCharAction(), new ReadOnlyAction(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        new DeleteWordAction(deletePrevWordAction),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        new DeleteWordAction(deleteNextWordAction),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        new WritableAction(), new CutAction(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        new CopyAction(), new PasteAction(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        new VerticalPageAction(pageUpAction, -1, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        new VerticalPageAction(pageDownAction, 1, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        new VerticalPageAction(selectionPageUpAction, -1, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        new VerticalPageAction(selectionPageDownAction, 1, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
        new PageAction(selectionPageLeftAction, true, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        new PageAction(selectionPageRightAction, false, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        new InsertBreakAction(), new BeepAction(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        new NextVisualPositionAction(forwardAction, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
                                     SwingConstants.EAST),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        new NextVisualPositionAction(backwardAction, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
                                     SwingConstants.WEST),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        new NextVisualPositionAction(selectionForwardAction, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
                                     SwingConstants.EAST),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        new NextVisualPositionAction(selectionBackwardAction, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                                     SwingConstants.WEST),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        new NextVisualPositionAction(upAction, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                                     SwingConstants.NORTH),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        new NextVisualPositionAction(downAction, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                                     SwingConstants.SOUTH),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        new NextVisualPositionAction(selectionUpAction, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                                     SwingConstants.NORTH),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        new NextVisualPositionAction(selectionDownAction, true,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                                     SwingConstants.SOUTH),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        new BeginWordAction(beginWordAction, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        new EndWordAction(endWordAction, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        new BeginWordAction(selectionBeginWordAction, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        new EndWordAction(selectionEndWordAction, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        new PreviousWordAction(previousWordAction, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        new NextWordAction(nextWordAction, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
        new PreviousWordAction(selectionPreviousWordAction, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
        new NextWordAction(selectionNextWordAction, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        new BeginLineAction(beginLineAction, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        new EndLineAction(endLineAction, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        new BeginLineAction(selectionBeginLineAction, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        new EndLineAction(selectionEndLineAction, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        new BeginParagraphAction(beginParagraphAction, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
        new EndParagraphAction(endParagraphAction, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        new BeginParagraphAction(selectionBeginParagraphAction, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        new EndParagraphAction(selectionEndParagraphAction, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
        new BeginAction(beginAction, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
        new EndAction(endAction, false),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
        new BeginAction(selectionBeginAction, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
        new EndAction(selectionEndAction, true),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
        new DefaultKeyTypedAction(), new InsertTabAction(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        new SelectWordAction(), new SelectLineAction(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        new SelectParagraphAction(), new SelectAllAction(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        new UnselectAction(), new ToggleComponentOrientationAction(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        new DumpModelAction()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * The action that is executed by default if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * a <em>key typed event</em> is received and there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * is no keymap entry.  There is a variation across
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * different VM's in what gets sent as a <em>key typed</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * event, and this action tries to filter out the undesired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * events.  This filters the control characters and those
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * with the ALT modifier.  It allows Control-Alt sequences
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * through as these form legitimate unicode characters on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * some PC keyboards.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * If the event doesn't get filtered, it will try to insert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * content into the text editor.  The content is fetched
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * from the command string of the ActionEvent.  The text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * entry is done through the <code>replaceSelection</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * method on the target text component.  This is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * action that will be fired for most text entry tasks.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * @see DefaultEditorKit#defaultKeyTypedAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * @see Keymap#setDefaultAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * @see Keymap#getDefaultAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    public static class DefaultKeyTypedAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
         * Creates this object with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        public DefaultKeyTypedAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
            super(defaultKeyTypedAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
         * The operation to perform when this action is triggered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
         * @param e the action event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            if ((target != null) && (e != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                if ((! target.isEditable()) || (! target.isEnabled())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                String content = e.getActionCommand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                int mod = e.getModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                if ((content != null) && (content.length() > 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                    ((mod & ActionEvent.ALT_MASK) == (mod & ActionEvent.CTRL_MASK))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                    char c = content.charAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                    if ((c >= 0x20) && (c != 0x7F)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                        target.replaceSelection(content);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * Places content into the associated document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * If there is a selection, it is removed before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * the new content is added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * @see DefaultEditorKit#insertContentAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    public static class InsertContentAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
         * Creates this object with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        public InsertContentAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            super(insertContentAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
         * The operation to perform when this action is triggered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
         * @param e the action event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            if ((target != null) && (e != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
                if ((! target.isEditable()) || (! target.isEnabled())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
                    UIManager.getLookAndFeel().provideErrorFeedback(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                String content = e.getActionCommand();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                if (content != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
                    target.replaceSelection(content);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                    UIManager.getLookAndFeel().provideErrorFeedback(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        }
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
     * Places a line/paragraph break into the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * If there is a selection, it is removed before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * the break is added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     * @see DefaultEditorKit#insertBreakAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    public static class InsertBreakAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
         * Creates this object with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        public InsertBreakAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            super(insertBreakAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
         * The operation to perform when this action is triggered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
         * @param e the action event
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                if ((! target.isEditable()) || (! target.isEnabled())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                    UIManager.getLookAndFeel().provideErrorFeedback(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                target.replaceSelection("\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * Places a tab character into the document. If there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * is a selection, it is removed before the tab is added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * @see DefaultEditorKit#insertTabAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    public static class InsertTabAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
         * Creates this object with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        public InsertTabAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
            super(insertTabAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
         * The operation to perform when this action is triggered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
         * @param e the action event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                if ((! target.isEditable()) || (! target.isEnabled())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
                    UIManager.getLookAndFeel().provideErrorFeedback(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
                target.replaceSelection("\t");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * Deletes the character of content that precedes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * current caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     * @see DefaultEditorKit#deletePrevCharAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
    static class DeletePrevCharAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
         * Creates this object with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        DeletePrevCharAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
            super(deletePrevCharAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
         * The operation to perform when this action is triggered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
         * @param e the action event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
            boolean beep = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            if ((target != null) && (target.isEditable())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                    Document doc = target.getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                    Caret caret = target.getCaret();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                    int dot = caret.getDot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                    int mark = caret.getMark();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                    if (dot != mark) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                        doc.remove(Math.min(dot, mark), Math.abs(dot - mark));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                        beep = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                    } else if (dot > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                        int delChars = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                        if (dot > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                            String dotChars = doc.getText(dot - 2, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                            char c0 = dotChars.charAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                            char c1 = dotChars.charAt(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                            if (c0 >= '\uD800' && c0 <= '\uDBFF' &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
                                c1 >= '\uDC00' && c1 <= '\uDFFF') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                                delChars = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                        doc.remove(dot - delChars, delChars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                        beep = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                } catch (BadLocationException bl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
            if (beep) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                UIManager.getLookAndFeel().provideErrorFeedback(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     * Deletes the character of content that follows the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * current caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * @see DefaultEditorKit#deleteNextCharAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
    static class DeleteNextCharAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        /* Create this object with the appropriate identifier. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        DeleteNextCharAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            super(deleteNextCharAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
            boolean beep = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            if ((target != null) && (target.isEditable())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                    Document doc = target.getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                    Caret caret = target.getCaret();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                    int dot = caret.getDot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                    int mark = caret.getMark();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                    if (dot != mark) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                        doc.remove(Math.min(dot, mark), Math.abs(dot - mark));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                        beep = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                    } else if (dot < doc.getLength()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                        int delChars = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
                        if (dot < doc.getLength() - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                            String dotChars = doc.getText(dot, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                            char c0 = dotChars.charAt(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                            char c1 = dotChars.charAt(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                            if (c0 >= '\uD800' && c0 <= '\uDBFF' &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                                c1 >= '\uDC00' && c1 <= '\uDFFF') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                                delChars = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                        doc.remove(dot, delChars);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                        beep = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                } catch (BadLocationException bl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
            if (beep) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
                UIManager.getLookAndFeel().provideErrorFeedback(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     * Deletes the word that precedes/follows the beginning of the selection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    static class DeleteWordAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        DeleteWordAction(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
            super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
            assert (name == deletePrevWordAction)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                || (name == deleteNextWordAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
         * The operation to perform when this action is triggered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
         * @param e the action event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            final JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            if ((target != null) && (e != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                if ((! target.isEditable()) || (! target.isEnabled())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                    UIManager.getLookAndFeel().provideErrorFeedback(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                boolean beep = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
                    final int start = target.getSelectionStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                    final Element line =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                        Utilities.getParagraphElement(target, start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                    int end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                    if (deleteNextWordAction == getValue(Action.NAME)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                        end = Utilities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
                            getNextWordInParagraph(target, line, start, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                        if (end == java.text.BreakIterator.DONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                            //last word in the paragraph
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                            final int endOfLine = line.getEndOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                            if (start == endOfLine - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                                //for last position remove last \n
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                                end = endOfLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                                //remove to the end of the paragraph
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                                end = endOfLine - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                        end = Utilities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
                            getPrevWordInParagraph(target, line, start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                        if (end == java.text.BreakIterator.DONE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
                            //there is no previous word in the paragraph
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
                            final int startOfLine = line.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
                            if (start == startOfLine) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                                //for first position remove previous \n
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
                                end = startOfLine - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                                //remove to the start of the paragraph
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                                end = startOfLine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                    int offs = Math.min(start, end);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
                    int len = Math.abs(end - start);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
                    if (offs >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                        target.getDocument().remove(offs, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                        beep = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                } catch (BadLocationException ignore) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
                if (beep) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
                    UIManager.getLookAndFeel().provideErrorFeedback(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
     * Sets the editor into read-only mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     * @see DefaultEditorKit#readOnlyAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
    static class ReadOnlyAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        /* Create this object with the appropriate identifier. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        ReadOnlyAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
            super(readOnlyAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
         * The operation to perform when this action is triggered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
         * @param e the action event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                target.setEditable(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            }
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
     * Sets the editor into writeable mode.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
     * @see DefaultEditorKit#writableAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
    static class WritableAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
        /* Create this object with the appropriate identifier. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        WritableAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
            super(writableAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
         * The operation to perform when this action is triggered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
         * @param e the action event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                target.setEditable(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
     * Cuts the selected region and place its contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
     * into the system clipboard.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     * @see DefaultEditorKit#cutAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    public static class CutAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        /** Create this object with the appropriate identifier. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        public CutAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
            super(cutAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
         * The operation to perform when this action is triggered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
         * @param e the action event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
                target.cut();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
     * Copies the selected region and place its contents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
     * into the system clipboard.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     * @see DefaultEditorKit#copyAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
    public static class CopyAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
        /** Create this object with the appropriate identifier. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
        public CopyAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
            super(copyAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
         * The operation to perform when this action is triggered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
         * @param e the action event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
                target.copy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
     * Pastes the contents of the system clipboard into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
     * selected region, or before the caret if nothing is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
     * selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
     * @see DefaultEditorKit#pasteAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
    public static class PasteAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        /** Create this object with the appropriate identifier. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
        public PasteAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
            super(pasteAction);
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
         * The operation to perform when this action is triggered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
         * @param e the action event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
                target.paste();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
     * Creates a beep.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
     * <strong>Warning:</strong>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
     * Serialized objects of this class will not be compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
     * future Swing releases. The current serialization support is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
     * appropriate for short term storage or RMI between applications running
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
     * the same version of Swing.  As of 1.4, support for long term storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
     * of all JavaBeans<sup><font size="-2">TM</font></sup>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
     * has been added to the <code>java.beans</code> package.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
     * Please see {@link java.beans.XMLEncoder}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
     * @see DefaultEditorKit#beepAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
    public static class BeepAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        /** Create this object with the appropriate identifier. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
        public BeepAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
            super(beepAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
         * The operation to perform when this action is triggered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
         * @param e the action event
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
            UIManager.getLookAndFeel().provideErrorFeedback(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
     * Scrolls up/down vertically.  The select version of this action extends
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
     * the selection, instead of simply moving the caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
     * @see DefaultEditorKit#pageUpAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
     * @see DefaultEditorKit#pageDownAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
    static class VerticalPageAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
        /** Create this object with the appropriate identifier. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
        public VerticalPageAction(String nm, int direction, boolean select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
            this.direction = direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
                Rectangle visible = target.getVisibleRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
                Rectangle newVis = new Rectangle(visible);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
                int selectedIndex = target.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
                int scrollAmount = direction *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
                        target.getScrollableBlockIncrement(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
                                  visible, SwingConstants.VERTICAL, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
                int initialY = visible.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
                Caret caret = target.getCaret();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
                Point magicPosition = caret.getMagicCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
                if (selectedIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
                        Rectangle dotBounds = target.modelToView(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
                                                     selectedIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
                        int x = (magicPosition != null) ? magicPosition.x :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
                                                          dotBounds.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
                        int h = dotBounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
                        if (h > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
                            // We want to scroll by a multiple of caret height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
                            // rounding towards lower integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
                            scrollAmount = scrollAmount / h * h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
                        newVis.y = constrainY(target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
                                initialY + scrollAmount, visible.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
                        int newIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
                        if (visible.contains(dotBounds.x, dotBounds.y)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
                            // Dot is currently visible, base the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
                            // location off the old, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
                            newIndex = target.viewToModel(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
                                new Point(x, constrainY(target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
                                          dotBounds.y + scrollAmount, 0)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
                            // Dot isn't visible, choose the top or the bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
                            // for the new location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
                            if (direction == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
                                newIndex = target.viewToModel(new Point(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
                                    x, newVis.y));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
                            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
                                newIndex = target.viewToModel(new Point(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
                                    x, newVis.y + visible.height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
                        newIndex = constrainOffset(target, newIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
                        if (newIndex != selectedIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
                            // Make sure the new visible location contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
                            // the location of dot, otherwise Caret will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
                            // cause an additional scroll.
4968
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1464
                            int newY = getAdjustedY(target, newVis, newIndex);
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1465
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1466
                            if (direction == -1 && newY <= initialY || direction == 1 && newY >= initialY) {
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1467
                                // Change index and correct newVis.y only if won't cause scrolling upward
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1468
                                newVis.y = newY;
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1469
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1470
                                if (select) {
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1471
                                    target.moveCaretPosition(newIndex);
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1472
                                } else {
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1473
                                    target.setCaretPosition(newIndex);
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1474
                                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
                    } catch (BadLocationException ble) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
                    newVis.y = constrainY(target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
                            initialY + scrollAmount, visible.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
                if (magicPosition != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
                    caret.setMagicCaretPosition(magicPosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
                target.scrollRectToVisible(newVis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
         * Makes sure <code>y</code> is a valid location in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
         * <code>target</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
        private int constrainY(JTextComponent target, int y, int vis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
            if (y < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
                y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
            else if (y + vis > target.getHeight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
                y = Math.max(0, target.getHeight() - vis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
            return y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
         * Ensures that <code>offset</code> is a valid offset into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
         * model for <code>text</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
        private int constrainOffset(JTextComponent text, int offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
            Document doc = text.getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
            if ((offset != 0) && (offset > doc.getLength())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
                offset = doc.getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
            if (offset  < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
                offset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
            return offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
        /**
4968
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1520
         * Returns adjustsed {@code y} position that indicates the location to scroll to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
         * after selecting <code>index</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
         */
4968
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1523
        private int getAdjustedY(JTextComponent text, Rectangle visible, int index) {
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1524
            int result = visible.y;
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1525
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                Rectangle dotBounds = text.modelToView(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
4968
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1529
                if (dotBounds.y < visible.y) {
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1530
                    result = dotBounds.y;
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1531
                } else {
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1532
                    if ((dotBounds.y > visible.y + visible.height) ||
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1533
                            (dotBounds.y + dotBounds.height > visible.y + visible.height)) {
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1534
                        result = dotBounds.y + dotBounds.height - visible.height;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                }
4968
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1537
            } catch (BadLocationException ble) {
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1538
            }
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1539
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1540
            return result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
         * Adjusts the Rectangle to contain the bounds of the character at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
         * <code>index</code> in response to a page up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
         * Direction to scroll, 1 is down, -1 is up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
        private int direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
     * Pages one view to the left or right.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
    static class PageAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
        /** Create this object with the appropriate identifier. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
        public PageAction(String nm, boolean left, boolean select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
            this.left = left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
                int selectedIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
                Rectangle visible = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
                target.computeVisibleRect(visible);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
                if (left) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
                    visible.x = Math.max(0, visible.x - visible.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
                    visible.x += visible.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
                selectedIndex = target.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
                if(selectedIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
                    if (left) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
                        selectedIndex = target.viewToModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
                            (new Point(visible.x, visible.y));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
                        selectedIndex = target.viewToModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
                            (new Point(visible.x + visible.width - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
                                       visible.y + visible.height - 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
                    Document doc = target.getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
                    if ((selectedIndex != 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
                        (selectedIndex  > (doc.getLength()-1))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
                        selectedIndex = doc.getLength()-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
                    else if(selectedIndex  < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
                        selectedIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                    if (select)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
                        target.moveCaretPosition(selectedIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
                        target.setCaretPosition(selectedIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
        private boolean left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
    static class DumpModelAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
        DumpModelAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
            super("dump-model");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
                Document d = target.getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
                if (d instanceof AbstractDocument) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
                    ((AbstractDocument) d).dump(System.err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
     * Action to move the selection by way of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
     * getNextVisualPositionFrom method. Constructor indicates direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
     * to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
    static class NextVisualPositionAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
         * @param nm  the name of the action, Action.NAME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
         * @param select whether to extend the selection when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
         *  changing the caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
        NextVisualPositionAction(String nm, boolean select, int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
            this.direction = direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
                Caret caret = target.getCaret();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
                DefaultCaret bidiCaret = (caret instanceof DefaultCaret) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
                                              (DefaultCaret)caret : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
                int dot = caret.getDot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
                Position.Bias[] bias = new Position.Bias[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
                Point magicPosition = caret.getMagicCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
                    if(magicPosition == null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
                       (direction == SwingConstants.NORTH ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
                        direction == SwingConstants.SOUTH)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
                        Rectangle r = (bidiCaret != null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
                                target.getUI().modelToView(target, dot,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
                                                      bidiCaret.getDotBias()) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
                                target.modelToView(dot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
                        magicPosition = new Point(r.x, r.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
                    NavigationFilter filter = target.getNavigationFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
                    if (filter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
                        dot = filter.getNextVisualPositionFrom
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
                                     (target, dot, (bidiCaret != null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
                                      bidiCaret.getDotBias() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
                                      Position.Bias.Forward, direction, bias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
                        dot = target.getUI().getNextVisualPositionFrom
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                                     (target, dot, (bidiCaret != null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
                                      bidiCaret.getDotBias() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
                                      Position.Bias.Forward, direction, bias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                    if(bias[0] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
                        bias[0] = Position.Bias.Forward;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
                    if(bidiCaret != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
                        if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
                            bidiCaret.moveDot(dot, bias[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
                            bidiCaret.setDot(dot, bias[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
                        if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
                            caret.moveDot(dot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
                            caret.setDot(dot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
                    if(magicPosition != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
                       (direction == SwingConstants.NORTH ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
                        direction == SwingConstants.SOUTH)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
                        target.getCaret().setMagicCaretPosition(magicPosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
                } catch (BadLocationException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
        private int direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
     * Position the caret to the beginning of the word.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
     * @see DefaultEditorKit#beginWordAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
     * @see DefaultEditorKit#selectBeginWordAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
    static class BeginWordAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
         * @param nm  the name of the action, Action.NAME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
         * @param select whether to extend the selection when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
         *  changing the caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
        BeginWordAction(String nm, boolean select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
                    int offs = target.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
                    int begOffs = Utilities.getWordStart(target, offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
                    if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
                        target.moveCaretPosition(begOffs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
                        target.setCaretPosition(begOffs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
                } catch (BadLocationException bl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
                    UIManager.getLookAndFeel().provideErrorFeedback(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
     * Position the caret to the end of the word.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
     * @see DefaultEditorKit#endWordAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
     * @see DefaultEditorKit#selectEndWordAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
    static class EndWordAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
         * @param nm  the name of the action, Action.NAME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
         * @param select whether to extend the selection when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
         *  changing the caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
        EndWordAction(String nm, boolean select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
                    int offs = target.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
                    int endOffs = Utilities.getWordEnd(target, offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
                    if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
                        target.moveCaretPosition(endOffs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
                        target.setCaretPosition(endOffs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
                } catch (BadLocationException bl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
                    UIManager.getLookAndFeel().provideErrorFeedback(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
     * Position the caret to the beginning of the previous word.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
     * @see DefaultEditorKit#previousWordAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
     * @see DefaultEditorKit#selectPreviousWordAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
    static class PreviousWordAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
         * @param nm  the name of the action, Action.NAME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
         * @param select whether to extend the selection when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
         *  changing the caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
        PreviousWordAction(String nm, boolean select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
                int offs = target.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
                boolean failed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
                    Element curPara =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
                            Utilities.getParagraphElement(target, offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
                    offs = Utilities.getPreviousWord(target, offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
                    if(offs < curPara.getStartOffset()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
                        // we should first move to the end of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
                        // previous paragraph (bug #4278839)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
                        offs = Utilities.getParagraphElement(target, offs).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
                                getEndOffset() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
                } catch (BadLocationException bl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
                    if (offs != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
                        offs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
                        failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
                if (!failed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
                    if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
                        target.moveCaretPosition(offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
                        target.setCaretPosition(offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
                    UIManager.getLookAndFeel().provideErrorFeedback(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
     * Position the caret to the next of the word.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
     * @see DefaultEditorKit#nextWordAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
     * @see DefaultEditorKit#selectNextWordAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
    static class NextWordAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
         * @param nm  the name of the action, Action.NAME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
         * @param select whether to extend the selection when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
         *  changing the caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
        NextWordAction(String nm, boolean select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
                int offs = target.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
                boolean failed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
                int oldOffs = offs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
                Element curPara =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
                        Utilities.getParagraphElement(target, offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
                    offs = Utilities.getNextWord(target, offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
                    if(offs >= curPara.getEndOffset() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
                            oldOffs != curPara.getEndOffset() - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
                        // we should first move to the end of current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
                        // paragraph (bug #4278839)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
                        offs = curPara.getEndOffset() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
                } catch (BadLocationException bl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
                    int end = target.getDocument().getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
                    if (offs != end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
                        if(oldOffs != curPara.getEndOffset() - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
                            offs = curPara.getEndOffset() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
                        offs = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
                        failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
                if (!failed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
                    if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
                        target.moveCaretPosition(offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
                        target.setCaretPosition(offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
                    UIManager.getLookAndFeel().provideErrorFeedback(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
     * Position the caret to the beginning of the line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
     * @see DefaultEditorKit#beginLineAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
     * @see DefaultEditorKit#selectBeginLineAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
    static class BeginLineAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
         * @param nm  the name of the action, Action.NAME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
         * @param select whether to extend the selection when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
         *  changing the caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
        BeginLineAction(String nm, boolean select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
                    int offs = target.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
                    int begOffs = Utilities.getRowStart(target, offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
                    if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
                        target.moveCaretPosition(begOffs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
                        target.setCaretPosition(begOffs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
                } catch (BadLocationException bl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
                    UIManager.getLookAndFeel().provideErrorFeedback(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
     * Position the caret to the end of the line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
     * @see DefaultEditorKit#endLineAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
     * @see DefaultEditorKit#selectEndLineAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
    static class EndLineAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
         * @param nm  the name of the action, Action.NAME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
         * @param select whether to extend the selection when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
         *  changing the caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
        EndLineAction(String nm, boolean select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
                    int offs = target.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
                    int endOffs = Utilities.getRowEnd(target, offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
                    if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
                        target.moveCaretPosition(endOffs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
                        target.setCaretPosition(endOffs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
                } catch (BadLocationException bl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
                    UIManager.getLookAndFeel().provideErrorFeedback(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
     * Position the caret to the beginning of the paragraph.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
     * @see DefaultEditorKit#beginParagraphAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
     * @see DefaultEditorKit#selectBeginParagraphAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
    static class BeginParagraphAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
         * @param nm  the name of the action, Action.NAME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
         * @param select whether to extend the selection when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
         *  changing the caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
        BeginParagraphAction(String nm, boolean select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
                int offs = target.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
                Element elem = Utilities.getParagraphElement(target, offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
                offs = elem.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
                if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
                    target.moveCaretPosition(offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
                    target.setCaretPosition(offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
     * Position the caret to the end of the paragraph.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
     * @see DefaultEditorKit#endParagraphAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
     * @see DefaultEditorKit#selectEndParagraphAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
    static class EndParagraphAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
         * @param nm  the name of the action, Action.NAME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
         * @param select whether to extend the selection when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
         *  changing the caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
        EndParagraphAction(String nm, boolean select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
                int offs = target.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
                Element elem = Utilities.getParagraphElement(target, offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
                offs = Math.min(target.getDocument().getLength(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
                                elem.getEndOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
                if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
                    target.moveCaretPosition(offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
                    target.setCaretPosition(offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
     * Move the caret to the beginning of the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
     * @see DefaultEditorKit#beginAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
    static class BeginAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
        /* Create this object with the appropriate identifier. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
        BeginAction(String nm, boolean select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
                if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
                    target.moveCaretPosition(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
                    target.setCaretPosition(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
     * Move the caret to the end of the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
     * @see DefaultEditorKit#endAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
    static class EndAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
        /* Create this object with the appropriate identifier. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
        EndAction(String nm, boolean select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
                Document doc = target.getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
                int dot = doc.getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
                if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
                    target.moveCaretPosition(dot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
                    target.setCaretPosition(dot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
     * Select the word around the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
     * @see DefaultEditorKit#endAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
    static class SelectWordAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
         * @param nm  the name of the action, Action.NAME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
         * @param select whether to extend the selection when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
         *  changing the caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
        SelectWordAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
            super(selectWordAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
            start = new BeginWordAction("pigdog", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
            end = new EndWordAction("pigdog", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
            start.actionPerformed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
            end.actionPerformed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
        private Action start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
        private Action end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
     * Select the line around the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
     * @see DefaultEditorKit#endAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
    static class SelectLineAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
         * @param nm  the name of the action, Action.NAME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
         * @param select whether to extend the selection when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
         *  changing the caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
        SelectLineAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
            super(selectLineAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
            start = new BeginLineAction("pigdog", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
            end = new EndLineAction("pigdog", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
            start.actionPerformed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
            end.actionPerformed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
        private Action start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
        private Action end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
     * Select the paragraph around the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
     * @see DefaultEditorKit#endAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
    static class SelectParagraphAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
         * @param nm  the name of the action, Action.NAME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
         * @param select whether to extend the selection when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
         *  changing the caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
        SelectParagraphAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
            super(selectParagraphAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
            start = new BeginParagraphAction("pigdog", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
            end = new EndParagraphAction("pigdog", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
            start.actionPerformed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
            end.actionPerformed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
        private Action start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
        private Action end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
     * Select the entire document
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
     * @see DefaultEditorKit#endAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
    static class SelectAllAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
         * @param nm  the name of the action, Action.NAME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
         * @param select whether to extend the selection when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
         *  changing the caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
        SelectAllAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
            super(selectAllAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
                Document doc = target.getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
                target.setCaretPosition(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
                target.moveCaretPosition(doc.getLength());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
     * Remove the selection, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
     * @see DefaultEditorKit#unselectAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
    static class UnselectAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
        UnselectAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
            super(unselectAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
                target.setCaretPosition(target.getCaretPosition());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
     * Toggles the ComponentOrientation of the text component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
     * @see DefaultEditorKit#toggleComponentOrientationAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
    static class ToggleComponentOrientationAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
        ToggleComponentOrientationAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
            super(toggleComponentOrientationAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
                ComponentOrientation last = target.getComponentOrientation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
                ComponentOrientation next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
                if( last == ComponentOrientation.RIGHT_TO_LEFT )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
                    next = ComponentOrientation.LEFT_TO_RIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
                    next = ComponentOrientation.RIGHT_TO_LEFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
                target.setComponentOrientation(next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
                target.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
}