ColumnList.java revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* ident "%Z%%M% %I% %E% SMI"
*
* Copyright (c) 2000 by Sun Microsystems, Inc.
* All rights reserved.
*/
/**
*
* Copyright 1995-1996 Active Software Inc.
*
* @version @(#)ColumnList.java 1.62 97/05/02
* @author Tilman Sporkert
*/
/* BEGIN JSTYLED */
/**
* with scrollbars etc.
*
* A ColumnList has the following features/attributes:
* headers: An array of Strings. The size of
* this array determines the number
* of columns in the list. There will be one additional, hidden
* column that can be used for any Object.
* The length of the header string defines the initial width of the
* column. To make it wider, add spaces to the end of the string.
* If a header field is of the form "name=header", then only the
* "header" part will actually be used for the visible header.
* The "name" part is available through
* getNames() or getNameColumn()
* selectable: If true, records can be selected
* with the mouse. A LIST_EVENT gets posted.
* editable: If true, records can be edited with the mouse.
* Columns
* containing a checkbox are currently the only editable columns.
* highlight_items: If true, new entries will be
* highlighted in orange, slowly
* fading out.
* showHeaders: If set to false, the headers will not be shown.
*
*
* @author Tilman Sporkert
*/
/* END JSTYLED */
public class ColumnList extends ScrollPanel {
// Entry attributes
static final int HIGHLIGHT = 1;
int validSortColumns = 0;
// how many of them were actually recognized?
boolean[] sortAscend = null;
// event type for getting a chance to cancel the selection of a row
public final static int CONFIRM_SELECT = 4863;
// event type for applying an edit
public final static int APPLY_EDIT = 4864;
/**
* create a new ColumnList with no information
* about the columns
*/
public ColumnList() {
}
/**
* create a new ColumnList, with the given columns, and
* given visible
* rows.
*
*/
boolean selectable,
boolean highlight_items) {
this();
// setFormat(format);
}
/**
* Sets the column to be editable or not.
* If a column is editable, then
* all the strings that are in the column will
* be able to be modified.
*
*/
}
/**
* Sets all the columns to be editable or not. If a column is
* editable, then all the strings that are in the column will
* be able to be modified.
*
*/
public void setTextEditable(boolean value) {
}
/**
* Gets the current value of the textEditable attribute.
*
*/
public boolean getTextEditable(int column) {
}
/**
* Call this when a CONFIRM_SELECT event is received if you
* don't want the selection to be changed.
*/
public void cancelSelect() {
}
/**
* Call this to edit the given column of the
* currently selected row.
*
*/
}
/**
* Call this to force edits to be applied.
*/
public boolean applyChanges() {
return canvas.applyChanges();
}
/**
* Call this when a APPLY_EDIT event is received if you
* don't want the change to be applied.
*/
public void cancelApply() {
}
/**
* Call this when you want to cancel any edit that might
* currently be going on.
*/
public void cancelEdit() {
canvas.cancelEdit();
}
public int getEditRow() {
return canvas.getEditRow();
}
public int getEditColumn() {
return canvas.getEditColumn();
}
/**
* Sets the foreground color.
*
*/
}
/**
* Gets the current foreground color.
*
* @return Color
*/
public Color getCanvasForeground() {
return canvas.getForeground();
}
/**
* Sets the background color.
*
*/
}
/**
* Gets the current background color.
*
* @return Color
*/
public Color getCanvasBackground() {
return canvas.getBackground();
}
/**
* Sets the font attribute.
*
*/
}
/**
* Gets the font attribute.
*
*/
public Font getCanvasFont() {
}
public Dimension preferredSize() {
Dimension d = super.preferredSize();
// Do NOT account for hbar height as
// we want preferredSize height to accomodate
// just the header and visibleRow data exactly
return d;
}
/**
* Set the desired number of rows to be displayed.
* This affects the
* minimumSize() and preferredSize() of the widget.
* The actual rows
* displayed by the widget depend on how the
* LayoutManager interprets
* those values.
*
*/
public void setVisibleRows(int rows) {
}
// for backward compatibility
public void setDisplayRows(int rows) {
}
/**
* Set the desired number of "visible" chars, i.e.
* the total width of
* the column list. Defaults to "all".
*
*/
public void setVisibleChars(int chars) {
}
/**
* Sets the header strings.
*
*/
boolean hasKeys = false;
keys[h] = false;
if (offset > 0) {
keys[h] = true;
hasKeys = true;
}
offset + 1);
} else {
realHeaders[h] = headers[h];
}
}
if (!hasKeys)
} else {
}
}
/* BEGIN JSTYLED */
/**
* Set the sort order. Input is an array of
column names, optionally
* preceded with a '+' for Ascend (default)
or '-' for descend.
* This call should be made after setHeaders(), and
before adding items.
* Items should only be added with addItem(Object[] entry).
*
* If any of the names supplied do not match a
column name, then
* they will be silently ignored.
*
*/
/*
* Fix for Sun Bug # 4069218: incorrect sortNames
* causes array out of bounds
* error on addItem(...).
* -> If name is not recognized (i.e. getNameColumn() returns -1),
* Then that entry is *silently* ignored.
* -> Later we may want to throw some kind of exception.
*
*/
/* END JSTYLED */
int acceptedIndex = 0;
int nameColumn;
boolean ascend;
ascend = true;
ascend = false;
} else {
ascend = true;
}
if (nameColumn != -1) {
// only process if recognized.
acceptedIndex ++;
}
}
// Need to remember the actual number of accepted sort columns.
} else {
sortColumns = null;
validSortColumns = 0;
sortAscend = null;
}
}
/**
* set column formating. There is one letter for each column, with
* l = left, c = center, r = right
*
*/
if (f == /* NOI18N */ 'c')
else if (f == /* NOI18N */ 'r')
else
}
}
/**
* Sets the selectable attribute.
*
*/
public void setSelectable(boolean selectable) {
}
/**
* Sets the editable attribute.
*
*/
public void setEditable(boolean editable) {
}
/**
* Sets the hightLightItems attribute.
*
*/
public void setHighlightItems(boolean highlight_items) {
}
}
public boolean getHighlighted(int row) {
}
/**
* Sets the showHeaders attribute.
*
*/
public void setShowHeaders(boolean showHeaders) {
}
/**
* Sets the showVerticalLines attribute.
*
*/
public void setShowVerticalLines(boolean showVerticalLines) {
}
/**
* Sets the showHorizontalLines attribute.
*
*/
public void setShowHorizontalLines(boolean showHorizontalLines) {
}
/**
* Sets the autoWidth attribute.
*
*/
public void setAutoWidth(boolean autoWidth) {
}
/**
* Adds an item to the list. If the list has no
* keys defined, the item
* will be appended at the end of the list.
* Otherwise, the existing entries
* will be searched for an entry with the same key values.
* If there is
* such an entry, it will get replaced. Otherwise, the
* record goes at the
* end.
*
* @param values the record
* @param updateView whether to update the view
* @return index of new record
*/
boolean setSelectedRow = false;
for (int r = 0; r < entries(); r++)
// found a matching entry
// when sorting, take out the old one, and put the new
// one in at its proper place
if (getSelectedRow() == r)
setSelectedRow = true;
break;
}
// no sorting -> just replace
if (updateView)
updateView();
return r;
}
}
for (int r = 0; r < entries(); r++) {
for (int c = 0; c < validSortColumns; c++) {
int colIndex = sortColumns[c];
if (!sortAscend[c])
if (comp < 0) {
if (setSelectedRow)
selectRow(r);
if (updateView)
updateView();
return r;
} else if (comp > 0)
break;
}
}
}
if (setSelectedRow)
if (updateView)
updateView();
return (entries() - 1);
}
/**
* Adds an item to the list.
*
*/
}
/**
* Compares a row to the specified values.
*
*/
for (int c = 0; c < getColumns(); c++) {
if (keys[c]) {
return false;
}
}
return true;
}
/**
* Adds an item at a specific location. An existing record will be
* replaced. You should not use this method if you have sorting
* enabled!
*
*/
updateView();
}
/**
* Insert a new item at a specific location.
* Existing records will be
* moved back. You should not use this method if you have sorting
* enabled!
*
*/
updateView();
}
/**
* Deletes the items.
*/
public void delItems() {
delItems(true);
}
public void delItems(boolean updateView) {
if (updateView)
updateView();
}
/**
* Delete the items.
*
*/
updateView();
}
/**
* Delete an item.
*
*/
for (int r = 0; r < entries(); r++)
updateView();
return true;
}
}
return false;
}
/**
* Select a row.
*
*/
}
// for backwards compatibility
}
/**
* Gets the selectedRow attribute.
*/
public int getSelectedRow() {
return canvas.selectedRow;
}
public int getHighlightedRow() {
return canvas.getSelectedRow();
}
/**
* Gets the bounds.
*/
public Rectangle getListBounds() {
}
/**
* Gets the entries.
*/
public int entries() {
}
/**
* Gets the columns.
*/
public int getColumns() {
}
/**
* Gets the names of all the columns.
*/
return names;
}
/**
* Gets the column with the specified name.
*
*/
return n;
return -1;
}
/**
* Gets an item in the specified row and column.
*
*/
}
/**
* Gets the "Object" for a row.
*
*/
}
/**
* Warning: If you are changing the value of a
* key column, another record
* that matches your keys will get deleted.
* If you are changing
* the value of a sort column, your record
* might get moved to a
* new position.
* The function returns the new row index.
*
*/
return -1;
// skip the checks if value didn't change (but not when value isn't
// representable as a string, for example hwhen an icon has no label)
return row;
boolean setSelectedRow = false;
if (getSelectedRow() == row)
setSelectedRow = true;
// did we update a key column?
for (int r = 0; r < entries(); r++)
// found a matching entry at a different location
if (r < row)
row--; // we just moved down one entry
break;
}
}
if (isSortColumn(column)) {
for (int r = 0; r < entries(); r++) {
int colIndex = sortColumns[c];
if (!sortAscend[c])
if (comp < 0) {
row = r;
}
if (setSelectedRow)
return row;
} else if (comp > 0)
break;
}
}
}
if (setSelectedRow)
return row;
}
private boolean isSortColumn(int column) {
if (sortColumns == null)
return false;
for (int c = 0; c < validSortColumns; c++)
if (sortColumns[c] == column)
return true;
return false;
}
/**
* Sets the object for a row
*
*/
}
/**
* Swaps the entries in two rows
*
*/
}
/**
* Gets the Y coordinate of the upper edge of a
* row in the column list.
* Returns -1 if the row is not visible. Returns -2 is the list is
* not layed out yet.
*
* @param row index of desired row
* @return Y coordinage of row
*/
}
/**
* Gets the row height of entries in the list
*
* @return height of a row
*/
public int getRowHeight() {
}
/**
* Calls repaint() on the ColumnListCanvas. Needed
* if an Object in the
* column list has been changed directly(without going through
* putItem).
*/
public void needsRepaint() {
}
/**
* Redraws everything, and re-evaluates the need for scroll bars
*/
public void updateView() {
updateWindow();
}
void setHBarValue(int value) {
}
void setVBarValue(int value) {
}
}
}