com.miginfocom.calendar.layout
Class FlexGridLayout

java.lang.Object
  extended by com.miginfocom.calendar.layout.ActivityLayout
      extended by com.miginfocom.calendar.layout.FlexGridLayout
All Implemented Interfaces:
java.io.Serializable

public class FlexGridLayout
extends ActivityLayout

An activity layout that is comparable to GridLayout, but a lot more flexible. Also incorporates ideas from FlowLayout.
The algorithm starts at a corner (normally) of the bounds and then continues to layout the views in one direction. It wraps at the bounds' end or at a specific row/column count or aspect ratio.
Does not use the min/max/preferred size of the activity view.'s paint object (AShape for instance).

See Also:
Serialized Form

Constructor Summary
FlexGridLayout()
          No-arg constr.
FlexGridLayout(AtRefRangeNumber startX, AtRefRangeNumber startY, boolean goRight, boolean goDown, java.lang.Number wrapGeometry, java.lang.Integer cellWidth, java.lang.Integer cellHeight, int vGap, int hGap, PlaceRect placeRect)
          Constructor.
FlexGridLayout(AtRefRangeNumber startX, AtRefRangeNumber startY, boolean goRight, boolean goDown, java.lang.Number wrapGeometry, java.lang.Integer cellWidth, java.lang.Integer cellHeight, int vGap, int hGap, PlaceRect placeRect, java.lang.String[] layoutContexts)
          Constructor.
 
Method Summary
 boolean equals(java.lang.Object o)
           
 java.lang.Integer getCellHeight()
          Returns the grid cell height in pixels.
 java.lang.Integer getCellWidth()
          Returns the grid cell width in pixels.
 java.lang.String[] getDefaultContexts()
          Returns the contexts this layout will report a higher priority to layout.
 int getHorizontalGap()
          Returns the horizontal gap in pixels between two adjactant rectangles.
 int getLayoutPriority(ActivityView actView)
          Returns in which degree this layout accepts responsibility for laying out this ActivityView.
 PlaceRect getPlaceRect()
          Returns where within the total available layout bounds we should layout.
 AtRefRangeNumber getStartX()
          Returns where the first activity should be placed in the bounds.
 AtRefRangeNumber getStartY()
          Returns where the first activity should be placed in the bounds.
 int getVerticalGap()
          Returns the vertical gap in pixels between two adjactant rectangles.
 java.lang.Number getWrapGeometry()
          Returns the number of columns/rows in the primary dimension.
 boolean isGoDown()
          Returns if "next" activity should be placed below.
 boolean isGoRight()
          Returns if "next" activity should be placed to the right.
 boolean isMatchStartOnly()
          If true only the start of the activities will be the cell and thus all activities will only span one cell.
 TimeSpanList layout(DateGrid dateGrid, TimeSpanList actViewList, java.util.ArrayList occRects, ImmutableDateRange onlyRange)
          Layout the activities within the bounds.
protected  void layoutView(ActivityView actView, java.awt.Rectangle r, TimeSpanList noFitList)
          Lays out just one view.
protected  void layoutViews(java.util.ArrayList actViews, java.awt.Rectangle r, TimeSpanList noFitList, boolean isHor)
          Lays out views.
 void setCellHeight(java.lang.Integer cellHeight)
          Sets the grid cell height in pixels.
 void setCellWidth(java.lang.Integer cellWidth)
          Sets the grid cell width in pixels.
 void setGoDown(boolean goDown)
          Sets if "next" activity should be placed below.
 void setGoRight(boolean goRight)
          Sets if "next" activity should be placed to the right.
 void setHorizontalGap(int hGap)
          Sets the horizontal gap in pixels between two adjactant rectangles.
 void setMatchStartOnly(boolean b)
          If true only the start of the activities will be the cell and thus all activities will only span one cell.
 void setPlaceRect(PlaceRect placeRect)
          Sets within the total available layout bounds we should layout.
 void setStartX(AtRefRangeNumber startX)
          Sets where the first activity should be placed in the bounds.
 void setStartY(AtRefRangeNumber startY)
          Sets where the first activity should be placed in the bounds.
 void setVerticalGap(int vGap)
          Sets the vertical gap in pixels between two adjactant rectangles.
 void setWrapGeometry(java.lang.Number wrapGeom)
          Sets the number of columns/rows in the primary dimension.
 
