A
TableManager
is a custom Yoix container that is used to manage
TableColumns
and other components as a single table.
Tablemanagers do not create windows, which means you only see them when
they are in a visible
Frame,
Dialog,
or
Window.
Yoix programs normally interact with a
TableManager
using event handlers and by reading or writing the following fields:
| background |
The
Color
that is used to paint the background of the tablemanager.
It is also the default background color assigned to components in the
layout
array that do not pick their own.
Reading returns a snapshot of the current color.
Writing immediately sets the tablemanager's background,
and the background of components contained in the tablemanager
that do not pick their own, to the new color.
| | cellsize |
A
Dimension
that measures distances in units of 72 dots per inch
with a
height
that is the maximum distance between adjacent lines of text in all visible
tablecolumns, and a
width
that is an average distance between adjacent characters in all visible
tablecolumns.
Reading returns a snapshot of the current cellsize.
Writing is not allowed and will result in an
invalidaccess
error.
| | clickradius |
A
double
that determines how far the cursor can move, in units of 72 dots per inch,
after a mouse button is pressed in an active tablecolumn without canceling
the selection process.
Reading returns the current clickradius.
Writing immediately sets the clickradius to the new value.
| | components |
A
Dictionary
maintained by the interpreter's layout machinery that maps
tag
fields to actual components;
every component contained in the tablemanager has an entry in the dictionary.
Add the tablemanager to another container (e.g., a frame or panel)
and entries in the
components
dictionary are copied into the new container's
components
dictionary.
In addition, the
root
field in each component is automatically set to the top-level container,
so the
components
dictionary is easy to find, and that means individual components
can find each other by name using the
root.components
dictionary.
| | cursor |
An
Object
that should be an
int,
Image,
or
String
that selects the cursor shown when the pointer is over the tablemanager.
It is also the default cursor assigned to components in the tablemanager's
layout
array that do not pick their own.
A
cursor
that is an
int
should be one of the cursors defined in the
yoix.awt.Cursor
dictionary.
A
cursor
that is an
Image
can describe the cursor using its
size
and
hotspot
fields and often draws it using its
paint
function.
A
cursor
that is a
String
should be the name of a cursor that is already defined in
yoix.awt.Cursor
or the name a local a file or URL that contains a GIF or JPEG image
that will be used as the cursor.
Reading returns the current cursor.
Writing immediately sets the tablemanager's cursor,
and the cursor of components contained in the tablemanager
that do not pick their own, to the new value.
A tablemanager that does not set its own cursor uses
DEFAULT_CURSOR.
| | enabled |
An
int
that is
1
when the tablemanager,
or any of the components contained in the tablemanager,
can respond to user input, and
0
otherwise.
Reading returns the current state.
Writing immediately sets the tablemanager's state to the new value.
This field has not been completely implemented.
| | extent |
A
Dimension
that measures distances in units of 72 dots per inch
with a
height
that is the maximum vertical size of all visible tablecolumns,
and a
width
that is the total width of the table,
which may not match what is current visible on the screen.
Reading returns a snapshot of the current extent.
Writing is not allowed and will result in an
invalidaccess
error.
| | focusable |
An
int
that is non-zero (the default)
when the tablemanager can accept the keyboard focus and zero
when it can not.
Reading returns the tablemanager's current focusable state.
Writing immediately changes the tablemanager's focusable state to the new value,
which means the focus is automatically transferred if the new value is zero
and the tablemanager is the current focus owner.
| | focusowner |
A read-only
int
that is non-zero when the tablemanager has the focus.
| | font |
The
Font,
or font name if it is a
String,
that is used as the default font assigned to components in the
layout
array that do not pick their own.
Reading returns a snapshot of the current font.
Writing immediately changes the tablemanager's font,
and the font used by all components contained in the tablemanager
that do not pick their own, to the new font.
| | foreground |
The
Color
that is used as the default foreground color assigned to components in the
layout
array that do not pick their own.
Reading returns a snapshot of the current color.
Writing immediately sets the tablemanager's foreground,
and the foreground of components contained in the tablemanager
that do not pick their own, to the new color.
| | fronttoback |
An
int
that is
1
when components that appear earlier in the
layout
array are placed on top of components that appear later, and
0
when the stacking order is reversed.
In practice,
GridBagLayout
and
CardLayout
are only layout managers where stacking components makes sense.
Reading returns the current stacking order.
Writing immediately tries to change the stacking order.
| | highlighted |
A read/write field that accepts an
int
value when being written to and returns a
String
value when being read from.
The
int
value indicates the row across all columns
within the table that should be highlighted.
The
String
value is the text from each column that is currently highlighted.
An individual column that is not highlighted is represented by an
empty string.
If no column contains a highlighted row, then
NULL
is returned.
Adjacent columns are always separated by the
outputfilter
string.
| | html(...) |
A
Builtin
that returns a
String
that is an HTML representation of the rows and columns of the managed table.
The representation is neither a complete HTML page nor a complete HTML table,
but only an HTML specification of the row and column data.
The built-in accepts from zero to four arguments, inclusive.
With no arguments, all the rows and columns are included.
Row and column selection can be accomplished in one of two ways:
| 1. |
One or two
int
arguments can be provided which specify how many rows (one argument) or
rows and columns (two arguments) should be included.
| | 2. |
Alternatively, one or two
Array
values containing
int
values can be supplied to specify specific rows (one argument) or specific
rows and columns (two arguments) to be included.
|
It is possible to mix these, namely row selection may be given by a single
int
while column selection is made through an
Array.
Similarly, row and column attribute information can be included in one of
two ways:
| 1. |
One or two
String
arguments can be provided which specify attributes for all rows (one argument) or
for all rows and all columns (two arguments).
| | 2. |
Alternatively, one or two
Array
values containing
String
values can be supplied to specify specific row attributes (one argument)
or specific row and column attributes (two arguments).
|
As before, a
String
can be used for one argument and an
Array
for the other.
Alignment information for the columns is automatically included based on the
alignment information of each
TableColumn.
| | index |
An
Array
of
int
values that lists each currently selected row from all tablecolumns.
Negative values indicate no selection has been made in that tablecolumn.
When writing, only a single
int
value (rather than an
Array)
is allowed and it indicates the row to mark selected in all tablecolumns.
| | inputfilter |
An
Object,
that must be a
String
or
Array,
that controls how strings stored in the
text
field are separated into the columns and rows that are loaded in the table.
The default inputfilter assumes each row ends at the next newline
and that columns are separated by the
|
character.
Reading returns the current inputfilter.
Writing changes the filter that is used the next time the table is loaded.
When inputfilter is a string, each line in
text
corresponds to a row in the table and any character in the inputfilter
string qualifies as a column separator;
leading and trailing column separators can be omitted.
An inputfilter that is an array must be arranged in triples that consist
of a prefix that is a string,
a column number that is an integer,
and a simple character translator that is a string or
NULL.
Each line in
text
is compared to the prefix in each triple.
When there is a match the prefix is stripped from the line,
characters in the line at even positions in the character translator string
(i.e., the third element in each triple) are translated into characters
at the corresponding odd positions,
and the resulting string is stored in the column selected by the second
element of the triple.
| | layout |
An
Array
of objects, often just components, that the
layoutmanager
arranges in the tablemanager.
Reading returns the current array.
Writing immediately clears tablemanager and then arranges the new
set of components in the tablemanager.
| | layoutmanager |
A
LayoutManager
that takes components from the
layout
array, arranges them in the tablemanager, updates the tablemanager's
components
dictionary, and makes sure the
root
field in each component is set to the tablemanager.
Reading returns the current layout manager.
Writing, when
validate
is non-zero, immediately clears the tablemanager and then rearranges
the components in the
layout
array using the new layout manager.
Yoix tablemanagers use a
FlowLayout
as their default layout manager.
| | location |
A
Point
that determines the location of the tablemanager
in a coordinate system that has its origin at the upper left corner
of the container closest to the tablemanager (in the component hierarchy)
that actually contains it, positive x to the right, positive y down,
and a resolution of 72 dots per inch.
Reading returns a snapshot of the current location.
Writing is allowed, but layout managers usually get the final say, so setting
location
should be viewed as a request that may not be honored.
| | nextcard |
An
Object
that
CardLayout
layout managers use to pick the next component that is displayed in the
tablemanager.
See the description of
CardLayout
for more details.
| | origin |
A
Point
that is primarily used to scroll the table vertically or horizontally.
Changing
origin.y
scrolls each tablecolumn up or down by exactly the same amount.
Changing
origin.x
shifts the entire table left or right.
Reading returns a snapshot of the current origin.
Writing immediately sets the origin to the new value.
| | outputfilter |
A
String
that is used to separate adjacent columns when the
selected
field is read.
Reading returns the current separator string.
Writing changes the separator that is used the next time
selected
is read.
| | popup |
A
PopupMenu
that is associated with the tablemanager.
Reading returns the current popup menu.
Writing immediately shows the popup menu at the point in the tablemanager's coordinate
system specified by the popup menu's
location
field, assuming of course that the tablemanager is showing on the screen.
Storing
TRUE
in the popup menu's
visible
field, which was added in release 1.2.0, is an easy way to show the
popup menu that currently belongs to the tablemanager.
| | requestfocus |
An
int
that can be used to request or transfer the keyboard focus.
Storing a non-zero value in
requestfocus
tries to get the focus.
Storing
0
tries to transfer the focus.
Reading
requestfocus
does not currently return any useful information.
| | root |
An
Object
that is automatically updated by the interpreter's layout machinery
so it is always the top-level object that contains the tablemanager.
For example, put a tablemanager in a panel and
root
will be set to the top-level panel;
add the top-level panel to a frame and the tablemanager's
root
field will be set to that frame.
A tablemanager's event handlers can use
root
when they need to interact with the other components in the container.
| | selected |
A
String
that is the concatenation of the currently selected row from all tablecolumns,
or
NULL
if there is no current selection.
Adjacent columns are always separated by the
outputfilter
string.
Writing is not allowed and will result in an
invalidaccess
error.
| | showing |
A read-only
int
that is non-zero when the tablemanager is showing on the screen.
| | size |
A
Dimension
that determines the size of the tablemanager
in units of 72 dots per inch.
Reading returns a snapshot of the current size.
Writing is allowed, but layout managers usually get the final say, so setting
size
should be viewed as a request that may not be honored.
| | syncViewport(Rectangle viewport, Dimension extent, Dimension cellsize) |
A
Function
that is called whenever it is not
NULL
and a change, like a new font or a resize,
modifies the appearance of the text that is displayed in the tablecolumns
managed by the tablemanager.
The function should use the
viewport,
extent,
and
cellsize
arguments to do whatever is required to synchronize other components,
like scrollbars, to the table.
| | tag |
A
String
used to identify the tablemanager that is either supplied when
the tablemanager is declared, or automatically generated otherwise.
Add a tablemanager to a container, like a
Frame
or
Panel,
and the interpreter's layout machinery updates the
root
field so it points at the top-level container and then adds the tablemanager, as
tag,
to the
root.components
dictionary.
| | text |
A
String
of characters that represents the text that is displayed in the table.
The rows and columns are extracted from
text
and displayed in the tablecolumns using the value stored in the
inputfilter
field,
which by default assumes each row ends at the next newline and that columns
are separated by the
|
character.
Reading returns the text that was loaded in the table.
Writing loads the table with the new text, which is immediately displayed
in the tablecolumns managed by the tablemanager.
| | validate |
An
int
that is
1
when changing the
layoutmanager
field takes effect immediately, and
0
when the change is delayed, often until after the
layout,
size,
or
validate
fields change.
Storing a
1
in
validate
always runs Java's layout manager, even when nothing has changed.
| | viewport |
A
Rectangle
with a
height
that is the minimum vertical size of all visible tablecolumns,
a
width
that is the horizontal size of the container that is displaying the table,
and with
x
and
y
fields that match the corresponding fields in
origin.
Reading returns a snapshot of the current viewport.
Writing is not allowed and will result in an
invalidaccess
error.
| | visible |
An
int
that is
1
when the tablemanager is visible, and
0
otherwise.
Reading returns the current visibility.
Writing immediately sets the tablemanager's visibility to the new state.
|
Several permanent fields have not been documented and should not be
used in Yoix applications.
Event handlers are functions that must be added to a tablemanager when it is
declared.
The handlers that work with tablemanagers are listed below;
the names should be familiar if you have done some Java programming.
The
actionPerformed
and
itemStateChanged
event handlers are only for menus.
| |
| Event Handlers: |
actionPerformed,
componentHidden,
componentMoved,
componentResized,
componentShown,
dragDropEnd,
dragEnter,
dragExit,
dragGestureRecognized,
dragMouseMoved,
dragOver,
drop,
dropActionChanged,
focusGained,
focusLost,
invocationRun,
itemStateChanged,
keyPressed,
keyReleased,
keyTyped,
mouseClicked,
mouseDragged,
mouseEntered,
mouseExited,
mouseMoved,
mousePressed,
mouseReleased,
mouseWheelMoved
| | |
| Example: |
On a UNIX-like system the program,
import yoix.*.*;
String text = "";
String line;
File fp;
Header(String name, int alignment) {
return(new Label {
String text = name;
Color background = Color.black;
Color foreground = Color.white;
int alignment = alignment;
});
}
HeaderConstraint(int number) {
return(new GridBagConstraints {
int gridx = number;
int gridy = 1;
int fill = HORIZONTAL;
Insets insets = {double left = 1;};
});
}
Column(int rows, int columns, int alignment, Function action) {
return(new TableColumn {
int rows = rows;
int columns = columns;
int alignment = alignment;
Color background = Color.white;
Color foreground = (action == NULL) ? Color.black : Color.blue;
Color visitcolor = (action == NULL) ? NULL : Color.magenta;
Function actionPerformed = action;
});
}
ColumnConstraint(int number) {
return(new GridBagConstraints {
int gridx = number;
int gridy = 2;
int fill = BOTH;
Insets insets = {double left = 1, top = 1;};
});
}
actionPerformed(ActionEvent e) {
printf("you just picked %s\n", e.command);
}
syncViewport(viewport, extent, cell) {
Pointer vbar;
if (root != NULL) {
vbar = root.components.vbar;
vbar.cellheight = cell.height;
vbar.minimum = 0;
vbar.maximum =
(extent.height + viewport.height)/cell.height - 1;
vbar.visibleamount = viewport.height/cell.height;
vbar.unitincrement = 1;
vbar.blockincrement = viewport.height/cell.height - 1;
}
}
Frame f = {
Dimension size = NULL;
Array layout = {
new TableManager {
String tag = "passwd";
String inputfilter = ":";
Color background = Color.red;
Function syncViewport = global.syncViewport;
GridBagLayout layoutmanager;
int nextcolumn = 1;
Array layout = {
Header("Name", CENTER),
HeaderConstraint(nextcolumn),
Column(20, 10, LEFT, global.actionPerformed),
ColumnConstraint(nextcolumn++),
Header("Password", CENTER),
HeaderConstraint(nextcolumn),
Column(20, 15, LEFT, NULL),
ColumnConstraint(nextcolumn++),
Header("UID", RIGHT),
HeaderConstraint(nextcolumn),
Column(20, 6, RIGHT, NULL),
ColumnConstraint(nextcolumn++),
Header("GID", RIGHT),
HeaderConstraint(nextcolumn),
Column(20, 6, RIGHT, NULL),
ColumnConstraint(nextcolumn++),
Header("GECOS", LEFT),
HeaderConstraint(nextcolumn),
Column(20, 40, LEFT, NULL),
ColumnConstraint(nextcolumn++),
};
}, WEST,
new Scrollbar {
String tag = "vbar";
double cellheight;
adjustmentValueChanged(e) {
Point origin = root.components.passwd.origin;
origin.y = value*cellheight;
root.components.passwd.origin = origin;
}
}, EAST,
};
};
if ((fp = fopen("/etc/passwd", "r")) != NULL) {
while ((line = fp.nextline) != NULL) {
if (line[0] != '#')
text += line + "\n";
}
f.components.passwd.text = text;
fclose(fp);
}
f.visible = TRUE;
will display part of your password file in a scrollable table
that recognizes when you click on a user's login name.
Individual rows are automatically separated into columns because
fields in a UNIX password file are colon separated, which is the
only character that we put in the tablemanager's
inputfilter
string.
| | |
| See Also: |
BorderLayout,
Button,
Canvas,
CardLayout,
Checkbox,
Choice,
CustomLayout,
Dialog,
FileDialog,
FlowLayout
Frame,
GridBagLayout,
GridLayout
Label,
List,
Menu,
MenuBar,
PopupMenu,
postEvent,
ScrollPane,
Scrollbar,
TableColumn,
TextArea,
TextCanvas,
TextField,
TextTerm,
Window
|
|