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