jdk/src/share/classes/javax/swing/text/CompositeView.java
author malenkov
Mon, 14 Oct 2013 13:59:38 +0400
changeset 21256 dfb1f9090caa
parent 20158 1c5d22e5b898
child 22260 c9185e010e03
permissions -rw-r--r--
7016396: (spec) JCK test mentioned in 6735293 is still failing Reviewed-by: alexsch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 2006, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.SwingConstants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <code>CompositeView</code> is an abstract <code>View</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * implementation which manages one or more child views.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * (Note that <code>CompositeView</code> is intended
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * for managing relatively small numbers of child views.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * <code>CompositeView</code> is intended to be used as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * a starting point for <code>View</code> implementations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * such as <code>BoxView</code>, that will contain child
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <code>View</code>s. Subclasses that wish to manage the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * collection of child <code>View</code>s should use the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * {@link #replace} method.  As <code>View</code> invokes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * <code>replace</code> during <code>DocumentListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * notification, you normally won't need to directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * invoke <code>replace</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <p>While <code>CompositeView</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * does not impose a layout policy on its child <code>View</code>s,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * it does allow for inseting the child <code>View</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * it will contain.  The insets can be set by either
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * {@link #setInsets} or {@link #setParagraphInsets}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <p>In addition to the abstract methods of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * {@link javax.swing.text.View},
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * subclasses of <code>CompositeView</code> will need to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * override:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <li>{@link #isBefore} - Used to test if a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *     <code>View</code> location is before the visual space
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *     of the <code>CompositeView</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <li>{@link #isAfter} - Used to test if a given
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *     <code>View</code> location is after the visual space
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *     of the <code>CompositeView</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <li>{@link #getViewAtPoint} - Returns the view at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *     a given visual location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <li>{@link #childAllocation} - Returns the bounds of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *     a particular child <code>View</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *     <code>getChildAllocation</code> will invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *     <code>childAllocation</code> after offseting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *     the bounds by the <code>Inset</code>s of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *     <code>CompositeView</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
public abstract class CompositeView extends View {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Constructs a <code>CompositeView</code> for the given element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @param elem  the element this view is responsible for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public CompositeView(Element elem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        super(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        children = new View[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        nchildren = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        childAlloc = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * Loads all of the children to initialize the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * This is called by the {@link #setParent}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * method.  Subclasses can reimplement this to initialize
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * their child views in a different manner.  The default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * implementation creates a child view for each
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * child element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @param f the view factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @see #setParent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    protected void loadChildren(ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        if (f == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            // No factory. This most likely indicates the parent view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            // has changed out from under us, bail!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        Element e = getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        int n = e.getElementCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        if (n > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            View[] added = new View[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                added[i] = f.create(e.getElement(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            replace(0, 0, added);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    // --- View methods ---------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * Sets the parent of the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * This is reimplemented to provide the superclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * behavior as well as calling the <code>loadChildren</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * method if this view does not already have children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * The children should not be loaded in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * constructor because the act of setting the parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * may cause them to try to search up the hierarchy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * (to get the hosting <code>Container</code> for example).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * If this view has children (the view is being moved
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * from one place in the view hierarchy to another),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * the <code>loadChildren</code> method will not be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * @param parent the parent of the view, <code>null</code> if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public void setParent(View parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        super.setParent(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if ((parent != null) && (nchildren == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            ViewFactory f = getViewFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            loadChildren(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Returns the number of child views of this view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   146
     * @return the number of views &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @see #getView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    public int getViewCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        return nchildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Returns the n-th view in this container.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   156
     * @param n the number of the desired view, &gt;= 0 &amp;&amp; &lt; getViewCount()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @return the view at index <code>n</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    public View getView(int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        return children[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * Replaces child views.  If there are no views to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * this acts as an insert.  If there are no views to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * add this acts as a remove.  Views being removed will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * have the parent set to <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * and the internal reference to them removed so that they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * may be garbage collected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @param offset the starting index into the child views to insert
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   172
     *   the new views; &gt;= 0 and &lt;= getViewCount
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @param length the number of existing child views to remove;
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   174
     *   this should be a value &gt;= 0 and &lt;= (getViewCount() - offset)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @param views the child views to add; this value can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *  <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *   to indicate no children are being added (useful to remove)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public void replace(int offset, int length, View[] views) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        // make sure an array exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        if (views == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            views = ZERO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        // update parent reference on removed views
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        for (int i = offset; i < offset + length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            if (children[i].getParent() == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                // in FlowView.java view might be referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                // from two super-views as a child. see logicalView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                children[i].setParent(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            children[i] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        // update the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        int delta = views.length - length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        int src = offset + length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        int nmove = nchildren - src;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        int dest = src + delta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        if ((nchildren + delta) >= children.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            // need to grow the array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            int newLength = Math.max(2*children.length, nchildren + delta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            View[] newChildren = new View[newLength];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            System.arraycopy(children, 0, newChildren, 0, offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            System.arraycopy(views, 0, newChildren, offset, views.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            System.arraycopy(children, src, newChildren, dest, nmove);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            children = newChildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            // patch the existing array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            System.arraycopy(children, src, children, dest, nmove);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            System.arraycopy(views, 0, children, offset, views.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        nchildren = nchildren + delta;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        // update parent reference on added views
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        for (int i = 0; i < views.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            views[i].setParent(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Fetches the allocation for the given child view to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * render into. This enables finding out where various views
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * are located.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   226
     * @param index the index of the child, &gt;= 0 &amp;&amp; &lt; getViewCount()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @param a  the allocation to this view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @return the allocation to the child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    public Shape getChildAllocation(int index, Shape a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        Rectangle alloc = getInsideAllocation(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        childAllocation(index, alloc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        return alloc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Provides a mapping from the document model coordinate space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * to the coordinate space of the view mapped to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   240
     * @param pos the position to convert &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @param b a bias value of either <code>Position.Bias.Forward</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *  or <code>Position.Bias.Backward</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @return the bounding box of the given position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @exception BadLocationException  if the given position does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *   not represent a valid location in the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @see View#modelToView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        boolean isBackward = (b == Position.Bias.Backward);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        int testPos = (isBackward) ? Math.max(0, pos - 1) : pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if(isBackward && testPos < getStartOffset()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        int vIndex = getViewIndexAtPosition(testPos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        if ((vIndex != -1) && (vIndex < getViewCount())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            View v = getView(vIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            if(v != null && testPos >= v.getStartOffset() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
               testPos < v.getEndOffset()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                Shape childShape = getChildAllocation(vIndex, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                if (childShape == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                    // We are likely invalid, fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                Shape retShape = v.modelToView(pos, childShape, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                if(retShape == null && v.getEndOffset() == pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                    if(++vIndex < getViewCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                        v = getView(vIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                        retShape = v.modelToView(pos, getChildAllocation(vIndex, a), b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                return retShape;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        throw new BadLocationException("Position not represented by view",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                                       pos);
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
     * Provides a mapping from the document model coordinate space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * to the coordinate space of the view mapped to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   283
     * @param p0 the position to convert &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @param b0 the bias toward the previous character or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *  next character represented by p0, in case the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *  position is a boundary of two views; either
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     *  <code>Position.Bias.Forward</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *  <code>Position.Bias.Backward</code>
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   289
     * @param p1 the position to convert &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * @param b1 the bias toward the previous character or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     *  next character represented by p1, in case the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *  position is a boundary of two views
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @return the bounding box of the given position is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @exception BadLocationException  if the given position does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *   not represent a valid location in the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @exception IllegalArgumentException for an invalid bias argument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @see View#viewToModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    public Shape modelToView(int p0, Position.Bias b0, int p1, Position.Bias b1, Shape a) throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        if (p0 == getStartOffset() && p1 == getEndOffset()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            return a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        Rectangle alloc = getInsideAllocation(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        Rectangle r0 = new Rectangle(alloc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        View v0 = getViewAtPosition((b0 == Position.Bias.Backward) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                                    Math.max(0, p0 - 1) : p0, r0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        Rectangle r1 = new Rectangle(alloc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        View v1 = getViewAtPosition((b1 == Position.Bias.Backward) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                                    Math.max(0, p1 - 1) : p1, r1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        if (v0 == v1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            if (v0 == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                return a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            // Range contained in one view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            return v0.modelToView(p0, b0, p1, b1, r0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        // Straddles some views.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        int viewCount = getViewCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        int counter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        while (counter < viewCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            View v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            // Views may not be in same order as model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            // v0 or v1 may be null if there is a gap in the range this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            // view contains.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            if ((v = getView(counter)) == v0 || v == v1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                View endView;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                Rectangle retRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                Rectangle tempRect = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                if (v == v0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                    retRect = v0.modelToView(p0, b0, v0.getEndOffset(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                                             Position.Bias.Backward, r0).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                              getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                    endView = v1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                    retRect = v1.modelToView(v1.getStartOffset(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                                             Position.Bias.Forward,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                                             p1, b1, r1).getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                    endView = v0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                // Views entirely covered by range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                while (++counter < viewCount &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                       (v = getView(counter)) != endView) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
                    tempRect.setBounds(alloc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                    childAllocation(counter, tempRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
                    retRect.add(tempRect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                // End view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                if (endView != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                    Shape endShape;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
                    if (endView == v1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
                        endShape = v1.modelToView(v1.getStartOffset(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                                                  Position.Bias.Forward,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                                                  p1, b1, r1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                        endShape = v0.modelToView(p0, b0, v0.getEndOffset(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                                                  Position.Bias.Backward, r0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                    if (endShape instanceof Rectangle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                        retRect.add((Rectangle)endShape);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                    else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                        retRect.add(endShape.getBounds());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                return retRect;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            counter++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        throw new BadLocationException("Position not represented by view", p0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * Provides a mapping from the view coordinate space to the logical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * coordinate space of the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   381
     * @param x   x coordinate of the view location to convert &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   382
     * @param y   y coordinate of the view location to convert &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * @param bias either <code>Position.Bias.Forward</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     *  <code>Position.Bias.Backward</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * @return the location within the model that best represents the
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   387
     *  given point in the view &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * @see View#viewToModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    public int viewToModel(float x, float y, Shape a, Position.Bias[] bias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        Rectangle alloc = getInsideAllocation(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        if (isBefore((int) x, (int) y, alloc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            // point is before the range represented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            int retValue = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                retValue = getNextVisualPositionFrom(-1, Position.Bias.Forward,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                                                     a, EAST, bias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            } catch (BadLocationException ble) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            catch (IllegalArgumentException iae) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            if(retValue == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                retValue = getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                bias[0] = Position.Bias.Forward;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            return retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        } else if (isAfter((int) x, (int) y, alloc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            // point is after the range represented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            int retValue = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                retValue = getNextVisualPositionFrom(-1, Position.Bias.Forward,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                                                     a, WEST, bias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            } catch (BadLocationException ble) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            catch (IllegalArgumentException iae) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            if(retValue == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                // NOTE: this could actually use end offset with backward.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                retValue = getEndOffset() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                bias[0] = Position.Bias.Forward;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            return retValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            // locate the child and pass along the request
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            View v = getViewAtPoint((int) x, (int) y, alloc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
              return v.viewToModel(x, y, alloc, bias);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * Provides a way to determine the next visually represented model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * location that one might place a caret.  Some views may not be visible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * they might not be in the same order found in the model, or they just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * might not allow access to some of the locations in the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * This is a convenience method for {@link #getNextNorthSouthVisualPositionFrom}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * and {@link #getNextEastWestVisualPositionFrom}.
21256
dfb1f9090caa 7016396: (spec) JCK test mentioned in 6735293 is still failing
malenkov
parents: 20158
diff changeset
   438
     * This method enables specifying a position to convert
dfb1f9090caa 7016396: (spec) JCK test mentioned in 6735293 is still failing
malenkov
parents: 20158
diff changeset
   439
     * within the range of &gt;=0.  If the value is -1, a position
dfb1f9090caa 7016396: (spec) JCK test mentioned in 6735293 is still failing
malenkov
parents: 20158
diff changeset
   440
     * will be calculated automatically.  If the value &lt; -1,
dfb1f9090caa 7016396: (spec) JCK test mentioned in 6735293 is still failing
malenkov
parents: 20158
diff changeset
   441
     * the {@code BadLocationException} will be thrown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     *
21256
dfb1f9090caa 7016396: (spec) JCK test mentioned in 6735293 is still failing
malenkov
parents: 20158
diff changeset
   443
     * @param pos the position to convert
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * @param b a bias value of either <code>Position.Bias.Forward</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     *  or <code>Position.Bias.Backward</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @param direction the direction from the current position that can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *  be thought of as the arrow keys typically found on a keyboard;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     *  this may be one of the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     *  <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     *  <li><code>SwingConstants.WEST</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *  <li><code>SwingConstants.EAST</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *  <li><code>SwingConstants.NORTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     *  <li><code>SwingConstants.SOUTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *  </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @param biasRet an array containing the bias that was checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * @return the location within the model that best represents the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     *  location visual position
21256
dfb1f9090caa 7016396: (spec) JCK test mentioned in 6735293 is still failing
malenkov
parents: 20158
diff changeset
   459
     * @exception BadLocationException the given position is not a valid
dfb1f9090caa 7016396: (spec) JCK test mentioned in 6735293 is still failing
malenkov
parents: 20158
diff changeset
   460
     *                                 position within the document
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * @exception IllegalArgumentException if <code>direction</code> is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                                         int direction, Position.Bias[] biasRet)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
      throws BadLocationException {
21256
dfb1f9090caa 7016396: (spec) JCK test mentioned in 6735293 is still failing
malenkov
parents: 20158
diff changeset
   466
        if (pos < -1) {
dfb1f9090caa 7016396: (spec) JCK test mentioned in 6735293 is still failing
malenkov
parents: 20158
diff changeset
   467
            throw new BadLocationException("invalid position", pos);
dfb1f9090caa 7016396: (spec) JCK test mentioned in 6735293 is still failing
malenkov
parents: 20158
diff changeset
   468
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        Rectangle alloc = getInsideAllocation(a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        switch (direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        case NORTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            return getNextNorthSouthVisualPositionFrom(pos, b, a, direction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                                                       biasRet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        case SOUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            return getNextNorthSouthVisualPositionFrom(pos, b, a, direction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                                                       biasRet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        case EAST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            return getNextEastWestVisualPositionFrom(pos, b, a, direction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                                                     biasRet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        case WEST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            return getNextEastWestVisualPositionFrom(pos, b, a, direction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                                                     biasRet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            throw new IllegalArgumentException("Bad direction: " + direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * Returns the child view index representing the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * position in the model.  This is implemented to call the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * <code>getViewIndexByPosition</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * method for backward compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   495
     * @param pos the position &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * @return  index of the view representing the given position, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     *   -1 if no view represents that position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    public int getViewIndex(int pos, Position.Bias b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        if(b == Position.Bias.Backward) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            pos -= 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        if ((pos >= getStartOffset()) && (pos < getEndOffset())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            return getViewIndexAtPosition(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    // --- local methods ----------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * Tests whether a point lies before the rectangle range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   516
     * @param x the X coordinate &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   517
     * @param y the Y coordinate &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * @param alloc the rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * @return true if the point is before the specified range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    protected abstract boolean isBefore(int x, int y, Rectangle alloc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * Tests whether a point lies after the rectangle range.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   526
     * @param x the X coordinate &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   527
     * @param y the Y coordinate &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * @param alloc the rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * @return true if the point is after the specified range
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    protected abstract boolean isAfter(int x, int y, Rectangle alloc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * Fetches the child view at the given coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   536
     * @param x the X coordinate &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   537
     * @param y the Y coordinate &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * @param alloc the parent's allocation on entry, which should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     *   be changed to the child's allocation on exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * @return the child view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    protected abstract View getViewAtPoint(int x, int y, Rectangle alloc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * Returns the allocation for a given child.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   547
     * @param index the index of the child, &gt;= 0 &amp;&amp; &lt; getViewCount()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * @param a  the allocation to the interior of the box on entry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     *   and the allocation of the child view at the index on exit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    protected abstract void childAllocation(int index, Rectangle a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * Fetches the child view that represents the given position in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * the model.  This is implemented to fetch the view in the case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * where there is a child view for each child element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   558
     * @param pos the position &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
     * @param a  the allocation to the interior of the box on entry,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     *   and the allocation of the view containing the position on exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * @return  the view representing the given position, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     *   <code>null</code> if there isn't one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    protected View getViewAtPosition(int pos, Rectangle a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        int index = getViewIndexAtPosition(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        if ((index >= 0) && (index < getViewCount())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            View v = getView(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            if (a != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                childAllocation(index, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            return v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * Fetches the child view index representing the given position in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * the model.  This is implemented to fetch the view in the case
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * where there is a child view for each child element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   581
     * @param pos the position &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * @return  index of the view representing the given position, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     *   -1 if no view represents that position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    protected int getViewIndexAtPosition(int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        Element elem = getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        return elem.getElementIndex(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * Translates the immutable allocation given to the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * to a mutable allocation that represents the interior
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * allocation (i.e. the bounds of the given allocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * with the top, left, bottom, and right insets removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * It is expected that the returned value would be further
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * mutated to represent an allocation to a child view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * This is implemented to reuse an instance variable so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * it avoids creating excessive Rectangles.  Typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * the result of calling this method would be fed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * the <code>childAllocation</code> method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * @param a the allocation given to the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * @return the allocation that represents the inside of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     *   view after the margins have all been removed; if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     *   given allocation was <code>null</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     *   the return value is <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    protected Rectangle getInsideAllocation(Shape a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        if (a != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            // get the bounds, hopefully without allocating
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            // a new rectangle.  The Shape argument should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            // not be modified... we copy it into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            // child allocation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
            Rectangle alloc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            if (a instanceof Rectangle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                alloc = (Rectangle) a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                alloc = a.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            childAlloc.setBounds(alloc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            childAlloc.x += getLeftInset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            childAlloc.y += getTopInset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            childAlloc.width -= getLeftInset() + getRightInset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            childAlloc.height -= getTopInset() + getBottomInset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            return childAlloc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * Sets the insets from the paragraph attributes specified in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     * the given attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     * @param attr the attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    protected void setParagraphInsets(AttributeSet attr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        // Since version 1.1 doesn't have scaling and assumes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        // a pixel is equal to a point, we just cast the point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        // sizes to integers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        top = (short) StyleConstants.getSpaceAbove(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        left = (short) StyleConstants.getLeftIndent(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        bottom = (short) StyleConstants.getSpaceBelow(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        right = (short) StyleConstants.getRightIndent(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     * Sets the insets for the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   650
     * @param top the top inset &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   651
     * @param left the left inset &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   652
     * @param bottom the bottom inset &gt;= 0
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   653
     * @param right the right inset &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    protected void setInsets(short top, short left, short bottom, short right) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        this.top = top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        this.left = left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        this.right = right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        this.bottom = bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     * Gets the left inset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   665
     * @return the inset &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    protected short getLeftInset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
        return left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * Gets the right inset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   674
     * @return the inset &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    protected short getRightInset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        return right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * Gets the top inset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   683
     * @return the inset &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    protected short getTopInset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        return top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * Gets the bottom inset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   692
     * @return the inset &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    protected short getBottomInset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
        return bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * Returns the next visual position for the cursor, in either the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     * north or south direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   702
     * @param pos the position to convert &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * @param b a bias value of either <code>Position.Bias.Forward</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     *  or <code>Position.Bias.Backward</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * @param direction the direction from the current position that can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     *  be thought of as the arrow keys typically found on a keyboard;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     *  this may be one of the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     *  <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     *  <li><code>SwingConstants.NORTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     *  <li><code>SwingConstants.SOUTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     *  </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * @param biasRet an array containing the bias that was checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * @return the location within the model that best represents the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     *  north or south location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * @exception BadLocationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * @exception IllegalArgumentException if <code>direction</code> is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * @see #getNextVisualPositionFrom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * @return the next position west of the passed in position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    protected int getNextNorthSouthVisualPositionFrom(int pos, Position.Bias b,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                                                      Shape a, int direction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
                                                      Position.Bias[] biasRet)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
                                                throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        return Utilities.getNextVisualPositionFrom(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                            this, pos, b, a, direction, biasRet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * Returns the next visual position for the cursor, in either the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * east or west direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     *
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 5506
diff changeset
   734
    * @param pos the position to convert &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * @param b a bias value of either <code>Position.Bias.Forward</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     *  or <code>Position.Bias.Backward</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * @param direction the direction from the current position that can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     *  be thought of as the arrow keys typically found on a keyboard;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     *  this may be one of the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     *  <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     *  <li><code>SwingConstants.WEST</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     *  <li><code>SwingConstants.EAST</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     *  </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * @param biasRet an array containing the bias that was checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * @return the location within the model that best represents the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     *  west or east location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * @exception BadLocationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * @exception IllegalArgumentException if <code>direction</code> is invalid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * @see #getNextVisualPositionFrom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    protected int getNextEastWestVisualPositionFrom(int pos, Position.Bias b,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
                                                    Shape a,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                                                    int direction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
                                                    Position.Bias[] biasRet)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
                                                throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
        return Utilities.getNextVisualPositionFrom(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                            this, pos, b, a, direction, biasRet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * Determines in which direction the next view lays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * Consider the <code>View</code> at index n. Typically the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * <code>View</code>s are layed out from left to right,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * so that the <code>View</code> to the EAST will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * at index n + 1, and the <code>View</code> to the WEST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * will be at index n - 1. In certain situations,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * such as with bidirectional text, it is possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * that the <code>View</code> to EAST is not at index n + 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * but rather at index n - 1, or that the <code>View</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * to the WEST is not at index n - 1, but index n + 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * In this case this method would return true, indicating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * <code>View</code>s are layed out in descending order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * This unconditionally returns false, subclasses should override this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * method if there is the possibility for laying <code>View</code>s in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * descending order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * @param position position into the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * @param bias either <code>Position.Bias.Forward</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     *          <code>Position.Bias.Backward</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * @return false
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    protected boolean flipEastAndWestAtEnds(int position,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                                            Position.Bias bias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    // ---- member variables ---------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    private static View[] ZERO = new View[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
    private View[] children;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    private int nchildren;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    private short left;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    private short right;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
    private short top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    private short bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
    private Rectangle childAlloc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
}