jdk/src/java.desktop/share/classes/javax/swing/text/DefaultEditorKit.java
author smarks
Tue, 29 Aug 2017 12:16:28 -0700
changeset 47020 2c55106dc37b
parent 44655 06871a50a4b5
child 47165 eb0b0e665926
permissions -rw-r--r--
8186851: fix misspellings of "dependent" and "independent" in the JDK repo Reviewed-by: bpb, psadhukhan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
44655
06871a50a4b5 8177461: Wrong references are used in the javadoc in the java.desktop module
serb
parents: 42216
diff changeset
     2
 * Copyright (c) 1997, 2017, 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. */
42216
621af0ebf6c4 8169518: Suppress Deprecation warnings for deprecated Swing APIs
prr
parents: 25859
diff changeset
  1432
        @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
                Rectangle visible = target.getVisibleRect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
                Rectangle newVis = new Rectangle(visible);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
                int selectedIndex = target.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
                int scrollAmount = direction *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
                        target.getScrollableBlockIncrement(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
                                  visible, SwingConstants.VERTICAL, direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
                int initialY = visible.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
                Caret caret = target.getCaret();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
                Point magicPosition = caret.getMagicCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
                if (selectedIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
                        Rectangle dotBounds = target.modelToView(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
                                                     selectedIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
                        int x = (magicPosition != null) ? magicPosition.x :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
                                                          dotBounds.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
                        int h = dotBounds.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
                        if (h > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
                            // We want to scroll by a multiple of caret height,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
                            // rounding towards lower integer
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
                            scrollAmount = scrollAmount / h * h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
                        newVis.y = constrainY(target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
                                initialY + scrollAmount, visible.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
                        int newIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
                        if (visible.contains(dotBounds.x, dotBounds.y)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
                            // Dot is currently visible, base the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
                            // location off the old, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
                            newIndex = target.viewToModel(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
                                new Point(x, constrainY(target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
                                          dotBounds.y + scrollAmount, 0)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
                        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
                            // Dot isn't visible, choose the top or the bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
                            // for the new location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
                            if (direction == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
                                newIndex = target.viewToModel(new Point(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
                                    x, newVis.y));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
                            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
                                newIndex = target.viewToModel(new Point(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
                                    x, newVis.y + visible.height));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
                        newIndex = constrainOffset(target, newIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
                        if (newIndex != selectedIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
                            // Make sure the new visible location contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
                            // the location of dot, otherwise Caret will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
                            // 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
  1487
                            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
  1488
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1489
                            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
  1490
                                // 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
  1491
                                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
  1492
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1493
                                if (select) {
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1494
                                    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
  1495
                                } else {
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1496
                                    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
  1497
                                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
                    } catch (BadLocationException ble) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
                    newVis.y = constrainY(target,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
                            initialY + scrollAmount, visible.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
                if (magicPosition != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
                    caret.setMagicCaretPosition(magicPosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
                target.scrollRectToVisible(newVis);
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
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
         * Makes sure <code>y</code> is a valid location in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
         * <code>target</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
        private int constrainY(JTextComponent target, int y, int vis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
            if (y < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
                y = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
            else if (y + vis > target.getHeight()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
                y = Math.max(0, target.getHeight() - vis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
            return y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
         * Ensures that <code>offset</code> is a valid offset into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
         * model for <code>text</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
        private int constrainOffset(JTextComponent text, int offset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
            Document doc = text.getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
            if ((offset != 0) && (offset > doc.getLength())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
                offset = doc.getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
            if (offset  < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
                offset = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
            return offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
        /**
4968
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1543
         * Returns adjustsed {@code y} position that indicates the location to scroll to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
         * after selecting <code>index</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
         */
42216
621af0ebf6c4 8169518: Suppress Deprecation warnings for deprecated Swing APIs
prr
parents: 25859
diff changeset
  1546
        @SuppressWarnings("deprecation")
4968
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1547
        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
  1548
            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
  1549
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
                Rectangle dotBounds = text.modelToView(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
4968
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1553
                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
  1554
                    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
  1555
                } else {
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1556
                    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
  1557
                            (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
  1558
                        result = dotBounds.y + dotBounds.height - visible.height;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                }
4968
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1561
            } 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
  1562
            }
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1563
517b279d7f2b 6917744: JScrollPane Page Up/Down keys do not handle correctly html tables with different cells contents
rupashka
parents: 2
diff changeset
  1564
            return result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
         * Adjusts the Rectangle to contain the bounds of the character at
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
         * <code>index</code> in response to a page up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
         * Direction to scroll, 1 is down, -1 is up.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
        private int direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
     * Pages one view to the left or right.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23307
diff changeset
  1583
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
    static class PageAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
        /** Create this object with the appropriate identifier. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
        public PageAction(String nm, boolean left, boolean select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
            this.left = left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
        /** The operation to perform when this action is triggered. */
42216
621af0ebf6c4 8169518: Suppress Deprecation warnings for deprecated Swing APIs
prr
parents: 25859
diff changeset
  1594
        @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
                int selectedIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
                Rectangle visible = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                target.computeVisibleRect(visible);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                if (left) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
                    visible.x = Math.max(0, visible.x - visible.width);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
                    visible.x += visible.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
                selectedIndex = target.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
                if(selectedIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
                    if (left) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
                        selectedIndex = target.viewToModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
                            (new Point(visible.x, visible.y));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
                        selectedIndex = target.viewToModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
                            (new Point(visible.x + visible.width - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
                                       visible.y + visible.height - 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
                    Document doc = target.getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
                    if ((selectedIndex != 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
                        (selectedIndex  > (doc.getLength()-1))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
                        selectedIndex = doc.getLength()-1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
                    else if(selectedIndex  < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
                        selectedIndex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
                    if (select)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
                        target.moveCaretPosition(selectedIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
                    else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
                        target.setCaretPosition(selectedIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
        private boolean left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23307
diff changeset
  1639
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
    static class DumpModelAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
        DumpModelAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
            super("dump-model");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
                Document d = target.getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
                if (d instanceof AbstractDocument) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
                    ((AbstractDocument) d).dump(System.err);
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
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
     * Action to move the selection by way of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
     * getNextVisualPositionFrom method. Constructor indicates direction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
     * to use.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23307
diff changeset
  1662
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
    static class NextVisualPositionAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
         * @param nm  the name of the action, Action.NAME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
         * @param select whether to extend the selection when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
         *  changing the caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
        NextVisualPositionAction(String nm, boolean select, int direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
            this.direction = direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
        /** The operation to perform when this action is triggered. */
42216
621af0ebf6c4 8169518: Suppress Deprecation warnings for deprecated Swing APIs
prr
parents: 25859
diff changeset
  1678
        @SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
                Caret caret = target.getCaret();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
                DefaultCaret bidiCaret = (caret instanceof DefaultCaret) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                                              (DefaultCaret)caret : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                int dot = caret.getDot();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
                Position.Bias[] bias = new Position.Bias[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
                Point magicPosition = caret.getMagicCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
                    if(magicPosition == null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
                       (direction == SwingConstants.NORTH ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
                        direction == SwingConstants.SOUTH)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
                        Rectangle r = (bidiCaret != null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
                                target.getUI().modelToView(target, dot,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
                                                      bidiCaret.getDotBias()) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
                                target.modelToView(dot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
                        magicPosition = new Point(r.x, r.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
                    NavigationFilter filter = target.getNavigationFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
                    if (filter != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
                        dot = filter.getNextVisualPositionFrom
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
                                     (target, dot, (bidiCaret != null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
                                      bidiCaret.getDotBias() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
                                      Position.Bias.Forward, direction, bias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
                        dot = target.getUI().getNextVisualPositionFrom
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
                                     (target, dot, (bidiCaret != null) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
                                      bidiCaret.getDotBias() :
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
                                      Position.Bias.Forward, direction, bias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
                    if(bias[0] == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
                        bias[0] = Position.Bias.Forward;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
                    if(bidiCaret != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
                        if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
                            bidiCaret.moveDot(dot, bias[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
                            bidiCaret.setDot(dot, bias[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
                        if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
                            caret.moveDot(dot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
                            caret.setDot(dot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
                    if(magicPosition != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
                       (direction == SwingConstants.NORTH ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
                        direction == SwingConstants.SOUTH)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
                        target.getCaret().setMagicCaretPosition(magicPosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
                } catch (BadLocationException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
        private int direction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
     * Position the caret to the beginning of the word.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
     * @see DefaultEditorKit#beginWordAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
     * @see DefaultEditorKit#selectBeginWordAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23307
diff changeset
  1751
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
    static class BeginWordAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
         * @param nm  the name of the action, Action.NAME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
         * @param select whether to extend the selection when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
         *  changing the caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
        BeginWordAction(String nm, boolean select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
                    int offs = target.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
                    int begOffs = Utilities.getWordStart(target, offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
                    if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
                        target.moveCaretPosition(begOffs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
                        target.setCaretPosition(begOffs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
                } catch (BadLocationException bl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
                    UIManager.getLookAndFeel().provideErrorFeedback(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
                }
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
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
     * Position the caret to the end of the word.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
     * @see DefaultEditorKit#endWordAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
     * @see DefaultEditorKit#selectEndWordAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23307
diff changeset
  1792
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
    static class EndWordAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
         * @param nm  the name of the action, Action.NAME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
         * @param select whether to extend the selection when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
         *  changing the caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
        EndWordAction(String nm, boolean select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
                    int offs = target.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
                    int endOffs = Utilities.getWordEnd(target, offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
                    if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
                        target.moveCaretPosition(endOffs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
                        target.setCaretPosition(endOffs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
                } catch (BadLocationException bl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
                    UIManager.getLookAndFeel().provideErrorFeedback(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
                }
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
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
     * Position the caret to the beginning of the previous word.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
     * @see DefaultEditorKit#previousWordAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
     * @see DefaultEditorKit#selectPreviousWordAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23307
diff changeset
  1833
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
    static class PreviousWordAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
         * @param nm  the name of the action, Action.NAME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
         * @param select whether to extend the selection when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
         *  changing the caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
        PreviousWordAction(String nm, boolean select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
                int offs = target.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
                boolean failed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
                    Element curPara =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
                            Utilities.getParagraphElement(target, offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
                    offs = Utilities.getPreviousWord(target, offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
                    if(offs < curPara.getStartOffset()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
                        // we should first move to the end of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
                        // previous paragraph (bug #4278839)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
                        offs = Utilities.getParagraphElement(target, offs).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
                                getEndOffset() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
                } catch (BadLocationException bl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
                    if (offs != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
                        offs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
                        failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
                if (!failed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
                    if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
                        target.moveCaretPosition(offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
                        target.setCaretPosition(offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
                    UIManager.getLookAndFeel().provideErrorFeedback(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
                }
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
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
     * Position the caret to the next of the word.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
     * @see DefaultEditorKit#nextWordAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
     * @see DefaultEditorKit#selectNextWordAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23307
diff changeset
  1893
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
    static class NextWordAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
         * @param nm  the name of the action, Action.NAME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
         * @param select whether to extend the selection when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
         *  changing the caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
        NextWordAction(String nm, boolean select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
                int offs = target.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
                boolean failed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
                int oldOffs = offs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
                Element curPara =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
                        Utilities.getParagraphElement(target, offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
                    offs = Utilities.getNextWord(target, offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
                    if(offs >= curPara.getEndOffset() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
                            oldOffs != curPara.getEndOffset() - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
                        // we should first move to the end of current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
                        // paragraph (bug #4278839)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
                        offs = curPara.getEndOffset() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
                } catch (BadLocationException bl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
                    int end = target.getDocument().getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
                    if (offs != end) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
                        if(oldOffs != curPara.getEndOffset() - 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
                            offs = curPara.getEndOffset() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
                        offs = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
                        failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
                if (!failed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
                    if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
                        target.moveCaretPosition(offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
                        target.setCaretPosition(offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
                    UIManager.getLookAndFeel().provideErrorFeedback(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
                }
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
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
     * Position the caret to the beginning of the line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
     * @see DefaultEditorKit#beginLineAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
     * @see DefaultEditorKit#selectBeginLineAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23307
diff changeset
  1959
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
    static class BeginLineAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
         * @param nm  the name of the action, Action.NAME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
         * @param select whether to extend the selection when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
         *  changing the caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
        BeginLineAction(String nm, boolean select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
                    int offs = target.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
                    int begOffs = Utilities.getRowStart(target, offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
                    if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
                        target.moveCaretPosition(begOffs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
                        target.setCaretPosition(begOffs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
                } catch (BadLocationException bl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
                    UIManager.getLookAndFeel().provideErrorFeedback(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
                }
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
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
     * Position the caret to the end of the line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
     * @see DefaultEditorKit#endLineAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
     * @see DefaultEditorKit#selectEndLineAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23307
diff changeset
  2000
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
    static class EndLineAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
         * @param nm  the name of the action, Action.NAME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
         * @param select whether to extend the selection when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
         *  changing the caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
        EndLineAction(String nm, boolean select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
                    int offs = target.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
                    int endOffs = Utilities.getRowEnd(target, offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
                    if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
                        target.moveCaretPosition(endOffs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
                        target.setCaretPosition(endOffs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
                } catch (BadLocationException bl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
                    UIManager.getLookAndFeel().provideErrorFeedback(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
                }
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
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
     * Position the caret to the beginning of the paragraph.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
     * @see DefaultEditorKit#beginParagraphAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
     * @see DefaultEditorKit#selectBeginParagraphAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23307
diff changeset
  2041
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
    static class BeginParagraphAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
         * @param nm  the name of the action, Action.NAME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
         * @param select whether to extend the selection when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
         *  changing the caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
        BeginParagraphAction(String nm, boolean select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
                int offs = target.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
                Element elem = Utilities.getParagraphElement(target, offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
                offs = elem.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
                if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
                    target.moveCaretPosition(offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
                    target.setCaretPosition(offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
                }
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
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
     * Position the caret to the end of the paragraph.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
     * @see DefaultEditorKit#endParagraphAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
     * @see DefaultEditorKit#selectEndParagraphAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23307
diff changeset
  2079
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
    static class EndParagraphAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
         * @param nm  the name of the action, Action.NAME.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
         * @param select whether to extend the selection when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
         *  changing the caret position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
        EndParagraphAction(String nm, boolean select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
                int offs = target.getCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
                Element elem = Utilities.getParagraphElement(target, offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
                offs = Math.min(target.getDocument().getLength(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
                                elem.getEndOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
                if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
                    target.moveCaretPosition(offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
                    target.setCaretPosition(offs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
                }
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
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
     * Move the caret to the beginning of the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
     * @see DefaultEditorKit#beginAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23307
diff changeset
  2117
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
    static class BeginAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
        /* Create this object with the appropriate identifier. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
        BeginAction(String nm, boolean select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
                if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
                    target.moveCaretPosition(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
                    target.setCaretPosition(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
                }
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
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
     * Move the caret to the end of the document.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
     * @see DefaultEditorKit#endAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23307
diff changeset
  2146
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
    static class EndAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
        /* Create this object with the appropriate identifier. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
        EndAction(String nm, boolean select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
            super(nm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
            this.select = select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
                Document doc = target.getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
                int dot = doc.getLength();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
                if (select) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
                    target.moveCaretPosition(dot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
                    target.setCaretPosition(dot);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
                }
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
        private boolean select;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
     * Select the word around the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
     * @see DefaultEditorKit#endAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23307
diff changeset
  2177
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
    static class SelectWordAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
        SelectWordAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
            super(selectWordAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
            start = new BeginWordAction("pigdog", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
            end = new EndWordAction("pigdog", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
            start.actionPerformed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
            end.actionPerformed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
        private Action start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
        private Action end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
     * Select the line around the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
     * @see DefaultEditorKit#endAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23307
diff changeset
  2204
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
    static class SelectLineAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
        SelectLineAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
            super(selectLineAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
            start = new BeginLineAction("pigdog", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
            end = new EndLineAction("pigdog", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
            start.actionPerformed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
            end.actionPerformed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
        private Action start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
        private Action end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
     * Select the paragraph around the caret
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
     * @see DefaultEditorKit#endAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23307
diff changeset
  2231
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
    static class SelectParagraphAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
        SelectParagraphAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
            super(selectParagraphAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
            start = new BeginParagraphAction("pigdog", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
            end = new EndParagraphAction("pigdog", true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
            start.actionPerformed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
            end.actionPerformed(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
        private Action start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
        private Action end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
     * Select the entire document
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
     * @see DefaultEditorKit#endAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23307
diff changeset
  2258
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
    static class SelectAllAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
        SelectAllAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
            super(selectAllAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
                Document doc = target.getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
                target.setCaretPosition(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
                target.moveCaretPosition(doc.getLength());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
     * Remove the selection, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
     * @see DefaultEditorKit#unselectAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23307
diff changeset
  2285
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
    static class UnselectAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
        UnselectAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
            super(unselectAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
                target.setCaretPosition(target.getCaretPosition());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
     * Toggles the ComponentOrientation of the text component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
     * @see DefaultEditorKit#toggleComponentOrientationAction
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
     * @see DefaultEditorKit#getActions
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
     */
23697
e556a715949f 8034169: Fix serial lint warnings in javax.swing
darcy
parents: 23307
diff changeset
  2310
    @SuppressWarnings("serial") // Superclass is not serializable across versions
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
    static class ToggleComponentOrientationAction extends TextAction {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
         * Create this action with the appropriate identifier.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
        ToggleComponentOrientationAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
            super(toggleComponentOrientationAction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
        /** The operation to perform when this action is triggered. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
        public void actionPerformed(ActionEvent e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
            JTextComponent target = getTextComponent(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
            if (target != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
                ComponentOrientation last = target.getComponentOrientation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
                ComponentOrientation next;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
                if( last == ComponentOrientation.RIGHT_TO_LEFT )
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
                    next = ComponentOrientation.LEFT_TO_RIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
                    next = ComponentOrientation.RIGHT_TO_LEFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
                target.setComponentOrientation(next);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
                target.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
}