AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YChart | YDAT | YWAIT | Byzgraf | FAQs
JTextCanvas typedict
 
A JTextCanvas is the Swing version of the custom Yoix component that is sometimes used to display, scroll, and otherwise manage text messages. Yoix programs normally interact with a JTextCanvas using event handlers and by reading or writing the following fields:
alignment An int that controls the positioning of the text in the textcanvas. The value should be LEFT, CENTER, or RIGHT, which are all defined in yoix.swing. Reading returns the current alignment. Writing immediately repaints the text using the new alignment.
autotrim An int that is 1 when white space is automatically trimmed from both ends of every string read from or written to the text field, and 0 otherwise.
background The Color that is used to paint the background of the textcanvas. Reading returns a snapshot of the current color. Writing immediately changes the background to the new color. Storing NULL in background is special and means use the background of the nearest component that contains the textcanvas and was assigned a background color other than NULL; if no component qualifies the textcanvas uses VM.screen.background.
border An Object that should be a Border, Insets, Number, or String that describes the border that is drawn around this textcanvas. A NULL value, which is the default, means no border. A border that is an Insets or Number is handled differently than most other Swing components, because it is used, in combination with the insets field, to set the extent of the highlighted border, in units of 72 dots per inch, that is drawn around the textcanvas. A border that is a String is a quick way to surround this textcanvas with a border that uses the String as its title. Reading returns a snapshot of the current border. Writing immediately sets the textcanvas's border to the new value.
bordercolor The base Color that is used to pick the shadow colors for the highlighted border. The textcanvas's background is used when bordercolor is NULL. Reading returns a snapshot of the current color. Writing immediately changes the bordercolor to the new color.
cellsize A Dimension that measures distances in units of 72 dots per inch with a height field that is the distance between adjacent lines of text, and a width that is an estimate of the distance between adjacent characters. Reading returns a snapshot of the current cellsize. Writing is not allowed and will result in an invalidaccess error.
columns An int that specifies the number of columns in a textcanvas. Layout managers usually get the final say, so setting columns should be viewed as a request that will not always be honored. Reading returns the number of columns currently used by the textcanvas. Writing tries to change the number of columns used by the textcanvas.
cursor An Object that should be an int, Image, or String that selects the cursor shown when the pointer is over the textcanvas. 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 changes the textcanvas's cursor to the new value. Storing STANDARD_CURSOR (the default) or NULL in cursor is special and means use the cursor assigned to the nearest component that contains the textcanvas and was assigned a cursor other than STANDARD_CURSOR; if no component qualifies the textcanvas uses DEFAULT_CURSOR.