Methods inherited from class com.miginfocom.calendar.layout.ActivityLayout
getLayoutContexts, isInContexts, setLayoutContexts, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FlexGridLayout

public FlexGridLayout()
No-arg constr. Calls:
this(new AtEnd(0), new AtStart(0), false, true, null, new Integer(16), new Integer(16), 2, 2, null);


FlexGridLayout

public FlexGridLayout(AtRefRangeNumber startX,
                      AtRefRangeNumber startY,
                      boolean goRight,
                      boolean goDown,
                      java.lang.Number wrapGeometry,
                      java.lang.Integer cellWidth,
                      java.lang.Integer cellHeight,
                      int vGap,
                      int hGap,
                      PlaceRect placeRect)
Constructor.

Parameters:
startX - Where the first activity should be placed in the bounds. Not null.
startY - Where the first activity should be placed in the bounds. Not null.
goRight - If "next" activity should be placed to the right. false means left.
goDown - If "next" activity should be placed to below. false means above.
wrapGeometry - If Integer it's the number of columns/rows in the primary dimension before wraping to next row/col.
If Float then it's the primDim/secDim aspect ratio. E.g. 2.0f would create a grid that has twise as many columns as rows (if HORIZONTAL).
If null it works like FlowLayout where the the layout wraps when it comes to the end of the opposite bounds.
cellWidth - If not null specifies the grid cell width in pixels. If null the size will be set so they span the bounds.
cellHeight - If not null specifies the grid cell height in pixels. If null the size will be set so they span the bounds.
hGap - The horizontal gap in pixels between two adjactant cell bounds.
vGap - The vertical gap in pixels between two adjactant cell bounds.
placeRect - If not null specifies where within the total available layout bounds we should layout. null means the whole bounds should be used.

FlexGridLayout

public FlexGridLayout(AtRefRangeNumber startX,
                      AtRefRangeNumber startY,
                      boolean goRight,
                      boolean goDown,
                      java.lang.Number wrapGeometry,
                      java.lang.Integer cellWidth,
                      java.lang.Integer cellHeight,
                      int vGap,
                      int hGap,
                      PlaceRect placeRect,
                      java.lang.String[] layoutContexts)
Constructor.

Parameters:
startX - Where the first activity should be placed in the bounds. Not null.
startY - Where the first activity should be placed in the bounds. Not null.
goRight - If "next" activity should be placed to the right. false means left.
goDown - If "next" activity should be placed to below. false means above.
wrapGeometry - If Integer it's the number of columns/rows in the primary dimension before wraping to next row/col.
If Float then it's the primDim/secDim aspect ratio. E.g. 2.0f would create a grid that has twise as many columns as rows (if HORIZONTAL).
If null it works like FlowLayout where the the layout wraps when it comes to the end of the opposite bounds.
cellWidth - If not null specifies the grid cell width in pixels. If null the size will be set so they span the bounds.
cellHeight - If not null specifies the grid cell height in pixels. If null the size will be set so they span the bounds.
hGap - The horizontal gap in pixels between two adjactant cell bounds.
vGap - The vertical gap in pixels between two adjactant cell bounds.
placeRect - If not null specifies where within the total available layout bounds we should layout. null means the whole bounds should be used.
layoutContexts - The layout contexts this layout should react to. If null the default one {"FlexGrid"} is used.
Method Detail

getLayoutPriority

