0N/A/*
3909N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/Apackage javax.swing.text;
0N/A
0N/Aimport java.awt.*;
0N/Aimport java.util.BitSet;
0N/Aimport java.util.Vector;
0N/Aimport javax.swing.SizeRequirements;
0N/Aimport javax.swing.event.DocumentEvent;
0N/A
0N/Aimport javax.swing.text.html.HTML;
0N/A
0N/A/**
0N/A * <p>
0N/A * Implements View interface for a table, that is composed of an
0N/A * element structure where the child elements of the element
0N/A * this view is responsible for represent rows and the child
0N/A * elements of the row elements are cells. The cell elements can
0N/A * have an arbitrary element structure under them, which will
0N/A * be built with the ViewFactory returned by the getViewFactory
0N/A * method.
0N/A * <pre>
0N/A *
0N/A * &nbsp; TABLE
0N/A * &nbsp; ROW
0N/A * &nbsp; CELL
0N/A * &nbsp; CELL
0N/A * &nbsp; ROW
0N/A * &nbsp; CELL
0N/A * &nbsp; CELL
0N/A *
0N/A * </pre>
0N/A * <p>
0N/A * This is implemented as a hierarchy of boxes, the table itself
0N/A * is a vertical box, the rows are horizontal boxes, and the cells
0N/A * are vertical boxes. The cells are allowed to span multiple
0N/A * columns and rows. By default, the table can be thought of as
0N/A * being formed over a grid (i.e. somewhat like one would find in
0N/A * gridbag layout), where table cells can request to span more
0N/A * than one grid cell. The default horizontal span of table cells
0N/A * will be based upon this grid, but can be changed by reimplementing
0N/A * the requested span of the cell (i.e. table cells can have independant
0N/A * spans if desired).
0N/A *
0N/A * @author Timothy Prinzing
0N/A * @see View
0N/A */
0N/Apublic abstract class TableView extends BoxView {
0N/A
0N/A /**
0N/A * Constructs a TableView for the given element.
0N/A *
0N/A * @param elem the element that this view is responsible for
0N/A */
0N/A public TableView(Element elem) {
0N/A super(elem, View.Y_AXIS);
611N/A rows = new Vector<TableRow>();
0N/A gridValid = false;
0N/A }
0N/A
0N/A /**
0N/A * Creates a new table row.
0N/A *
0N/A * @param elem an element
0N/A * @return the row
0N/A */
0N/A protected TableRow createTableRow(Element elem) {
0N/A return new TableRow(elem);
0N/A }
0N/A
0N/A /**
0N/A * @deprecated Table cells can now be any arbitrary
0N/A * View implementation and should be produced by the
0N/A * ViewFactory rather than the table.
0N/A *
0N/A * @param elem an element
0N/A * @return the cell
0N/A */
0N/A @Deprecated
0N/A protected TableCell createTableCell(Element elem) {
0N/A return new TableCell(elem);
0N/A }
0N/A
0N/A /**
0N/A * The number of columns in the table.
0N/A */
0N/A int getColumnCount() {
0N/A return columnSpans.length;
0N/A }
0N/A
0N/A /**
0N/A * Fetches the span (width) of the given column.
0N/A * This is used by the nested cells to query the
0N/A * sizes of grid locations outside of themselves.
0N/A */
0N/A int getColumnSpan(int col) {
0N/A return columnSpans[col];
0N/A }
0N/A
0N/A /**
0N/A * The number of rows in the table.
0N/A */
0N/A int getRowCount() {
0N/A return rows.size();
0N/A }
0N/A
0N/A /**
0N/A * Fetches the span (height) of the given row.
0N/A */
0N/A int getRowSpan(int row) {
0N/A View rv = getRow(row);
0N/A if (rv != null) {
0N/A return (int) rv.getPreferredSpan(Y_AXIS);
0N/A }
0N/A return 0;
0N/A }
0N/A
0N/A TableRow getRow(int row) {
0N/A if (row < rows.size()) {
611N/A return rows.elementAt(row);
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Determines the number of columns occupied by
0N/A * the table cell represented by given element.
0N/A */
0N/A /*protected*/ int getColumnsOccupied(View v) {
0N/A // PENDING(prinz) this code should be in the html
0N/A // paragraph, but we can't add api to enable it.
0N/A AttributeSet a = v.getElement().getAttributes();
0N/A String s = (String) a.getAttribute(HTML.Attribute.COLSPAN);
0N/A if (s != null) {
0N/A try {
0N/A return Integer.parseInt(s);
0N/A } catch (NumberFormatException nfe) {
0N/A // fall through to one column
0N/A }
0N/A }
0N/A
0N/A return 1;
0N/A }
0N/A
0N/A /**
0N/A * Determines the number of rows occupied by
0N/A * the table cell represented by given element.
0N/A */
0N/A /*protected*/ int getRowsOccupied(View v) {
0N/A // PENDING(prinz) this code should be in the html
0N/A // paragraph, but we can't add api to enable it.
0N/A AttributeSet a = v.getElement().getAttributes();
0N/A String s = (String) a.getAttribute(HTML.Attribute.ROWSPAN);
0N/A if (s != null) {
0N/A try {
0N/A return Integer.parseInt(s);
0N/A } catch (NumberFormatException nfe) {
0N/A // fall through to one row
0N/A }
0N/A }
0N/A
0N/A return 1;
0N/A }
0N/A
0N/A /*protected*/ void invalidateGrid() {
0N/A gridValid = false;
0N/A }
0N/A
0N/A protected void forwardUpdate(DocumentEvent.ElementChange ec,
0N/A DocumentEvent e, Shape a, ViewFactory f) {
0N/A super.forwardUpdate(ec, e, a, f);
0N/A // A change in any of the table cells usually effects the whole table,
0N/A // so redraw it all!
0N/A if (a != null) {
0N/A Component c = getContainer();
0N/A if (c != null) {
0N/A Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a :
0N/A a.getBounds();
0N/A c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Change the child views. This is implemented to
0N/A * provide the superclass behavior and invalidate the
0N/A * grid so that rows and columns will be recalculated.
0N/A */
0N/A public void replace(int offset, int length, View[] views) {
0N/A super.replace(offset, length, views);
0N/A invalidateGrid();
0N/A }
0N/A
0N/A /**
0N/A * Fill in the grid locations that are placeholders
0N/A * for multi-column, multi-row, and missing grid
0N/A * locations.
0N/A */
0N/A void updateGrid() {
0N/A if (! gridValid) {
0N/A // determine which views are table rows and clear out
0N/A // grid points marked filled.
0N/A rows.removeAllElements();
0N/A int n = getViewCount();
0N/A for (int i = 0; i < n; i++) {
0N/A View v = getView(i);
0N/A if (v instanceof TableRow) {
611N/A rows.addElement((TableRow) v);
0N/A TableRow rv = (TableRow) v;
0N/A rv.clearFilledColumns();
0N/A rv.setRow(i);
0N/A }
0N/A }
0N/A
0N/A int maxColumns = 0;
0N/A int nrows = rows.size();
0N/A for (int row = 0; row < nrows; row++) {
0N/A TableRow rv = getRow(row);
0N/A int col = 0;
0N/A for (int cell = 0; cell < rv.getViewCount(); cell++, col++) {
0N/A View cv = rv.getView(cell);
0N/A // advance to a free column
0N/A for (; rv.isFilled(col); col++);
0N/A int rowSpan = getRowsOccupied(cv);
0N/A int colSpan = getColumnsOccupied(cv);
0N/A if ((colSpan > 1) || (rowSpan > 1)) {
0N/A // fill in the overflow entries for this cell
0N/A int rowLimit = row + rowSpan;
0N/A int colLimit = col + colSpan;
0N/A for (int i = row; i < rowLimit; i++) {
0N/A for (int j = col; j < colLimit; j++) {
0N/A if (i != row || j != col) {
0N/A addFill(i, j);
0N/A }
0N/A }
0N/A }
0N/A if (colSpan > 1) {
0N/A col += colSpan - 1;
0N/A }
0N/A }
0N/A }
0N/A maxColumns = Math.max(maxColumns, col);
0N/A }
0N/A
0N/A // setup the column layout/requirements
0N/A columnSpans = new int[maxColumns];
0N/A columnOffsets = new int[maxColumns];
0N/A columnRequirements = new SizeRequirements[maxColumns];
0N/A for (int i = 0; i < maxColumns; i++) {
0N/A columnRequirements[i] = new SizeRequirements();
0N/A }
0N/A gridValid = true;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Mark a grid location as filled in for a cells overflow.
0N/A */
0N/A void addFill(int row, int col) {
0N/A TableRow rv = getRow(row);
0N/A if (rv != null) {
0N/A rv.fillColumn(col);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Lays out the columns to fit within the given target span.
0N/A * Returns the results through {@code offsets} and {@code spans}.
0N/A *
0N/A * @param targetSpan the given span for total of all the table
0N/A * columns
0N/A * @param reqs the requirements desired for each column. This
0N/A * is the column maximum of the cells minimum, preferred, and
0N/A * maximum requested span
0N/A * @param spans the return value of how much to allocated to
0N/A * each column
0N/A * @param offsets the return value of the offset from the
0N/A * origin for each column
0N/A */
0N/A protected void layoutColumns(int targetSpan, int[] offsets, int[] spans,
0N/A SizeRequirements[] reqs) {
0N/A // allocate using the convenience method on SizeRequirements
0N/A SizeRequirements.calculateTiledPositions(targetSpan, null, reqs,
0N/A offsets, spans);
0N/A }
0N/A
0N/A /**
0N/A * Perform layout for the minor axis of the box (i.e. the
0N/A * axis orthoginal to the axis that it represents). The results
0N/A * of the layout should be placed in the given arrays which represent
0N/A * the allocations to the children along the minor axis. This
0N/A * is called by the superclass whenever the layout needs to be
0N/A * updated along the minor axis.
0N/A * <p>
0N/A * This is implemented to call the
3370N/A * {@link #layoutColumns layoutColumns} method, and then
0N/A * forward to the superclass to actually carry out the layout
0N/A * of the tables rows.
0N/A *
0N/A * @param targetSpan the total span given to the view, which
0N/A * whould be used to layout the children.
0N/A * @param axis the axis being layed out.
0N/A * @param offsets the offsets from the origin of the view for
0N/A * each of the child views. This is a return value and is
0N/A * filled in by the implementation of this method.
0N/A * @param spans the span of each child view. This is a return
0N/A * value and is filled in by the implementation of this method.
0N/A */
0N/A protected void layoutMinorAxis(int targetSpan, int axis, int[] offsets, int[] spans) {
0N/A // make grid is properly represented
0N/A updateGrid();
0N/A
0N/A // all of the row layouts are invalid, so mark them that way
0N/A int n = getRowCount();
0N/A for (int i = 0; i < n; i++) {
0N/A TableRow row = getRow(i);
0N/A row.layoutChanged(axis);
0N/A }
0N/A
0N/A // calculate column spans
0N/A layoutColumns(targetSpan, columnOffsets, columnSpans, columnRequirements);
0N/A
0N/A // continue normal layout
0N/A super.layoutMinorAxis(targetSpan, axis, offsets, spans);
0N/A }
0N/A
0N/A /**
0N/A * Calculate the requirements for the minor axis. This is called by
0N/A * the superclass whenever the requirements need to be updated (i.e.
0N/A * a preferenceChanged was messaged through this view).
0N/A * <p>
0N/A * This is implemented to calculate the requirements as the sum of the
0N/A * requirements of the columns.
0N/A */
0N/A protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements r) {
0N/A updateGrid();
0N/A
0N/A // calculate column requirements for each column
0N/A calculateColumnRequirements(axis);
0N/A
0N/A
0N/A // the requirements are the sum of the columns.
0N/A if (r == null) {
0N/A r = new SizeRequirements();
0N/A }
0N/A long min = 0;
0N/A long pref = 0;
0N/A long max = 0;
611N/A for (SizeRequirements req : columnRequirements) {
0N/A min += req.minimum;
0N/A pref += req.preferred;
0N/A max += req.maximum;
0N/A }
0N/A r.minimum = (int) min;
0N/A r.preferred = (int) pref;
0N/A r.maximum = (int) max;
0N/A r.alignment = 0;
0N/A return r;
0N/A }
0N/A
0N/A /*
0N/A boolean shouldTrace() {
0N/A AttributeSet a = getElement().getAttributes();
0N/A Object o = a.getAttribute(HTML.Attribute.ID);
0N/A if ((o != null) && o.equals("debug")) {
0N/A return true;
0N/A }
0N/A return false;
0N/A }
0N/A */
0N/A
0N/A /**
0N/A * Calculate the requirements for each column. The calculation
0N/A * is done as two passes over the table. The table cells that
0N/A * occupy a single column are scanned first to determine the
0N/A * maximum of minimum, preferred, and maximum spans along the
0N/A * give axis. Table cells that span multiple columns are excluded
0N/A * from the first pass. A second pass is made to determine if
0N/A * the cells that span multiple columns are satisfied. If the
0N/A * column requirements are not satisified, the needs of the
0N/A * multi-column cell is mixed into the existing column requirements.
0N/A * The calculation of the multi-column distribution is based upon
0N/A * the proportions of the existing column requirements and taking
0N/A * into consideration any constraining maximums.
0N/A */
0N/A void calculateColumnRequirements(int axis) {
0N/A // pass 1 - single column cells
0N/A boolean hasMultiColumn = false;
0N/A int nrows = getRowCount();
0N/A for (int i = 0; i < nrows; i++) {
0N/A TableRow row = getRow(i);
0N/A int col = 0;
0N/A int ncells = row.getViewCount();
0N/A for (int cell = 0; cell < ncells; cell++, col++) {
0N/A View cv = row.getView(cell);
0N/A for (; row.isFilled(col); col++); // advance to a free column
0N/A int rowSpan = getRowsOccupied(cv);
0N/A int colSpan = getColumnsOccupied(cv);
0N/A if (colSpan == 1) {
0N/A checkSingleColumnCell(axis, col, cv);
0N/A } else {
0N/A hasMultiColumn = true;
0N/A col += colSpan - 1;
0N/A }
0N/A }
0N/A }
0N/A
0N/A // pass 2 - multi-column cells
0N/A if (hasMultiColumn) {
0N/A for (int i = 0; i < nrows; i++) {
0N/A TableRow row = getRow(i);
0N/A int col = 0;
0N/A int ncells = row.getViewCount();
0N/A for (int cell = 0; cell < ncells; cell++, col++) {
0N/A View cv = row.getView(cell);
0N/A for (; row.isFilled(col); col++); // advance to a free column
0N/A int colSpan = getColumnsOccupied(cv);
0N/A if (colSpan > 1) {
0N/A checkMultiColumnCell(axis, col, colSpan, cv);
0N/A col += colSpan - 1;
0N/A }
0N/A }
0N/A }
0N/A }
0N/A
0N/A /*
0N/A if (shouldTrace()) {
0N/A System.err.println("calc:");
0N/A for (int i = 0; i < columnRequirements.length; i++) {
0N/A System.err.println(" " + i + ": " + columnRequirements[i]);
0N/A }
0N/A }
0N/A */
0N/A }
0N/A
0N/A /**
0N/A * check the requirements of a table cell that spans a single column.
0N/A */
0N/A void checkSingleColumnCell(int axis, int col, View v) {
0N/A SizeRequirements req = columnRequirements[col];
0N/A req.minimum = Math.max((int) v.getMinimumSpan(axis), req.minimum);
0N/A req.preferred = Math.max((int) v.getPreferredSpan(axis), req.preferred);
0N/A req.maximum = Math.max((int) v.getMaximumSpan(axis), req.maximum);
0N/A }
0N/A
0N/A /**
0N/A * check the requirements of a table cell that spans multiple
0N/A * columns.
0N/A */
0N/A void checkMultiColumnCell(int axis, int col, int ncols, View v) {
0N/A // calculate the totals
0N/A long min = 0;
0N/A long pref = 0;
0N/A long max = 0;
0N/A for (int i = 0; i < ncols; i++) {
0N/A SizeRequirements req = columnRequirements[col + i];
0N/A min += req.minimum;
0N/A pref += req.preferred;
0N/A max += req.maximum;
0N/A }
0N/A
0N/A // check if the minimum size needs adjustment.
0N/A int cmin = (int) v.getMinimumSpan(axis);
0N/A if (cmin > min) {
0N/A /*
0N/A * the columns that this cell spans need adjustment to fit
0N/A * this table cell.... calculate the adjustments. The
0N/A * maximum for each cell is the maximum of the existing
0N/A * maximum or the amount needed by the cell.
0N/A */
0N/A SizeRequirements[] reqs = new SizeRequirements[ncols];
0N/A for (int i = 0; i < ncols; i++) {
0N/A SizeRequirements r = reqs[i] = columnRequirements[col + i];
0N/A r.maximum = Math.max(r.maximum, (int) v.getMaximumSpan(axis));
0N/A }
0N/A int[] spans = new int[ncols];
0N/A int[] offsets = new int[ncols];
0N/A SizeRequirements.calculateTiledPositions(cmin, null, reqs,
0N/A offsets, spans);
0N/A // apply the adjustments
0N/A for (int i = 0; i < ncols; i++) {
0N/A SizeRequirements req = reqs[i];
0N/A req.minimum = Math.max(spans[i], req.minimum);
0N/A req.preferred = Math.max(req.minimum, req.preferred);
0N/A req.maximum = Math.max(req.preferred, req.maximum);
0N/A }
0N/A }
0N/A
0N/A // check if the preferred size needs adjustment.
0N/A int cpref = (int) v.getPreferredSpan(axis);
0N/A if (cpref > pref) {
0N/A /*
0N/A * the columns that this cell spans need adjustment to fit
0N/A * this table cell.... calculate the adjustments. The
0N/A * maximum for each cell is the maximum of the existing
0N/A * maximum or the amount needed by the cell.
0N/A */
0N/A SizeRequirements[] reqs = new SizeRequirements[ncols];
0N/A for (int i = 0; i < ncols; i++) {
0N/A SizeRequirements r = reqs[i] = columnRequirements[col + i];
0N/A }
0N/A int[] spans = new int[ncols];
0N/A int[] offsets = new int[ncols];
0N/A SizeRequirements.calculateTiledPositions(cpref, null, reqs,
0N/A offsets, spans);
0N/A // apply the adjustments
0N/A for (int i = 0; i < ncols; i++) {
0N/A SizeRequirements req = reqs[i];
0N/A req.preferred = Math.max(spans[i], req.preferred);
0N/A req.maximum = Math.max(req.preferred, req.maximum);
0N/A }
0N/A }
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Fetches the child view that represents the given position in
0N/A * the model. This is implemented to walk through the children
0N/A * looking for a range that contains the given position. In this
0N/A * view the children do not necessarily have a one to one mapping
0N/A * with the child elements.
0N/A *
0N/A * @param pos the search position >= 0
0N/A * @param a the allocation to the table on entry, and the
0N/A * allocation of the view containing the position on exit
0N/A * @return the view representing the given position, or
0N/A * <code>null</code> if there isn't one
0N/A */
0N/A protected View getViewAtPosition(int pos, Rectangle a) {
0N/A int n = getViewCount();
0N/A for (int i = 0; i < n; i++) {
0N/A View v = getView(i);
0N/A int p0 = v.getStartOffset();
0N/A int p1 = v.getEndOffset();
0N/A if ((pos >= p0) && (pos < p1)) {
0N/A // it's in this view.
0N/A if (a != null) {
0N/A childAllocation(i, a);
0N/A }
0N/A return v;
0N/A }
0N/A }
0N/A if (pos == getEndOffset()) {
0N/A View v = getView(n - 1);
0N/A if (a != null) {
0N/A this.childAllocation(n - 1, a);
0N/A }
0N/A return v;
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A // ---- variables ----------------------------------------------------
0N/A
0N/A int[] columnSpans;
0N/A int[] columnOffsets;
0N/A SizeRequirements[] columnRequirements;
611N/A Vector<TableRow> rows;
0N/A boolean gridValid;
0N/A static final private BitSet EMPTY = new BitSet();
0N/A
0N/A /**
0N/A * View of a row in a row-centric table.
0N/A */
0N/A public class TableRow extends BoxView {
0N/A
0N/A /**
0N/A * Constructs a TableView for the given element.
0N/A *
0N/A * @param elem the element that this view is responsible for
0N/A * @since 1.4
0N/A */
0N/A public TableRow(Element elem) {
0N/A super(elem, View.X_AXIS);
0N/A fillColumns = new BitSet();
0N/A }
0N/A
0N/A void clearFilledColumns() {
0N/A fillColumns.and(EMPTY);
0N/A }
0N/A
0N/A void fillColumn(int col) {
0N/A fillColumns.set(col);
0N/A }
0N/A
0N/A boolean isFilled(int col) {
0N/A return fillColumns.get(col);
0N/A }
0N/A
0N/A /** get location in the overall set of rows */
0N/A int getRow() {
0N/A return row;
0N/A }
0N/A
0N/A /**
0N/A * set location in the overall set of rows, this is
0N/A * set by the TableView.updateGrid() method.
0N/A */
0N/A void setRow(int row) {
0N/A this.row = row;
0N/A }
0N/A
0N/A /**
0N/A * The number of columns present in this row.
0N/A */
0N/A int getColumnCount() {
0N/A int nfill = 0;
0N/A int n = fillColumns.size();
0N/A for (int i = 0; i < n; i++) {
0N/A if (fillColumns.get(i)) {
0N/A nfill ++;
0N/A }
0N/A }
0N/A return getViewCount() + nfill;
0N/A }
0N/A
0N/A /**
0N/A * Change the child views. This is implemented to
0N/A * provide the superclass behavior and invalidate the
0N/A * grid so that rows and columns will be recalculated.
0N/A */
0N/A public void replace(int offset, int length, View[] views) {
0N/A super.replace(offset, length, views);
0N/A invalidateGrid();
0N/A }
0N/A
0N/A /**
0N/A * Perform layout for the major axis of the box (i.e. the
0N/A * axis that it represents). The results of the layout should
0N/A * be placed in the given arrays which represent the allocations
0N/A * to the children along the major axis.
0N/A * <p>
0N/A * This is re-implemented to give each child the span of the column
0N/A * width for the table, and to give cells that span multiple columns
0N/A * the multi-column span.
0N/A *
0N/A * @param targetSpan the total span given to the view, which
0N/A * whould be used to layout the children.
0N/A * @param axis the axis being layed out.
0N/A * @param offsets the offsets from the origin of the view for
0N/A * each of the child views. This is a return value and is
0N/A * filled in by the implementation of this method.
0N/A * @param spans the span of each child view. This is a return
0N/A * value and is filled in by the implementation of this method.
0N/A */
0N/A protected void layoutMajorAxis(int targetSpan, int axis, int[] offsets, int[] spans) {
0N/A int col = 0;
0N/A int ncells = getViewCount();
0N/A for (int cell = 0; cell < ncells; cell++, col++) {
0N/A View cv = getView(cell);
0N/A for (; isFilled(col); col++); // advance to a free column
0N/A int colSpan = getColumnsOccupied(cv);
0N/A spans[cell] = columnSpans[col];
0N/A offsets[cell] = columnOffsets[col];
0N/A if (colSpan > 1) {
0N/A int n = columnSpans.length;
0N/A for (int j = 1; j < colSpan; j++) {
0N/A // Because the table may be only partially formed, some
0N/A // of the columns may not yet exist. Therefore we check
0N/A // the bounds.
0N/A if ((col+j) < n) {
0N/A spans[cell] += columnSpans[col+j];
0N/A }
0N/A }
0N/A col += colSpan - 1;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Perform layout for the minor axis of the box (i.e. the
0N/A * axis orthoginal to the axis that it represents). The results
0N/A * of the layout should be placed in the given arrays which represent
0N/A * the allocations to the children along the minor axis. This
0N/A * is called by the superclass whenever the layout needs to be
0N/A * updated along the minor axis.
0N/A * <p>
0N/A * This is implemented to delegate to the superclass, then adjust
0N/A * the span for any cell that spans multiple rows.
0N/A *
0N/A * @param targetSpan the total span given to the view, which
0N/A * whould be used to layout the children.
0N/A * @param axis the axis being layed out.
0N/A * @param offsets the offsets from the origin of the view for
0N/A * each of the child views. This is a return value and is
0N/A * filled in by the implementation of this method.
0N/A * @param spans the span of each child view. This is a return
0N/A * value and is filled in by the implementation of this method.
0N/A */
0N/A protected void layoutMinorAxis(int targetSpan, int axis, int[] offsets, int[] spans) {
0N/A super.layoutMinorAxis(targetSpan, axis, offsets, spans);
0N/A int col = 0;
0N/A int ncells = getViewCount();
0N/A for (int cell = 0; cell < ncells; cell++, col++) {
0N/A View cv = getView(cell);
0N/A for (; isFilled(col); col++); // advance to a free column
0N/A int colSpan = getColumnsOccupied(cv);
0N/A int rowSpan = getRowsOccupied(cv);
0N/A if (rowSpan > 1) {
0N/A for (int j = 1; j < rowSpan; j++) {
0N/A // test bounds of each row because it may not exist
0N/A // either because of error or because the table isn't
0N/A // fully loaded yet.
0N/A int row = getRow() + j;
0N/A if (row < TableView.this.getViewCount()) {
0N/A int span = TableView.this.getSpan(Y_AXIS, getRow()+j);
0N/A spans[cell] += span;
0N/A }
0N/A }
0N/A }
0N/A if (colSpan > 1) {
0N/A col += colSpan - 1;
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Determines the resizability of the view along the
0N/A * given axis. A value of 0 or less is not resizable.
0N/A *
0N/A * @param axis may be either View.X_AXIS or View.Y_AXIS
0N/A * @return the resize weight
0N/A * @exception IllegalArgumentException for an invalid axis
0N/A */
0N/A public int getResizeWeight(int axis) {
0N/A return 1;
0N/A }
0N/A
0N/A /**
0N/A * Fetches the child view that represents the given position in
0N/A * the model. This is implemented to walk through the children
0N/A * looking for a range that contains the given position. In this
0N/A * view the children do not necessarily have a one to one mapping
0N/A * with the child elements.
0N/A *
0N/A * @param pos the search position >= 0
0N/A * @param a the allocation to the table on entry, and the
0N/A * allocation of the view containing the position on exit
0N/A * @return the view representing the given position, or
0N/A * <code>null</code> if there isn't one
0N/A */
0N/A protected View getViewAtPosition(int pos, Rectangle a) {
0N/A int n = getViewCount();
0N/A for (int i = 0; i < n; i++) {
0N/A View v = getView(i);
0N/A int p0 = v.getStartOffset();
0N/A int p1 = v.getEndOffset();
0N/A if ((pos >= p0) && (pos < p1)) {
0N/A // it's in this view.
0N/A if (a != null) {
0N/A childAllocation(i, a);
0N/A }
0N/A return v;
0N/A }
0N/A }
0N/A if (pos == getEndOffset()) {
0N/A View v = getView(n - 1);
0N/A if (a != null) {
0N/A this.childAllocation(n - 1, a);
0N/A }
0N/A return v;
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /** columns filled by multi-column or multi-row cells */
0N/A BitSet fillColumns;
0N/A /** the row within the overall grid */
0N/A int row;
0N/A }
0N/A
0N/A /**
0N/A * @deprecated A table cell can now be any View implementation.
0N/A */
0N/A @Deprecated
0N/A public class TableCell extends BoxView implements GridCell {
0N/A
0N/A /**
0N/A * Constructs a TableCell for the given element.
0N/A *
0N/A * @param elem the element that this view is responsible for
0N/A * @since 1.4
0N/A */
0N/A public TableCell(Element elem) {
0N/A super(elem, View.Y_AXIS);
0N/A }
0N/A
0N/A // --- GridCell methods -------------------------------------
0N/A
0N/A /**
0N/A * Gets the number of columns this cell spans (e.g. the
0N/A * grid width).
0N/A *
0N/A * @return the number of columns
0N/A */
0N/A public int getColumnCount() {
0N/A return 1;
0N/A }
0N/A
0N/A /**
0N/A * Gets the number of rows this cell spans (that is, the
0N/A * grid height).
0N/A *
0N/A * @return the number of rows
0N/A */
0N/A public int getRowCount() {
0N/A return 1;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Sets the grid location.
0N/A *
0N/A * @param row the row >= 0
0N/A * @param col the column >= 0
0N/A */
0N/A public void setGridLocation(int row, int col) {
0N/A this.row = row;
0N/A this.col = col;
0N/A }
0N/A
0N/A /**
0N/A * Gets the row of the grid location
0N/A */
0N/A public int getGridRow() {
0N/A return row;
0N/A }
0N/A
0N/A /**
0N/A * Gets the column of the grid location
0N/A */
0N/A public int getGridColumn() {
0N/A return col;
0N/A }
0N/A
0N/A int row;
0N/A int col;
0N/A }
0N/A
0N/A /**
0N/A * <em>
0N/A * THIS IS NO LONGER USED, AND WILL BE REMOVED IN THE
0N/A * NEXT RELEASE. THE JCK SIGNATURE TEST THINKS THIS INTERFACE
0N/A * SHOULD EXIST
0N/A * </em>
0N/A */
0N/A interface GridCell {
0N/A
0N/A /**
0N/A * Sets the grid location.
0N/A *
0N/A * @param row the row >= 0
0N/A * @param col the column >= 0
0N/A */
0N/A public void setGridLocation(int row, int col);
0N/A
0N/A /**
0N/A * Gets the row of the grid location
0N/A */
0N/A public int getGridRow();
0N/A
0N/A /**
0N/A * Gets the column of the grid location
0N/A */
0N/A public int getGridColumn();
0N/A
0N/A /**
0N/A * Gets the number of columns this cell spans (e.g. the
0N/A * grid width).
0N/A *
0N/A * @return the number of columns
0N/A */
0N/A public int getColumnCount();
0N/A
0N/A /**
0N/A * Gets the number of rows this cell spans (that is, the
0N/A * grid height).
0N/A *
0N/A * @return the number of rows
0N/A */
0N/A public int getRowCount();
0N/A
0N/A }
0N/A
0N/A}