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
SpringLayout typedict
 
A SpringLayout is a layout manager that arranges the components in a container based on positioning constraints, each of which reference two components at a time, by means of the components' respective tags, and establish a constraining relationship between specific edges of those components. This layout approach differs from other layout managers in that the order of the constraints in the container's layout array is unimportant. Components should be AWT or Swing components and should be tagged for reference by the constraints as should the container itself. Constraints should be expressed using SpringConstraints objects. For regularized layouts, such as grids, the defaults indicated by the SpringLayout field values can be used to obviate the need for SpringConstraints objects. When both fields and constraints are present, the constraints take precedence.

The SpringLayout layout manager used with SpringConstraints is primarily intended for WYSIWYG builders or other automated layout situations as opposed to hand coding, particularly of complex layouts. For the latter situation, the GridBagLayout layout manager with GridBagConstraints is recommended.

The fields in a SpringLayout are:
columns This int can be used in lieu of explicit SpringConstraints to organize the managed components into a maximum number of columns. Row count is determined by the number of available components or by the rows field, if present. If insufficient components are available to fill all the specified cells, empty cells will be generated as needed.
hgap This Number can be used in lieu of explicit SpringConstraints to specify the horizontal spacing between components in units of 72 dots per inch.
orientation This field specifies the compaction orientation meaning excess space in cells are removed according to the orientation specification. Possible values and their meanings are:
  • NONE: no compaction occurs; neither in the vertical nor horizontal orientations. The result is that all cells are the same size much like occurs when a GridLayout layout manager is used.
  • HORIZTONAL: compaction occurs in the horizontal direction so that all rows are the same height, but columns will be different widths, though all cells in a particular column will have the same width.
  • VERTICAL: compaction occurs in the vertical direction so that all columns are the same width, but rows will be different heights, though all cells in a particular row will have the same height.
  • BOTH: compaction occurs in both directions so that columns will have different widths and rows will be different heights, though all cells in a particular row will have the same height and all cells in a particular column will have the same width.
type A read-only int that is set to SPRINGLAYOUT, which is defined in yoix.awt and yoix.swing.
rows This int can be used in lieu of explicit SpringConstraints to organize the managed components into a maximum number of rows. Column count is determined by the number of available components or by the columns field, if present. If insufficient components are available to fill all the specified cells, empty cells will be generated as needed.
vgap This Number can be used in lieu of explicit SpringConstraints to specify the vertical spacing between components in units of 72 dots per inch.
 
 Example:   The program,
import yoix.*.*;

JFrame jf = {
    String tag = "$_frame";
    Dimension size = NULL;
    int       visible = TRUE;

    SpringLayout layoutmanager;
    Array layout = {
        new JLabel {
            String tag = "$_label";
            String text = "Label";
        },
        new JTextField {
            String tag = "$_field";
            String text = "Text field";
            int    columns = 10;
        },

        new SpringConstraints {
            String anchorcomp = "$_frame";
            int    anchoredge = WEST;
            String dependcomp = "$_label";
            int    dependedge = WEST;
            int    spring = 18;
        },
        new SpringConstraints {
            String anchorcomp = "$_frame";
            int    anchoredge = NORTH;
            String dependcomp = "$_label";
            int    dependedge = NORTH;
            int    spring = 18;
        },

        new SpringConstraints {
            String anchorcomp = "$_label";
            int    anchoredge = EAST;
            String dependcomp = "$_field";
            int    dependedge = WEST;
            int    spring = 5;
        },
        new SpringConstraints {
            String anchorcomp = "$_frame";
            int    anchoredge = NORTH;
            String dependcomp = "$_field";
            int    dependedge = NORTH;
            int    spring = 18;
        },

        new SpringConstraints {
            String anchorcomp = "$_field";
            int    anchoredge = EAST;
            String dependcomp = "$_frame";
            int    dependedge = EAST;
            int    spring = 18;
        },
        new SpringConstraints {
            String anchorcomp = "$_field";
            int    anchoredge = SOUTH;
            String dependcomp = "$_frame";
            int    dependedge = SOUTH;
            int    spring = 18;
        },
    };
};
shows how two components, a JLabel and a JTextField are added to a frame that uses a SpringLayout as its layout manager and SpringConstraints to constrain the components.

This program,

import yoix.*.*;

JFrame jf = {
    String tag = "$_frame";
    Dimension size = NULL;
    int       visible = TRUE;
    int       border = 18;

    SpringLayout layoutmanager = {
        int columns = 4;
        int orientation = HORIZONTAL;
        int vgap = 6;
        int hgap = 3;
    };
    Array layout = {
        new JLabel {
            String text = "Label One:";
            int    alignment = RIGHT;
        },
        new JTextField {
            String text = "Text field 1";
            int    columns = 20;
        },

        new JLabel {
            String text = "Label the Second:";
            int    alignment = RIGHT;
        },
        new JTextField {
            String text = "Text field 2";
            int    columns = 40;
        },

        new JLabel {
            String text = "Label Three:";
            int    alignment = RIGHT;
        },
        new JTextField {
            String text = "Text field 3";
            int    columns = 30;
        },

        new JLabel {
            String text = "L4:";
            int    alignment = RIGHT;
        },
        new JTextField {
            String text = "Text field 4";
            int    columns = 15;
        },

        new JLabel {
            String text = "Label Five:";
            int    alignment = RIGHT;
        },
        new JTextField {
            String text = "Text field 5";
            int    columns = 15;
        },
    };
};
shows SpringLayout being used to layout several labels and textfields without the use of explicit SpringConstraints. Because compaction is occuring in the horizontal orientation, the displayed components will occupy less space than if a GridLayout had been used.
 
 See Also:   BorderLayout, BoxLayout, CardLayout, CustomLayout, FlowLayout, GridBagLayout, GridLayout, LayoutManager

 

Yoix is a registered trademark of AT&T Inc.