Class FrameArranger

  extended by

public class FrameArranger
extends java.lang.Object

This class arranges internal frames in a designated area of a desktop pane. All frames will have the same size. At construction of the frame arranger, the number of frames and the area can be specified as well as the space that should be between the frames, and the minimum and maximum dimensions of a frame.

The frames are layed out in a grid. The frame arranger determines the optimal grid dimensions and the size of each frame. This is done in three steps.

First it is determined what grid dimensions are possible with the specified number of frames. Iterating over the number of frames (i = 1..n), the frames can be layed out in a grid of i rows and Math.ceil(n/i) columns. Some of the arrangements can result into one or more empty rows. These arrangements are not considered in further steps. In some arrangements the frames cannot be large enough for the specified minimum dimension. These arrangements are not further considered either.

Now it is possible that no grid arrangement is possible. In that case all frames will be layed out overlapping each other. Each frame will have the minimum dimension and one frame will be located 10 pixels to the right bottom of another frame.

Given a set of possible arrangements, the second step is to determine the arrangements in which the frame size can be as large as possible. With the available desktop area, required space between the frames and minimum and maximum frame dimensions, the frame size in an arrangement can be calculated and this size can be maximised.

In the third step it is attempted to find an arrangement in which the width/height proportion of the frames is optimal. This frame arranger considers the proportion optimal when the width equals the height (square proportion). It is determined which arrangement approaches the square proportion most closely. There may be two such arrangements (so that width1/height1 = height2/width2). In that case the frame arranger chooses the arrangement with maximum width.

After constructing the frame arranger, the bounding rectangle of a frame can simply be obtained with getBoundsForFrame().

Constructor Summary
FrameArranger(int nboxes, java.awt.Rectangle area, int space, int minWidth, int maxWidth, int minHeight, int maxHeight)
          Constructs a new frame arranger.
Method Summary
 java.awt.Rectangle getBoundsForFrame(int index)
          Returns the bounding rectangle (specifying size and location) of the frame with the specified index.
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public FrameArranger(int nboxes,
                     java.awt.Rectangle area,
                     int space,
                     int minWidth,
                     int maxWidth,
                     int minHeight,
                     int maxHeight)

Constructs a new frame arranger. The arranger will lay out nboxes frames in the specified area of a desktop pane. There will be a space of space pixels between the frames and the frames will not be smaller than (minWidth,minHeight) and not be larger than (maxWidth,maxHeight).

nboxes - the number of frames to lay out
area - the available area to lay out the frames
space - the amount of space between the frames
minWidth - the minimum width of a frame
maxWidth - the maximum width of a frame
minHeight - the minimum height of a frame
maxHeight - the maximum height of a frame
Method Detail


public java.awt.Rectangle getBoundsForFrame(int index)

Returns the bounding rectangle (specifying size and location) of the frame with the specified index.

index - the index of a frame
the bounding rectangle of the specified frame