Side of Software
Print Preview Library 1.8.1

sos.preview
Class MatrixLayout

java.lang.Object
  |
  +--sos.preview.MatrixLayout
All Implemented Interfaces:
java.awt.LayoutManager, ScalingLayoutManager, ScrollableLayoutManager, java.io.Serializable

public class MatrixLayout
extends java.lang.Object
implements ScrollableLayoutManager, ScalingLayoutManager, java.io.Serializable

A layout scheme that arranges components into rows and columns that fit the bounds of the container's parent. Typically, the container's parent is a viewport.

The matrix layout divides the container into "screens," where a screen is the size of the container's parent. Within each screen, the layout places the child components in equal-sized grid cells. It uses as many screens as necessary, and leftover cells are empty.

To get the child components to fit within the screen, it may have to scale them. It scales each child component the same amount. If a child component has a smaller preferred size, it will not fill the grid cell allotted to it. In this case, MatrixLayout uses the horizontal and vertical alignments to position the component within the cell.

Each screen has a left, right, top, and bottom margin, and each margin is the same across all screens. The gap between rows and columns is given by the vertical and horizontal spacing, respectively.

When the container needs to be scrolled, MatrixLayout suggests scrolling so that the next screen is completely visible.

When calculating the preferred size, MatrixLayout uses the current size of the container's parent. If the parent's size has not yet been set, the layout prefers a size where each child component is its preferred size.

The following diagram illustrates the placement of child components and the screen's padding:

MatrixLayout takes the container's component orientation into accout. The above diagram assumes a locale where the orientation is left-to-right and horizontal.

Since:
1.0
See Also:
FitAllLayout, FitLayout, ZoomLayout, ScalingLayoutManager, ScrollableLayoutManager

Constructor Summary
MatrixLayout(int numRows, int numColumns)
          Creates a MatrixLayout with the specified number of rows and columns per viewable area.
MatrixLayout(int numRows, int numColumns, int horizontalAlignment, int verticalAlignment)
          Creates a MatrixLayout with the specified number of rows and columns per viewable area and with the specified alignments.
MatrixLayout(int numRows, int numColumns, int horizontalSpacing, int verticalSpacing, int minLeftMargin, int minRightMargin, int minTopMargin, int minBottomMargin)
          Creates a MatrixLayout with the specified number of rows and columns per viewable area and with the specified spacing.
MatrixLayout(int numRows, int numColumns, int horizontalAlignment, int verticalAlignment, int horizontalSpacing, int verticalSpacing, int minLeftMargin, int minRightMargin, int minTopMargin, int minBottomMargin)
          Creates a MatrixLayout with the specified number of rows and columns per viewable area, the specified alignments, and the specified spacing.
 
Method Summary
 void addLayoutComponent(java.lang.String name, java.awt.Component component)
          If the layout manager uses a per-component string, adds the specified component to the layout, associating it with the specified name.
 boolean equals(java.lang.Object obj)
          Indicates whether some other object is "equal to" this one.
 int getColumnCount()
          Returns the number of columns per visible area.
 java.awt.Dimension getPreferredScrollableViewportSize(java.awt.Container container)
          Returns the specified container's preferred scrollable viewport size.
 int getRowCount()
          Returns the number of rows per visible area.
 int getScrollableBlockIncrement(java.awt.Container container, java.awt.Rectangle rectangle, int orientation, int direction)
          Returns the specified container's scrollable block increment.
 boolean getScrollableTracksViewportHeight(java.awt.Container container)
          Returns true if a viewport should always force the height of the specified container to match the height of the viewport.
 boolean getScrollableTracksViewportWidth(java.awt.Container container)
          Returns true if a viewport should always force the width of the specified container to match the width of the viewport.
 int getScrollableUnitIncrement(java.awt.Container container, java.awt.Rectangle rectangle, int orientation, int direction)
          Returns the specified container's scrollable unit increment.
 int hashCode()
          Returns a hash code value for the object.
 void layoutContainer(java.awt.Container container)
          Lays out the specified container.
 java.awt.Dimension minimumLayoutSize(java.awt.Container container)
          Calculates the minimum size dimensions for the specified container, given the components it contains.
 java.awt.Dimension preferredLayoutSize(java.awt.Container container)
          Calculates the preferred size dimensions for the specified container, given the components it contains.
 double preferredScale(java.awt.Container container)
          Returns the scale of the specified container's components if the container were to get its preferred size.
 void removeLayoutComponent(java.awt.Component component)
          Removes the specified component from the layout.
 double scaleComponents(java.awt.Container container)
          Lays out the container's components and returns the scale factor.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MatrixLayout

public MatrixLayout(int numRows,
                    int numColumns)
             throws java.lang.IllegalArgumentException
Creates a MatrixLayout with the specified number of rows and columns per viewable area.

