jdk/src/share/classes/javax/swing/text/ParagraphView.java
author darcy
Thu, 27 Aug 2009 11:48:35 -0700
changeset 3709 e7cf22d025bb
parent 3342 fc3326a698e3
child 3713 3f49733cf145
permissions -rw-r--r--
6876628: @throw instead of @throws in two ParagraphView classes Reviewed-by: peterz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.font.TextAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.swing.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.SizeRequirements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * View of a simple line-wrapping paragraph that supports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * multiple fonts, colors, components, icons, etc.  It is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * basically a vertical box with a margin around it.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * contents of the box are a bunch of rows which are special
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * horizontal boxes.  This view creates a collection of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * views that represent the child elements of the paragraph
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * element.  Each of these views are placed into a row
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * directly if they will fit, otherwise the <code>breakView</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * method is called to try and carve the view into pieces
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * that fit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * @author  Scott Violet
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * @author  Igor Kushnirskiy
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * @see     View
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
public class ParagraphView extends FlowView implements TabExpander {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * Constructs a <code>ParagraphView</code> for the given element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * @param elem the element that this view is responsible for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public ParagraphView(Element elem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        super(elem, View.Y_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        setPropertiesFromAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        Document doc = elem.getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        Object i18nFlag = doc.getProperty(AbstractDocument.I18NProperty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        if ((i18nFlag != null) && i18nFlag.equals(Boolean.TRUE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                if (i18nStrategy == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
                    // the classname should probably come from a property file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
                    String classname = "javax.swing.text.TextLayoutStrategy";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                    ClassLoader loader = getClass().getClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                    if (loader != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                        i18nStrategy = loader.loadClass(classname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                        i18nStrategy = Class.forName(classname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                Object o = i18nStrategy.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                if (o instanceof FlowStrategy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                    strategy = (FlowStrategy) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            } catch (Throwable e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                throw new StateInvariantError("ParagraphView: Can't create i18n strategy: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
                                              + e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Sets the type of justification.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * @param j one of the following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * <li><code>StyleConstants.ALIGN_LEFT</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * <li><code>StyleConstants.ALIGN_CENTER</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * <li><code>StyleConstants.ALIGN_RIGHT</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    protected void setJustification(int j) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        justification = j;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * Sets the line spacing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * @param ls the value is a factor of the line hight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    protected void setLineSpacing(float ls) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        lineSpacing = ls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * Sets the indent on the first line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @param fi the value in points
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    protected void setFirstLineIndent(float fi) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        firstLineIndent = (int) fi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * Set the cached properties from the attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    protected void setPropertiesFromAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        AttributeSet attr = getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            setParagraphInsets(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            Integer a = (Integer)attr.getAttribute(StyleConstants.Alignment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            int alignment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            if (a == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
                Document doc = getElement().getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                Object o = doc.getProperty(TextAttribute.RUN_DIRECTION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                if ((o != null) && o.equals(TextAttribute.RUN_DIRECTION_RTL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                    alignment = StyleConstants.ALIGN_RIGHT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                    alignment = StyleConstants.ALIGN_LEFT;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                alignment = a.intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            setJustification(alignment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            setLineSpacing(StyleConstants.getLineSpacing(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            setFirstLineIndent(StyleConstants.getFirstLineIndent(attr));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * Returns the number of views that this view is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * responsible for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * The child views of the paragraph are rows which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * have been used to arrange pieces of the <code>View</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * that represent the child elements.  This is the number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * of views that have been tiled in two dimensions,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * and should be equivalent to the number of child elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * to the element this view is responsible for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @return the number of views that this <code>ParagraphView</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *          is responsible for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    protected int getLayoutViewCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        return layoutPool.getViewCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Returns the view at a given <code>index</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * The child views of the paragraph are rows which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * have been used to arrange pieces of the <code>Views</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * that represent the child elements.  This methods returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * the view responsible for the child element index
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * (prior to breaking).  These are the Views that were
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * produced from a factory (to represent the child
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * elements) and used for layout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @param index the <code>index</code> of the desired view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @return the view at <code>index</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    protected View getLayoutView(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        return layoutPool.getView(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * Returns the next visual position for the cursor, in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * either the east or west direction.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * Overridden from <code>CompositeView</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * @param pos position into the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @param b either <code>Position.Bias.Forward</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *          <code>Position.Bias.Backward</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * @param direction either <code>SwingConstants.NORTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *          or <code>SwingConstants.SOUTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @param biasRet an array containing the bias that were checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *  in this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @return the location in the model that represents the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     *  next location visual position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    protected int getNextNorthSouthVisualPositionFrom(int pos, Position.Bias b,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                                                      Shape a, int direction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                                                      Position.Bias[] biasRet)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                                                throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        int vIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        if(pos == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            vIndex = (direction == NORTH) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                     getViewCount() - 1 : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            if(b == Position.Bias.Backward && pos > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                vIndex = getViewIndexAtPosition(pos - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                vIndex = getViewIndexAtPosition(pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            if(direction == NORTH) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                if(vIndex == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                    return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                vIndex--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            else if(++vIndex >= getViewCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        // vIndex gives index of row to look in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        JTextComponent text = (JTextComponent)getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        Caret c = text.getCaret();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        Point magicPoint;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        magicPoint = (c != null) ? c.getMagicCaretPosition() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        int x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        if(magicPoint == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            Shape posBounds;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                posBounds = text.getUI().modelToView(text, pos, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            } catch (BadLocationException exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                posBounds = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            if(posBounds == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                x = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                x = posBounds.getBounds().x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            x = magicPoint.x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        return getClosestPositionTo(pos, b, a, direction, biasRet, vIndex, x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * Returns the closest model position to <code>x</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * <code>rowIndex</code> gives the index of the view that corresponds
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * that should be looked in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @param pos  position into the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @param direction one of the following values:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * <li><code>SwingConstants.NORTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * <li><code>SwingConstants.SOUTH</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @param biasRet an array containing the bias that were checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *  in this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @param rowIndex the index of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @param x the x coordinate of interest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * @return the closest model position to <code>x</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    // NOTE: This will not properly work if ParagraphView contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    // other ParagraphViews. It won't raise, but this does not message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    // the children views with getNextVisualPositionFrom.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    protected int getClosestPositionTo(int pos, Position.Bias b, Shape a,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                                       int direction, Position.Bias[] biasRet,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                                       int rowIndex, int x)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
              throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        JTextComponent text = (JTextComponent)getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        Document doc = getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        AbstractDocument aDoc = (doc instanceof AbstractDocument) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                                (AbstractDocument)doc : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        View row = getView(rowIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        int lastPos = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        // This could be made better to check backward positions too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        biasRet[0] = Position.Bias.Forward;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        for(int vc = 0, numViews = row.getViewCount(); vc < numViews; vc++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            View v = row.getView(vc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            int start = v.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            boolean ltr = (aDoc != null) ? aDoc.isLeftToRight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                           (start, start + 1) : true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            if(ltr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                lastPos = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                for(int end = v.getEndOffset(); lastPos < end; lastPos++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                    float xx = text.modelToView(lastPos).getBounds().x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                    if(xx >= x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                        while (++lastPos < end &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                               text.modelToView(lastPos).getBounds().x == xx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                        return --lastPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                lastPos--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                for(lastPos = v.getEndOffset() - 1; lastPos >= start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                    lastPos--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                    float xx = text.modelToView(lastPos).getBounds().x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                    if(xx >= x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                        while (--lastPos >= start &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                               text.modelToView(lastPos).getBounds().x == xx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                        return ++lastPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                lastPos++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        if(lastPos == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            return getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        return lastPos;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * Determines in which direction the next view lays.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * Consider the <code>View</code> at index n.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * Typically the <code>View</code>s are layed out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * from left to right, so that the <code>View</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * to the EAST will be at index n + 1, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * <code>View</code> to the WEST will be at index n - 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * In certain situations, such as with bidirectional text,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * it is possible that the <code>View</code> to EAST is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * at index n + 1, but rather at index n - 1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * or that the <code>View</code> to the WEST is not at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * index n - 1, but index n + 1.  In this case this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * would return true, indicating the <code>View</code>s are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * layed out in descending order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * This will return true if the text is layed out right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * to left at position, otherwise false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @param position position into the model
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @param bias either <code>Position.Bias.Forward</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *          <code>Position.Bias.Backward</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @return true if the text is layed out right to left at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *         position, otherwise false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    protected boolean flipEastAndWestAtEnds(int position,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                                            Position.Bias bias) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        Document doc = getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        if(doc instanceof AbstractDocument &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
           !((AbstractDocument)doc).isLeftToRight(getStartOffset(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                                                  getStartOffset() + 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    // --- FlowView methods ---------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * Fetches the constraining span to flow against for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * the given child index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @param index the index of the view being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @return the constraining span for the given view at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     *  <code>index</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
    public int getFlowSpan(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        View child = getView(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        int adjust = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        if (child instanceof Row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            Row row = (Row) child;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            adjust = row.getLeftInset() + row.getRightInset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        return (layoutSpan == Integer.MAX_VALUE) ? layoutSpan
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                                                 : (layoutSpan - adjust);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * Fetches the location along the flow axis that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * flow span will start at.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @param index the index of the view being queried
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @return the location for the given view at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *  <code>index</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    public int getFlowStart(int index) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        View child = getView(index);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        int adjust = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        if (child instanceof Row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            Row row = (Row) child;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
            adjust = row.getLeftInset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        return tabBase + adjust;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * Create a <code>View</code> that should be used to hold a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * a row's worth of children in a flow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @return the new <code>View</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    protected View createRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        return new Row(getElement());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    // --- TabExpander methods ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * Returns the next tab stop position given a reference position.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * This view implements the tab coordinate system, and calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * <code>getTabbedSpan</code> on the logical children in the process
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * of layout to determine the desired span of the children.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * logical children can delegate their tab expansion upward to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * the paragraph which knows how to expand tabs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * <code>LabelView</code> is an example of a view that delegates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * its tab expansion needs upward to the paragraph.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * This is implemented to try and locate a <code>TabSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * in the paragraph element's attribute set.  If one can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * found, its settings will be used, otherwise a default expansion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * will be provided.  The base location for for tab expansion
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * is the left inset from the paragraphs most recent allocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * (which is what the layout of the children is based upon).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @param x the X reference position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @param tabOffset the position within the text stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     *   that the tab occurred at >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @return the trailing end of the tab expansion >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * @see TabSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * @see TabStop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * @see LabelView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    public float nextTabStop(float x, int tabOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        // If the text isn't left justified, offset by 10 pixels!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        if(justification != StyleConstants.ALIGN_LEFT)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            return x + 10.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        x -= tabBase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        TabSet tabs = getTabSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        if(tabs == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            // a tab every 72 pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            return (float)(tabBase + (((int)x / 72 + 1) * 72));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        TabStop tab = tabs.getTabAfter(x + .01f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        if(tab == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            // no tab, do a default of 5 pixels.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            // Should this cause a wrapping of the line?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            return tabBase + x + 5.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        int alignment = tab.getAlignment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        int offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        switch(alignment) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        case TabStop.ALIGN_LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            // Simple case, left tab.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            return tabBase + tab.getPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        case TabStop.ALIGN_BAR:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            // PENDING: what does this mean?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            return tabBase + tab.getPosition();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        case TabStop.ALIGN_RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        case TabStop.ALIGN_CENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            offset = findOffsetToCharactersInString(tabChars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                                                    tabOffset + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        case TabStop.ALIGN_DECIMAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            offset = findOffsetToCharactersInString(tabDecimalChars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                                                    tabOffset + 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        if (offset == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            offset = getEndOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        float charsSize = getPartialSize(tabOffset + 1, offset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        switch(alignment) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        case TabStop.ALIGN_RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        case TabStop.ALIGN_DECIMAL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            // right and decimal are treated the same way, the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            // position will be the location of the tab less the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            // partialSize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            return tabBase + Math.max(x, tab.getPosition() - charsSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        case TabStop.ALIGN_CENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            // Similar to right, but half the partialSize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            return tabBase + Math.max(x, tab.getPosition() - charsSize / 2.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        // will never get here!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * Gets the <code>Tabset</code> to be used in calculating tabs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * @return the <code>TabSet</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
    protected TabSet getTabSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        return StyleConstants.getTabSet(getElement().getAttributes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * Returns the size used by the views between
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * <code>startOffset</code> and <code>endOffset</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * This uses <code>getPartialView</code> to calculate the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * size if the child view implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * <code>TabableView</code> interface. If a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * size is needed and a <code>View</code> does not implement
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * the <code>TabableView</code> interface,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * the <code>preferredSpan</code> will be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * @param startOffset the starting document offset >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * @param endOffset the ending document offset >= startOffset
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * @return the size >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    protected float getPartialSize(int startOffset, int endOffset) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        float size = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        int viewIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        int numViews = getViewCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        View view;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        int viewEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        int tempEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        // Have to search layoutPool!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        // PENDING: when ParagraphView supports breaking location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        // into layoutPool will have to change!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        viewIndex = getElement().getElementIndex(startOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        numViews = layoutPool.getViewCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        while(startOffset < endOffset && viewIndex < numViews) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            view = layoutPool.getView(viewIndex++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            viewEnd = view.getEndOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            tempEnd = Math.min(endOffset, viewEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            if(view instanceof TabableView)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                size += ((TabableView)view).getPartialSpan(startOffset, tempEnd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            else if(startOffset == view.getStartOffset() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                    tempEnd == view.getEndOffset())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                size += view.getPreferredSpan(View.X_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                // PENDING: should we handle this better?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                return 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            startOffset = viewEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        return size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * Finds the next character in the document with a character in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * <code>string</code>, starting at offset <code>start</code>. If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * there are no characters found, -1 will be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * @param string the string of characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @param start where to start in the model >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * @return the document offset, or -1 if no characters found
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    protected int findOffsetToCharactersInString(char[] string,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                                                 int start) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
        int stringLength = string.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        int end = getEndOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        Segment seg = new Segment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            getDocument().getText(start, end - start, seg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        } catch (BadLocationException ble) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        for(int counter = seg.offset, maxCounter = seg.offset + seg.count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            counter < maxCounter; counter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            char currentChar = seg.array[counter];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            for(int subCounter = 0; subCounter < stringLength;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
                subCounter++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
                if(currentChar == string[subCounter])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                    return counter - seg.offset + start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        // No match.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * Returns where the tabs are calculated from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     * @return where tabs are calculated from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    protected float getTabBase() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        return (float)tabBase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    // ---- View methods ----------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * Renders using the given rendering surface and area on that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * surface.  This is implemented to delgate to the superclass
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * after stashing the base coordinate for tab calculations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
     * @param g the rendering surface to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
     * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
     * @see View#paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
    public void paint(Graphics g, Shape a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a : a.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        tabBase = alloc.x + getLeftInset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        super.paint(g, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        // line with the negative firstLineIndent value needs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        // special handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        if (firstLineIndent < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            Shape sh = getChildAllocation(0, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            if ((sh != null) &&  sh.intersects(alloc)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                int x = alloc.x + getLeftInset() + firstLineIndent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                int y = alloc.y + getTopInset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                Rectangle clip = g.getClipBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                tempRect.x = x + getOffset(X_AXIS, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                tempRect.y = y + getOffset(Y_AXIS, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                tempRect.width = getSpan(X_AXIS, 0) - firstLineIndent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                tempRect.height = getSpan(Y_AXIS, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                if (tempRect.intersects(clip)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                    tempRect.x = tempRect.x - firstLineIndent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                    paintChild(g, tempRect, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * Determines the desired alignment for this view along an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     * axis.  This is implemented to give the alignment to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
     * center of the first row along the y axis, and the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     * along the x axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * @param axis may be either <code>View.X_AXIS</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     *   <code>View.Y_AXIS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * @return the desired alignment.  This should be a value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     *   between 0.0 and 1.0 inclusive, where 0 indicates alignment at the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     *   origin and 1.0 indicates alignment to the full span
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     *   away from the origin.  An alignment of 0.5 would be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     *   center of the view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    public float getAlignment(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
        switch (axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        case Y_AXIS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            float a = 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            if (getViewCount() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                int paragraphSpan = (int) getPreferredSpan(View.Y_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                View v = getView(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                int rowSpan = (int) v.getPreferredSpan(View.Y_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                a = (paragraphSpan != 0) ? ((float)(rowSpan / 2)) / paragraphSpan : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            return a;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        case X_AXIS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            return 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            throw new IllegalArgumentException("Invalid axis: " + axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * Breaks this view on the given axis at the given length.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     * <code>ParagraphView</code> instances are breakable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     * along the <code>Y_AXIS</code> only, and only if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     * <code>len</code> is after the first line.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     * @param axis may be either <code>View.X_AXIS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     *  or <code>View.Y_AXIS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * @param len specifies where a potential break is desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     *  along the given axis >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * @param a the current allocation of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * @return the fragment of the view that represents the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     *  given span, if the view can be broken; if the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     *  doesn't support breaking behavior, the view itself is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     *  returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * @see View#breakView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
    public View breakView(int axis, float len, Shape a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        if(axis == View.Y_AXIS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            if(a != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                Rectangle alloc = a.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                setSize(alloc.width, alloc.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            // Determine what row to break on.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            // PENDING(prinz) add break support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * Gets the break weight for a given location.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * <code>ParagraphView</code> instances are breakable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * along the <code>Y_AXIS</code> only, and only if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * <code>len</code> is after the first row.  If the length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * is less than one row, a value of <code>BadBreakWeight</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * @param axis may be either <code>View.X_AXIS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     *  or <code>View.Y_AXIS</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * @param len specifies where a potential break is desired >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * @return a value indicating the attractiveness of breaking here;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     *  either <code>GoodBreakWeight</code> or <code>BadBreakWeight</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * @see View#getBreakWeight
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    public int getBreakWeight(int axis, float len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        if(axis == View.Y_AXIS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
            // PENDING(prinz) make this return a reasonable value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            // when paragraph breaking support is re-implemented.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            // If less than one row, bad weight value should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            // returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            //return GoodBreakWeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            return BadBreakWeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        return BadBreakWeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * Calculate the needs for the paragraph along the minor axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
     * <p>This uses size requirements of the superclass, modified to take into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * account the non-breakable areas at the adjacent views edges.  The minimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * size requirements for such views should be no less than the sum of all
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * adjacent fragments.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * <p>If the {@code axis} parameter is neither {@code View.X_AXIS} nor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * {@code View.Y_AXIS}, {@link IllegalArgumentException} is thrown.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * {@code r} parameter is {@code null,} a new {@code SizeRequirements}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * object is created, otherwise the supplied {@code SizeRequirements}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * object is returned.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * @param axis  the minor axis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * @param r     the input {@code SizeRequirements} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * @return      the new or adjusted {@code SizeRequirements} object
3709
e7cf22d025bb 6876628: @throw instead of @throws in two ParagraphView classes
darcy
parents: 3342
diff changeset
   719
     * @throws IllegalArgumentException  if the {@code axis} parameter is invalid
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
    @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    protected SizeRequirements calculateMinorAxisRequirements(int axis,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                                                        SizeRequirements r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        r = super.calculateMinorAxisRequirements(axis, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        float min = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
        float glue = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        int n = getLayoutViewCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
            View v = getLayoutView(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            float span = v.getMinimumSpan(axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
            if (v.getBreakWeight(axis, 0, v.getMaximumSpan(axis))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
                                                        > View.BadBreakWeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
                // find the longest non-breakable fragments at the view edges
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
                int p0 = v.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                int p1 = v.getEndOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                float start = findEdgeSpan(v, axis, p0, p0, p1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                float end = findEdgeSpan(v, axis, p1, p0, p1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                glue += start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                min = Math.max(min, Math.max(span, glue));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
                glue = end;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                // non-breakable view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
                glue += span;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
                min = Math.max(min, glue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        r.minimum = Math.max(r.minimum, (int) min);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        r.preferred = Math.max(r.minimum,  r.preferred);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        r.maximum = Math.max(r.preferred, r.maximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * Binary search for the longest non-breakable fragment at the view edge.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    private float findEdgeSpan(View v, int axis, int fp, int p0, int p1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
        int len = p1 - p0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        if (len <= 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            // further fragmentation is not possible
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            return v.getMinimumSpan(axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            int mid = p0 + len / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            boolean startEdge = mid > fp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
            // initial view is breakable hence must support fragmentation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
            View f = startEdge ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
                v.createFragment(fp, mid) : v.createFragment(mid, fp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            boolean breakable = f.getBreakWeight(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                    axis, 0, f.getMaximumSpan(axis)) > View.BadBreakWeight;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            if (breakable == startEdge) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                p1 = mid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
                p0 = mid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            return findEdgeSpan(f, axis, fp, p0, p1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * Gives notification from the document that attributes were changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * in a location that this view is responsible for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * @param changes the change information from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     *  associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * @param a the current allocation of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * @param f the factory to use to rebuild if the view has children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * @see View#changedUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
    public void changedUpdate(DocumentEvent changes, Shape a, ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        // update any property settings stored, and layout should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        // recomputed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
        setPropertiesFromAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
        layoutChanged(X_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        layoutChanged(Y_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        super.changedUpdate(changes, a, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    // --- variables -----------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    private int justification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
    private float lineSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    /** Indentation for the first line, from the left inset. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
    protected int firstLineIndent = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * Used by the TabExpander functionality to determine
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * where to base the tab calculations.  This is basically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * the location of the left side of the paragraph.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
    private int tabBase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * Used to create an i18n-based layout strategy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
    static Class i18nStrategy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    /** Used for searching for a tab. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
    static char[] tabChars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    /** Used for searching for a tab or decimal character. */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
    static char[] tabDecimalChars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        tabChars = new char[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
        tabChars[0] = '\t';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
        tabDecimalChars = new char[2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
        tabDecimalChars[0] = '\t';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
        tabDecimalChars[1] = '.';
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * Internally created view that has the purpose of holding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * the views that represent the children of the paragraph
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * that have been arranged in rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
    class Row extends BoxView {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        Row(Element elem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
            super(elem, View.X_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
         * This is reimplemented to do nothing since the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
         * paragraph fills in the row with its needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
         * children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        protected void loadChildren(ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
         * Fetches the attributes to use when rendering.  This view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
         * isn't directly responsible for an element so it returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
         * the outer classes attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        public AttributeSet getAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            View p = getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
            return (p != null) ? p.getAttributes() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        public float getAlignment(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            if (axis == View.X_AXIS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                switch (justification) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
                case StyleConstants.ALIGN_LEFT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
                    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
                case StyleConstants.ALIGN_RIGHT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
                case StyleConstants.ALIGN_CENTER:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                    return 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
                case StyleConstants.ALIGN_JUSTIFIED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                    float rv = 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
                    //if we can justifiy the content always align to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                    //the left.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
                    if (isJustifiableDocument()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
                        rv = 0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
                    return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
            return super.getAlignment(axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
         * Provides a mapping from the document model coordinate space
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
         * to the coordinate space of the view mapped to it.  This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
         * implemented to let the superclass find the position along
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
         * the major axis and the allocation of the row is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
         * along the minor axis, so that even though the children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
         * are different heights they all get the same caret height.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
         * @param pos the position to convert
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
         * @param a the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
         * @return the bounding box of the given position
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
         * @exception BadLocationException  if the given position does not represent a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
         *   valid location in the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
         * @see View#modelToView
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
        public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            Rectangle r = a.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            View v = getViewAtPosition(pos, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            if ((v != null) && (!v.getElement().isLeaf())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                // Don't adjust the height if the view represents a branch.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
                return super.modelToView(pos, a, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            r = a.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
            int height = r.height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            int y = r.y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
            Shape loc = super.modelToView(pos, a, b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            r = loc.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            r.height = height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            r.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
         * Range represented by a row in the paragraph is only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
         * a subset of the total range of the paragraph element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
         * @see View#getRange
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        public int getStartOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            int offs = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            int n = getViewCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                View v = getView(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                offs = Math.min(offs, v.getStartOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
            return offs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        public int getEndOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            int offs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            int n = getViewCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                View v = getView(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                offs = Math.max(offs, v.getEndOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
            return offs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
         * Perform layout for the minor axis of the box (i.e. the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
         * axis orthoginal to the axis that it represents).  The results
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
         * of the layout should be placed in the given arrays which represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
         * the allocations to the children along the minor axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
         * This is implemented to do a baseline layout of the children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
         * by calling BoxView.baselineLayout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
         * @param targetSpan the total span given to the view, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
         *  whould be used to layout the children.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
         * @param axis the axis being layed out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
         * @param offsets the offsets from the origin of the view for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
         *  each of the child views.  This is a return value and is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
         *  filled in by the implementation of this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
         * @param spans the span of each child view.  This is a return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
         *  value and is filled in by the implementation of this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
         * @return the offset and span for each child view in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
         *  offsets and spans parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        protected void layoutMinorAxis(int targetSpan, int axis, int[] offsets, int[] spans) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            baselineLayout(targetSpan, axis, offsets, spans);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        protected SizeRequirements calculateMinorAxisRequirements(int axis,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
                                                                  SizeRequirements r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            return baselineRequirements(axis, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        private boolean isLastRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            View parent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
            return ((parent = getParent()) == null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                    || this == parent.getView(parent.getViewCount() - 1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        private boolean isBrokenRow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
            boolean rv = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            int viewsCount = getViewCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
            if (viewsCount > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
                View lastView = getView(viewsCount - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                if (lastView.getBreakWeight(X_AXIS, 0, 0) >=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
                      ForcedBreakWeight) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                    rv = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
            return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
        private boolean isJustifiableDocument() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
            return (! Boolean.TRUE.equals(getDocument().getProperty(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
                          AbstractDocument.I18NProperty)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
         * Whether we need to justify this {@code Row}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
         * At this time (jdk1.6) we support justification on for non
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
         * 18n text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
         * @return {@code true} if this {@code Row} should be justified.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
        private boolean isJustifyEnabled() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
            boolean ret = (justification == StyleConstants.ALIGN_JUSTIFIED);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
            //no justification for i18n documents
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
            ret = ret && isJustifiableDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
            //no justification for the last row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            ret = ret && ! isLastRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
            //no justification for the broken rows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
            ret = ret && ! isBrokenRow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
            return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
        //Calls super method after setting spaceAddon to 0.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        //Justification should not affect MajorAxisRequirements
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
        @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        protected SizeRequirements calculateMajorAxisRequirements(int axis,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
                SizeRequirements r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
            int oldJustficationData[] = justificationData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            justificationData = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            SizeRequirements ret = super.calculateMajorAxisRequirements(axis, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            if (isJustifyEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                justificationData = oldJustficationData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
            return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        protected void layoutMajorAxis(int targetSpan, int axis,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                                       int[] offsets, int[] spans) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
            int oldJustficationData[] = justificationData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            justificationData = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
            super.layoutMajorAxis(targetSpan, axis, offsets, spans);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            if (! isJustifyEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            int currentSpan = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
            for (int span : spans) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                currentSpan += span;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            if (currentSpan == targetSpan) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                //no need to justify
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            // we justify text by enlarging spaces by the {@code spaceAddon}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            // justification is started to the right of the rightmost TAB.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            // leading and trailing spaces are not extendable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            // GlyphPainter1 uses
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
            // justificationData
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            // for all painting and measurement.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            int extendableSpaces = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            int startJustifiableContent = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            int endJustifiableContent = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            int lastLeadingSpaces = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            int rowStartOffset = getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            int rowEndOffset = getEndOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            int spaceMap[] = new int[rowEndOffset - rowStartOffset];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            Arrays.fill(spaceMap, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            for (int i = getViewCount() - 1; i >= 0 ; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                View view = getView(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                if (view instanceof GlyphView) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                    GlyphView.JustificationInfo justificationInfo =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                        ((GlyphView) view).getJustificationInfo(rowStartOffset);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
                    final int viewStartOffset = view.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                    final int offset = viewStartOffset - rowStartOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                    for (int j = 0; j < justificationInfo.spaceMap.length(); j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
                        if (justificationInfo.spaceMap.get(j)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
                            spaceMap[j + offset] = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                    if (startJustifiableContent > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                        if (justificationInfo.end >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                            extendableSpaces += justificationInfo.trailingSpaces;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                            lastLeadingSpaces += justificationInfo.trailingSpaces;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
                    if (justificationInfo.start >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                        startJustifiableContent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
                            justificationInfo.start + viewStartOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                        extendableSpaces += lastLeadingSpaces;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                    if (justificationInfo.end >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                          && endJustifiableContent < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                        endJustifiableContent =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                            justificationInfo.end + viewStartOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
                    extendableSpaces += justificationInfo.contentSpaces;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                    lastLeadingSpaces = justificationInfo.leadingSpaces;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                    if (justificationInfo.hasTab) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
            if (extendableSpaces <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
                //there is nothing we can do to justify
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
            int adjustment = (targetSpan - currentSpan);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
            int spaceAddon = (extendableSpaces > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                ?  adjustment / extendableSpaces
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            int spaceAddonLeftoverEnd = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
            for (int i = startJustifiableContent - rowStartOffset,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
                     leftover = adjustment - spaceAddon * extendableSpaces;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
                     leftover > 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                     leftover -= spaceMap[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                     i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                spaceAddonLeftoverEnd = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            if (spaceAddon > 0 || spaceAddonLeftoverEnd >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                justificationData = (oldJustficationData != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
                    ? oldJustficationData
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
                    : new int[END_JUSTIFIABLE + 1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                justificationData[SPACE_ADDON] = spaceAddon;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                justificationData[SPACE_ADDON_LEFTOVER_END] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
                    spaceAddonLeftoverEnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
                justificationData[START_JUSTIFIABLE] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
                    startJustifiableContent - rowStartOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                justificationData[END_JUSTIFIABLE] =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                    endJustifiableContent - rowStartOffset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                super.layoutMajorAxis(targetSpan, axis, offsets, spans);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
        //for justified row we assume the maximum horizontal span
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        //is MAX_VALUE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        public float getMaximumSpan(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
            float ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
            if (View.X_AXIS == axis
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                  && isJustifyEnabled()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                ret = Float.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
              ret = super.getMaximumSpan(axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
            return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
         * Fetches the child view index representing the given position in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
         * the model.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
         * @param pos the position >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
         * @return  index of the view representing the given position, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
         *   -1 if no view represents that position
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
        protected int getViewIndexAtPosition(int pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            // This is expensive, but are views are not necessarily layed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
            // out in model order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
            if(pos < getStartOffset() || pos >= getEndOffset())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            for(int counter = getViewCount() - 1; counter >= 0; counter--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                View v = getView(counter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                if(pos >= v.getStartOffset() &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                   pos < v.getEndOffset()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                    return counter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
         * Gets the left inset.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
         * @return the inset
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        protected short getLeftInset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            View parentView;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            int adjustment = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
            if ((parentView = getParent()) != null) { //use firstLineIdent for the first row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                if (this == parentView.getView(0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                    adjustment = firstLineIndent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
            return (short)(super.getLeftInset() + adjustment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
        protected short getBottomInset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
            return (short)(super.getBottomInset() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                           ((minorRequest != null) ? minorRequest.preferred : 0) *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                           lineSpacing);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        final static int SPACE_ADDON = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        final static int SPACE_ADDON_LEFTOVER_END = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        final static int START_JUSTIFIABLE = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        //this should be the last index in justificationData
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        final static int END_JUSTIFIABLE = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        int justificationData[] = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
}