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