jdk/src/share/classes/javax/swing/text/html/TableView.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 1639 a97859015238
child 10320 fb28887eb9f2
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
     2
 * Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1639
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.swing.text.html;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.awt.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.BitSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.swing.SizeRequirements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.swing.event.DocumentEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.swing.text.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * HTML table view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @author  Timothy Prinzing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @see     View
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/*public*/ class TableView extends BoxView implements ViewFactory {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * Constructs a TableView for the given element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * @param elem the element that this view is responsible for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public TableView(Element elem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        super(elem, View.Y_AXIS);
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
    51
        rows = new Vector<RowView>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        gridValid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        captionIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        totalColumnRequirements = new SizeRequirements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * Creates a new table row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * @param elem an element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @return the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    protected RowView createTableRow(Element elem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        // PENDING(prinz) need to add support for some of the other
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        // elements, but for now just ignore anything that is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        // a TR.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        Object o = elem.getAttributes().getAttribute(StyleConstants.NameAttribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        if (o == HTML.Tag.TR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            return new RowView(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * The number of columns in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public int getColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        return columnSpans.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Fetches the span (width) of the given column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * This is used by the nested cells to query the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * sizes of grid locations outside of themselves.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public int getColumnSpan(int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        if (col < columnSpans.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            return columnSpans[col];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * The number of rows in the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public int getRowCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        return rows.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * Fetch the span of multiple rows.  This includes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * the border area.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    public int getMultiRowSpan(int row0, int row1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        RowView rv0 = getRow(row0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        RowView rv1 = getRow(row1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        if ((rv0 != null) && (rv1 != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            int index0 = rv0.viewIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            int index1 = rv1.viewIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            int span = getOffset(Y_AXIS, index1) - getOffset(Y_AXIS, index0) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                getSpan(Y_AXIS, index1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            return span;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        return 0;
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
     * Fetches the span (height) of the given row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public int getRowSpan(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        RowView rv = getRow(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        if (rv != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            return getSpan(Y_AXIS, rv.viewIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    RowView getRow(int row) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        if (row < rows.size()) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   130
            return rows.elementAt(row);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    protected View getViewAtPoint(int x, int y, Rectangle alloc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        int n = getViewCount();
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   137
        View v;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        Rectangle allocation = new Rectangle();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            allocation.setBounds(alloc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            childAllocation(i, allocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            v = getView(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            if (v instanceof RowView) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                v = ((RowView)v).findViewAtPoint(x, y, allocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                if (v != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                    alloc.setBounds(allocation);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                    return v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        return super.getViewAtPoint(x, y, alloc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * Determines the number of columns occupied by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * the table cell represented by given element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    protected int getColumnsOccupied(View v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        AttributeSet a = v.getElement().getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        if (a.isDefined(HTML.Attribute.COLSPAN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            String s = (String) a.getAttribute(HTML.Attribute.COLSPAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            if (s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    return Integer.parseInt(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                } catch (NumberFormatException nfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                    // fall through to one column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * Determines the number of rows occupied by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * the table cell represented by given element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    protected int getRowsOccupied(View v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        AttributeSet a = v.getElement().getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if (a.isDefined(HTML.Attribute.ROWSPAN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            String s = (String) a.getAttribute(HTML.Attribute.ROWSPAN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            if (s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                    return Integer.parseInt(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                } catch (NumberFormatException nfe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                    // fall through to one row
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    protected void invalidateGrid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        gridValid = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    protected StyleSheet getStyleSheet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        HTMLDocument doc = (HTMLDocument) getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        return doc.getStyleSheet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Update the insets, which contain the caption if there
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * is a caption.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    void updateInsets() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        short top = (short) painter.getInset(TOP, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        short bottom = (short) painter.getInset(BOTTOM, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (captionIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            View caption = getView(captionIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            short h = (short) caption.getPreferredSpan(Y_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            AttributeSet a = caption.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            Object align = a.getAttribute(CSS.Attribute.CAPTION_SIDE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            if ((align != null) && (align.equals("bottom"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                bottom += h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                top += h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        setInsets(top, (short) painter.getInset(LEFT, this),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                  bottom, (short) painter.getInset(RIGHT, this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * Update any cached values that come from attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    protected void setPropertiesFromAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        StyleSheet sheet = getStyleSheet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        attr = sheet.getViewAttributes(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        painter = sheet.getBoxPainter(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            setInsets((short) painter.getInset(TOP, this),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                      (short) painter.getInset(LEFT, this),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                          (short) painter.getInset(BOTTOM, this),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
                      (short) painter.getInset(RIGHT, this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            CSS.LengthValue lv = (CSS.LengthValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                attr.getAttribute(CSS.Attribute.BORDER_SPACING);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            if (lv != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                cellSpacing = (int) lv.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                cellSpacing = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            lv = (CSS.LengthValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    attr.getAttribute(CSS.Attribute.BORDER_TOP_WIDTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            if (lv != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    borderWidth = (int) lv.getValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                    borderWidth = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Fill in the grid locations that are placeholders
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * for multi-column, multi-row, and missing grid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * locations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    void updateGrid() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        if (! gridValid) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            relativeCells = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            multiRowCells = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            // determine which views are table rows and clear out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            // grid points marked filled.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            captionIndex = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            rows.removeAllElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            int n = getViewCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                View v = getView(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                if (v instanceof RowView) {
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   276
                    rows.addElement((RowView) v);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
                    RowView rv = (RowView) v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                    rv.clearFilledColumns();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
                    rv.rowIndex = rows.size() - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                    rv.viewIndex = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
                    Object o = v.getElement().getAttributes().getAttribute(StyleConstants.NameAttribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                    if (o instanceof HTML.Tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                        HTML.Tag kind = (HTML.Tag) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                        if (kind == HTML.Tag.CAPTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                            captionIndex = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            int maxColumns = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            int nrows = rows.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            for (int row = 0; row < nrows; row++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                RowView rv = getRow(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                int col = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                for (int cell = 0; cell < rv.getViewCount(); cell++, col++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                    View cv = rv.getView(cell);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                    if (! relativeCells) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                        AttributeSet a = cv.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                        CSS.LengthValue lv = (CSS.LengthValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                            a.getAttribute(CSS.Attribute.WIDTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                        if ((lv != null) && (lv.isPercentage())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                            relativeCells = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                    // advance to a free column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                    for (; rv.isFilled(col); col++);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                    int rowSpan = getRowsOccupied(cv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                    if (rowSpan > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                        multiRowCells = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                    int colSpan = getColumnsOccupied(cv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                    if ((colSpan > 1) || (rowSpan > 1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                        // fill in the overflow entries for this cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                        int rowLimit = row + rowSpan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                        int colLimit = col + colSpan;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                        for (int i = row; i < rowLimit; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                            for (int j = col; j < colLimit; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                                if (i != row || j != col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                                    addFill(i, j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                        if (colSpan > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
                            col += colSpan - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                maxColumns = Math.max(maxColumns, col);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            // setup the column layout/requirements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            columnSpans = new int[maxColumns];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            columnOffsets = new int[maxColumns];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            columnRequirements = new SizeRequirements[maxColumns];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            for (int i = 0; i < maxColumns; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                columnRequirements[i] = new SizeRequirements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                columnRequirements[i].maximum = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            gridValid = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * Mark a grid location as filled in for a cells overflow.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
    void addFill(int row, int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        RowView rv = getRow(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        if (rv != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            rv.fillColumn(col);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * Layout the columns to fit within the given target span.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * @param targetSpan the given span for total of all the table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     *  columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @param reqs the requirements desired for each column.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     *  is the column maximum of the cells minimum, preferred, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     *  maximum requested span
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * @param spans the return value of how much to allocated to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     *  each column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * @param offsets the return value of the offset from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *  origin for each column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @return the offset from the origin and the span for each column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *  in the offsets and spans parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    protected void layoutColumns(int targetSpan, int[] offsets, int[] spans,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                                 SizeRequirements[] reqs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        //clean offsets and spans
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        Arrays.fill(offsets, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        Arrays.fill(spans, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        colIterator.setLayoutArrays(offsets, spans, targetSpan);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        CSS.calculateTiledLayout(colIterator, targetSpan);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * Calculate the requirements for each column.  The calculation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * is done as two passes over the table.  The table cells that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * occupy a single column are scanned first to determine the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * maximum of minimum, preferred, and maximum spans along the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * give axis.  Table cells that span multiple columns are excluded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * from the first pass.  A second pass is made to determine if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * the cells that span multiple columns are satisfied.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * column requirements are not satisified, the needs of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * multi-column cell is mixed into the existing column requirements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * The calculation of the multi-column distribution is based upon
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * the proportions of the existing column requirements and taking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * into consideration any constraining maximums.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    void calculateColumnRequirements(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        // clean columnRequirements
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        for (SizeRequirements req : columnRequirements) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            req.minimum = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            req.preferred = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            req.maximum = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        Container host = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        if (host != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            if (host instanceof JTextComponent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                skipComments = !((JTextComponent)host).isEditable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                skipComments = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        // pass 1 - single column cells
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        boolean hasMultiColumn = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        int nrows = getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        for (int i = 0; i < nrows; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            RowView row = getRow(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            int col = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            int ncells = row.getViewCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            for (int cell = 0; cell < ncells; cell++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                View cv = row.getView(cell);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                if (skipComments && !(cv instanceof CellView)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                for (; row.isFilled(col); col++); // advance to a free column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                int rowSpan = getRowsOccupied(cv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                int colSpan = getColumnsOccupied(cv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                if (colSpan == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    checkSingleColumnCell(axis, col, cv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                    hasMultiColumn = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                    col += colSpan - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                col++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        // pass 2 - multi-column cells
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        if (hasMultiColumn) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            for (int i = 0; i < nrows; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                RowView row = getRow(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                int col = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                int ncells = row.getViewCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                for (int cell = 0; cell < ncells; cell++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                    View cv = row.getView(cell);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                    if (skipComments && !(cv instanceof CellView)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                        continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                    for (; row.isFilled(col); col++); // advance to a free column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                    int colSpan = getColumnsOccupied(cv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    if (colSpan > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                        checkMultiColumnCell(axis, col, colSpan, cv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                        col += colSpan - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                    col++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * check the requirements of a table cell that spans a single column.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    void checkSingleColumnCell(int axis, int col, View v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        SizeRequirements req = columnRequirements[col];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        req.minimum = Math.max((int) v.getMinimumSpan(axis), req.minimum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        req.preferred = Math.max((int) v.getPreferredSpan(axis), req.preferred);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * check the requirements of a table cell that spans multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    void checkMultiColumnCell(int axis, int col, int ncols, View v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        // calculate the totals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        long min = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        long pref = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        long max = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        for (int i = 0; i < ncols; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            SizeRequirements req = columnRequirements[col + i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            min += req.minimum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            pref += req.preferred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            max += req.maximum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        // check if the minimum size needs adjustment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        int cmin = (int) v.getMinimumSpan(axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        if (cmin > min) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
             * the columns that this cell spans need adjustment to fit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
             * this table cell.... calculate the adjustments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
            SizeRequirements[] reqs = new SizeRequirements[ncols];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            for (int i = 0; i < ncols; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                reqs[i] = columnRequirements[col + i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            int[] spans = new int[ncols];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            int[] offsets = new int[ncols];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            SizeRequirements.calculateTiledPositions(cmin, null, reqs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                                                     offsets, spans);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            // apply the adjustments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            for (int i = 0; i < ncols; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                SizeRequirements req = reqs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                req.minimum = Math.max(spans[i], req.minimum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                req.preferred = Math.max(req.minimum, req.preferred);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                req.maximum = Math.max(req.preferred, req.maximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        // check if the preferred size needs adjustment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        int cpref = (int) v.getPreferredSpan(axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        if (cpref > pref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
             * the columns that this cell spans need adjustment to fit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
             * this table cell.... calculate the adjustments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            SizeRequirements[] reqs = new SizeRequirements[ncols];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            for (int i = 0; i < ncols; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                reqs[i] = columnRequirements[col + i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            int[] spans = new int[ncols];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            int[] offsets = new int[ncols];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            SizeRequirements.calculateTiledPositions(cpref, null, reqs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                                                     offsets, spans);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            // apply the adjustments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            for (int i = 0; i < ncols; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                SizeRequirements req = reqs[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                req.preferred = Math.max(spans[i], req.preferred);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                req.maximum = Math.max(req.preferred, req.maximum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
    // --- BoxView methods -----------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * Calculate the requirements for the minor axis.  This is called by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * the superclass whenever the requirements need to be updated (i.e.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * a preferenceChanged was messaged through this view).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * This is implemented to calculate the requirements as the sum of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * requirements of the columns and then adjust it if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * CSS width or height attribute is specified and applicable to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * the axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        updateGrid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        // calculate column requirements for each column
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        calculateColumnRequirements(axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        // the requirements are the sum of the columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        if (r == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
            r = new SizeRequirements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        long min = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        long pref = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        int n = columnRequirements.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            SizeRequirements req = columnRequirements[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            min += req.minimum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            pref += req.preferred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        int adjust = (n + 1) * cellSpacing + 2 * borderWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        min += adjust;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        pref += adjust;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        r.minimum = (int) min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        r.preferred = (int) pref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        r.maximum = (int) pref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        AttributeSet attr = getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        CSS.LengthValue cssWidth = (CSS.LengthValue)attr.getAttribute(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                                                    CSS.Attribute.WIDTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        if (BlockView.spanSetFromAttributes(axis, r, cssWidth, null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            if (r.minimum < (int)min) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                // The user has requested a smaller size than is needed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                // show the table, override it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                r.maximum = r.minimum = r.preferred = (int) min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        totalColumnRequirements.minimum = r.minimum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        totalColumnRequirements.preferred = r.preferred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        totalColumnRequirements.maximum = r.maximum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        // set the alignment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        Object o = attr.getAttribute(CSS.Attribute.TEXT_ALIGN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        if (o != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            // set horizontal alignment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            String ta = o.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
            if (ta.equals("left")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                r.alignment = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            } else if (ta.equals("center")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                r.alignment = 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
            } else if (ta.equals("right")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                r.alignment = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                r.alignment = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            r.alignment = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     * Calculate the requirements for the major axis.  This is called by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * the superclass whenever the requirements need to be updated (i.e.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * a preferenceChanged was messaged through this view).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * This is implemented to provide the superclass behavior adjusted for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     * multi-row table cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
    protected SizeRequirements calculateMajorAxisRequirements(int axis, SizeRequirements r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        updateInsets();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        rowIterator.updateAdjustments();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        r = CSS.calculateTiledRequirements(rowIterator, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        r.maximum = r.preferred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * Perform layout for the minor axis of the box (i.e. the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * axis orthoginal to the axis that it represents).  The results
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * of the layout should be placed in the given arrays which represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * the allocations to the children along the minor axis.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * is called by the superclass whenever the layout needs to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * updated along the minor axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * This is implemented to call the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * <a href="#layoutColumns">layoutColumns</a> method, and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * forward to the superclass to actually carry out the layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * of the tables rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * @param targetSpan the total span given to the view, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     *  whould be used to layout the children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     * @param axis the axis being layed out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     * @param offsets the offsets from the origin of the view for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     *  each of the child views.  This is a return value and is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     *  filled in by the implementation of this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     * @param spans the span of each child view;  this is a return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     *  value and is filled in by the implementation of this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * @return the offset and span for each child view in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     *  offsets and spans parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
    protected void layoutMinorAxis(int targetSpan, int axis, int[] offsets, int[] spans) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        // make grid is properly represented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        updateGrid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        // all of the row layouts are invalid, so mark them that way
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        int n = getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            RowView row = getRow(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            row.layoutChanged(axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
        // calculate column spans
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        layoutColumns(targetSpan, columnOffsets, columnSpans, columnRequirements);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        // continue normal layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
        super.layoutMinorAxis(targetSpan, axis, offsets, spans);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     * Perform layout for the major axis of the box (i.e. the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     * axis that it represents).  The results
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     * of the layout should be placed in the given arrays which represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     * the allocations to the children along the minor axis.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * is called by the superclass whenever the layout needs to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * updated along the minor axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * This method is where the layout of the table rows within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * table takes place.  This method is implemented to call the use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * the RowIterator and the CSS collapsing tile to layout
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * with border spacing and border collapsing capabilities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * @param targetSpan the total span given to the view, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     *  whould be used to layout the children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * @param axis the axis being layed out
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * @param offsets the offsets from the origin of the view for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     *  each of the child views; this is a return value and is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     *  filled in by the implementation of this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * @param spans the span of each child view; this is a return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     *  value and is filled in by the implementation of this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     * @return the offset and span for each child view in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     *  offsets and spans parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    protected void layoutMajorAxis(int targetSpan, int axis, int[] offsets, int[] spans) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        rowIterator.setLayoutArrays(offsets, spans);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        CSS.calculateTiledLayout(rowIterator, targetSpan);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        if (captionIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            // place the caption
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
            View caption = getView(captionIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
            int h = (int) caption.getPreferredSpan(Y_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
            spans[captionIndex] = h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            short boxBottom = (short) painter.getInset(BOTTOM, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            if (boxBottom != getBottomInset()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
                offsets[captionIndex] = targetSpan + boxBottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
                offsets[captionIndex] = - getTopInset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * Fetches the child view that represents the given position in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * the model.  This is implemented to walk through the children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * looking for a range that contains the given position.  In this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * view the children do not necessarily have a one to one mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * with the child elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * @param pos  the search position >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * @param a  the allocation to the table on entry, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     *   allocation of the view containing the position on exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * @return  the view representing the given position, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     *   null if there isn't one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
    protected View getViewAtPosition(int pos, Rectangle a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        int n = getViewCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            View v = getView(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            int p0 = v.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            int p1 = v.getEndOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            if ((pos >= p0) && (pos < p1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
                // it's in this view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
                if (a != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
                    childAllocation(i, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
                return v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
        if (pos == getEndOffset()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
            View v = getView(n - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
            if (a != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
                this.childAllocation(n - 1, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            return v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
    // --- View methods ---------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * Fetches the attributes to use when rendering.  This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * implemented to multiplex the attributes specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
     * model with a StyleSheet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    public AttributeSet getAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        if (attr == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            StyleSheet sheet = getStyleSheet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            attr = sheet.getViewAttributes(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        return attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * Renders using the given rendering surface and area on that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * surface.  This is implemented to delegate to the css box
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * painter to paint the border and background prior to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * interior.  The superclass culls rendering the children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * that don't directly intersect the clip and the row may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * have cells hanging from a row above in it.  The table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * does not use the superclass rendering behavior and instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * paints all of the rows and lets the rows cull those
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     * cells not intersecting the clip region.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     * @param g the rendering surface to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
     * @param allocation the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * @see View#paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
    public void paint(Graphics g, Shape allocation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
        // paint the border
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        Rectangle a = allocation.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        setSize(a.width, a.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        if (captionIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            // adjust the border for the caption
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            short top = (short) painter.getInset(TOP, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            short bottom = (short) painter.getInset(BOTTOM, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            if (top != getTopInset()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
                int h = getTopInset() - top;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
                a.y += h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
                a.height -= h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
                a.height -= getBottomInset() - bottom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
        painter.paint(g, a.x, a.y, a.width, a.height, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        // paint interior
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
        int n = getViewCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
        for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            View v = getView(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
            v.paint(g, getChildAllocation(i, allocation));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
        //super.paint(g, a);
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
     * Establishes the parent view for this view.  This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * guaranteed to be called before any other methods if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * parent view is functioning properly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
     * This is implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * to forward to the superclass as well as call the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * <a href="#setPropertiesFromAttributes">setPropertiesFromAttributes</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * method to set the paragraph properties from the css
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * attributes.  The call is made at this time to ensure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * the ability to resolve upward through the parents
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * view attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * @param parent the new parent, or null if the view is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     *  being removed from a parent it was previously added
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     *  to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    public void setParent(View parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        super.setParent(parent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        if (parent != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            setPropertiesFromAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * Fetches the ViewFactory implementation that is feeding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * the view hierarchy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * This replaces the ViewFactory with an implementation that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * calls through to the createTableRow and createTableCell
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * methods.   If the element given to the factory isn't a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * table row or cell, the request is delegated to the factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * produced by the superclass behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * @return the factory, null if none
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    public ViewFactory getViewFactory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        return this;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * Gives notification that something was inserted into
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
     * the document in a location that this view is responsible for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * This replaces the ViewFactory with an implementation that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * calls through to the createTableRow and createTableCell
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * methods.   If the element given to the factory isn't a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * table row or cell, the request is delegated to the factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * passed as an argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * @param e the change information from the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * @param a the current allocation of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * @param f the factory to use to rebuild if the view has children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * @see View#insertUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    public void insertUpdate(DocumentEvent e, Shape a, ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
        super.insertUpdate(e, a, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * Gives notification that something was removed from the document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * in a location that this view is responsible for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * This replaces the ViewFactory with an implementation that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * calls through to the createTableRow and createTableCell
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * methods.   If the element given to the factory isn't a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * table row or cell, the request is delegated to the factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * passed as an argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * @param e the change information from the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * @param a the current allocation of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * @param f the factory to use to rebuild if the view has children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * @see View#removeUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
    public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
        super.removeUpdate(e, a, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * Gives notification from the document that attributes were changed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * in a location that this view is responsible for.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * This replaces the ViewFactory with an implementation that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * calls through to the createTableRow and createTableCell
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * methods.   If the element given to the factory isn't a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * table row or cell, the request is delegated to the factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     * passed as an argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     * @param e the change information from the associated document
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * @param a the current allocation of the view
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * @param f the factory to use to rebuild if the view has children
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * @see View#changedUpdate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
    public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        super.changedUpdate(e, a, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
    protected void forwardUpdate(DocumentEvent.ElementChange ec,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
                                 DocumentEvent e, Shape a, ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        super.forwardUpdate(ec, e, a, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        // A change in any of the table cells usually effects the whole table,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        // so redraw it all!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        if (a != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            Component c = getContainer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
            if (c != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
                Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a :
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
                                   a.getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
                c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * Change the child views.  This is implemented to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * provide the superclass behavior and invalidate the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * grid so that rows and columns will be recalculated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    public void replace(int offset, int length, View[] views) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        super.replace(offset, length, views);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        invalidateGrid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    // --- ViewFactory methods ------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * The table itself acts as a factory for the various
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * views that actually represent pieces of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * All other factory activity is delegated to the factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * returned by the parent of the table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
    public View create(Element elem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
        Object o = elem.getAttributes().getAttribute(StyleConstants.NameAttribute);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
        if (o instanceof HTML.Tag) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
            HTML.Tag kind = (HTML.Tag) o;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            if (kind == HTML.Tag.TR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                return createTableRow(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            } else if ((kind == HTML.Tag.TD) || (kind == HTML.Tag.TH)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
                return new CellView(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            } else if (kind == HTML.Tag.CAPTION) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                return new javax.swing.text.html.ParagraphView(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
        // default is to delegate to the normal factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
        View p = getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
        if (p != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
            ViewFactory f = p.getViewFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            if (f != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                return f.create(elem);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    // ---- variables ----------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    private AttributeSet attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    private StyleSheet.BoxPainter painter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    private int cellSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
    private int borderWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * The index of the caption view if there is a caption.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     * This has a value of -1 if there is no caption.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * caption lives in the inset area of the table, and is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * updated with each time the grid is recalculated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
    private int captionIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     * Do any of the table cells contain a relative size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     * specification?  This is updated with each call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
     * updateGrid().  If this is true, the ColumnIterator
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
     * will do extra work to calculate relative cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * specifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
    private boolean relativeCells;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     * Do any of the table cells span multiple rows?  If
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * true, the RowRequirementIterator will do additional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * work to adjust the requirements of rows spanned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     * a single table cell.  This is updated with each call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
     * updateGrid().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    private boolean multiRowCells;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
    int[] columnSpans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    int[] columnOffsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * SizeRequirements for all the columns.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
    SizeRequirements totalColumnRequirements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
    SizeRequirements[] columnRequirements;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
    RowIterator rowIterator = new RowIterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    ColumnIterator colIterator = new ColumnIterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
1287
a04aca99c77a 6722802: Code improvement and warnings removing from the javax.swing.text package
rupashka
parents: 2
diff changeset
   993
    Vector<RowView> rows;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    // whether to display comments inside table or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    boolean skipComments = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    boolean gridValid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
    static final private BitSet EMPTY = new BitSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
    class ColumnIterator implements CSS.LayoutIterator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
         * Disable percentage adjustments which should only apply
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
         * when calculating layout, not requirements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        void disablePercentages() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            percentages = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
         * Update percentage adjustments if they are needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
        private void updatePercentagesAndAdjustmentWeights(int span) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
            adjustmentWeights = new int[columnRequirements.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
            for (int i = 0; i < columnRequirements.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
                adjustmentWeights[i] = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
            if (relativeCells) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
                percentages = new int[columnRequirements.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                percentages = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            int nrows = getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            for (int rowIndex = 0; rowIndex < nrows; rowIndex++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
                RowView row = getRow(rowIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
                int col = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                int ncells = row.getViewCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
                for (int cell = 0; cell < ncells; cell++, col++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                    View cv = row.getView(cell);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
                    for (; row.isFilled(col); col++); // advance to a free column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
                    int rowSpan = getRowsOccupied(cv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
                    int colSpan = getColumnsOccupied(cv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
                    AttributeSet a = cv.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
                    CSS.LengthValue lv = (CSS.LengthValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                        a.getAttribute(CSS.Attribute.WIDTH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
                    if ( lv != null ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
                        int len = (int) (lv.getValue(span) / colSpan + 0.5f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
                        for (int i = 0; i < colSpan; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
                            if (lv.isPercentage()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
                                // add a percentage requirement
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
                                percentages[col+i] = Math.max(percentages[col+i], len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
                                adjustmentWeights[col + i] = Math.max(adjustmentWeights[col + i], WorstAdjustmentWeight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
                            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
                                adjustmentWeights[col + i] = Math.max(adjustmentWeights[col + i], WorstAdjustmentWeight - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                    col += colSpan - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
         * Set the layout arrays to use for holding layout results
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        public void setLayoutArrays(int offsets[], int spans[], int targetSpan) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            this.offsets = offsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            this.spans = spans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            updatePercentagesAndAdjustmentWeights(targetSpan);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
        // --- RequirementIterator methods -------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
        public int getCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            return columnRequirements.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
        public void setIndex(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
            col = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        public void setOffset(int offs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
            offsets[col] = offs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        public int getOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            return offsets[col];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
        public void setSpan(int span) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            spans[col] = span;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        public int getSpan() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            return spans[col];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        public float getMinimumSpan(float parentSpan) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
            // do not care for percentages, since min span can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            // be less than columnRequirements[col].minimum,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
            // but can be less than percentage value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
            return columnRequirements[col].minimum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        public float getPreferredSpan(float parentSpan) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
            if ((percentages != null) && (percentages[col] != 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
                return Math.max(percentages[col], columnRequirements[col].minimum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            return columnRequirements[col].preferred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        public float getMaximumSpan(float parentSpan) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            return columnRequirements[col].maximum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        public float getBorderWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
            return borderWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        public float getLeadingCollapseSpan() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            return cellSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        public float getTrailingCollapseSpan() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            return cellSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        public int getAdjustmentWeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
            return adjustmentWeights[col];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
         * Current column index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
        private int col;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
         * percentage values (may be null since there
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
         * might not be any).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
        private int[] percentages;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        private int[] adjustmentWeights;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        private int[] offsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
        private int[] spans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
    class RowIterator implements CSS.LayoutIterator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        RowIterator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
        void updateAdjustments() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            int axis = Y_AXIS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            if (multiRowCells) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                // adjust requirements of multi-row cells
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                int n = getRowCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
                adjustments = new int[n];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
                    RowView rv = getRow(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                    if (rv.multiRowCells == true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                        int ncells = rv.getViewCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                        for (int j = 0; j < ncells; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
                            View v = rv.getView(j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
                            int nrows = getRowsOccupied(v);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
                            if (nrows > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
                                int spanNeeded = (int) v.getPreferredSpan(axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
                                adjustMultiRowSpan(spanNeeded, nrows, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
                adjustments = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
            }
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
         * Fixup preferences to accomodate a multi-row table cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
         * if not already covered by existing preferences.  This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
         * a no-op if not all of the rows needed (to do this check/fixup)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
         * have arrived yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        void adjustMultiRowSpan(int spanNeeded, int nrows, int rowIndex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            if ((rowIndex + nrows) > getCount()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
                // rows are missing (could be a bad rowspan specification)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
                // or not all the rows have arrived.  Do the best we can with
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
                // the current set of rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
                nrows = getCount() - rowIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
                if (nrows < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
            int span = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
            for (int i = 0; i < nrows; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
                RowView rv = getRow(rowIndex + i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
                span += rv.getPreferredSpan(Y_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            if (spanNeeded > span) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
                int adjust = (spanNeeded - span);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
                int rowAdjust = adjust / nrows;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
                int firstAdjust = rowAdjust + (adjust - (rowAdjust * nrows));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                RowView rv = getRow(rowIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
                adjustments[rowIndex] = Math.max(adjustments[rowIndex],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                                                 firstAdjust);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
                for (int i = 1; i < nrows; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
                    adjustments[rowIndex + i] = Math.max(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                        adjustments[rowIndex + i], rowAdjust);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
        void setLayoutArrays(int[] offsets, int[] spans) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            this.offsets = offsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            this.spans = spans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
        // --- RequirementIterator methods -------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        public void setOffset(int offs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            RowView rv = getRow(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
            if (rv != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                offsets[rv.viewIndex] = offs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        public int getOffset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
            RowView rv = getRow(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
            if (rv != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                return offsets[rv.viewIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        public void setSpan(int span) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
            RowView rv = getRow(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
            if (rv != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                spans[rv.viewIndex] = span;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
        public int getSpan() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
            RowView rv = getRow(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
            if (rv != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
                return spans[rv.viewIndex];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
        public int getCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
            return rows.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        public void setIndex(int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
            row = i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        public float getMinimumSpan(float parentSpan) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            return getPreferredSpan(parentSpan);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        public float getPreferredSpan(float parentSpan) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
            RowView rv = getRow(row);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
            if (rv != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                int adjust = (adjustments != null) ? adjustments[row] : 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                return rv.getPreferredSpan(TableView.this.getAxis()) + adjust;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
        public float getMaximumSpan(float parentSpan) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
            return getPreferredSpan(parentSpan);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        public float getBorderWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
            return borderWidth;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        public float getLeadingCollapseSpan() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            return cellSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        public float getTrailingCollapseSpan() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
            return cellSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
        public int getAdjustmentWeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
         * Current row index
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
        private int row;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
         * Adjustments to the row requirements to handle multi-row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
         * table cells.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
        private int[] adjustments;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
        private int[] offsets;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        private int[] spans;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
     * View of a row in a row-centric table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
    public class RowView extends BoxView {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
         * Constructs a TableView for the given element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
         * @param elem the element that this view is responsible for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        public RowView(Element elem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
            super(elem, View.X_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            fillColumns = new BitSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
            RowView.this.setPropertiesFromAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        void clearFilledColumns() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
            fillColumns.and(EMPTY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
        void fillColumn(int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
            fillColumns.set(col);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        boolean isFilled(int col) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
            return fillColumns.get(col);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
         * The number of columns present in this row.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        int getColumnCount() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            int nfill = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
            int n = fillColumns.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
            for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
                if (fillColumns.get(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
                    nfill ++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
            return getViewCount() + nfill;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
         * Fetches the attributes to use when rendering.  This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
         * implemented to multiplex the attributes specified in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
         * model with a StyleSheet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
        public AttributeSet getAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
            return attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
        View findViewAtPoint(int x, int y, Rectangle alloc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
            int n = getViewCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
            for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
                if (getChildAllocation(i, alloc).contains(x, y)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
                    childAllocation(i, alloc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
                    return getView(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
        protected StyleSheet getStyleSheet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
            HTMLDocument doc = (HTMLDocument) getDocument();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
            return doc.getStyleSheet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
         * This is called by a child to indicate its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
         * preferred span has changed.  This is implemented to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
         * execute the superclass behavior and well as try to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
         * determine if a row with a multi-row cell hangs across
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
         * this row.  If a multi-row cell covers this row it also
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
         * needs to propagate a preferenceChanged so that it will
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
         * recalculate the multi-row cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
         * @param child the child view
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
         * @param width true if the width preference should change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
         * @param height true if the height preference should change
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        public void preferenceChanged(View child, boolean width, boolean height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
            super.preferenceChanged(child, width, height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
            if (TableView.this.multiRowCells && height) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
                for (int i = rowIndex  - 1; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                    RowView rv = TableView.this.getRow(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                    if (rv.multiRowCells) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
                        rv.preferenceChanged(null, false, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
        // The major axis requirements for a row are dictated by the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
        // requirements. These methods use the value calculated by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
        // TableView.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
        protected SizeRequirements calculateMajorAxisRequirements(int axis, SizeRequirements r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
            SizeRequirements req = new SizeRequirements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
            req.minimum = totalColumnRequirements.minimum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
            req.maximum = totalColumnRequirements.maximum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
            req.preferred = totalColumnRequirements.preferred;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
            req.alignment = 0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
            return req;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
        public float getMinimumSpan(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
            float value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
            if (axis == View.X_AXIS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
                value = totalColumnRequirements.minimum + getLeftInset() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                        getRightInset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                value = super.getMinimumSpan(axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
        public float getMaximumSpan(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
            float value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
            if (axis == View.X_AXIS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
                // We're flexible.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
                value = (float)Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
                value = super.getMaximumSpan(axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
        public float getPreferredSpan(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
            float value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
            if (axis == View.X_AXIS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
                value = totalColumnRequirements.preferred + getLeftInset() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
                        getRightInset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
            else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
                value = super.getPreferredSpan(axis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
            return value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
        public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
            super.changedUpdate(e, a, f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
            int pos = e.getOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
            if (pos <= getStartOffset() && (pos + e.getLength()) >=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
                getEndOffset()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
                RowView.this.setPropertiesFromAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
         * Renders using the given rendering surface and area on that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
         * surface.  This is implemented to delegate to the css box
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
         * painter to paint the border and background prior to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
         * interior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
         * @param g the rendering surface to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
         * @param allocation the allocated region to render into
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
         * @see View#paint
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        public void paint(Graphics g, Shape allocation) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
            Rectangle a = (Rectangle) allocation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
            painter.paint(g, a.x, a.y, a.width, a.height, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
            super.paint(g, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
         * Change the child views.  This is implemented to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
         * provide the superclass behavior and invalidate the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
         * grid so that rows and columns will be recalculated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
        public void replace(int offset, int length, View[] views) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
            super.replace(offset, length, views);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
            invalidateGrid();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
         * Calculate the height requirements of the table row.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
         * requirements of multi-row cells are not considered for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
         * calculation.  The table itself will check and adjust the row
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
         * requirements for all the rows that have multi-row cells spanning
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
         * them.  This method updates the multi-row flag that indicates that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
         * this row and rows below need additional consideration.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
        protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
//          return super.calculateMinorAxisRequirements(axis, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
            long min = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
            long pref = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
            long max = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
            multiRowCells = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
            int n = getViewCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
            for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
                View v = getView(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
                if (getRowsOccupied(v) > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
                    multiRowCells = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
                    max = Math.max((int) v.getMaximumSpan(axis), max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
                    min = Math.max((int) v.getMinimumSpan(axis), min);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
                    pref = Math.max((int) v.getPreferredSpan(axis), pref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
                    max = Math.max((int) v.getMaximumSpan(axis), max);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
            if (r == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
                r = new SizeRequirements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
                r.alignment = 0.5f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
            r.preferred = (int) pref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
            r.minimum = (int) min;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
            r.maximum = (int) max;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
            return r;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
         * Perform layout for the major axis of the box (i.e. the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
         * axis that it represents).  The results of the layout should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
         * be placed in the given arrays which represent the allocations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
         * to the children along the major axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
         * This is re-implemented to give each child the span of the column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
         * width for the table, and to give cells that span multiple columns
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
         * the multi-column span.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
         * @param targetSpan the total span given to the view, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
         *  whould be used to layout the children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
         * @param axis the axis being layed out
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
         * @param offsets the offsets from the origin of the view for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
         *  each of the child views; this is a return value and is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
         *  filled in by the implementation of this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
         * @param spans the span of each child view; this is a return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
         *  value and is filled in by the implementation of this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
         * @return the offset and span for each child view in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
         *  offsets and spans parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
        protected void layoutMajorAxis(int targetSpan, int axis, int[] offsets, int[] spans) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
            int col = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
            int ncells = getViewCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
            for (int cell = 0; cell < ncells; cell++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
                View cv = getView(cell);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
                if (skipComments && !(cv instanceof CellView)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
                for (; isFilled(col); col++); // advance to a free column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
                int colSpan = getColumnsOccupied(cv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
                spans[cell] = columnSpans[col];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
                offsets[cell] = columnOffsets[col];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
                if (colSpan > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
                    int n = columnSpans.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
                    for (int j = 1; j < colSpan; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
                        // Because the table may be only partially formed, some
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
                        // of the columns may not yet exist.  Therefore we check
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
                        // the bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
                        if ((col+j) < n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
                            spans[cell] += columnSpans[col+j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
                            spans[cell] += cellSpacing;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                    col += colSpan - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                col++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
         * Perform layout for the minor axis of the box (i.e. the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
         * axis orthoginal to the axis that it represents).  The results
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
         * of the layout should be placed in the given arrays which represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
         * the allocations to the children along the minor axis.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
         * is called by the superclass whenever the layout needs to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
         * updated along the minor axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
         * This is implemented to delegate to the superclass, then adjust
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
         * the span for any cell that spans multiple rows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
         * @param targetSpan the total span given to the view, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
         *  whould be used to layout the children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
         * @param axis the axis being layed out
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
         * @param offsets the offsets from the origin of the view for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
         *  each of the child views; this is a return value and is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
         *  filled in by the implementation of this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
         * @param spans the span of each child view; this is a return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
         *  value and is filled in by the implementation of this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
         * @return the offset and span for each child view in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
         *  offsets and spans parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
        protected void layoutMinorAxis(int targetSpan, int axis, int[] offsets, int[] spans) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
            super.layoutMinorAxis(targetSpan, axis, offsets, spans);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
            int col = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
            int ncells = getViewCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
            for (int cell = 0; cell < ncells; cell++, col++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
                View cv = getView(cell);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
                for (; isFilled(col); col++); // advance to a free column
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
                int colSpan = getColumnsOccupied(cv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
                int rowSpan = getRowsOccupied(cv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
                if (rowSpan > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
                    int row0 = rowIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
                    int row1 = Math.min(rowIndex + rowSpan - 1, getRowCount()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                    spans[cell] = getMultiRowSpan(row0, row1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
                if (colSpan > 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
                    col += colSpan - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
         * Determines the resizability of the view along the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
         * given axis.  A value of 0 or less is not resizable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
         * @param axis may be either View.X_AXIS or View.Y_AXIS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
         * @return the resize weight
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
         * @exception IllegalArgumentException for an invalid axis
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
        public int getResizeWeight(int axis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
         * Fetches the child view that represents the given position in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
         * the model.  This is implemented to walk through the children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
         * looking for a range that contains the given position.  In this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
         * view the children do not necessarily have a one to one mapping
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
         * with the child elements.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
         * @param pos  the search position >= 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
         * @param a  the allocation to the table on entry, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
         *   allocation of the view containing the position on exit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
         * @return  the view representing the given position, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
         *   null if there isn't one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
        protected View getViewAtPosition(int pos, Rectangle a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
            int n = getViewCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
            for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
                View v = getView(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
                int p0 = v.getStartOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
                int p1 = v.getEndOffset();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
                if ((pos >= p0) && (pos < p1)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
                    // it's in this view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
                    if (a != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
                        childAllocation(i, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
                    return v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
            if (pos == getEndOffset()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
                View v = getView(n - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
                if (a != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
                    this.childAllocation(n - 1, a);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
                return v;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
         * Update any cached values that come from attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
        void setPropertiesFromAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
            StyleSheet sheet = getStyleSheet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
            attr = sheet.getViewAttributes(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
            painter = sheet.getBoxPainter(attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
        private StyleSheet.BoxPainter painter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
        private AttributeSet attr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
        /** columns filled by multi-column or multi-row cells */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
        BitSet fillColumns;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
         * The row index within the overall grid
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
        int rowIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
         * The view index (for row index to view index conversion).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
         * This is set by the updateGrid method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
        int viewIndex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
         * Does this table row have cells that span multiple rows?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
        boolean multiRowCells;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
     * Default view of an html table cell.  This needs to be moved
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
     * somewhere else.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
    class CellView extends BlockView {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
         * Constructs a TableCell for the given element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
         * @param elem the element that this view is responsible for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
        public CellView(Element elem) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
            super(elem, Y_AXIS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
         * Perform layout for the major axis of the box (i.e. the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
         * axis that it represents).  The results of the layout should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
         * be placed in the given arrays which represent the allocations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
         * to the children along the major axis.  This is called by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
         * superclass to recalculate the positions of the child views
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
         * when the layout might have changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
         * This is implemented to delegate to the superclass to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
         * tile the children.  If the target span is greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
         * was needed, the offsets are adjusted to align the children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
         * (i.e. position according to the html valign attribute).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
         * @param targetSpan the total span given to the view, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
         *  whould be used to layout the children
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
         * @param axis the axis being layed out
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
         * @param offsets the offsets from the origin of the view for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
         *  each of the child views; this is a return value and is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
         *  filled in by the implementation of this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
         * @param spans the span of each child view; this is a return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
         *  value and is filled in by the implementation of this method
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
         * @return the offset and span for each child view in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
         *  offsets and spans parameters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
        protected void layoutMajorAxis(int targetSpan, int axis, int[] offsets, int[] spans) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
            super.layoutMajorAxis(targetSpan, axis, offsets, spans);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
            // calculate usage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
            int used = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
            int n = spans.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
            for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
                used += spans[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
            // calculate adjustments
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
            int adjust = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
            if (used < targetSpan) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
                // PENDING(prinz) change to use the css alignment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
                String valign = (String) getElement().getAttributes().getAttribute(
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
                    HTML.Attribute.VALIGN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
                if (valign == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
                    AttributeSet rowAttr = getElement().getParentElement().getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
                    valign = (String) rowAttr.getAttribute(HTML.Attribute.VALIGN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
                if ((valign == null) || valign.equals("middle")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
                    adjust = (targetSpan - used) / 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
                } else if (valign.equals("bottom")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
                    adjust = targetSpan - used;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
            // make adjustments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
            if (adjust != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
                for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
                    offsets[i] += adjust;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
         * Calculate the requirements needed along the major axis.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
         * This is called by the superclass whenever the requirements
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
         * need to be updated (i.e. a preferenceChanged was messaged
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
         * through this view).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
         * This is implemented to delegate to the superclass, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
         * indicate the maximum size is very large (i.e. the cell
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
         * is willing to expend to occupy the full height of the row).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
         * @param axis the axis being layed out.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
         * @param r the requirements to fill in.  If null, a new one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
         *  should be allocated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
        protected SizeRequirements calculateMajorAxisRequirements(int axis,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
                                                                  SizeRequirements r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
            SizeRequirements req = super.calculateMajorAxisRequirements(axis, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
            req.maximum = Integer.MAX_VALUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
            return req;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
        @Override
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
        protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
            SizeRequirements rv = super.calculateMinorAxisRequirements(axis, r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
            //for the cell the minimum should be derived from the child views
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
            //the parent behaviour is to use CSS for that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
            int n = getViewCount();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
            int min = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
            for (int i = 0; i < n; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
                View v = getView(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
                min = Math.max((int) v.getMinimumSpan(axis), min);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
            rv.minimum = Math.min(rv.minimum, min);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
            return rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
}