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
JLayeredPane typedict
 
A JLayeredPane represents a simple container that is implemented using the Java Swing JLayeredPane class. It behaves more like a JDesktopPane than a JPanel because it lets you group components together, but it does not impose a structure on those components. Instead the components pick their own position and size using their location, size, and layer fields. The most important difference between a JLayeredPane and a JDesktopPane, is how JInternalFrames are handled, and in most situations you should use a JDesktopPane to manage JInternalFrames. In addition, a layeredpane can be used as a drawing canvas. Layeredpanes do not create windows, which means you only see them when they are in a visible JFrame, JDialog, or JWindow. Yoix programs normally interact with a JLayeredPane using event handlers and by reading or writing the following fields:
background The Color that is used to paint the background of the layeredpane. 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 layeredpane's background, and the background of components contained in the layeredpane that do not pick their own, to the new color.
backgroundhints An int that controls how backgroundimage is displayed in the layeredpane. The value should be one of SCALE_AREA, SCALE_DEFAULT, SCALE_FAST, SCALE_NONE, SCALE_REPLICATE, SCALE_SMOOTH, or SCALE_TILE, which are all defined in yoix.image. SCALE_NONE places the unscaled image in the upper left corner of the layeredpane, while SCALE_TILE (the default) tiles the entire layeredpane with the unscaled image. The other values select the algorithm used to scale backgroundimage so it fills the entire layeredpane. Reading returns the current hints. Writing immediately repaints the layeredpane using the new hints to display the background image.
backgroundimage An Object that should be an Image or String that identifies an image that is automatically displayed as part of the layeredpane's background in a way that is controlled by the value assigned to backgroundhints. A NULL value, which is the default, means there is no image. A backgroundimage that is a String should name a local a file or URL that contains a GIF or JPEG image. Reading returns the current image. Writing immediately repaints the layeredpane using the new image.
border An Object that should be a Border, Insets, Number, or String that describes the border that is drawn around this layeredpane. A NULL value, which is the default, means no border. A border that is an Insets or Number is an easy way to describe margins (i.e., an EmptyBorder), in units of 72 dots per inch, that are left around the sides of this layeredpane. A border that is a String is a quick way to surround this layeredpane with a border that uses the String as its title. Reading returns a snapshot of the current border. Writing immediately sets the layeredpane's border 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 layeredpane has an entry in the dictionary. Add the layeredpane 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 layeredpane. It is also the default cursor assigned to components in the layeredpane'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 layeredpane's cursor, and the cursor of components contained in the layeredpane that do not pick their own, to the new value. A layeredpane that does not set its own cursor uses DEFAULT_CURSOR.