public int getLayoutPriority(ActivityView actView)
Description copied from class: ActivityLayout
Returns in which degree this layout accepts responsibility for laying out this ActivityView.
The Activity.getLayoutContext() and the duration is normally used to determine this. The installed layout with the highest priority will get the chance to layout the actView later on. TimeBoundsLayout will always return 0 so returning a negative value will make sure that this layout won't be called to layout that actView (that is if TimeBoundsLayout is installed in the DateArea. Should normally be < 10.

Specified by:
getLayoutPriority in class ActivityLayout
Parameters:
actView - The view that is to be laid out
Returns:
If this layout accepts responsibility for laying out this ActivityView.

getDefaultContexts

public java.lang.String[] getDefaultContexts()
Returns the contexts this layout will report a higher priority to layout.

Specified by:
getDefaultContexts in class ActivityLayout
Returns:
new String[] {"FlexGrid"}

layout

public TimeSpanList layout(DateGrid dateGrid,
                           TimeSpanList actViewList,
                           java.util.ArrayList occRects,
                           ImmutableDateRange onlyRange)
Description copied from class: ActivityLayout
Layout the activities within the bounds. All activities that couldn't fit for some reason should have their bounds set to null.

Specified by:
layout in class ActivityLayout
Parameters:
dateGrid - The Grid to layout the activities within
actViewList - A number of ActivityView objects to layout. Will not be "changed". The individual views should be sorted in the preferred order to paint the activities later.
occRects - The areas (Rectangle2D) that currently are not free. They may or may not be within the bounds. They also may or may not be ignored, but if they are ignored, they will possibly be painted over or paint over something else. Not null.
onlyRange - The layout range that actually need to be laid out. If null all in actViewList should be laid out. This argument is mostly for optimizing. Since the container can't know which dates translates to what pixels this optimization is up to the atcivity layout.
Returns:
A list with DateRangeIs representing time spans that couldn't be laid out due to shortage of free space. Not null and it should be a newly created list that can be overtaken by the caller of this method.

layoutView

protected void layoutView(ActivityView actView,
                          java.awt.Rectangle r,
                          TimeSpanList noFitList)
Lays out just one view. Should have the same algorithm as layoutViews(java.util.ArrayList, java.awt.Rectangle, com.miginfocom.util.dates.TimeSpanList, boolean) but has a separate code path since it can be much more optimized.

Parameters:
actView - The view to lay out
r - The rectangle to normally stay within. Can be empty but never null.
noFitList - Fill in this list with the activity view's date ranges that doesn't fit

layoutViews

protected void layoutViews(java.util.ArrayList actViews,
                           java.awt.Rectangle r,
                           TimeSpanList noFitList,
                           boolean isHor)
Lays out views.

Parameters:
actViews - A list of at least two ActivityViews.
r - The rectangle to normally stay within. Can be empty but never null.
noFitList - Fill in this list with the activity view's date ranges that doesn't fit
isHor - If the primary dimension is horizontal

isMatchStartOnly

public boolean isMatchStartOnly()
If true only the start of the activities will be the cell and thus all activities will only span one cell.

Returns:
The current value. Default is true.
Since:
6.5

setMatchStartOnly

public void setMatchStartOnly(boolean b)
If true only the start of the activities will be the cell and thus all activities will only span one cell.

Parameters:
b - The new value. Default is true.
Since:
6.5

getStartX

public AtRefRangeNumber getStartX()
Returns where the first activity should be placed in the bounds. Not null.

Returns:
Where the first activity should be placed in the bounds. Not null.

setStartX

public void setStartX(AtRefRangeNumber startX)
Sets where the first activity should be placed in the bounds. Not null.

Parameters:
startX - Where the first activity should be placed in the bounds. Not null.

getStartY

public AtRefRangeNumber getStartY()
Returns where the first activity should be placed in the bounds. Not null.

Returns:
Where the first activity should be placed in the bounds. Not null.

setStartY

public void setStartY(AtRefRangeNumber startY)
Sets where the first activity should be placed in the bounds. Not null.