doublebuffered An int that is 1 when the textcanvas uses double-buffering to draw itself, 0 when it does not, and starts with a default value that is selected by Java for the textcanvas. Reading returns the current double-buffering behavior. Writing immediately sets the textcanvas's double-buffering behavior to the new value. Note that double-buffering may be required when transparent components are used.
dragenabled An int that should be set to 1 when this textcanvas wants to use the automatic drag handling that Swing provides for some components, and 0 (the default) when it does not. Components that do not provide automatic drag handling always return 0 when their dragenabled field is read, so storing 1 in dragenabled should only be viewed as a request for a service that may not be available. Swing components can always take complete control of their drag and drop handling using their transferhandler field or special drag and drop event handlers.
enabled An Object that is 1 when the textcanvas can respond to user input, 0 when it can not respond, and NULL (the default) when the textcanvas inherits the value from the nearest lightweight container, like a JPanel, that contains the textcanvas and has its enabled field set to something other than NULL. The top-level application window that contains the textcanvas always gets the final say, so disabling that window always disables the textcanvas. Reading returns the current state. Writing immediately sets the textcanvas's state to the new value.
extent A Dimension that measures distances in units of 72 dots per inch with a height field that is the vertical size of all the lines of text, and a width that is the horizontal size of the longest line of text. 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 textcanvas can accept the keyboard focus and zero when it can not. Reading returns the textcanvas's current focusable state. Writing immediately changes the textcanvas's focusable state to the new value, which means the focus is automatically transferred if the new value is zero and the textcanvas is the current focus owner.
focusowner A read-only int that is non-zero when the textcanvas has the focus.
font The Font, or font name if it is a String, used to paint the text displayed by the textcanvas. Reading returns a snapshot of the current font. Writing immediately repaints the text in the new font.
foreground The Color used to paint the text displayed by the textcanvas. Reading returns a snapshot of the current color. Writing immediately repaints the text in the new color. Storing NULL in foreground is special and means use the foreground of the nearest component that contains the textcanvas and was assigned a foreground color other than NULL; if no component qualifies the textcanvas uses VM.screen.foreground.
insets An Object, usually an Insets or Number, that sets margins around the textcanvas that determine how close text comes to the edges. In addition, insets also determines the maximum size of the highlighted border in any direction, independent of the values stored in border. An insets that is a number is an easy way to describe a uniform margin. Reading returns a snapshot of the current insets. Writing immediately sets the insets to the new value.
ipad An Insets that measures distances in units of 72 dots per inch that adjusts the vertical margins at the top and bottom of each line displayed by the textcanvas according to the values stored in ipad.top and ipad.bottom. Adjustments corresponding to ipad.left and ipad.right have not been implemented yet. Reading returns a snapshot of the current padding. Writing immediately repaints the text using the new padding.
layer An int, often a small number between 0 and 99, that identifies the depth of this textcanvas when it is added to a JLayeredPane or JDesktopPane. Components assigned to lower numbered layers are drawn before the components in higher numbered layers. Writing immediately changes the textcanvas's layer, which usually means the JLayeredPane or JDesktopPane that contains the textcanvas will be repainted.
location A Point that determines the location of the textcanvas in a coordinate system that has its origin at the upper left corner of the container closest to the textcanvas (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.
nextfocus An Object that identifies the component that receives the focus after this textcanvas when the focus traverses from one component to the next (usually by means of the keyboard TAB character). When nextfocus is a String it is assumed to be the tag associated with the target component, which must belong to the same top-level container (e.g., the same JFrame) as this textcanvas. A NULL value means the component that gets the focus after this textcanvas will be selected by Java's default focus traversal policy. Reading returns the value last stored or NULL if the value was a String that did not reference a component. Writing immediately changes the component that gets the focus after this textcanvas.
opaque An Object that is 1 when the textcanvas is opaque, 0 when it is transparent, and NULL (the default) when the textcanvas inherits the value from the nearest component that contains the textcanvas and has its opaque field set to something other than NULL.
origin A Point that is the location of the upper left corner of the printable area (i.e., left corner plus insets) of the textcanvas in a coordinate system that has its origin at the upper left corner of the first line of text, positive x to the right, positive y down, and a resolution of 72 dots per inch. Reading returns a snapshot of the current origin. Writing immediately sets the origin to the new value.
popup A JPopupMenu that is associated with the textcanvas. Reading returns the current popup menu. Writing immediately shows the popup menu at the point in the textcanvas's coordinate system specified by the popup menu's location field, assuming of course that the textcanvas 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 textcanvas.
preferredsize A Dimension that is used by layout managers when they need to know the textcanvas's preferred size in units of 72 dots per inch. A NULL value means the textcanvas has no preference. A non-positive height or width is allowed and simply means the textcanvas has no preference for that dimension. Reading returns the current preferred size. Writing changes the preferred size and immediately notifies root.layoutmanager, which means the components contained in root may be repositioned and resized.
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.
requestfocusenabled An int that is 1 (the default) when actions, like mouse clicks or changes to the requestfocus field, can steal the keyboard focus and 0 when they can not. Note that this field does not affect acceptance of the keyboard focus during normal focus traversal. Reading returns the current state. Writing immediately sets the textcanvas's state to the new value.
root An Object that is automatically updated by the interpreter's layout machinery so it is always the top-level object that contains the textcanvas. For example, put a textcanvas in a panel and root will be set to that panel; add the panel to a frame and the textcanvas's root field will be set to that frame. A textcanvas's event handlers can use root when they need to interact with the other components in the container.
rows An int that specifies the number of rows in a textcanvas. Layout managers usually get the final say, so setting rows should be viewed as a request that will not always be honored. Reading returns the number of rows currently used by the textcanvas. Writing tries to change the number of rows used by the textcanvas.
showing A read-only int that is non-zero when the textcanvas is showing on the screen.
size A Dimension that determines the size of the textcanvas 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.
state An int that controls how the border of the textcanvas, if there is one, is drawn. When state is 0 the left and top parts of the border are drawn in a brighter color than the right and bottom parts, which makes it look like the interior of the textcanvas is raised. The border colors are reversed when state is 1, which makes it look like the interior of the textcanvas is depressed.
subtext([int offset[, int length]]) A built-in that returns the current text within the given range. When absent, offset defaults to the zero position and length defaults to the length from the offset to the end of the current text.
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 textcanvas. The function should use the viewport, extent, and cellsize arguments to do whatever is required to synchronize other components, like scrollbars, to the textcanvas.
tag A String used to identify the textcanvas that is either supplied when the textcanvas is declared, or automatically generated otherwise. Add a textcanvas to a container, like a JFrame or JPanel, and the interpreter's layout machinery updates the root field so it points at the top-level container and then adds the textcanvas, as tag, to the root.components dictionary.
text A String of characters that is displayed in the textcanvas. Reading returns the current text. Writing immediately paints the new text.
textmode An int that determines how lines displayed in the textcanvas are collected from the input text. The value should be LINEMODE or WORDMODE, which are defined in yoix.swing. Reading returns the current mode. Writing immediately sets the mode to the new value.

In LINEMODE tabs are expanded and all characters, up to the next newline character, are considered to be part of the next display line. In WORDMODE whitespace delimited tokens are collected and then grouped into display lines based on the value of textwrap. When it is 0 each token starts a new display line; otherwise space separated tokens are added to the next display line until there is no more room or a break is forced by the <p> or <br> tokens.

textwrap An int that is 1 when a line of text that is wider than the printable area of the textcanvas can be wrapped onto the next line, and 0 when it cannot. Reading returns the current textwrap. Writing immediately sets the textwrap to the new value.

The textmode field controls what happens when a line needs to be wrapped. In LINEMODE mode individual words can be split across lines; in WORDMODE they cannot.

tooltiptext A String of characters that is displayed in a tightly sized pop-up window that appears near the cursor whenever the cursor lingers over the textcanvas. Setting this value to NULL (the default) disables the tooltip mechanism. Reading returns the current tooltip text. Writing immediately sets the new tooltip text.
transferhandler An Object that should be a TransferHandler or String that determines how the textcanvas handles data transfer operations like drag and drop. A value that is a String but not "" means the field named by the String should be used as the source and sink of the data that is transferred by the textcanvas. The result is the same as assigning the String to the property field in a TransferHandler and then assigning that TransferHandler to transferhandler. The empty String "" is special and refers to the TransferHandler that Swing uses for automatic drag handling, if there is one.

Swing components that provide automatic drag handling start out with a transferhandler field that is not NULL, but the automatic drag handling is not enabled until 1 is stored in dragenabled. Swing components that provide their own drag and drop event handlers currently must store NULL in transferhandler before those event handlers will start working.

viewport An Rectangle that completely describes the printable area of the textcanvas in a coordinate system that has its origin at the upper left corner of the first line of text, positive x to the right, positive y down, and a resolution of 72 dots per inch. In other words, the x and y fields match the corresponding fields in origin, while height and width give the dimensions of the printable area of the textcanvas. 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 textcanvas is visible, and 0 otherwise. Reading returns the current visibility. Writing immediately sets the textcanvas'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 textcanvas when it is declared. The handlers that work with textcanvases are listed below; the names should be familiar if you have done some Java programming.
 
 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:   The program,
import yoix.*.*;

JFrame f = {
    Array layout = {
        new JTextCanvas {
            String tag = "textcanvas";
            Color  background = Color.white;

            syncViewport(port, extent, cell) {
                JScrollbar vbar = root.components.vbar;

                vbar.cell = cell;
                vbar.minimum = 0;
                vbar.maximum =
                    (extent.height + port.height)/cell.height - 1;
                vbar.visibleamount = port.height/cell.height;
                vbar.unitincrement = 1;
                vbar.blockincrement = port.height/cell.height - 1;
            }
        }, CENTER,

        new JScrollbar {
            Dimension cell;
            String    tag = "vbar";

            adjustmentValueChanged(e) {
                Point origin = root.components.textcanvas.origin;

                origin.y = value*cell.height;
                root.components.textcanvas.origin = origin;
            }
        }, EAST,
    };

    windowOpened(e) {
        Stream stream;

        if ((stream = open("http://www.att.com", "r")) != NULL) {
            components.textcanvas.text = readStream(stream);
            close(stream);
        }
    }
};

f.visible = TRUE;
is a nontrivial example that shows how a textcanvas and scrollbar can operate together.
 
 See Also:   appendText, BevelBorder, Border, EmptyBorder, EtchedBorder, invokeLater, JButton, JCanvas, JCheckBox, JCheckBoxMenuItem, JChoice, JColorChooser, JComboBox, JDesktopPane, JDialog, JFileChooser, JFileDialog, JFrame, JInternalFrame, JLabel, JLayeredPane, JList, JMenu, JMenuBar, JMenuItem, JPanel, JPasswordField, JPopupMenu, JProgressBar, JRadioButton, JRadioButtonMenuItem, JScrollBar, JScrollPane, JSeparator, JSlider, JSplitPane, JTabbedPane, JTable, JTextArea, JTextField, JTextPane, JTextTerm, JToggleButton, JToolBar, JTree, JWindow, LineBorder, MatteBorder, postEvent, SoftBevelBorder, TransferHandler

 

Yoix is a registered trademark of AT&T Inc.