Parameters:
numRows - The number of rows of components per viewable area
numColumns - The number of columns of components per viewable area
Throws:
java.lang.IllegalArgumentException - if numRows < 1 or numColumns < 1
See Also:
MatrixLayout(int,int,int,int,int,int,int,int,int,int)

MatrixLayout

public MatrixLayout(int numRows,
                    int numColumns,
                    int horizontalAlignment,
                    int verticalAlignment)
             throws java.lang.IllegalArgumentException
Creates a MatrixLayout with the specified number of rows and columns per viewable area and with the specified alignments.

Parameters:
numRows - The number of rows of components per viewable area
numColumns - The number of columns of components per viewable area
horizontalAlignment - Horizontal alignment of components that are not as wide as the widest component in the container. Acceptable values are SwingConstants.CENTER, SwingConstants.LEFT, SwingConstants.RIGHT, SwingConstants.LEADING, and SwingConstants.TRAILING.
verticalAlignment - Vertical alignment of components that are not as tall as the tallest component in the container. Acceptable values are SwingConstants.CENTER, SwingConstants.TOP, and SwingConstants.BOTTOM.
Throws:
java.lang.IllegalArgumentException - if numRows < 1, numColumns < 1, or one of the alignment parameters is unacceptable
See Also:
MatrixLayout(int,int,int,int,int,int,int,int,int,int)

MatrixLayout

public MatrixLayout(int numRows,
                    int numColumns,
                    int horizontalSpacing,
                    int verticalSpacing,
                    int minLeftMargin,
                    int minRightMargin,
                    int minTopMargin,
                    int minBottomMargin)
             throws java.lang.IllegalArgumentException
Creates a MatrixLayout with the specified number of rows and columns per viewable area and with the specified spacing.

Parameters:
numRows - The number of rows of components per viewable area
numColumns - The number of columns of components per viewable area
horizontalSpacing - Horizontal spacing between components
verticalSpacing - Vertical spacing between components
minLeftMargin - Minimum left margin
minRightMargin - Minimum right margin
minTopMargin - Minimum top margin
minBottomMargin - Minimum bottom margin
Throws:
java.lang.IllegalArgumentException - if numRows < 1, numColumns < 1, or one of the spacing parameters is negative
See Also:
MatrixLayout(int,int,int,int,int,int,int,int,int,int)

MatrixLayout

public MatrixLayout(int numRows,
                    int numColumns,
                    int horizontalAlignment,
                    int verticalAlignment,
                    int horizontalSpacing,
                    int verticalSpacing,
                    int minLeftMargin,
                    int minRightMargin,
                    int minTopMargin,
                    int minBottomMargin)
             throws java.lang.IllegalArgumentException
Creates a MatrixLayout with the specified number of rows and columns per viewable area, the specified alignments, and the specified spacing.

Parameters:
numRows - The number of rows of components per viewable area
numColumns - The number of columns of components per viewable area
horizontalAlignment - Horizontal alignment of components that are not as wide as the widest component in the container. Acceptable values are SwingConstants.CENTER, SwingConstants.LEFT, SwingConstants.RIGHT, SwingConstants.LEADING, and SwingConstants.TRAILING.
verticalAlignment - Vertical alignment of components that are not as tall as the tallest component in the container. Acceptable values are SwingConstants.CENTER, SwingConstants.TOP, and SwingConstants.BOTTOM.
horizontalSpacing - Horizontal spacing between components
verticalSpacing - Vertical spacing between components
minLeftMargin - Minimum left margin
minRightMargin - Minimum right margin
minTopMargin - Minimum top margin
minBottomMargin - Minimum bottom margin
Throws:
java.lang.IllegalArgumentException - if numRows < 1, numColumns < 1, one of the alignment parameters is unacceptable, or one of the spacing parameters is negative
Method Detail

addLayoutComponent

public void addLayoutComponent(java.lang.String name,
                               java.awt.Component component)
If the layout manager uses a per-component string, adds the specified component to the layout, associating it with the specified name.

Specified by:
addLayoutComponent in interface java.awt.LayoutManager
Parameters:
name - the string to be associated with the component
component - the component to be added

equals

public boolean equals(java.lang.Object obj)
Indicates whether some other object is "equal to" this one.

Overrides:
equals in class java.lang.Object
Parameters:
obj - the reference object with which to compare
Returns:
true if this object is the same as obj

getColumnCount

public int getColumnCount()
Returns the number of columns per visible area.

Returns:
the number of columns

getPreferredScrollableViewportSize

public java.awt.Dimension getPreferredScrollableViewportSize(java.awt.Container container)
Description copied from interface: ScrollableLayoutManager
Returns the specified container's preferred scrollable viewport size. The semantics are the same as javax.swing.Scrollable#getPreferredScrollableViewportSize, except the container is a parameter instead of the receiver.

Specified by:
getPreferredScrollableViewportSize in interface ScrollableLayoutManager
Parameters:
container - Container for which the preferred size is requested
Returns:
The preferred scrollable viewport size of container

