com.miginfocom.calendar.grid
Class GridUtil

java.lang.Object
  extended by com.miginfocom.calendar.grid.GridUtil

public class GridUtil
extends java.lang.Object

Utility class to help with grid line and row layout.


Constructor Summary
GridUtil()
           
 
Method Summary
static java.lang.Integer[] getCellSizeBounds(GridSegmentSpec segmentSpec)
          Returns the minimum, preferred and maximum size of the rows.
static int[] getCellSizes(GridRow[] rows, GridRowLayout subRowLayout, GridSegmentSpec segmentSpec, int targetSize, boolean toBounds)
          Distributes the sizes the segmentSpec indicate of segmentSpec.getCellCount() number of cells using targetSize as the size that the returned size should add up to.
static GridRow getGridRow(int pos, GridRow[] rows, int maxDepth)
          Recursively get the deapest grid row that pos hits.
static java.lang.Integer getGridRowIndex(int pos, GridRow[] rows, boolean lenient)
          Return the index of which, if any, of rows that pos hits.
static GridRow getGridRowWithCategory(java.lang.Object categoryId, GridRow parentRow)
          Recursively get the deapest grid row that has a CategoryFilter that has a category with ID categoryId
static void mergePositions(int startPos, GridRow[] rows, GridLine[] lines)
          Merges the positions of the grid lines and grid rows so they don't overlap
static void registerRowListeners(java.beans.PropertyChangeListener listener, GridRow[] rows, boolean add)
          Register or deregister a PropertyChangeListener on all grid rows (and grid lines) so we can dispatch the grid row changes to the property change listeners for this class
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GridUtil

public GridUtil()
Method Detail

mergePositions

public static void mergePositions(int startPos,
                                  GridRow[] rows,
                                  GridLine[] lines)
Merges the positions of the grid lines and grid rows so they don't overlap

Parameters:
startPos - The start of the first grid line.
rows - The grid rows. At least one and always one less than lines.
lines - The grid rows. At least two and always one more than rows.

getGridRow

public static GridRow getGridRow(int pos,
                                 GridRow[] rows,
                                 int maxDepth)
Recursively get the deapest grid row that pos hits. Follows the same rules but for a hitted row that row's potential sub rows are then asked.

Parameters:
pos - The position to test.
rows - The rows that is to be tested which one contains pos.
maxDepth - The maximum depth to recursively check for sub rows. If 0 then one of rows will be returned.
Returns:
The row that was hit or null if none.

getGridRowWithCategory

public static GridRow getGridRowWithCategory(java.lang.Object categoryId,
                                             GridRow parentRow)
Recursively get the deapest grid row that has a CategoryFilter that has a category with ID categoryId

Parameters:
categoryId - The category to
parentRow - The row which children to check. The row itself will also be checked.
Returns:
The row that was found or null if none.

getCellSizeBounds

public static java.lang.Integer[] getCellSizeBounds(GridSegmentSpec segmentSpec)
Returns the minimum, preferred and maximum size of the rows.

Parameters:
segmentSpec - The spec to get the segments from.
Returns:
min, pref and max size. min is never null.

getCellSizes

public static int[] getCellSizes(GridRow[] rows,
                                 GridRowLayout subRowLayout,
                                 GridSegmentSpec segmentSpec,
                                 int targetSize,
                                 boolean toBounds)
Distributes the sizes the segmentSpec indicate of segmentSpec.getCellCount() number of cells using targetSize as the size that the returned size should add up to.

Parameters:
rows - The rows. Will be checked for size constraints. If they have none segmentSpec will fill in for that row. Must be same count as segmentSpec.getCellCount().
subRowLayout - The layout for the subrows in rows.
segmentSpec - The spec to get the segments from.
targetSize - The size that normaly is available for the cells
toBounds - If the layed out size should try to sum up to targetSize.

If true:

  1. All relative values (I.e. no a AtNumber) will be normalised so they add upp to 1.0. Otherwise if there are for instance just two preferred sizes, both with value 0.7f, the sum of the returned sizes will be 40% more than bounds. This might, or might not, be desirable depending on what's being layed out.
  2. Preferred relative values are relative to the remaining size when the absolute sizes have been taken away, so all match up to a total length of bounds. MAX/MIN, though, are not. They are, if they are relative (I.e. no a AtNumber) relative to the whole of bounds.
  3. The layout algorithm will try to give every size its preferred size but will scale them within MIN/MAX to fit the bounds.
Returns:
The sizes. Always of length segmentSpec.getCellCount().

getGridRowIndex

public static java.lang.Integer getGridRowIndex(int pos,
                                                GridRow[] rows,
                                                boolean lenient)
Return the index of which, if any, of rows that pos hits.

NOTE! Rows must not overlap and must be after each other for this method to work.

Parameters:
pos - The position to test.
rows - The rows that is to be tested which one contains pos.
lenient - If true the first/last row is returned if pos is outside the bounds that rows and gaps spans.
Returns:
The index of one of rows that pos hits or null if none.

registerRowListeners

public static void registerRowListeners(java.beans.PropertyChangeListener listener,
                                        GridRow[] rows,
                                        boolean add)
Register or deregister a PropertyChangeListener on all grid rows (and grid lines) so we can dispatch the grid row changes to the property change listeners for this class

Parameters:
rows - The rows to register or deregister listeners for.
add - If true the listeners are added, if false removed.


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.