Parameters:
startY - Where the first activity should be placed in the bounds. Not null.

isGoRight

public boolean isGoRight()
Returns if "next" activity should be placed to the right. false means left.

Returns:
If "next" activity should be placed to the right.

setGoRight

public void setGoRight(boolean goRight)
Sets if "next" activity should be placed to the right. false means left.

Parameters:
goRight - true if "next" activity should be placed to the right.

isGoDown

public boolean isGoDown()
Returns if "next" activity should be placed below. false means above.

Returns:
If "next" activity should be placed below.

setGoDown

public void setGoDown(boolean goDown)
Sets if "next" activity should be placed below.

Parameters:
goDown - true if "next" activity should be placed below.

getWrapGeometry

public java.lang.Number getWrapGeometry()
Returns the number of columns/rows in the primary dimension. If Integer it's the number of columns/rows in the primary dimension, before wraping to next row/col.
If Float then it's the primDim/secDim aspect ratio. E.g. 2.0f would create a grid that has twise as many columns as rows (if HORIZONTAL).
If null it works like FlowLayout where the the layout wraps when it comes to the end of the opposite bounds.

Returns:
The number of columns/rows or it's raio in the primary dimension.

setWrapGeometry

public void setWrapGeometry(java.lang.Number wrapGeom)
Sets the number of columns/rows in the primary dimension. If an Integer it's the number of columns/rows in the primary dimension, before wraping to next row/col.
If Float then it's the primDim/secDim aspect ratio. E.g. 2.0f would create a grid that has twise as many columns as rows (if HORIZONTAL).
If null it works like FlowLayout where the the layout wraps when it comes to the end of the opposite bounds.

Parameters:
wrapGeom - The number of columns/rows or it's raio in the primary dimension.

getCellWidth

public java.lang.Integer getCellWidth()
Returns the grid cell width in pixels. If not null specifies the grid cell width in pixels. If null the size wil fit the bounds.

Returns:
The grid cell width in pixels. May be null.

setCellWidth

public void setCellWidth(java.lang.Integer cellWidth)
Sets the grid cell width in pixels. If not null specifies the grid cell width in pixels. If null the size wil fit the bounds.

Parameters:
cellWidth - The grid cell width in pixels. May be null.

getCellHeight

public java.lang.Integer getCellHeight()
Returns the grid cell height in pixels. If not null specifies the grid cell height in pixels. If null the size will fit the bounds.

Returns:
The grid cell height in pixels. May be null.

setCellHeight

public void setCellHeight(java.lang.Integer cellHeight)
Sets the grid cell height in pixels. If not null specifies the grid cell height in pixels. If null the size will fit the bounds.

Parameters:
cellHeight - The grid cell height in pixels. May be null.

getHorizontalGap

public int getHorizontalGap()
Returns the horizontal gap in pixels between two adjactant rectangles.

Returns:
The horizontal gap in pixels between two adjactant rectangles.

setHorizontalGap

public void setHorizontalGap(int hGap)
Sets the horizontal gap in pixels between two adjactant rectangles.

Parameters:
hGap - The horizontal gap in pixels between two adjactant rectangles.

getVerticalGap

public int getVerticalGap()
Returns the vertical gap in pixels between two adjactant rectangles.

Returns:
The vertical gap in pixels between two adjactant rectangles.

setVerticalGap

public void setVerticalGap(int vGap)
Sets the vertical gap in pixels between two adjactant rectangles.

Parameters:
vGap - The vertical gap in pixels between two adjactant rectangles.

getPlaceRect

public PlaceRect getPlaceRect()
Returns where within the total available layout bounds we should layout.

Returns:
Where within the total available layout bounds we should layout. May be null.

setPlaceRect

public void setPlaceRect(PlaceRect placeRect)
Sets within the total available layout bounds we should layout.

Parameters:
placeRect - If not null specifies where within the total available layout bounds we should layout. null means the whole bounds shoule be used.

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.