doublebuffered An int that is 1 when the layeredpane uses double-buffering to draw itself, 0 when it does not, and starts with a default value that is selected by Java for the layeredpane. Reading returns the current double-buffering behavior. Writing immediately sets the layeredpane'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 layeredpane 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 layeredpane can respond to user input, 0 when it can not respond, and NULL (the default) when the layeredpane inherits the value from the nearest lightweight container, like a JPanel, that contains the layeredpane and has its enabled field set to something other than NULL. The top-level application window that contains the layeredpane always gets the final say, so disabling that window always disables the layeredpane. Reading returns the current state. Writing immediately sets the layeredpane's state to the new value, which can also change the state of the components contained in the layeredpane.
focusable An int that is non-zero (the default) when the layeredpane can accept the keyboard focus and zero when it can not. Reading returns the layeredpane's current focusable state. Writing immediately changes the layeredpane's focusable state to the new value, which means the focus is automatically transferred if the new value is zero and the layeredpane is the current focus owner.
focusowner A read-only int that is non-zero when the layeredpane 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 layeredpane's font, and the font used by all components contained in the layeredpane 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 layeredpane's foreground, and the foreground of components contained in the layeredpane that do not pick their own, to the new color.
graphics A Graphics object that defines properties and built-ins that are used to apply graphics operations to this layeredpane. Writing after a layeredpane has been created is not allowed and will result in an invalidaccess error.
icon An Image that is displayed in the tab associated with the layeredpane when the layeredpane is put in a JTabbedPane. Reading returns a snapshot of the current icon. Writing immediately changes the icon displayed by the tab that a JTabbedPane associates with the layeredpane.
layer An int, often a small number between 0 and 99, that identifies the depth of this layeredpane when it is added to another JLayeredPane or JDesktopPane. Components assigned to lower numbered layers are drawn before the components in higher numbered layers. Writing immediately changes the layeredpane's layer, which usually means the JLayeredPane or JDesktopPane that contains this layeredpane will be repainted.
layout An Array of Swing components that the layoutmanager puts in the layeredpane. All Swing components, including JInternalFrames are treated equally, and that is the most important difference between a JLayeredPane and a JDesktopPane. Reading returns the current array. Writing immediately clears layeredpane and then arranges the new set of components in the layeredpane.
layoutmanager A LayoutManager that is permanently set to NULL, because layeredpanes use a special-purpose layout manager for managing its components. All Swing components, including JInternalFrames, are treated equally, but layoutmanager does not impose a structure on the components listed in layout. Instead each component picks its own position and size using its location, size, and layer fields. The layeredpane updates its own components dictionary, just like other layout managers, and makes sure the root field in each component is set to the top-level component containing the layeredpane. Writing is not allowed and will result in an invalidaccess error.
location A Point that determines the location of the layeredpane in a coordinate system that has its origin at the upper left corner of the container closest to the layeredpane (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 layeredpane 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 layeredpane. A NULL value means the component that gets the focus after this layeredpane 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 layeredpane.
opaque An Object that is 1 when the layeredpane is opaque, 0 when it is transparent, and NULL (the default) when the layeredpane inherits the value from the nearest component that contains the layeredpane and has its opaque field set to something other than NULL. Changing a layeredpane's opaque field can immediately change the appearance of the components contained in the layeredpane.
paint([Rectangle rect]) A Function that is called, if it is not NULL, whenever the layeredpane needs to be painted. The optional rect argument describes the rectangle that needs repainting in the coordinate system specified by graphics.CTM, which by default has its origin at the layeredpane's upper left corner, positive x to the right, positive y down, and a resolution of 72 dots per inch.
popup A JPopupMenu that is associated with the layeredpane. Reading returns the current popup menu. Writing immediately shows the popup menu at the point in the layeredpane's coordinate system specified by the popup menu's location field, assuming of course that the layeredpane 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 layeredpane.
preferredsize A Dimension that is used by layout managers when they need to know the layeredpane's preferred size in units of 72 dots per inch. A NULL value means the layeredpane has no preference. A non-positive height or width is allowed and simply means the layeredpane 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.
repaint([int immediate]) A Builtin that tells the layeredpane to completely repaint itself, which means the background is regenerated and then the layeredpane's paint function is called. If the optional immediate argument is non-zero the repaint request is handled immediately rather than being queued as an event that is processed later. Obviously repaint should not be called, either directly or indirectly, from the layeredpane's paint function, however erasedrawable is safe because it does not trigger a paint call.
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 when actions, like mouse clicks or changes to the requestfocus field, can steal the keyboard focus and 0 (the default) 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 layeredpane'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 layeredpane. For example, put a layeredpane in another layeredpane and root will be set to the top-level layeredpane; add the top-level layeredpane to a frame and the original layeredpane's root field will be set to that frame. A layeredpane's event handlers can use root when they need to interact with the other components in the container.
showing A read-only int that is non-zero when the layeredpane is showing on the screen.
size A Dimension that determines the size of the layeredpane 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.
tag A String used to identify the layeredpane that is either supplied when the layeredpane is declared, or automatically generated otherwise. Add a layeredpane to a container, like a JFrame or even another JPanel, and the interpreter's layout machinery updates the root field so it points at the top-level container and then adds the layeredpane, as tag, to the root.components dictionary.
title A String that is the text that the tab associated with the layeredpane displays when the layeredpane is put in a JTabbedPane. Reading returns a snapshot of the current title. Writing immediately changes the text displayed by the tab that a JTabbedPane associates with the layeredpane.
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 layeredpane. 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 layeredpane 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 layeredpane. 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.

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.
visible An int that is 1 when the layeredpane is visible, and 0 otherwise. Reading returns the current visibility. Writing immediately sets the layeredpane'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 layeredpane when it is declared. The handlers that work with layeredpanes 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:   The program,
import yoix.*.*;

JFrame f = {
    Array layout = {
        new JLabel {
            String text = "A JLayeredPane Test";
            String font = "Lucida-bold-14";
        }, NORTH,

        new JLayeredPane {
            Color background = Color.green;

            Array layout = {
                new JButton {
                    String tag = "$_button";
                    String text = "Move";
                    Color  background = Color.blue;
                    int    layer = 0;

                    Dimension size = {
                        double height = 72;
                        double width = 72;
                    };

                    Point location = {
                        double x = 72;
                        double y = 72;
                    };

                    actionPerformed(e) {
                        Point p = this.location;
                        Dimension sz = this.size;

                        p.x += 18;
                        this.location = p;
                        sz.height += 9;
                        this.size = sz;
                        this.layer += 1;
                    }
                },

                new JLabel {
                    String text = "A Label At Layer 3";
                    Color  background = Color.red;
                    int    layer = 3;

                    Point location = {
                        double x = 90;
                        double y = 90;
                    };
                },
            };
        }, CENTER,

        new JButton {
            String text = "Reset";

            actionPerformed(e) {
                Object button = root.components.$_button;

                button.layer = 0;

                button.size = new Dimension {
                    double height = 72;
                    double width = 72;
                };

                button.location = new Point {
                    double x = 72;
                    double y = 72;
                };

            }
        }, SOUTH,
    };
};

f.visible = TRUE;
puts a button and a label in a layered pane and changes the button's layer, size, and location when it is pressed. Notice what happens when the button's layer is larger than the label's layer. Hitting the reset button restores the original settings.
 
 See Also:   BevelBorder, Border, BorderLayout, BoxLayout, CardLayout, CustomLayout, EmptyBorder, EtchedBorder, FlowLayout, GridBagLayout, GridLayout, invokeLater, JButton, JCanvas, JCheckBox, JCheckBoxMenuItem, JChoice, JColorChooser, JComboBox, JDesktopPane, JDialog, JFileChooser, JFileDialog, JFrame, JInternalFrame, JLabel, JList, JMenu, JMenuBar, JMenuItem, JPanel, JPasswordField, JPopupMenu, JProgressBar, JRadioButton, JRadioButtonMenuItem, JScrollBar, JScrollPane, JSeparator, JSlider, JSplitPane, JTabbedPane, JTable, JTextArea, JTextCanvas, JTextField, JTextPane, JTextTerm, JToggleButton, JToolBar, JTree, JWindow, LayoutManager, LineBorder, MatteBorder, postEvent, SoftBevelBorder, TransferHandler

 

Yoix is a registered trademark of AT&T Inc.