eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'GridBagLayoutView':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: GridBagLayoutView


Inheritance:

   Object
   |
   +--GraphicsMedium
      |
      +--DisplaySurface
         |
         +--SimpleView
            |
            +--PanelView
               |
               +--GridBagLayoutView

Package:
stx:libwidg2
Category:
Views-Layout
Version:
rev: 1.16 date: 2023/05/30 12:29:37
user: cg
file: GridBagLayoutView.st directory: libwidg2
module: stx stc-classLibrary: libwidg2

Description:


GridBagLayout is a flexible layout manager that aligns components vertically and horizontally,
without requiring that the components be the same size. Each GridBagLayout uses a dynamic rectangular 
grid of cells, with each component occupying one or more cells (called its display area).
Each component managed by a GridBagLayout is associated with a GridBagConstraints instance that 
specifies how the component is laid out within its display area. How a GridBagLayout places a set of 
components depends on each component's GridBagConstraints and minimum size, as well as the preferred 
size of the components' container.

To use a GridBagLayout effectively, you must customize one or more of its components' GridBagConstraints.
You customize a GridBagConstraints object by setting one or more of its instance variables:

    gridX
    gridY
		Specifies the cell at the upper left of the component's display area, where the 
		upper-left-most cell has address gridX=0, gridY=0. Use #RELATIVE (the default value)
		to specify that the component be just placed just to the right of (for gridX)
		or just below (for gridY) the component that was added to the container just before 
		this component was added.

    gridWidth
    gridHeight
		Specifies the number of cells in a row (for gridWidth) or column (for gridHeight)
		in the component's display area. The default value is 1. Use #REMAINDER to specify
		that the component be the last one in its row (for gridWidth) or column (for gridHeight).
		Use #RELATIVE to specify that the component be the next to last one in its row 
		(for gridWidth) or column (for gridHeight).

    fill
		Used when the component's display area is larger than the component's requested size
		to determine whether (and how) to resize the component.
		Valid values are
		    #NONE
			(the default),
		    #HORIZONTAL
			(make the component wide enough to fill its display area
			horizontally, but don't change its height),
		    #VERTICAL
			(make the component tall enough to fill its display area
			vertically, but don't change its width), and
		    #BOTH       
			(make the component fill its display area entirely).

    ipadX
    ipadY
		Specifies the internal padding: how much to add to the minimum size of the component.
		The width of the component will be at least its minimum width plus ipadX*2 pixels
		(since the padding applies to both sides of the component). Similarly, the height of 
		the component will be at least the minimum height plus ipadY*2 pixels.

    insets
		Specifies the external padding of the component -- the minimum amount of space between 
		the component and the edges of its display area.

    anchor
		Used when the component is smaller than its display area to determine where (within the area) 
		to place the component.
		Valid values are
			#CENTER (the default),
			#NORTH,
			#NORTHEAST,
			#EAST,
			#SOUTHEAST,
			#SOUTH,
			#SOUTHWEST,
			#WEST, 
			#NORTHWEST.

    weightX
    weightY
		Used to determine how to distribute space; this is important for specifying resizing 
		behavior. Unless you specify a weight for at least one component in a row (weightX)
		and column (weightY), all the components clump together in the center of their container.
		This is because when the weight is zero (the default), the GridBagLayout puts any extra 
		space between its grid of cells and the edges of the container.

copyright

COPYRIGHT (c) 1998 by Andreas Vogel / eXept Software AG All Rights Reserved This software is furnished under a license and may be used only in accordance with the terms of that license and with the inclusion of the above copyright notice. This software may not be provided or otherwise made available to, or used by, any other person. No title to or ownership of the software is hereby transferred.

Class protocol:

instance creation
o  new
Create a new instance of my class and do explizit initialization of it.


Instance protocol:

initialization
o  initialize
Initialize the instance. Mainly set our instance variables to required values.

layout
o  setChildPositions
(re)compute position of every child whenever children are added or my size has changed

private
o  adjustForGravity: c in: aRectangle

o  arrangeGrid
Lay out the grid.

o  constraints: anObject
Get the GridBag constraints for an object. As a fallback create new constraints for objects
which don't have any constraints yet.

o  getLayoutInfo: which
return a good extent, one that makes subviews fit

o  getMinSize: info
Figure out the minimum size of the master based on the information from getLayoutInfo. The
result will be returned as a rectangle with width and height set to the minimum size.

o  minimumLayoutSize
Return our minimum layout size. The width and height of the returned rectangle gives the minimum
layout size.

o  preferredLayoutSize
Return our preffered layout size. The width and height of the returned rectangle gives the
preferred layout size.

queries
o  computePreferredExtent
Return a good extent, one that makes subviews fit.
Return the the preferred extent as a point
where x and y represents the width and height of the extent.


Examples:


This example is taken from the java source and should produce the same layout. Check the file Grid*.gif in the java distribution.
    | v p c |
    c := #(
        #( fill: #BOTH weightX: 1.0 )                         
        #( fill: #BOTH weightX: 1.0 )                         
        #( fill: #BOTH weightX: 1.0 )                         
        #( fill: #BOTH weightX: 1.0 gridWidth: #REMAINDER ) 
        #( fill: #BOTH gridWidth: #REMAINDER )                
        #( fill: #BOTH gridWidth: #RELATIVE )                 
        #( fill: #BOTH gridWidth: #REMAINDER )                
        #( fill: #BOTH weightY: 1.0 gridHeight: 2 )
        #( fill: #BOTH gridWidth: #REMAINDER )                
        #( fill: #BOTH gridWidth: #REMAINDER )                
    ).           
    v := StandardSystemView new. v label:'GridBagLayoutView: Example 1'.
    p := GridBagLayoutView in:v. p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
    1 to: c size do:[ :i | | b |
        b := Button label:('Button ',(i displayString)) in:p. 
        b objectAttributeAt:#GridBagConstraints put:((#(GridBagConstraints) , (c at:i)) decodeAsLiteralArray). 
    ].
    v extent:(p preferredExtent). v open.
    | v p c |
    c := #(
        #( insets: #(Insets 2 2 2 2) fill: #BOTH weightX: 1.0 )                         
        #( insets: #(Insets 2 2 2 2) fill: #BOTH weightX: 1.0 )                         
        #( insets: #(Insets 2 2 2 2) fill: #BOTH weightX: 1.0 )                         
        #( insets: #(Insets 2 2 2 2) fill: #BOTH weightX: 1.0 gridWidth: #REMAINDER ) 
        #( insets: #(Insets 2 2 2 2) fill: #BOTH gridWidth: #REMAINDER )                
        #( insets: #(Insets 2 2 2 2) fill: #BOTH gridWidth: #RELATIVE )                 
        #( insets: #(Insets 2 2 2 2) fill: #BOTH gridWidth: #REMAINDER )                
        #( insets: #(Insets 2 2 2 2) fill: #BOTH weightY: 1.0 gridHeight: 2 )
        #( insets: #(Insets 2 2 2 2) fill: #BOTH gridWidth: #REMAINDER )                
        #( insets: #(Insets 2 2 2 2) fill: #BOTH gridWidth: #REMAINDER )                
    ).           
    v := StandardSystemView new. v label:'GridBagLayoutView: Example 2'.
    p := GridBagLayoutView in:v. p origin:(0.0 @ 0.0) corner:(1.0 @ 1.0).
    1 to: c size do:[ :i | | b |
        b := Button label:('Button ',(i displayString)) in:p. 
        b objectAttributeAt:#GridBagConstraints put:((#(GridBagConstraints) , (c at:i)) decodeAsLiteralArray). 
    ].
    v extent:(p preferredExtent). v open.


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Tue, 03 Dec 2024 17:10:09 GMT