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