0N/A/*
6130N/A * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage javax.swing.text;
0N/A
0N/Aimport java.awt.*;
0N/Aimport javax.swing.SwingConstants;
0N/Aimport javax.swing.event.*;
0N/A
0N/A/**
0N/A * <p>
0N/A * A very important part of the text package is the <code>View</code> class.
0N/A * As the name suggests it represents a view of the text model,
0N/A * or a piece of the text model.
0N/A * It is this class that is responsible for the look of the text component.
0N/A * The view is not intended to be some completely new thing that one must
0N/A * learn, but rather is much like a lightweight component.
0N/A * <p>
0N/ABy default, a view is very light. It contains a reference to the parent
0N/Aview from which it can fetch many things without holding state, and it
0N/Acontains a reference to a portion of the model (<code>Element</code>).
0N/AA view does not
0N/Ahave to exactly represent an element in the model, that is simply a typical
0N/Aand therefore convenient mapping. A view can alternatively maintain a couple
0N/Aof Position objects to maintain its location in the model (i.e. represent
0N/Aa fragment of an element). This is typically the result of formatting where
0N/Aviews have been broken down into pieces. The convenience of a substantial
0N/Arelationship to the element makes it easier to build factories to produce the
0N/Aviews, and makes it easier to keep track of the view pieces as the model is
0N/Achanged and the view must be changed to reflect the model. Simple views
0N/Atherefore represent an Element directly and complex views do not.
0N/A<p>
0N/AA view has the following responsibilities:
0N/A <dl>
0N/A
0N/A <dt><b>Participate in layout.</b>
0N/A <dd>
0N/A <p>The view has a <code>setSize</code> method which is like
0N/A <code>doLayout</code> and <code>setSize</code> in <code>Component</code> combined.
0N/A The view has a <code>preferenceChanged</code> method which is
0N/A like <code>invalidate</code> in <code>Component</code> except that one can
0N/A invalidate just one axis
0N/A and the child requesting the change is identified.
0N/A <p>A View expresses the size that it would like to be in terms of three
0N/A values, a minimum, a preferred, and a maximum span. Layout in a view is
0N/A can be done independently upon each axis. For a properly functioning View
0N/A implementation, the minimum span will be &lt;= the preferred span which in turn
0N/A will be &lt;= the maximum span.
0N/A </p>
0N/A <p align=center><img src="doc-files/View-flexibility.jpg"
0N/A alt="The above text describes this graphic.">
0N/A <p>The minimum set of methods for layout are:
0N/A <ul>
0N/A <li><a href="#getMinimumSpan(int)">getMinimumSpan</a>
0N/A <li><a href="#getPreferredSpan(int)">getPreferredSpan</a>
0N/A <li><a href="#getMaximumSpan(int)">getMaximumSpan</a>
0N/A <li><a href="#getAlignment(int)">getAlignment</a>
0N/A <li><a href="#preferenceChanged(javax.swing.text.View, boolean, boolean)">preferenceChanged</a>
0N/A <li><a href="#setSize(float, float)">setSize</a>
0N/A </ul>
0N/A
0N/A <p>The <code>setSize</code> method should be prepared to be called a number of times
0N/A (i.e. It may be called even if the size didn't change).
0N/A The <code>setSize</code> method
0N/A is generally called to make sure the View layout is complete prior to trying
0N/A to perform an operation on it that requires an up-to-date layout. A view's
0N/A size should <em>always</em> be set to a value within the minimum and maximum
0N/A span specified by that view. Additionally, the view must always call the
0N/A <code>preferenceChanged</code> method on the parent if it has changed the
0N/A values for the
0N/A layout it would like, and expects the parent to honor. The parent View is
0N/A not required to recognize a change until the <code>preferenceChanged</code>
0N/A has been sent.
0N/A This allows parent View implementations to cache the child requirements if
0N/A desired. The calling sequence looks something like the following:
0N/A </p>
0N/A <p align=center>
0N/A <img src="doc-files/View-layout.jpg"
0N/A alt="Sample calling sequence between parent view and child view:
0N/A setSize, getMinimum, getPreferred, getMaximum, getAlignment, setSize">
0N/A <p>The exact calling sequence is up to the layout functionality of
0N/A the parent view (if the view has any children). The view may collect
0N/A the preferences of the children prior to determining what it will give
0N/A each child, or it might iteratively update the children one at a time.
0N/A </p>
0N/A
0N/A <dt><b>Render a portion of the model.</b>
0N/A <dd>
0N/A <p>This is done in the paint method, which is pretty much like a component
0N/A paint method. Views are expected to potentially populate a fairly large
0N/A tree. A <code>View</code> has the following semantics for rendering:
0N/A </p>
0N/A <ul>
0N/A <li>The view gets its allocation from the parent at paint time, so it
0N/A must be prepared to redo layout if the allocated area is different from
0N/A what it is prepared to deal with.
0N/A <li>The coordinate system is the same as the hosting <code>Component</code>
0N/A (i.e. the <code>Component</code> returned by the
3370N/A {@link #getContainer getContainer} method).
0N/A This means a child view lives in the same coordinate system as the parent
0N/A view unless the parent has explicitly changed the coordinate system.
0N/A To schedule itself to be repainted a view can call repaint on the hosting
0N/A <code>Component</code>.
0N/A <li>The default is to <em>not clip</em> the children. It is more efficient
0N/A to allow a view to clip only if it really feels it needs clipping.
0N/A <li>The <code>Graphics</code> object given is not initialized in any way.
0N/A A view should set any settings needed.
0N/A <li>A <code>View</code> is inherently transparent. While a view may render into its
0N/A entire allocation, typically a view does not. Rendering is performed by
0N/A tranversing down the tree of <code>View</code> implementations.
0N/A Each <code>View</code> is responsible
0N/A for rendering its children. This behavior is depended upon for thread
0N/A safety. While view implementations do not necessarily have to be implemented
0N/A with thread safety in mind, other view implementations that do make use of
0N/A concurrency can depend upon a tree traversal to guarantee thread safety.
0N/A <li>The order of views relative to the model is up to the implementation.
0N/A Although child views will typically be arranged in the same order that they
0N/A occur in the model, they may be visually arranged in an entirely different
0N/A order. View implementations may have Z-Order associated with them if the
0N/A children are overlapping.
0N/A </ul>
0N/A <p>The methods for rendering are:
0N/A <ul>
0N/A <li><a href="#paint(java.awt.Graphics, java.awt.Shape)">paint</a>
0N/A </ul>
0N/A <p>
0N/A
0N/A <dt><b>Translate between the model and view coordinate systems.</b>
0N/A <dd>
0N/A <p>Because the view objects are produced from a factory and therefore cannot
0N/A necessarily be counted upon to be in a particular pattern, one must be able
0N/A to perform translation to properly locate spatial representation of the model.
0N/A The methods for doing this are:
0N/A <ul>
0N/A <li><a href="#modelToView(int, javax.swing.text.Position.Bias, int, javax.swing.text.Position.Bias, java.awt.Shape)">modelToView</a>
0N/A <li><a href="#viewToModel(float, float, java.awt.Shape, javax.swing.text.Position.Bias[])">viewToModel</a>
0N/A <li><a href="#getDocument()">getDocument</a>
0N/A <li><a href="#getElement()">getElement</a>
0N/A <li><a href="#getStartOffset()">getStartOffset</a>
0N/A <li><a href="#getEndOffset()">getEndOffset</a>
0N/A </ul>
0N/A <p>The layout must be valid prior to attempting to make the translation.
0N/A The translation is not valid, and must not be attempted while changes
0N/A are being broadcasted from the model via a <code>DocumentEvent</code>.
0N/A </p>
0N/A
0N/A <dt><b>Respond to changes from the model.</b>
0N/A <dd>
0N/A <p>If the overall view is represented by many pieces (which is the best situation
0N/A if one want to be able to change the view and write the least amount of new code),
0N/A it would be impractical to have a huge number of <code>DocumentListener</code>s.
0N/A If each
0N/A view listened to the model, only a few would actually be interested in the
0N/A changes broadcasted at any given time. Since the model has no knowledge of
0N/A views, it has no way to filter the broadcast of change information. The view
0N/A hierarchy itself is instead responsible for propagating the change information.
0N/A At any level in the view hierarchy, that view knows enough about its children to
0N/A best distribute the change information further. Changes are therefore broadcasted
0N/A starting from the root of the view hierarchy.
0N/A The methods for doing this are:
0N/A <ul>
3370N/A <li>{@link #insertUpdate insertUpdate}
3370N/A <li>{@link #removeUpdate removeUpdate}
3370N/A <li>{@link #changedUpdate changedUpdate}
0N/A </ul>
0N/A <p>
0N/A</dl>
0N/A *
0N/A * @author Timothy Prinzing
0N/A */
0N/Apublic abstract class View implements SwingConstants {
0N/A
0N/A /**
0N/A * Creates a new <code>View</code> object.
0N/A *
0N/A * @param elem the <code>Element</code> to represent
0N/A */
0N/A public View(Element elem) {
0N/A this.elem = elem;
0N/A }
0N/A
0N/A /**
0N/A * Returns the parent of the view.
0N/A *
0N/A * @return the parent, or <code>null</code> if none exists
0N/A */
0N/A public View getParent() {
0N/A return parent;
0N/A }
0N/A
0N/A /**
0N/A * Returns a boolean that indicates whether
0N/A * the view is visible or not. By default
0N/A * all views are visible.
0N/A *
0N/A * @return always returns true
0N/A */
0N/A public boolean isVisible() {
0N/A return true;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Determines the preferred span for this view along an
0N/A * axis.
0N/A *
0N/A * @param axis may be either <code>View.X_AXIS</code> or
0N/A * <code>View.Y_AXIS</code>
0N/A * @return the span the view would like to be rendered into.
0N/A * Typically the view is told to render into the span
0N/A * that is returned, although there is no guarantee.
0N/A * The parent may choose to resize or break the view
0N/A * @see View#getPreferredSpan
0N/A */
0N/A public abstract float getPreferredSpan(int axis);
0N/A
0N/A /**
0N/A * Determines the minimum span for this view along an
0N/A * axis.
0N/A *
0N/A * @param axis may be either <code>View.X_AXIS</code> or
0N/A * <code>View.Y_AXIS</code>
0N/A * @return the minimum span the view can be rendered into
0N/A * @see View#getPreferredSpan
0N/A */
0N/A public float getMinimumSpan(int axis) {
0N/A int w = getResizeWeight(axis);
0N/A if (w == 0) {
0N/A // can't resize
0N/A return getPreferredSpan(axis);
0N/A }
0N/A return 0;
0N/A }
0N/A
0N/A /**
0N/A * Determines the maximum span for this view along an
0N/A * axis.
0N/A *
0N/A * @param axis may be either <code>View.X_AXIS</code> or
0N/A * <code>View.Y_AXIS</code>
0N/A * @return the maximum span the view can be rendered into
0N/A * @see View#getPreferredSpan
0N/A */
0N/A public float getMaximumSpan(int axis) {
0N/A int w = getResizeWeight(axis);
0N/A if (w == 0) {
0N/A // can't resize
0N/A return getPreferredSpan(axis);
0N/A }
0N/A return Integer.MAX_VALUE;
0N/A }
0N/A
0N/A /**
0N/A * Child views can call this on the parent to indicate that
0N/A * the preference has changed and should be reconsidered
0N/A * for layout. By default this just propagates upward to
0N/A * the next parent. The root view will call
0N/A * <code>revalidate</code> on the associated text component.
0N/A *
0N/A * @param child the child view
0N/A * @param width true if the width preference has changed
0N/A * @param height true if the height preference has changed
0N/A * @see javax.swing.JComponent#revalidate
0N/A */
0N/A public void preferenceChanged(View child, boolean width, boolean height) {
0N/A View parent = getParent();
0N/A if (parent != null) {
0N/A parent.preferenceChanged(this, width, height);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Determines the desired alignment for this view along an
0N/A * axis. The desired alignment is returned. This should be
0N/A * a value >= 0.0 and <= 1.0, where 0 indicates alignment at
0N/A * the origin and 1.0 indicates alignment to the full span
0N/A * away from the origin. An alignment of 0.5 would be the
0N/A * center of the view.
0N/A *
0N/A * @param axis may be either <code>View.X_AXIS</code> or
0N/A * <code>View.Y_AXIS</code>
0N/A * @return the value 0.5
0N/A */
0N/A public float getAlignment(int axis) {
0N/A return 0.5f;
0N/A }
0N/A
0N/A /**
0N/A * Renders using the given rendering surface and area on that
0N/A * surface. The view may need to do layout and create child
0N/A * views to enable itself to render into the given allocation.
0N/A *
0N/A * @param g the rendering surface to use
0N/A * @param allocation the allocated region to render into
0N/A */
0N/A public abstract void paint(Graphics g, Shape allocation);
0N/A
0N/A /**
0N/A * Establishes the parent view for this view. This is
0N/A * guaranteed to be called before any other methods if the
0N/A * parent view is functioning properly. This is also
0N/A * the last method called, since it is called to indicate
0N/A * the view has been removed from the hierarchy as
0N/A * well. When this method is called to set the parent to
0N/A * null, this method does the same for each of its children,
0N/A * propogating the notification that they have been
0N/A * disconnected from the view tree. If this is
0N/A * reimplemented, <code>super.setParent()</code> should
0N/A * be called.
0N/A *
0N/A * @param parent the new parent, or <code>null</code> if the view is
0N/A * being removed from a parent
0N/A */
0N/A public void setParent(View parent) {
0N/A // if the parent is null then propogate down the view tree
0N/A if (parent == null) {
0N/A for (int i = 0; i < getViewCount(); i++) {
0N/A if (getView(i).getParent() == this) {
0N/A // in FlowView.java view might be referenced
0N/A // from two super-views as a child. see logicalView
0N/A getView(i).setParent(null);
0N/A }
0N/A }
0N/A }
0N/A this.parent = parent;
0N/A }
0N/A
0N/A /**
0N/A * Returns the number of views in this view. Since
0N/A * the default is to not be a composite view this
0N/A * returns 0.
0N/A *
0N/A * @return the number of views >= 0
0N/A * @see View#getViewCount
0N/A */
0N/A public int getViewCount() {
0N/A return 0;
0N/A }
0N/A
0N/A /**
0N/A * Gets the <i>n</i>th child view. Since there are no
0N/A * children by default, this returns <code>null</code>.
0N/A *
0N/A * @param n the number of the view to get, >= 0 && < getViewCount()
0N/A * @return the view
0N/A */
0N/A public View getView(int n) {
0N/A return null;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Removes all of the children. This is a convenience
0N/A * call to <code>replace</code>.
0N/A *
0N/A * @since 1.3
0N/A */
0N/A public void removeAll() {
0N/A replace(0, getViewCount(), null);
0N/A }
0N/A
0N/A /**
0N/A * Removes one of the children at the given position.
0N/A * This is a convenience call to <code>replace</code>.
0N/A * @since 1.3
0N/A */
0N/A public void remove(int i) {
0N/A replace(i, 1, null);
0N/A }
0N/A
0N/A /**
0N/A * Inserts a single child view. This is a convenience
0N/A * call to <code>replace</code>.
0N/A *
0N/A * @param offs the offset of the view to insert before >= 0
0N/A * @param v the view
0N/A * @see #replace
0N/A * @since 1.3
0N/A */
0N/A public void insert(int offs, View v) {
0N/A View[] one = new View[1];
0N/A one[0] = v;
0N/A replace(offs, 0, one);
0N/A }
0N/A
0N/A /**
0N/A * Appends a single child view. This is a convenience
0N/A * call to <code>replace</code>.
0N/A *
0N/A * @param v the view
0N/A * @see #replace
0N/A * @since 1.3
0N/A */
0N/A public void append(View v) {
0N/A View[] one = new View[1];
0N/A one[0] = v;
0N/A replace(getViewCount(), 0, one);
0N/A }
0N/A
0N/A /**
0N/A * Replaces child views. If there are no views to remove
0N/A * this acts as an insert. If there are no views to
0N/A * add this acts as a remove. Views being removed will
0N/A * have the parent set to <code>null</code>, and the internal reference
0N/A * to them removed so that they can be garbage collected.
0N/A * This is implemented to do nothing, because by default
0N/A * a view has no children.
0N/A *
0N/A * @param offset the starting index into the child views to insert
0N/A * the new views. This should be a value >= 0 and <= getViewCount
0N/A * @param length the number of existing child views to remove
0N/A * This should be a value >= 0 and <= (getViewCount() - offset).
0N/A * @param views the child views to add. This value can be
0N/A * <code>null</code> to indicate no children are being added
0N/A * (useful to remove).
0N/A * @since 1.3
0N/A */
0N/A public void replace(int offset, int length, View[] views) {
0N/A }
0N/A
0N/A /**
0N/A * Returns the child view index representing the given position in
0N/A * the model. By default a view has no children so this is implemented
0N/A * to return -1 to indicate there is no valid child index for any
0N/A * position.
0N/A *
0N/A * @param pos the position >= 0
0N/A * @return index of the view representing the given position, or
0N/A * -1 if no view represents that position
0N/A * @since 1.3
0N/A */
0N/A public int getViewIndex(int pos, Position.Bias b) {
0N/A return -1;
0N/A }
0N/A
0N/A /**
0N/A * Fetches the allocation for the given child view.
0N/A * This enables finding out where various views
0N/A * are located, without assuming how the views store
0N/A * their location. This returns <code>null</code> since the
0N/A * default is to not have any child views.
0N/A *
0N/A * @param index the index of the child, >= 0 && <
0N/A * <code>getViewCount()</code>
0N/A * @param a the allocation to this view
0N/A * @return the allocation to the child
0N/A */
0N/A public Shape getChildAllocation(int index, Shape a) {
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Provides a way to determine the next visually represented model
0N/A * location at which one might place a caret.
0N/A * Some views may not be visible,
0N/A * they might not be in the same order found in the model, or they just
0N/A * might not allow access to some of the locations in the model.
0N/A *
0N/A * @param pos the position to convert >= 0
0N/A * @param a the allocated region in which to render
0N/A * @param direction the direction from the current position that can
0N/A * be thought of as the arrow keys typically found on a keyboard.
0N/A * This will be one of the following values:
0N/A * <ul>
0N/A * <li>SwingConstants.WEST
0N/A * <li>SwingConstants.EAST
0N/A * <li>SwingConstants.NORTH
0N/A * <li>SwingConstants.SOUTH
0N/A * </ul>
0N/A * @return the location within the model that best represents the next
0N/A * location visual position
0N/A * @exception BadLocationException
0N/A * @exception IllegalArgumentException if <code>direction</code>
0N/A * doesn't have one of the legal values above
0N/A */
0N/A public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a,
0N/A int direction, Position.Bias[] biasRet)
0N/A throws BadLocationException {
3375N/A if (pos < -1) {
3375N/A // -1 is a reserved value, see the code below
3375N/A throw new BadLocationException("Invalid position", pos);
3375N/A }
0N/A
0N/A biasRet[0] = Position.Bias.Forward;
0N/A switch (direction) {
0N/A case NORTH:
0N/A case SOUTH:
0N/A {
0N/A if (pos == -1) {
0N/A pos = (direction == NORTH) ? Math.max(0, getEndOffset() - 1) :
0N/A getStartOffset();
0N/A break;
0N/A }
0N/A JTextComponent target = (JTextComponent) getContainer();
0N/A Caret c = (target != null) ? target.getCaret() : null;
0N/A // YECK! Ideally, the x location from the magic caret position
0N/A // would be passed in.
0N/A Point mcp;
0N/A if (c != null) {
0N/A mcp = c.getMagicCaretPosition();
0N/A }
0N/A else {
0N/A mcp = null;
0N/A }
0N/A int x;
0N/A if (mcp == null) {
0N/A Rectangle loc = target.modelToView(pos);
0N/A x = (loc == null) ? 0 : loc.x;
0N/A }
0N/A else {
0N/A x = mcp.x;
0N/A }
0N/A if (direction == NORTH) {
0N/A pos = Utilities.getPositionAbove(target, pos, x);
0N/A }
0N/A else {
0N/A pos = Utilities.getPositionBelow(target, pos, x);
0N/A }
0N/A }
0N/A break;
0N/A case WEST:
0N/A if(pos == -1) {
0N/A pos = Math.max(0, getEndOffset() - 1);
0N/A }
0N/A else {
0N/A pos = Math.max(0, pos - 1);
0N/A }
0N/A break;
0N/A case EAST:
0N/A if(pos == -1) {
0N/A pos = getStartOffset();
0N/A }
0N/A else {
0N/A pos = Math.min(pos + 1, getDocument().getLength());
0N/A }
0N/A break;
0N/A default:
0N/A throw new IllegalArgumentException("Bad direction: " + direction);
0N/A }
0N/A return pos;
0N/A }
0N/A
0N/A /**
0N/A * Provides a mapping, for a given character,
0N/A * from the document model coordinate space
0N/A * to the view coordinate space.
0N/A *
0N/A * @param pos the position of the desired character (>=0)
0N/A * @param a the area of the view, which encompasses the requested character
0N/A * @param b the bias toward the previous character or the
0N/A * next character represented by the offset, in case the
0N/A * position is a boundary of two views; <code>b</code> will have one
0N/A * of these values:
0N/A * <ul>
0N/A * <li> <code>Position.Bias.Forward</code>
0N/A * <li> <code>Position.Bias.Backward</code>
0N/A * </ul>
0N/A * @return the bounding box, in view coordinate space,
0N/A * of the character at the specified position
0N/A * @exception BadLocationException if the specified position does
0N/A * not represent a valid location in the associated document
0N/A * @exception IllegalArgumentException if <code>b</code> is not one of the
0N/A * legal <code>Position.Bias</code> values listed above
0N/A * @see View#viewToModel
0N/A */
0N/A public abstract Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException;
0N/A
0N/A /**
0N/A * Provides a mapping, for a given region,
0N/A * from the document model coordinate space
0N/A * to the view coordinate space. The specified region is
0N/A * created as a union of the first and last character positions.
0N/A *
0N/A * @param p0 the position of the first character (>=0)
0N/A * @param b0 the bias of the first character position,
0N/A * toward the previous character or the
0N/A * next character represented by the offset, in case the
0N/A * position is a boundary of two views; <code>b0</code> will have one
0N/A * of these values:
0N/A * <ul>
0N/A * <li> <code>Position.Bias.Forward</code>
0N/A * <li> <code>Position.Bias.Backward</code>
0N/A * </ul>
0N/A * @param p1 the position of the last character (>=0)
0N/A * @param b1 the bias for the second character position, defined
0N/A * one of the legal values shown above
0N/A * @param a the area of the view, which encompasses the requested region
0N/A * @return the bounding box which is a union of the region specified
0N/A * by the first and last character positions
0N/A * @exception BadLocationException if the given position does
0N/A * not represent a valid location in the associated document
0N/A * @exception IllegalArgumentException if <code>b0</code> or
0N/A * <code>b1</code> are not one of the
0N/A * legal <code>Position.Bias</code> values listed above
0N/A * @see View#viewToModel
0N/A */
0N/A public Shape modelToView(int p0, Position.Bias b0, int p1, Position.Bias b1, Shape a) throws BadLocationException {
0N/A Shape s0 = modelToView(p0, a, b0);
0N/A Shape s1;
0N/A if (p1 == getEndOffset()) {
0N/A try {
0N/A s1 = modelToView(p1, a, b1);
0N/A } catch (BadLocationException ble) {
0N/A s1 = null;
0N/A }
0N/A if (s1 == null) {
0N/A // Assume extends left to right.
0N/A Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a :
0N/A a.getBounds();
0N/A s1 = new Rectangle(alloc.x + alloc.width - 1, alloc.y,
0N/A 1, alloc.height);
0N/A }
0N/A }
0N/A else {
0N/A s1 = modelToView(p1, a, b1);
0N/A }
0N/A Rectangle r0 = s0.getBounds();
0N/A Rectangle r1 = (s1 instanceof Rectangle) ? (Rectangle) s1 :
0N/A s1.getBounds();
0N/A if (r0.y != r1.y) {
0N/A // If it spans lines, force it to be the width of the view.
0N/A Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a :
0N/A a.getBounds();
0N/A r0.x = alloc.x;
0N/A r0.width = alloc.width;
0N/A }
0N/A r0.add(r1);
0N/A return r0;
0N/A }
0N/A
0N/A /**
0N/A * Provides a mapping from the view coordinate space to the logical
0N/A * coordinate space of the model. The <code>biasReturn</code>
0N/A * argument will be filled in to indicate that the point given is
0N/A * closer to the next character in the model or the previous
0N/A * character in the model.
0N/A *
0N/A * @param x the X coordinate >= 0
0N/A * @param y the Y coordinate >= 0
0N/A * @param a the allocated region in which to render
0N/A * @return the location within the model that best represents the
0N/A * given point in the view >= 0. The <code>biasReturn</code>
0N/A * argument will be
0N/A * filled in to indicate that the point given is closer to the next
0N/A * character in the model or the previous character in the model.
0N/A */
0N/A public abstract int viewToModel(float x, float y, Shape a, Position.Bias[] biasReturn);
0N/A
0N/A /**
0N/A * Gives notification that something was inserted into
0N/A * the document in a location that this view is responsible for.
0N/A * To reduce the burden to subclasses, this functionality is
0N/A * spread out into the following calls that subclasses can
0N/A * reimplement:
0N/A * <ol>
3370N/A * <li>{@link #updateChildren updateChildren} is called
0N/A * if there were any changes to the element this view is
0N/A * responsible for. If this view has child views that are
0N/A * represent the child elements, then this method should do
0N/A * whatever is necessary to make sure the child views correctly
0N/A * represent the model.
3370N/A * <li>{@link #forwardUpdate forwardUpdate} is called
0N/A * to forward the DocumentEvent to the appropriate child views.
3370N/A * <li>{@link #updateLayout updateLayout} is called to
0N/A * give the view a chance to either repair its layout, to reschedule
0N/A * layout, or do nothing.
0N/A * </ol>
0N/A *
0N/A * @param e the change information from the associated document
0N/A * @param a the current allocation of the view
0N/A * @param f the factory to use to rebuild if the view has children
0N/A * @see View#insertUpdate
0N/A */
0N/A public void insertUpdate(DocumentEvent e, Shape a, ViewFactory f) {
0N/A if (getViewCount() > 0) {
0N/A Element elem = getElement();
0N/A DocumentEvent.ElementChange ec = e.getChange(elem);
0N/A if (ec != null) {
0N/A if (! updateChildren(ec, e, f)) {
0N/A // don't consider the element changes they
0N/A // are for a view further down.
0N/A ec = null;
0N/A }
0N/A }
0N/A forwardUpdate(ec, e, a, f);
0N/A updateLayout(ec, e, a);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gives notification that something was removed from the document
0N/A * in a location that this view is responsible for.
0N/A * To reduce the burden to subclasses, this functionality is
0N/A * spread out into the following calls that subclasses can
0N/A * reimplement:
0N/A * <ol>
3370N/A * <li>{@link #updateChildren updateChildren} is called
0N/A * if there were any changes to the element this view is
0N/A * responsible for. If this view has child views that are
0N/A * represent the child elements, then this method should do
0N/A * whatever is necessary to make sure the child views correctly
0N/A * represent the model.
3370N/A * <li>{@link #forwardUpdate forwardUpdate} is called
0N/A * to forward the DocumentEvent to the appropriate child views.
3370N/A * <li>{@link #updateLayout updateLayout} is called to
0N/A * give the view a chance to either repair its layout, to reschedule
0N/A * layout, or do nothing.
0N/A * </ol>
0N/A *
0N/A * @param e the change information from the associated document
0N/A * @param a the current allocation of the view
0N/A * @param f the factory to use to rebuild if the view has children
0N/A * @see View#removeUpdate
0N/A */
0N/A public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f) {
0N/A if (getViewCount() > 0) {
0N/A Element elem = getElement();
0N/A DocumentEvent.ElementChange ec = e.getChange(elem);
0N/A if (ec != null) {
0N/A if (! updateChildren(ec, e, f)) {
0N/A // don't consider the element changes they
0N/A // are for a view further down.
0N/A ec = null;
0N/A }
0N/A }
0N/A forwardUpdate(ec, e, a, f);
0N/A updateLayout(ec, e, a);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Gives notification from the document that attributes were changed
0N/A * in a location that this view is responsible for.
0N/A * To reduce the burden to subclasses, this functionality is
0N/A * spread out into the following calls that subclasses can
0N/A * reimplement:
0N/A * <ol>
3370N/A * <li>{@link #updateChildren updateChildren} is called
0N/A * if there were any changes to the element this view is
0N/A * responsible for. If this view has child views that are
0N/A * represent the child elements, then this method should do
0N/A * whatever is necessary to make sure the child views correctly
0N/A * represent the model.
3370N/A * <li>{@link #forwardUpdate forwardUpdate} is called
0N/A * to forward the DocumentEvent to the appropriate child views.
3370N/A * <li>{@link #updateLayout updateLayout} is called to
0N/A * give the view a chance to either repair its layout, to reschedule
0N/A * layout, or do nothing.
0N/A * </ol>
0N/A *
0N/A * @param e the change information from the associated document
0N/A * @param a the current allocation of the view
0N/A * @param f the factory to use to rebuild if the view has children
0N/A * @see View#changedUpdate
0N/A */
0N/A public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {
0N/A if (getViewCount() > 0) {
0N/A Element elem = getElement();
0N/A DocumentEvent.ElementChange ec = e.getChange(elem);
0N/A if (ec != null) {
0N/A if (! updateChildren(ec, e, f)) {
0N/A // don't consider the element changes they
0N/A // are for a view further down.
0N/A ec = null;
0N/A }
0N/A }
0N/A forwardUpdate(ec, e, a, f);
0N/A updateLayout(ec, e, a);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Fetches the model associated with the view.
0N/A *
0N/A * @return the view model, <code>null</code> if none
0N/A * @see View#getDocument
0N/A */
0N/A public Document getDocument() {
0N/A return elem.getDocument();
0N/A }
0N/A
0N/A /**
0N/A * Fetches the portion of the model for which this view is
0N/A * responsible.
0N/A *
0N/A * @return the starting offset into the model >= 0
0N/A * @see View#getStartOffset
0N/A */
0N/A public int getStartOffset() {
0N/A return elem.getStartOffset();
0N/A }
0N/A
0N/A /**
0N/A * Fetches the portion of the model for which this view is
0N/A * responsible.
0N/A *
0N/A * @return the ending offset into the model >= 0
0N/A * @see View#getEndOffset
0N/A */
0N/A public int getEndOffset() {
0N/A return elem.getEndOffset();
0N/A }
0N/A
0N/A /**
0N/A * Fetches the structural portion of the subject that this
0N/A * view is mapped to. The view may not be responsible for the
0N/A * entire portion of the element.
0N/A *
0N/A * @return the subject
0N/A * @see View#getElement
0N/A */
0N/A public Element getElement() {
0N/A return elem;
0N/A }
0N/A
0N/A /**
0N/A * Fetch a <code>Graphics</code> for rendering.
0N/A * This can be used to determine
0N/A * font characteristics, and will be different for a print view
0N/A * than a component view.
0N/A *
0N/A * @return a <code>Graphics</code> object for rendering
0N/A * @since 1.3
0N/A */
0N/A public Graphics getGraphics() {
0N/A // PENDING(prinz) this is a temporary implementation
0N/A Component c = getContainer();
0N/A return c.getGraphics();
0N/A }
0N/A
0N/A /**
0N/A * Fetches the attributes to use when rendering. By default
0N/A * this simply returns the attributes of the associated element.
0N/A * This method should be used rather than using the element
0N/A * directly to obtain access to the attributes to allow
0N/A * view-specific attributes to be mixed in or to allow the
0N/A * view to have view-specific conversion of attributes by
0N/A * subclasses.
0N/A * Each view should document what attributes it recognizes
0N/A * for the purpose of rendering or layout, and should always
0N/A * access them through the <code>AttributeSet</code> returned
0N/A * by this method.
0N/A */
0N/A public AttributeSet getAttributes() {
0N/A return elem.getAttributes();
0N/A }
0N/A
0N/A /**
0N/A * Tries to break this view on the given axis. This is
0N/A * called by views that try to do formatting of their
0N/A * children. For example, a view of a paragraph will
0N/A * typically try to place its children into row and
0N/A * views representing chunks of text can sometimes be
0N/A * broken down into smaller pieces.
0N/A * <p>
0N/A * This is implemented to return the view itself, which
0N/A * represents the default behavior on not being
0N/A * breakable. If the view does support breaking, the
0N/A * starting offset of the view returned should be the
0N/A * given offset, and the end offset should be less than
0N/A * or equal to the end offset of the view being broken.
0N/A *
0N/A * @param axis may be either <code>View.X_AXIS</code> or
0N/A * <code>View.Y_AXIS</code>
0N/A * @param offset the location in the document model
0N/A * that a broken fragment would occupy >= 0. This
0N/A * would be the starting offset of the fragment
0N/A * returned
0N/A * @param pos the position along the axis that the
0N/A * broken view would occupy >= 0. This may be useful for
0N/A * things like tab calculations
0N/A * @param len specifies the distance along the axis
0N/A * where a potential break is desired >= 0
0N/A * @return the fragment of the view that represents the
0N/A * given span, if the view can be broken. If the view
0N/A * doesn't support breaking behavior, the view itself is
0N/A * returned.
0N/A * @see ParagraphView
0N/A */
0N/A public View breakView(int axis, int offset, float pos, float len) {
0N/A return this;
0N/A }
0N/A
0N/A /**
0N/A * Creates a view that represents a portion of the element.
0N/A * This is potentially useful during formatting operations
0N/A * for taking measurements of fragments of the view. If
0N/A * the view doesn't support fragmenting (the default), it
0N/A * should return itself.
0N/A *
0N/A * @param p0 the starting offset >= 0. This should be a value
0N/A * greater or equal to the element starting offset and
0N/A * less than the element ending offset.
0N/A * @param p1 the ending offset > p0. This should be a value
0N/A * less than or equal to the elements end offset and
0N/A * greater than the elements starting offset.
0N/A * @return the view fragment, or itself if the view doesn't
0N/A * support breaking into fragments
0N/A * @see LabelView
0N/A */
0N/A public View createFragment(int p0, int p1) {
0N/A return this;
0N/A }
0N/A
0N/A /**
0N/A * Determines how attractive a break opportunity in
0N/A * this view is. This can be used for determining which
0N/A * view is the most attractive to call <code>breakView</code>
0N/A * on in the process of formatting. A view that represents
0N/A * text that has whitespace in it might be more attractive
0N/A * than a view that has no whitespace, for example. The
0N/A * higher the weight, the more attractive the break. A
0N/A * value equal to or lower than <code>BadBreakWeight</code>
0N/A * should not be considered for a break. A value greater
0N/A * than or equal to <code>ForcedBreakWeight</code> should
0N/A * be broken.
0N/A * <p>
0N/A * This is implemented to provide the default behavior
0N/A * of returning <code>BadBreakWeight</code> unless the length
0N/A * is greater than the length of the view in which case the
0N/A * entire view represents the fragment. Unless a view has
0N/A * been written to support breaking behavior, it is not
0N/A * attractive to try and break the view. An example of
0N/A * a view that does support breaking is <code>LabelView</code>.
0N/A * An example of a view that uses break weight is
0N/A * <code>ParagraphView</code>.
0N/A *
0N/A * @param axis may be either <code>View.X_AXIS</code> or
0N/A * <code>View.Y_AXIS</code>
0N/A * @param pos the potential location of the start of the
0N/A * broken view >= 0. This may be useful for calculating tab
0N/A * positions
0N/A * @param len specifies the relative length from <em>pos</em>
0N/A * where a potential break is desired >= 0
0N/A * @return the weight, which should be a value between
0N/A * ForcedBreakWeight and BadBreakWeight
0N/A * @see LabelView
0N/A * @see ParagraphView
0N/A * @see #BadBreakWeight
0N/A * @see #GoodBreakWeight
0N/A * @see #ExcellentBreakWeight
0N/A * @see #ForcedBreakWeight
0N/A */
0N/A public int getBreakWeight(int axis, float pos, float len) {
0N/A if (len > getPreferredSpan(axis)) {
0N/A return GoodBreakWeight;
0N/A }
0N/A return BadBreakWeight;
0N/A }
0N/A
0N/A /**
0N/A * Determines the resizability of the view along the
0N/A * given axis. A value of 0 or less is not resizable.
0N/A *
0N/A * @param axis may be either <code>View.X_AXIS</code> or
0N/A * <code>View.Y_AXIS</code>
0N/A * @return the weight
0N/A */
0N/A public int getResizeWeight(int axis) {
0N/A return 0;
0N/A }
0N/A
0N/A /**
0N/A * Sets the size of the view. This should cause
0N/A * layout of the view along the given axis, if it
0N/A * has any layout duties.
0N/A *
0N/A * @param width the width >= 0
0N/A * @param height the height >= 0
0N/A */
0N/A public void setSize(float width, float height) {
0N/A }
0N/A
0N/A /**
0N/A * Fetches the container hosting the view. This is useful for
0N/A * things like scheduling a repaint, finding out the host
0N/A * components font, etc. The default implementation
0N/A * of this is to forward the query to the parent view.
0N/A *
0N/A * @return the container, <code>null</code> if none
0N/A */
0N/A public Container getContainer() {
0N/A View v = getParent();
0N/A return (v != null) ? v.getContainer() : null;
0N/A }
0N/A
0N/A /**
0N/A * Fetches the <code>ViewFactory</code> implementation that is feeding
0N/A * the view hierarchy. Normally the views are given this
0N/A * as an argument to updates from the model when they
0N/A * are most likely to need the factory, but this
0N/A * method serves to provide it at other times.
0N/A *
0N/A * @return the factory, <code>null</code> if none
0N/A */
0N/A public ViewFactory getViewFactory() {
0N/A View v = getParent();
0N/A return (v != null) ? v.getViewFactory() : null;
0N/A }
0N/A
0N/A /**
0N/A * Returns the tooltip text at the specified location. The default
0N/A * implementation returns the value from the child View identified by
0N/A * the passed in location.
0N/A *
0N/A * @since 1.4
0N/A * @see JTextComponent#getToolTipText
0N/A */
0N/A public String getToolTipText(float x, float y, Shape allocation) {
0N/A int viewIndex = getViewIndex(x, y, allocation);
0N/A if (viewIndex >= 0) {
0N/A allocation = getChildAllocation(viewIndex, allocation);
0N/A Rectangle rect = (allocation instanceof Rectangle) ?
0N/A (Rectangle)allocation : allocation.getBounds();
0N/A if (rect.contains(x, y)) {
0N/A return getView(viewIndex).getToolTipText(x, y, allocation);
0N/A }
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Returns the child view index representing the given position in
0N/A * the view. This iterates over all the children returning the
0N/A * first with a bounds that contains <code>x</code>, <code>y</code>.
0N/A *
0N/A * @param x the x coordinate
0N/A * @param y the y coordinate
0N/A * @param allocation current allocation of the View.
0N/A * @return index of the view representing the given location, or
0N/A * -1 if no view represents that position
0N/A * @since 1.4
0N/A */
0N/A public int getViewIndex(float x, float y, Shape allocation) {
0N/A for (int counter = getViewCount() - 1; counter >= 0; counter--) {
0N/A Shape childAllocation = getChildAllocation(counter, allocation);
0N/A
0N/A if (childAllocation != null) {
0N/A Rectangle rect = (childAllocation instanceof Rectangle) ?
0N/A (Rectangle)childAllocation : childAllocation.getBounds();
0N/A
0N/A if (rect.contains(x, y)) {
0N/A return counter;
0N/A }
0N/A }
0N/A }
0N/A return -1;
0N/A }
0N/A
0N/A /**
0N/A * Updates the child views in response to receiving notification
0N/A * that the model changed, and there is change record for the
0N/A * element this view is responsible for. This is implemented
0N/A * to assume the child views are directly responsible for the
0N/A * child elements of the element this view represents. The
0N/A * <code>ViewFactory</code> is used to create child views for each element
0N/A * specified as added in the <code>ElementChange</code>, starting at the
0N/A * index specified in the given <code>ElementChange</code>. The number of
0N/A * child views representing the removed elements specified are
0N/A * removed.
0N/A *
0N/A * @param ec the change information for the element this view
0N/A * is responsible for. This should not be <code>null</code> if
0N/A * this method gets called
0N/A * @param e the change information from the associated document
0N/A * @param f the factory to use to build child views
0N/A * @return whether or not the child views represent the
0N/A * child elements of the element this view is responsible
0N/A * for. Some views create children that represent a portion
0N/A * of the element they are responsible for, and should return
0N/A * false. This information is used to determine if views
0N/A * in the range of the added elements should be forwarded to
0N/A * or not
0N/A * @see #insertUpdate
0N/A * @see #removeUpdate
0N/A * @see #changedUpdate
0N/A * @since 1.3
0N/A */
0N/A protected boolean updateChildren(DocumentEvent.ElementChange ec,
0N/A DocumentEvent e, ViewFactory f) {
0N/A Element[] removedElems = ec.getChildrenRemoved();
0N/A Element[] addedElems = ec.getChildrenAdded();
0N/A View[] added = null;
0N/A if (addedElems != null) {
0N/A added = new View[addedElems.length];
0N/A for (int i = 0; i < addedElems.length; i++) {
0N/A added[i] = f.create(addedElems[i]);
0N/A }
0N/A }
0N/A int nremoved = 0;
0N/A int index = ec.getIndex();
0N/A if (removedElems != null) {
0N/A nremoved = removedElems.length;
0N/A }
0N/A replace(index, nremoved, added);
0N/A return true;
0N/A }
0N/A
0N/A /**
0N/A * Forwards the given <code>DocumentEvent</code> to the child views
0N/A * that need to be notified of the change to the model.
0N/A * If there were changes to the element this view is
0N/A * responsible for, that should be considered when
0N/A * forwarding (i.e. new child views should not get
0N/A * notified).
0N/A *
0N/A * @param ec changes to the element this view is responsible
0N/A * for (may be <code>null</code> if there were no changes).
0N/A * @param e the change information from the associated document
0N/A * @param a the current allocation of the view
0N/A * @param f the factory to use to rebuild if the view has children
0N/A * @see #insertUpdate
0N/A * @see #removeUpdate
0N/A * @see #changedUpdate
0N/A * @since 1.3
0N/A */
0N/A protected void forwardUpdate(DocumentEvent.ElementChange ec,
0N/A DocumentEvent e, Shape a, ViewFactory f) {
0N/A Element elem = getElement();
0N/A int pos = e.getOffset();
0N/A int index0 = getViewIndex(pos, Position.Bias.Forward);
0N/A if (index0 == -1 && e.getType() == DocumentEvent.EventType.REMOVE &&
0N/A pos >= getEndOffset()) {
0N/A // Event beyond our offsets. We may have represented this, that is
0N/A // the remove may have removed one of our child Elements that
0N/A // represented this, so, we should foward to last element.
0N/A index0 = getViewCount() - 1;
0N/A }
0N/A int index1 = index0;
0N/A View v = (index0 >= 0) ? getView(index0) : null;
0N/A if (v != null) {
0N/A if ((v.getStartOffset() == pos) && (pos > 0)) {
0N/A // If v is at a boundary, forward the event to the previous
0N/A // view too.
0N/A index0 = Math.max(index0 - 1, 0);
0N/A }
0N/A }
0N/A if (e.getType() != DocumentEvent.EventType.REMOVE) {
0N/A index1 = getViewIndex(pos + e.getLength(), Position.Bias.Forward);
0N/A if (index1 < 0) {
0N/A index1 = getViewCount() - 1;
0N/A }
0N/A }
0N/A int hole0 = index1 + 1;
0N/A int hole1 = hole0;
0N/A Element[] addedElems = (ec != null) ? ec.getChildrenAdded() : null;
0N/A if ((addedElems != null) && (addedElems.length > 0)) {
0N/A hole0 = ec.getIndex();
0N/A hole1 = hole0 + addedElems.length - 1;
0N/A }
0N/A
0N/A // forward to any view not in the forwarding hole
0N/A // formed by added elements (i.e. they will be updated
0N/A // by initialization.
0N/A index0 = Math.max(index0, 0);
6130N/A index1 = Math.max((getViewCount() - 1), 0);
0N/A for (int i = index0; i <= index1; i++) {
0N/A if (! ((i >= hole0) && (i <= hole1))) {
0N/A v = getView(i);
0N/A if (v != null) {
0N/A Shape childAlloc = getChildAllocation(i, a);
0N/A forwardUpdateToView(v, e, childAlloc, f);
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Forwards the <code>DocumentEvent</code> to the give child view. This
0N/A * simply messages the view with a call to <code>insertUpdate</code>,
0N/A * <code>removeUpdate</code>, or <code>changedUpdate</code> depending
0N/A * upon the type of the event. This is called by
3370N/A * {@link #forwardUpdate forwardUpdate} to forward
0N/A * the event to children that need it.
0N/A *
0N/A * @param v the child view to forward the event to
0N/A * @param e the change information from the associated document
0N/A * @param a the current allocation of the view
0N/A * @param f the factory to use to rebuild if the view has children
0N/A * @see #forwardUpdate
0N/A * @since 1.3
0N/A */
0N/A protected void forwardUpdateToView(View v, DocumentEvent e,
0N/A Shape a, ViewFactory f) {
0N/A DocumentEvent.EventType type = e.getType();
0N/A if (type == DocumentEvent.EventType.INSERT) {
0N/A v.insertUpdate(e, a, f);
0N/A } else if (type == DocumentEvent.EventType.REMOVE) {
0N/A v.removeUpdate(e, a, f);
0N/A } else {
0N/A v.changedUpdate(e, a, f);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Updates the layout in response to receiving notification of
0N/A * change from the model. This is implemented to call
0N/A * <code>preferenceChanged</code> to reschedule a new layout
0N/A * if the <code>ElementChange</code> record is not <code>null</code>.
0N/A *
0N/A * @param ec changes to the element this view is responsible
0N/A * for (may be <code>null</code> if there were no changes)
0N/A * @param e the change information from the associated document
0N/A * @param a the current allocation of the view
0N/A * @see #insertUpdate
0N/A * @see #removeUpdate
0N/A * @see #changedUpdate
0N/A * @since 1.3
0N/A */
0N/A protected void updateLayout(DocumentEvent.ElementChange ec,
0N/A DocumentEvent e, Shape a) {
0N/A if ((ec != null) && (a != null)) {
0N/A // should damage more intelligently
0N/A preferenceChanged(null, true, true);
0N/A Container host = getContainer();
0N/A if (host != null) {
0N/A host.repaint();
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * The weight to indicate a view is a bad break
0N/A * opportunity for the purpose of formatting. This
0N/A * value indicates that no attempt should be made to
0N/A * break the view into fragments as the view has
0N/A * not been written to support fragmenting.
0N/A *
0N/A * @see #getBreakWeight
0N/A * @see #GoodBreakWeight
0N/A * @see #ExcellentBreakWeight
0N/A * @see #ForcedBreakWeight
0N/A */
0N/A public static final int BadBreakWeight = 0;
0N/A
0N/A /**
0N/A * The weight to indicate a view supports breaking,
0N/A * but better opportunities probably exist.
0N/A *
0N/A * @see #getBreakWeight
0N/A * @see #BadBreakWeight
0N/A * @see #ExcellentBreakWeight
0N/A * @see #ForcedBreakWeight
0N/A */
0N/A public static final int GoodBreakWeight = 1000;
0N/A
0N/A /**
0N/A * The weight to indicate a view supports breaking,
0N/A * and this represents a very attractive place to
0N/A * break.
0N/A *
0N/A * @see #getBreakWeight
0N/A * @see #BadBreakWeight
0N/A * @see #GoodBreakWeight
0N/A * @see #ForcedBreakWeight
0N/A */
0N/A public static final int ExcellentBreakWeight = 2000;
0N/A
0N/A /**
0N/A * The weight to indicate a view supports breaking,
0N/A * and must be broken to be represented properly
0N/A * when placed in a view that formats its children
0N/A * by breaking them.
0N/A *
0N/A * @see #getBreakWeight
0N/A * @see #BadBreakWeight
0N/A * @see #GoodBreakWeight
0N/A * @see #ExcellentBreakWeight
0N/A */
0N/A public static final int ForcedBreakWeight = 3000;
0N/A
0N/A /**
0N/A * Axis for format/break operations.
0N/A */
0N/A public static final int X_AXIS = HORIZONTAL;
0N/A
0N/A /**
0N/A * Axis for format/break operations.
0N/A */
0N/A public static final int Y_AXIS = VERTICAL;
0N/A
0N/A /**
0N/A * Provides a mapping from the document model coordinate space
0N/A * to the coordinate space of the view mapped to it. This is
0N/A * implemented to default the bias to <code>Position.Bias.Forward</code>
0N/A * which was previously implied.
0N/A *
0N/A * @param pos the position to convert >= 0
0N/A * @param a the allocated region in which to render
0N/A * @return the bounding box of the given position is returned
0N/A * @exception BadLocationException if the given position does
0N/A * not represent a valid location in the associated document
0N/A * @see View#modelToView
0N/A * @deprecated
0N/A */
0N/A @Deprecated
0N/A public Shape modelToView(int pos, Shape a) throws BadLocationException {
0N/A return modelToView(pos, a, Position.Bias.Forward);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Provides a mapping from the view coordinate space to the logical
0N/A * coordinate space of the model.
0N/A *
0N/A * @param x the X coordinate >= 0
0N/A * @param y the Y coordinate >= 0
0N/A * @param a the allocated region in which to render
0N/A * @return the location within the model that best represents the
0N/A * given point in the view >= 0
0N/A * @see View#viewToModel
0N/A * @deprecated
0N/A */
0N/A @Deprecated
0N/A public int viewToModel(float x, float y, Shape a) {
0N/A sharedBiasReturn[0] = Position.Bias.Forward;
0N/A return viewToModel(x, y, a, sharedBiasReturn);
0N/A }
0N/A
0N/A // static argument available for viewToModel calls since only
0N/A // one thread at a time may call this method.
0N/A static final Position.Bias[] sharedBiasReturn = new Position.Bias[1];
0N/A
0N/A private View parent;
0N/A private Element elem;
0N/A
0N/A};