jdk/src/share/classes/javax/swing/text/View.java
author yan
Fri, 04 Apr 2014 15:43:10 +0400
changeset 23715 54ae9dd9df73
parent 21982 fd6e5fe509df
permissions -rw-r--r--
8039074: Tidy warnings cleanup for javax.swing Reviewed-by: pchelko, alexsch Contributed-by: Alexander Stepanov <alexander.v.stepanov@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
17689
c6db20805a87 8014863: Line break calculations in Java 7 are incorrect.
mcherkas
parents: 9035
diff changeset
     2
 * Copyright (c) 1997, 2013, 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.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.swing.SwingConstants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * A very important part of the text package is the <code>View</code> class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * As the name suggests it represents a view of the text model,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * or a piece of the text model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * It is this class that is responsible for the look of the text component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * The view is not intended to be some completely new thing that one must
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * learn, but rather is much like a lightweight component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
By default, a view is very light.  It contains a reference to the parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
view from which it can fetch many things without holding state, and it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
contains a reference to a portion of the model (<code>Element</code>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
A view does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
have to exactly represent an element in the model, that is simply a typical
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
and therefore convenient mapping.  A view can alternatively maintain a couple
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
of Position objects to maintain its location in the model (i.e. represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
a fragment of an element).  This is typically the result of formatting where
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
views have been broken down into pieces.  The convenience of a substantial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
relationship to the element makes it easier to build factories to produce the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
views, and makes it easier  to keep track of the view pieces as the model is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
changed and the view must be changed to reflect the model.  Simple views
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
therefore represent an Element directly and complex views do not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
A view has the following responsibilities:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
  <dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    <dt><b>Participate in layout.</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    <dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    <p>The view has a <code>setSize</code> method which is like
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    <code>doLayout</code> and <code>setSize</code> in <code>Component</code> combined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    The view has a <code>preferenceChanged</code> method which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    like <code>invalidate</code> in <code>Component</code> except that one can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    invalidate just one axis
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    and the child requesting the change is identified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    <p>A View expresses the size that it would like to be in terms of three
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    values, a minimum, a preferred, and a maximum span.  Layout in a view is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    can be done independently upon each axis.  For a properly functioning View
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    implementation, the minimum span will be &lt;= the preferred span which in turn
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    will be &lt;= the maximum span.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    </p>
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 20428
diff changeset
    71
    <p style="text-align:center"><img src="doc-files/View-flexibility.jpg"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                     alt="The above text describes this graphic.">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    <p>The minimum set of methods for layout are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    <ul>
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 20126
diff changeset
    75
    <li>{@link #getMinimumSpan(int) getMinimumSpan}
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 20126
diff changeset
    76
    <li>{@link #getPreferredSpan(int) getPreferredSpan}
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 20126
diff changeset
    77
    <li>{@link #getMaximumSpan(int) getMaximumSpan}
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 20126
diff changeset
    78
    <li>{@link #getAlignment(int) getAlignment}
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 20126
diff changeset
    79
    <li>{@link #preferenceChanged(javax.swing.text.View, boolean, boolean) preferenceChanged}
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 20126
diff changeset
    80
    <li>{@link #setSize(float, float) setSize}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
  <p>The <code>setSize</code> method should be prepared to be called a number of times
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    (i.e. It may be called even if the size didn't change).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    The <code>setSize</code> method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    is generally called to make sure the View layout is complete prior to trying
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    to perform an operation on it that requires an up-to-date layout.  A view's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    size should <em>always</em> be set to a value within the minimum and maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    span specified by that view.  Additionally, the view must always call the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    <code>preferenceChanged</code> method on the parent if it has changed the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    values for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    layout it would like, and expects the parent to honor.  The parent View is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    not required to recognize a change until the <code>preferenceChanged</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    has been sent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    This allows parent View implementations to cache the child requirements if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    desired.  The calling sequence looks something like the following:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    </p>
20451
4cedf4e1560a 8025409: Fix javadoc comments errors and warning reported by doclint report
cl
parents: 20428
diff changeset
    98
    <p style="text-align:center">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
      <img src="doc-files/View-layout.jpg"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
       alt="Sample calling sequence between parent view and child view:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
       setSize, getMinimum, getPreferred, getMaximum, getAlignment, setSize">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    <p>The exact calling sequence is up to the layout functionality of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    the parent view (if the view has any children).  The view may collect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    the preferences of the children prior to determining what it will give
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    each child, or it might iteratively update the children one at a time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    <dt><b>Render a portion of the model.</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    <dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    <p>This is done in the paint method, which is pretty much like a component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    paint method.  Views are expected to potentially populate a fairly large
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    tree.  A <code>View</code> has the following semantics for rendering:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    <li>The view gets its allocation from the parent at paint time, so it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    must be prepared to redo layout if the allocated area is different from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    what it is prepared to deal with.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    <li>The coordinate system is the same as the hosting <code>Component</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    (i.e. the <code>Component</code> returned by the
7959
2e05332a8f5c 6589952: Swing: dead links in API documentation
rupashka
parents: 5506
diff changeset
   120
    {@link #getContainer getContainer} method).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    This means a child view lives in the same coordinate system as the parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    view unless the parent has explicitly changed the coordinate system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    To schedule itself to be repainted a view can call repaint on the hosting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    <code>Component</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    <li>The default is to <em>not clip</em> the children.  It is more efficient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    to allow a view to clip only if it really feels it needs clipping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    <li>The <code>Graphics</code> object given is not initialized in any way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    A view should set any settings needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    <li>A <code>View</code> is inherently transparent.  While a view may render into its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    entire allocation, typically a view does not.  Rendering is performed by
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21256
diff changeset
   131
    traversing down the tree of <code>View</code> implementations.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    Each <code>View</code> is responsible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    for rendering its children.  This behavior is depended upon for thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    safety.  While view implementations do not necessarily have to be implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    with thread safety in mind, other view implementations that do make use of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    concurrency can depend upon a tree traversal to guarantee thread safety.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    <li>The order of views relative to the model is up to the implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    Although child views will typically be arranged in the same order that they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    occur in the model, they may be visually arranged in an entirely different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    order.  View implementations may have Z-Order associated with them if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    children are overlapping.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    <p>The methods for rendering are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    <ul>
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 20126
diff changeset
   145
    <li>{@link #paint(java.awt.Graphics, java.awt.Shape) paint}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    <dt><b>Translate between the model and view coordinate systems.</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    <dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    <p>Because the view objects are produced from a factory and therefore cannot
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    necessarily be counted upon to be in a particular pattern, one must be able
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    to perform translation to properly locate spatial representation of the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    The methods for doing this are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    <ul>
20158
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 20126
diff changeset
   155
    <li>{@link #modelToView(int, javax.swing.text.Position.Bias, int, javax.swing.text.Position.Bias, java.awt.Shape) modelToView}
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 20126
diff changeset
   156
    <li>{@link #viewToModel(float, float, java.awt.Shape, javax.swing.text.Position.Bias[]) viewToModel}
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 20126
diff changeset
   157
    <li>{@link #getDocument() getDocument}
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 20126
diff changeset
   158
    <li>{@link #getElement() getElement}
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 20126
diff changeset
   159
    <li>{@link #getStartOffset() getStartOffset}
1c5d22e5b898 8025117: [cleanup] Eliminate doclint errors in javax/swing/text classes
yan
parents: 20126
diff changeset
   160
    <li>{@link #getEndOffset() getEndOffset}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    <p>The layout must be valid prior to attempting to make the translation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    The translation is not valid, and must not be attempted while changes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    are being broadcasted from the model via a <code>DocumentEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    <dt><b>Respond to changes from the model.</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    <dd>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    <p>If the overall view is represented by many pieces (which is the best situation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    if one want to be able to change the view and write the least amount of new code),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    it would be impractical to have a huge number of <code>DocumentListener</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    If each
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    view listened to the model, only a few would actually be interested in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    changes broadcasted at any given time.   Since the model has no knowledge of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    views, it has no way to filter the broadcast of change information.  The view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    hierarchy itself is instead responsible for propagating the change information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    At any level in the view hierarchy, that view knows enough about its children to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    best distribute the change information further.   Changes are therefore broadcasted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    starting from the root of the view hierarchy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    The methods for doing this are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    <ul>
7959
2e05332a8f5c 6589952: Swing: dead links in API documentation
rupashka
parents: 5506
diff changeset
   182
    <li>{@link #insertUpdate insertUpdate}
2e05332a8f5c 6589952: Swing: dead links in API documentation
rupashka
parents: 5506
diff changeset
   183
    <li>{@link #removeUpdate removeUpdate}
2e05332a8f5c 6589952: Swing: dead links in API documentation
rupashka
parents: 5506
diff changeset
   184
    <li>{@link #changedUpdate changedUpdate}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
</dl>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
public abstract class View implements SwingConstants {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Creates a new <code>View</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @param elem the <code>Element</code> to represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public View(Element elem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        this.elem = elem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * Returns the parent of the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @return the parent, or <code>null</code> if none exists
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public View getParent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *  Returns a boolean that indicates whether
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     *  the view is visible or not.  By default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *  all views are visible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *  @return always returns true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    public boolean isVisible() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        return true;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * Determines the preferred span for this view along an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @param axis may be either <code>View.X_AXIS</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *          <code>View.Y_AXIS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * @return   the span the view would like to be rendered into.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *           Typically the view is told to render into the span
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *           that is returned, although there is no guarantee.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *           The parent may choose to resize or break the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @see View#getPreferredSpan
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public abstract float getPreferredSpan(int axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * Determines the minimum span for this view along an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @param axis may be either <code>View.X_AXIS</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *          <code>View.Y_AXIS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @return  the minimum span the view can be rendered into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @see View#getPreferredSpan
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    public float getMinimumSpan(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        int w = getResizeWeight(axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if (w == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            // can't resize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            return getPreferredSpan(axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * Determines the maximum span for this view along an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @param axis may be either <code>View.X_AXIS</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *          <code>View.Y_AXIS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @return  the maximum span the view can be rendered into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @see View#getPreferredSpan
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    public float getMaximumSpan(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        int w = getResizeWeight(axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        if (w == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            // can't resize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            return getPreferredSpan(axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        return Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Child views can call this on the parent to indicate that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * the preference has changed and should be reconsidered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * for layout.  By default this just propagates upward to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * the next parent.  The root view will call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * <code>revalidate</code> on the associated text component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @param child the child view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @param width true if the width preference has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @param height true if the height preference has changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @see javax.swing.JComponent#revalidate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    public void preferenceChanged(View child, boolean width, boolean height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        View parent = getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            parent.preferenceChanged(this, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * Determines the desired alignment for this view along an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * axis.  The desired alignment is returned.  This should be
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   294
     * a value &gt;= 0.0 and &lt;= 1.0, where 0 indicates alignment at
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * the origin and 1.0 indicates alignment to the full span
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * away from the origin.  An alignment of 0.5 would be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * center of the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @param axis may be either <code>View.X_AXIS</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *          <code>View.Y_AXIS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @return the value 0.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    public float getAlignment(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        return 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * Renders using the given rendering surface and area on that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * surface.  The view may need to do layout and create child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * views to enable itself to render into the given allocation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @param g the rendering surface to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @param allocation the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public abstract void paint(Graphics g, Shape allocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * Establishes the parent view for this view.  This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * guaranteed to be called before any other methods if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * parent view is functioning properly.  This is also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * the last method called, since it is called to indicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * the view has been removed from the hierarchy as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * well. When this method is called to set the parent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * null, this method does the same for each of its children,
21278
ef8a3a2a72f2 8022746: List of spelling errors in API doc
malenkov
parents: 21256
diff changeset
   325
     * propagating the notification that they have been
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * disconnected from the view tree. If this is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * reimplemented, <code>super.setParent()</code> should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * be called.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @param parent the new parent, or <code>null</code> if the view is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *          being removed from a parent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    public void setParent(View parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        // if the parent is null then propogate down the view tree
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        if (parent == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            for (int i = 0; i < getViewCount(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
                if (getView(i).getParent() == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                    // in FlowView.java view might be referenced
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                    // from two super-views as a child. see logicalView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                    getView(i).setParent(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        this.parent = parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * Returns the number of views in this view.  Since
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * the default is to not be a composite view this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * returns 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   352
     * @return the number of views &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @see View#getViewCount
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    public int getViewCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * Gets the <i>n</i>th child view.  Since there are no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * children by default, this returns <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   363
     * @param n the number of the view to get, &gt;= 0 &amp;&amp; &lt; getViewCount()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * @return the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    public View getView(int n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        return null;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * Removes all of the children.  This is a convenience
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * call to <code>replace</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public void removeAll() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        replace(0, getViewCount(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * Removes one of the children at the given position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * This is a convenience call to <code>replace</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    public void remove(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        replace(i, 1, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * Inserts a single child view.  This is a convenience
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * call to <code>replace</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     *
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   394
     * @param offs the offset of the view to insert before &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @param v the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @see #replace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    public void insert(int offs, View v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        View[] one = new View[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        one[0] = v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        replace(offs, 0, one);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * Appends a single child view.  This is a convenience
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * call to <code>replace</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * @param v the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * @see #replace
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
    public void append(View v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        View[] one = new View[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        one[0] = v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        replace(getViewCount(), 0, one);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * Replaces child views.  If there are no views to remove
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * this acts as an insert.  If there are no views to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * add this acts as a remove.  Views being removed will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * have the parent set to <code>null</code>, and the internal reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * to them removed so that they can be garbage collected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * This is implemented to do nothing, because by default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * a view has no children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * @param offset the starting index into the child views to insert
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   429
     *   the new views.  This should be a value &gt;= 0 and &lt;= getViewCount
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * @param length the number of existing child views to remove
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   431
     *   This should be a value &gt;= 0 and &lt;= (getViewCount() - offset).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * @param views the child views to add.  This value can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *   <code>null</code> to indicate no children are being added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *   (useful to remove).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    public void replace(int offset, int length, View[] views) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * Returns the child view index representing the given position in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * the model.  By default a view has no children so this is implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * to return -1 to indicate there is no valid child index for any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     *
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   446
     * @param pos the position &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @return  index of the view representing the given position, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *   -1 if no view represents that position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    public int getViewIndex(int pos, Position.Bias b) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * Fetches the allocation for the given child view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * This enables finding out where various views
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * are located, without assuming how the views store
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * their location.  This returns <code>null</code> since the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * default is to not have any child views.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     *
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   462
     * @param index the index of the child, &gt;= 0 &amp;&amp; &lt;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     *          <code>getViewCount()</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * @param a  the allocation to this view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @return the allocation to the child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
    public Shape getChildAllocation(int index, Shape a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * Provides a way to determine the next visually represented model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * location at which one might place a caret.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * Some views may not be visible,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     * they might not be in the same order found in the model, or they just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * might not allow access to some of the locations in the model.
21256
dfb1f9090caa 7016396: (spec) JCK test mentioned in 6735293 is still failing
malenkov
parents: 20451
diff changeset
   477
     * This method enables specifying a position to convert
dfb1f9090caa 7016396: (spec) JCK test mentioned in 6735293 is still failing
malenkov
parents: 20451
diff changeset
   478
     * 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: 20451
diff changeset
   479
     * will be calculated automatically.  If the value &lt; -1,
dfb1f9090caa 7016396: (spec) JCK test mentioned in 6735293 is still failing
malenkov
parents: 20451
diff changeset
   480
     * the {@code BadLocationException} will be thrown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     *
21256
dfb1f9090caa 7016396: (spec) JCK test mentioned in 6735293 is still failing
malenkov
parents: 20451
diff changeset
   482
     * @param pos the position to convert
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @param a the allocated region in which to render
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * @param direction the direction from the current position that can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     *  be thought of as the arrow keys typically found on a keyboard.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     *  This will be one of the following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * <li>SwingConstants.WEST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * <li>SwingConstants.EAST
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * <li>SwingConstants.NORTH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * <li>SwingConstants.SOUTH
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @return the location within the model that best represents the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *  location visual position
21256
dfb1f9090caa 7016396: (spec) JCK test mentioned in 6735293 is still failing
malenkov
parents: 20451
diff changeset
   495
     * @exception BadLocationException the given position is not a valid
dfb1f9090caa 7016396: (spec) JCK test mentioned in 6735293 is still failing
malenkov
parents: 20451
diff changeset
   496
     *                                 position within the document
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * @exception IllegalArgumentException if <code>direction</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     *          doesn't have one of the legal values above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                                         int direction, Position.Bias[] biasRet)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
      throws BadLocationException {
7964
fda4ca3f7b24 6735293: javax.swing.text.NavigationFilter.getNextVisualPositionFrom() not always throws BadLocationException
rupashka
parents: 7959
diff changeset
   503
        if (pos < -1) {
fda4ca3f7b24 6735293: javax.swing.text.NavigationFilter.getNextVisualPositionFrom() not always throws BadLocationException
rupashka
parents: 7959
diff changeset
   504
            // -1 is a reserved value, see the code below
fda4ca3f7b24 6735293: javax.swing.text.NavigationFilter.getNextVisualPositionFrom() not always throws BadLocationException
rupashka
parents: 7959
diff changeset
   505
            throw new BadLocationException("Invalid position", pos);
fda4ca3f7b24 6735293: javax.swing.text.NavigationFilter.getNextVisualPositionFrom() not always throws BadLocationException
rupashka
parents: 7959
diff changeset
   506
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        biasRet[0] = Position.Bias.Forward;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        switch (direction) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        case NORTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        case SOUTH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            if (pos == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                pos = (direction == NORTH) ? Math.max(0, getEndOffset() - 1) :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                    getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            JTextComponent target = (JTextComponent) getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            Caret c = (target != null) ? target.getCaret() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            // YECK! Ideally, the x location from the magic caret position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            // would be passed in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            Point mcp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                mcp = c.getMagicCaretPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                mcp = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            int x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            if (mcp == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                Rectangle loc = target.modelToView(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                x = (loc == null) ? 0 : loc.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                x = mcp.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
            if (direction == NORTH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                pos = Utilities.getPositionAbove(target, pos, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                pos = Utilities.getPositionBelow(target, pos, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        case WEST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            if(pos == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                pos = Math.max(0, getEndOffset() - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                pos = Math.max(0, pos - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        case EAST:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            if(pos == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                pos = getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                pos = Math.min(pos + 1, getDocument().getLength());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            throw new IllegalArgumentException("Bad direction: " + direction);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        return pos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     * Provides a mapping, for a given character,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * from the document model coordinate space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * to the view coordinate space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     *
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   572
     * @param pos the position of the desired character (&gt;=0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * @param a the area of the view, which encompasses the requested character
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * @param b the bias toward the previous character or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     *  next character represented by the offset, in case the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     *  position is a boundary of two views; <code>b</code> will have one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     *  of these values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     * <li> <code>Position.Bias.Forward</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * <li> <code>Position.Bias.Backward</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * @return the bounding box, in view coordinate space,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     *          of the character at the specified position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * @exception BadLocationException  if the specified position does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     *   not represent a valid location in the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     * @exception IllegalArgumentException if <code>b</code> is not one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
     *          legal <code>Position.Bias</code> values listed above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * @see View#viewToModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    public abstract Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * Provides a mapping, for a given region,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     * from the document model coordinate space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     * to the view coordinate space. The specified region is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
     * created as a union of the first and last character positions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     *
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   598
     * @param p0 the position of the first character (&gt;=0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * @param b0 the bias of the first character position,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     *  toward the previous character or the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     *  next character represented by the offset, in case the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     *  position is a boundary of two views; <code>b0</code> will have one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     *  of these values:
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   604
     * <ul style="list-style-type:none">
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * <li> <code>Position.Bias.Forward</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * <li> <code>Position.Bias.Backward</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * </ul>
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   608
     * @param p1 the position of the last character (&gt;=0)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * @param b1 the bias for the second character position, defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     *          one of the legal values shown above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * @param a the area of the view, which encompasses the requested region
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * @return the bounding box which is a union of the region specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     *          by the first and last character positions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * @exception BadLocationException  if the given position does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     *   not represent a valid location in the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * @exception IllegalArgumentException if <code>b0</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     *          <code>b1</code> are not one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     *          legal <code>Position.Bias</code> values listed above
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * @see View#viewToModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    public Shape modelToView(int p0, Position.Bias b0, int p1, Position.Bias b1, Shape a) throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        Shape s0 = modelToView(p0, a, b0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        Shape s1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        if (p1 == getEndOffset()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                s1 = modelToView(p1, a, b1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            } catch (BadLocationException ble) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                s1 = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            if (s1 == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                // Assume extends left to right.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                                  a.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                s1 = new Rectangle(alloc.x + alloc.width - 1, alloc.y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                                   1, alloc.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
            s1 = modelToView(p1, a, b1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        Rectangle r0 = s0.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        Rectangle r1 = (s1 instanceof Rectangle) ? (Rectangle) s1 :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                                                   s1.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
        if (r0.y != r1.y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            // If it spans lines, force it to be the width of the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                              a.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
            r0.x = alloc.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            r0.width = alloc.width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        r0.add(r1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        return r0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * Provides a mapping from the view coordinate space to the logical
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * coordinate space of the model.  The <code>biasReturn</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * argument will be filled in to indicate that the point given is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * closer to the next character in the model or the previous
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     * character in the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     *
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   662
     * @param x the X coordinate &gt;= 0
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   663
     * @param y the Y coordinate &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     * @param a the allocated region in which to render
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * @return the location within the model that best represents the
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   666
     *  given point in the view &gt;= 0.  The <code>biasReturn</code>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     *  argument will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * filled in to indicate that the point given is closer to the next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * character in the model or the previous character in the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    public abstract int viewToModel(float x, float y, Shape a, Position.Bias[] biasReturn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * Gives notification that something was inserted into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * the document in a location that this view is responsible for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * To reduce the burden to subclasses, this functionality is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * spread out into the following calls that subclasses can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * reimplement:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * <ol>
7959
2e05332a8f5c 6589952: Swing: dead links in API documentation
rupashka
parents: 5506
diff changeset
   680
     * <li>{@link #updateChildren updateChildren} is called
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * if there were any changes to the element this view is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * responsible for.  If this view has child views that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * represent the child elements, then this method should do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * whatever is necessary to make sure the child views correctly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * represent the model.
7959
2e05332a8f5c 6589952: Swing: dead links in API documentation
rupashka
parents: 5506
diff changeset
   686
     * <li>{@link #forwardUpdate forwardUpdate} is called
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     * to forward the DocumentEvent to the appropriate child views.
7959
2e05332a8f5c 6589952: Swing: dead links in API documentation
rupashka
parents: 5506
diff changeset
   688
     * <li>{@link #updateLayout updateLayout} is called to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * give the view a chance to either repair its layout, to reschedule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * layout, or do nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * @param e the change information from the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     * @param a the current allocation of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * @param f the factory to use to rebuild if the view has children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * @see View#insertUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
    public void insertUpdate(DocumentEvent e, Shape a, ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        if (getViewCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            Element elem = getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            DocumentEvent.ElementChange ec = e.getChange(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            if (ec != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                if (! updateChildren(ec, e, f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                    // don't consider the element changes they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                    // are for a view further down.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                    ec = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
            forwardUpdate(ec, e, a, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            updateLayout(ec, e, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * Gives notification that something was removed from the document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * in a location that this view is responsible for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * To reduce the burden to subclasses, this functionality is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * spread out into the following calls that subclasses can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * reimplement:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * <ol>
7959
2e05332a8f5c 6589952: Swing: dead links in API documentation
rupashka
parents: 5506
diff changeset
   721
     * <li>{@link #updateChildren updateChildren} is called
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * if there were any changes to the element this view is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * responsible for.  If this view has child views that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * represent the child elements, then this method should do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * whatever is necessary to make sure the child views correctly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * represent the model.
7959
2e05332a8f5c 6589952: Swing: dead links in API documentation
rupashka
parents: 5506
diff changeset
   727
     * <li>{@link #forwardUpdate forwardUpdate} is called
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * to forward the DocumentEvent to the appropriate child views.
7959
2e05332a8f5c 6589952: Swing: dead links in API documentation
rupashka
parents: 5506
diff changeset
   729
     * <li>{@link #updateLayout updateLayout} is called to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * give the view a chance to either repair its layout, to reschedule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * layout, or do nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * @param e the change information from the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     * @param a the current allocation of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * @param f the factory to use to rebuild if the view has children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     * @see View#removeUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        if (getViewCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
            Element elem = getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            DocumentEvent.ElementChange ec = e.getChange(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
            if (ec != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                if (! updateChildren(ec, e, f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                    // don't consider the element changes they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                    // are for a view further down.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
                    ec = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
            forwardUpdate(ec, e, a, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
            updateLayout(ec, e, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * Gives notification from the document that attributes were changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * in a location that this view is responsible for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     * To reduce the burden to subclasses, this functionality is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * spread out into the following calls that subclasses can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * reimplement:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * <ol>
7959
2e05332a8f5c 6589952: Swing: dead links in API documentation
rupashka
parents: 5506
diff changeset
   762
     * <li>{@link #updateChildren updateChildren} is called
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * if there were any changes to the element this view is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * responsible for.  If this view has child views that are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * represent the child elements, then this method should do
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * whatever is necessary to make sure the child views correctly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * represent the model.
7959
2e05332a8f5c 6589952: Swing: dead links in API documentation
rupashka
parents: 5506
diff changeset
   768
     * <li>{@link #forwardUpdate forwardUpdate} is called
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * to forward the DocumentEvent to the appropriate child views.
7959
2e05332a8f5c 6589952: Swing: dead links in API documentation
rupashka
parents: 5506
diff changeset
   770
     * <li>{@link #updateLayout updateLayout} is called to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * give the view a chance to either repair its layout, to reschedule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * layout, or do nothing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * @param e the change information from the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * @param a the current allocation of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * @param f the factory to use to rebuild if the view has children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * @see View#changedUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        if (getViewCount() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            Element elem = getElement();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            DocumentEvent.ElementChange ec = e.getChange(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
            if (ec != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
                if (! updateChildren(ec, e, f)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                    // don't consider the element changes they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                    // are for a view further down.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                    ec = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            forwardUpdate(ec, e, a, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
            updateLayout(ec, e, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * Fetches the model associated with the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * @return the view model, <code>null</code> if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * @see View#getDocument
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    public Document getDocument() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
        return elem.getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * Fetches the portion of the model for which this view is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * responsible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     *
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   810
     * @return the starting offset into the model &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * @see View#getStartOffset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
    public int getStartOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
        return elem.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * Fetches the portion of the model for which this view is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * responsible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     *
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   821
     * @return the ending offset into the model &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * @see View#getEndOffset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    public int getEndOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        return elem.getEndOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * Fetches the structural portion of the subject that this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * view is mapped to.  The view may not be responsible for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * entire portion of the element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * @return the subject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * @see View#getElement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    public Element getElement() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        return elem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * Fetch a <code>Graphics</code> for rendering.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * This can be used to determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * font characteristics, and will be different for a print view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * than a component view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * @return a <code>Graphics</code> object for rendering
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    public Graphics getGraphics() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        // PENDING(prinz) this is a temporary implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        Component c = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
        return c.getGraphics();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
     * Fetches the attributes to use when rendering.  By default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * this simply returns the attributes of the associated element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * This method should be used rather than using the element
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * directly to obtain access to the attributes to allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * view-specific attributes to be mixed in or to allow the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * view to have view-specific conversion of attributes by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * Each view should document what attributes it recognizes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * for the purpose of rendering or layout, and should always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * access them through the <code>AttributeSet</code> returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * by this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
    public AttributeSet getAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
        return elem.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * Tries to break this view on the given axis.  This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * called by views that try to do formatting of their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * children.  For example, a view of a paragraph will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * typically try to place its children into row and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * views representing chunks of text can sometimes be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * broken down into smaller pieces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * This is implemented to return the view itself, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * represents the default behavior on not being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * breakable.  If the view does support breaking, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * starting offset of the view returned should be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * given offset, and the end offset should be less than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * or equal to the end offset of the view being broken.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * @param axis may be either <code>View.X_AXIS</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     *          <code>View.Y_AXIS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * @param offset the location in the document model
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   890
     *   that a broken fragment would occupy &gt;= 0.  This
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     *   would be the starting offset of the fragment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     *   returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * @param pos the position along the axis that the
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   894
     *  broken view would occupy &gt;= 0.  This may be useful for
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     *  things like tab calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * @param len specifies the distance along the axis
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   897
     *  where a potential break is desired &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     * @return the fragment of the view that represents the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
     *  given span, if the view can be broken.  If the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
     *  doesn't support breaking behavior, the view itself is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
     *  returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * @see ParagraphView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
    public View breakView(int axis, int offset, float pos, float len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * Creates a view that represents a portion of the element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * This is potentially useful during formatting operations
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * for taking measurements of fragments of the view.  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * the view doesn't support fragmenting (the default), it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     * should return itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     *
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   915
     * @param p0 the starting offset &gt;= 0.  This should be a value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     *   greater or equal to the element starting offset and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     *   less than the element ending offset.
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   918
     * @param p1 the ending offset &gt; p0.  This should be a value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     *   less than or equal to the elements end offset and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     *   greater than the elements starting offset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * @return the view fragment, or itself if the view doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     *   support breaking into fragments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * @see LabelView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    public View createFragment(int p0, int p1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * Determines how attractive a break opportunity in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * this view is.  This can be used for determining which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * view is the most attractive to call <code>breakView</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * on in the process of formatting.  A view that represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * text that has whitespace in it might be more attractive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * than a view that has no whitespace, for example.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * higher the weight, the more attractive the break.  A
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * value equal to or lower than <code>BadBreakWeight</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * should not be considered for a break.  A value greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * than or equal to <code>ForcedBreakWeight</code> should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * be broken.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * This is implemented to provide the default behavior
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     * of returning <code>BadBreakWeight</code> unless the length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     * is greater than the length of the view in which case the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     * entire view represents the fragment.  Unless a view has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     * been written to support breaking behavior, it is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     * attractive to try and break the view.  An example of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * a view that does support breaking is <code>LabelView</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * An example of a view that uses break weight is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * <code>ParagraphView</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * @param axis may be either <code>View.X_AXIS</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     *          <code>View.Y_AXIS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * @param pos the potential location of the start of the
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   955
     *   broken view &gt;= 0.  This may be useful for calculating tab
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     *   positions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * @param len specifies the relative length from <em>pos</em>
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   958
     *   where a potential break is desired &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * @return the weight, which should be a value between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     *   ForcedBreakWeight and BadBreakWeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * @see LabelView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     * @see ParagraphView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * @see #BadBreakWeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     * @see #GoodBreakWeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     * @see #ExcellentBreakWeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     * @see #ForcedBreakWeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    public int getBreakWeight(int axis, float pos, float len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        if (len > getPreferredSpan(axis)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
            return GoodBreakWeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        return BadBreakWeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * Determines the resizability of the view along the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * given axis.  A value of 0 or less is not resizable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * @param axis may be either <code>View.X_AXIS</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     *          <code>View.Y_AXIS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * @return the weight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    public int getResizeWeight(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * Sets the size of the view.  This should cause
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * layout of the view along the given axis, if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * has any layout duties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     *
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   992
     * @param width the width &gt;= 0
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
   993
     * @param height the height &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    public void setSize(float width, float height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * Fetches the container hosting the view.  This is useful for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * things like scheduling a repaint, finding out the host
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     * components font, etc.  The default implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * of this is to forward the query to the parent view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * @return the container, <code>null</code> if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
    public Container getContainer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        View v = getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        return (v != null) ? v.getContainer() : null;
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
     * Fetches the <code>ViewFactory</code> implementation that is feeding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * the view hierarchy.  Normally the views are given this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * as an argument to updates from the model when they
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * are most likely to need the factory, but this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * method serves to provide it at other times.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * @return the factory, <code>null</code> if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
    public ViewFactory getViewFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        View v = getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
        return (v != null) ? v.getViewFactory() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * Returns the tooltip text at the specified location. The default
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * implementation returns the value from the child View identified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * the passed in location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * @see JTextComponent#getToolTipText
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
    public String getToolTipText(float x, float y, Shape allocation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        int viewIndex = getViewIndex(x, y, allocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        if (viewIndex >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            allocation = getChildAllocation(viewIndex, allocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            Rectangle rect = (allocation instanceof Rectangle) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                             (Rectangle)allocation : allocation.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            if (rect.contains(x, y)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                return getView(viewIndex).getToolTipText(x, y, allocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * Returns the child view index representing the given position in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     * the view. This iterates over all the children returning the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     * first with a bounds that contains <code>x</code>, <code>y</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     * @param x the x coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     * @param y the y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     * @param allocation current allocation of the View.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     * @return  index of the view representing the given location, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     *   -1 if no view represents that position
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    public int getViewIndex(float x, float y, Shape allocation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        for (int counter = getViewCount() - 1; counter >= 0; counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            Shape childAllocation = getChildAllocation(counter, allocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            if (childAllocation != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                Rectangle rect = (childAllocation instanceof Rectangle) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                         (Rectangle)childAllocation : childAllocation.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                if (rect.contains(x, y)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                    return counter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        return -1;
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
     * Updates the child views in response to receiving notification
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     * that the model changed, and there is change record for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
     * element this view is responsible for.  This is implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * to assume the child views are directly responsible for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
     * child elements of the element this view represents.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     * <code>ViewFactory</code> is used to create child views for each element
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     * specified as added in the <code>ElementChange</code>, starting at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     * index specified in the given <code>ElementChange</code>.  The number of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     * child views representing the removed elements specified are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     * removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
     * @param ec the change information for the element this view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     *  is responsible for.  This should not be <code>null</code> if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
     *  this method gets called
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     * @param e the change information from the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     * @param f the factory to use to build child views
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     * @return whether or not the child views represent the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     *  child elements of the element this view is responsible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     *  for.  Some views create children that represent a portion
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
     *  of the element they are responsible for, and should return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     *  false.  This information is used to determine if views
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     *  in the range of the added elements should be forwarded to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     *  or not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
     * @see #insertUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
     * @see #removeUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     * @see #changedUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
    protected boolean updateChildren(DocumentEvent.ElementChange ec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                                         DocumentEvent e, ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        Element[] removedElems = ec.getChildrenRemoved();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        Element[] addedElems = ec.getChildrenAdded();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        View[] added = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        if (addedElems != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            added = new View[addedElems.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
            for (int i = 0; i < addedElems.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                added[i] = f.create(addedElems[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        int nremoved = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        int index = ec.getIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        if (removedElems != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            nremoved = removedElems.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
        replace(index, nremoved, added);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
     * Forwards the given <code>DocumentEvent</code> to the child views
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     * that need to be notified of the change to the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     * If there were changes to the element this view is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     * responsible for, that should be considered when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     * forwarding (i.e. new child views should not get
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
     * notified).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
     * @param ec changes to the element this view is responsible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     *  for (may be <code>null</code> if there were no changes).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     * @param e the change information from the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
     * @param a the current allocation of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * @param f the factory to use to rebuild if the view has children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     * @see #insertUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * @see #removeUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     * @see #changedUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
    protected void forwardUpdate(DocumentEvent.ElementChange ec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                                      DocumentEvent e, Shape a, ViewFactory f) {
20126
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1143
        calculateUpdateIndexes(e);
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1144
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1145
        int hole0 = lastUpdateIndex + 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        int hole1 = hole0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
        Element[] addedElems = (ec != null) ? ec.getChildrenAdded() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        if ((addedElems != null) && (addedElems.length > 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
            hole0 = ec.getIndex();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            hole1 = hole0 + addedElems.length - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        // forward to any view not in the forwarding hole
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        // formed by added elements (i.e. they will be updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        // by initialization.
20126
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1156
        for (int i = firstUpdateIndex; i <= lastUpdateIndex; i++) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            if (! ((i >= hole0) && (i <= hole1))) {
20126
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1158
                View v = getView(i);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                    Shape childAlloc = getChildAllocation(i, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                    forwardUpdateToView(v, e, childAlloc, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
    /**
20126
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1168
     * Calculates the first and the last indexes of the child views
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1169
     * that need to be notified of the change to the model.
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1170
     * @param e the change information from the associated document
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1171
     */
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1172
    void calculateUpdateIndexes(DocumentEvent e) {
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1173
        int pos = e.getOffset();
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1174
        firstUpdateIndex = getViewIndex(pos, Position.Bias.Forward);
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1175
        if (firstUpdateIndex == -1 && e.getType() == DocumentEvent.EventType.REMOVE &&
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1176
            pos >= getEndOffset()) {
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1177
            // Event beyond our offsets. We may have represented this, that is
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1178
            // the remove may have removed one of our child Elements that
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1179
            // represented this, so, we should forward to last element.
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1180
            firstUpdateIndex = getViewCount() - 1;
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1181
        }
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1182
        lastUpdateIndex = firstUpdateIndex;
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1183
        View v = (firstUpdateIndex >= 0) ? getView(firstUpdateIndex) : null;
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1184
        if (v != null) {
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1185
            if ((v.getStartOffset() == pos) && (pos > 0)) {
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1186
                // If v is at a boundary, forward the event to the previous
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1187
                // view too.
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1188
                firstUpdateIndex = Math.max(firstUpdateIndex - 1, 0);
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1189
            }
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1190
        }
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1191
        if (e.getType() != DocumentEvent.EventType.REMOVE) {
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1192
            lastUpdateIndex = getViewIndex(pos + e.getLength(), Position.Bias.Forward);
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1193
            if (lastUpdateIndex < 0) {
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1194
                lastUpdateIndex = getViewCount() - 1;
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1195
            }
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1196
        }
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1197
        firstUpdateIndex = Math.max(firstUpdateIndex, 0);
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1198
    }
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1199
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1200
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
     * Forwards the <code>DocumentEvent</code> to the give child view.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
     * simply messages the view with a call to <code>insertUpdate</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
     * <code>removeUpdate</code>, or <code>changedUpdate</code> depending
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
     * upon the type of the event.  This is called by
7959
2e05332a8f5c 6589952: Swing: dead links in API documentation
rupashka
parents: 5506
diff changeset
  1205
     * {@link #forwardUpdate forwardUpdate} to forward
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
     * the event to children that need it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     * @param v the child view to forward the event to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     * @param e the change information from the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
     * @param a the current allocation of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
     * @param f the factory to use to rebuild if the view has children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
     * @see #forwardUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
    protected void forwardUpdateToView(View v, DocumentEvent e,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                                           Shape a, ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        DocumentEvent.EventType type = e.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        if (type == DocumentEvent.EventType.INSERT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
            v.insertUpdate(e, a, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        } else if (type == DocumentEvent.EventType.REMOVE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            v.removeUpdate(e, a, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
            v.changedUpdate(e, a, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
     * Updates the layout in response to receiving notification of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
     * change from the model.  This is implemented to call
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
     * <code>preferenceChanged</code> to reschedule a new layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
     * if the <code>ElementChange</code> record is not <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
     * @param ec changes to the element this view is responsible
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     *  for (may be <code>null</code> if there were no changes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     * @param e the change information from the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     * @param a the current allocation of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     * @see #insertUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * @see #removeUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * @see #changedUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
    protected void updateLayout(DocumentEvent.ElementChange ec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                                    DocumentEvent e, Shape a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        if ((ec != null) && (a != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
            // should damage more intelligently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
            preferenceChanged(null, true, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
            Container host = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
            if (host != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                host.repaint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        }
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 weight to indicate a view is a bad break
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
     * opportunity for the purpose of formatting.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
     * value indicates that no attempt should be made to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
     * break the view into fragments as the view has
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
     * not been written to support fragmenting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
     * @see #getBreakWeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
     * @see #GoodBreakWeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
     * @see #ExcellentBreakWeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
     * @see #ForcedBreakWeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
    public static final int BadBreakWeight = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
     * The weight to indicate a view supports breaking,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
     * but better opportunities probably exist.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
     * @see #getBreakWeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
     * @see #BadBreakWeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
     * @see #ExcellentBreakWeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
     * @see #ForcedBreakWeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
    public static final int GoodBreakWeight = 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
     * The weight to indicate a view supports breaking,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
     * and this represents a very attractive place to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
     * break.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
     * @see #getBreakWeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
     * @see #BadBreakWeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
     * @see #GoodBreakWeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
     * @see #ForcedBreakWeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
    public static final int ExcellentBreakWeight = 2000;
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 weight to indicate a view supports breaking,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
     * and must be broken to be represented properly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
     * when placed in a view that formats its children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
     * by breaking them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
     * @see #getBreakWeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
     * @see #BadBreakWeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
     * @see #GoodBreakWeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * @see #ExcellentBreakWeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
    public static final int ForcedBreakWeight = 3000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
     * Axis for format/break operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
    public static final int X_AXIS = HORIZONTAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
     * Axis for format/break operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
    public static final int Y_AXIS = VERTICAL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
     * Provides a mapping from the document model coordinate space
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
     * to the coordinate space of the view mapped to it. This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
     * implemented to default the bias to <code>Position.Bias.Forward</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
     * which was previously implied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
     *
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
  1320
     * @param pos the position to convert &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
     * @param a the allocated region in which to render
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
     * @return the bounding box of the given position is returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
     * @exception BadLocationException  if the given position does
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
     *   not represent a valid location in the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
     * @see View#modelToView
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
     * @deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
    public Shape modelToView(int pos, Shape a) throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        return modelToView(pos, a, Position.Bias.Forward);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
     * Provides a mapping from the view coordinate space to the logical
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
     * coordinate space of the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
     *
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
  1338
     * @param x the X coordinate &gt;= 0
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
  1339
     * @param y the Y coordinate &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
     * @param a the allocated region in which to render
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
     * @return the location within the model that best represents the
20428
929cd48fca8a 8025249: [javadoc] fix some javadoc errors in javax/swing/
yan
parents: 20158
diff changeset
  1342
     *  given point in the view &gt;= 0
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
     * @see View#viewToModel
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
     * @deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
    public int viewToModel(float x, float y, Shape a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
        sharedBiasReturn[0] = Position.Bias.Forward;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
        return viewToModel(x, y, a, sharedBiasReturn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
    // static argument available for viewToModel calls since only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
    // one thread at a time may call this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
    static final Position.Bias[] sharedBiasReturn = new Position.Bias[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
    private View parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
    private Element elem;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
20126
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1359
    /**
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1360
     * The index of the first child view to be notified.
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1361
     */
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1362
    int firstUpdateIndex;
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1363
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1364
    /**
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1365
     * The index of the last child view to be notified.
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1366
     */
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1367
    int lastUpdateIndex;
e09648d4170c 8024395: Improve fix for line break calculations
dmarkov
parents: 18122
diff changeset
  1368
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
};