hashCode

public int hashCode()
Returns a hash code value for the object.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this object

preferredScale

public double preferredScale(java.awt.Container container)
Description copied from interface: ScalingLayoutManager
Returns the scale of the specified container's components if the container were to get its preferred size.

Specified by:
preferredScale in interface ScalingLayoutManager
Parameters:
container - container for which to calculate the scale
Returns:
the amount this layout manager would scale the specified container's components to achieve the preferred size

getRowCount

public int getRowCount()
Returns the number of rows per visible area.

Returns:
the number of rows

getScrollableBlockIncrement

public int getScrollableBlockIncrement(java.awt.Container container,
                                       java.awt.Rectangle rectangle,
                                       int orientation,
                                       int direction)
Description copied from interface: ScrollableLayoutManager
Returns the specified container's scrollable block increment. The semantics are the same as javax.swing.Scrollable#getScrollableBlockIncrement, except the container is a parameter instead of the receiver.

Specified by:
getScrollableBlockIncrement in interface ScrollableLayoutManager
Parameters:
container - The container that is being scrolled
rectangle - The view area visible within the viewport
orientation - The axis of the scrolling--either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL
direction - A negative number to indicate scrolling left or up, or a positive number to indicate scrolling right or down
Returns:
The amount the viewport should scroll as a result of a "block" increment. It should be positive.

getScrollableTracksViewportHeight

public boolean getScrollableTracksViewportHeight(java.awt.Container container)
Description copied from interface: ScrollableLayoutManager
Returns true if a viewport should always force the height of the specified container to match the height of the viewport. The semantics are the same as javax.swing.Scrollable#getScrollableTracksViewportHeight, except the container is a parameter instead of the receiver.

Specified by:
getScrollableTracksViewportHeight in interface ScrollableLayoutManager
Parameters:
container - The container in question
Returns:
true if a viewport should keep the container's height the same height of the viewport

getScrollableTracksViewportWidth

public boolean getScrollableTracksViewportWidth(java.awt.Container container)
Description copied from interface: ScrollableLayoutManager
Returns true if a viewport should always force the width of the specified container to match the width of the viewport. The semantics are the same as javax.swing.Scrollable#getScrollableTracksViewportWidth, except the container is a parameter instead of the receiver.

Specified by:
getScrollableTracksViewportWidth in interface ScrollableLayoutManager
Parameters:
container - The container in question
Returns:
true if a viewport should keep the container's width the same width of the viewport

getScrollableUnitIncrement

public int getScrollableUnitIncrement(java.awt.Container container,
                                      java.awt.Rectangle rectangle,
                                      int orientation,
                                      int direction)
Description copied from interface: ScrollableLayoutManager
Returns the specified container's scrollable unit increment. The semantics are the same as javax.swing.Scrollable#getScrollableUnitIncrement, except the container is a parameter instead of the receiver.

Specified by:
getScrollableUnitIncrement in interface ScrollableLayoutManager
Parameters:
container - The container that is being scrolled
rectangle - The view area visible within the viewport
orientation - The axis of the scrolling--either SwingConstants.VERTICAL or SwingConstants.HORIZONTAL
direction - A negative number to indicate scrolling left or up, or a positive number to indicate scrolling right or down
Returns:
The amount the viewport should scroll as a result of a "unit" increment. It should be positive.

layoutContainer

public void layoutContainer(java.awt.Container container)
Lays out the specified container.

Specified by:
layoutContainer in interface java.awt.LayoutManager
Parameters:
container - the container to be laid out

minimumLayoutSize

public java.awt.Dimension minimumLayoutSize(java.awt.Container container)
Calculates the minimum size dimensions for the specified container, given the components it contains.

Specified by:
minimumLayoutSize in interface java.awt.LayoutManager
Parameters:
container - the container to be laid out
Returns:
the minimum size of container

preferredLayoutSize

public java.awt.Dimension preferredLayoutSize(java.awt.Container container)
Calculates the preferred size dimensions for the specified container, given the components it contains.

Specified by:
preferredLayoutSize in interface java.awt.LayoutManager
Parameters:
container - the container to be laid out
Returns:
the preferred size of container

removeLayoutComponent

public void removeLayoutComponent(java.awt.Component component)
Removes the specified component from the layout.

Specified by:
removeLayoutComponent in interface java.awt.LayoutManager
Parameters:
component - the component to be removed

scaleComponents

public double scaleComponents(java.awt.Container container)
Description copied from interface: ScalingLayoutManager
Lays out the container's components and returns the scale factor.

Specified by:
scaleComponents in interface ScalingLayoutManager
Parameters:
container - container for which to lay out its children
Returns:
the amount the specified container's children were scaled

Side of Software
Print Preview Library 1.8.1

Copyright 2003-07 Side of Software (SOS). All rights reserved.