com.miginfocom.calendar.decorators
Class SelectionGridDecorator

java.lang.Object
  extended by com.miginfocom.calendar.decorators.AbstractGridDecorator
      extended by com.miginfocom.calendar.decorators.AbstractDateGridDecorator
          extended by com.miginfocom.calendar.decorators.SelectionGridDecorator
All Implemented Interfaces:
Decorator, GridDecorator, DateChangeListener, java.lang.Comparable, java.util.EventListener
Direct Known Subclasses:
ThemeSelectionGridDecorator

public class SelectionGridDecorator
extends AbstractDateGridDecorator
implements DateChangeListener

A decorator that paints the cells of a grid that has some kind of selection (E.g. MouseOver, Pressed, Selected, Selectable). Can paint the outline (with a stroke) or fill the background of the cells.


Constructor Summary
SelectionGridDecorator(DateArea dateArea, int layerIndex)
          Constructor.
SelectionGridDecorator(DateArea dateArea, int layerIndex, java.awt.Paint[] paints, int[] cellOutlineModes)
          Constructor used when no strokes is to be used.
SelectionGridDecorator(DateArea dateArea, int layerIndex, java.awt.Paint[] paints, java.awt.Stroke[] strokes, java.awt.Paint[] strokePaints, int[] cellOutlineModes)
          Constructor
 
Method Summary
 void dateRangeChanged(DateChangeEvent e)
          Called when a date range changed.
 void dispose()
          Clean up and deregister listeners.
 void doPaint(java.awt.Graphics2D g, java.awt.Rectangle bounds)
          Paint what should be painted.
 int getCellOutlineMode(int type)
          Return one of the modes how the area (polygon) around the date range to be painted should be positioned
 int[] getCellOutlineModes()
          Returns how the area (polygon) around the date range to be painted should be positioned.
 DateArea getDateArea()
          Might return null since the date area is kept in a WeakReference
 java.awt.Paint getPaint(int type)
          Returns one of the paints.
 java.awt.Paint[] getPaints()
          Returns the different paints used paint in the background of the corresponding date range.
 java.awt.Paint getStokePaint(int type)
          Return one of the stroke paints.
 java.awt.Stroke getStroke(int type)
          Returns one of the strokes.
 java.awt.Paint[] getStrokePaints()
          Returns the paints of the different strokes to draw around the corresponding date range.
 java.awt.Stroke[] getStrokes()
          Returns the different strokes to draw around the corresponding date range.
 void gridChanged(java.beans.PropertyChangeEvent e)
          Called when the grid changes.
 boolean isHideWhenNotExactCellDateRange()
          Property: If the selection should be hidden, i.e.
 boolean isShowSelectionWhenSelecting()
          Returns if the old selection should be shown when there is a new temporary selection (pressed).
protected  void paintRange(java.awt.Graphics2D g2, int paintRangeType)
          Paints the outline, and possibly fills the outline of the indicated range type.
protected  void paintRangePoly(java.awt.Graphics2D g, java.awt.Polygon fillPoly, java.awt.Polygon drawPoly, int rangeType)
          Paint the poly gon
protected  void repaintDateRange(DateRangeI dateRange, int type)
          Marks the cells that overlaps dateRange in the grid as invalid IF there would be any visual change if they was repainted.
 void setCellOutlineMode(int type, int mode)
          Sets one of the modes how the area (polygon) around the date range to be painted should be positioned
 void setCellOutlineModes(int[] cellModes)
          Sets how the area (polygon) around the date range to be painted should be positioned.
 void setHideWhenNotExactCellDateRange(boolean hideWhenNotExactCellDateRange)
          Property: If the selection should be hidden, i.e.
 void setPaint(int type, java.awt.Paint paint)
          Sets one of the paints.
 void setPaints(java.awt.Paint[] paints)
          Sets the different paints used paint in the background of the corresponding date range.
 void setShowSelectionWhenSelecting(boolean b)
          Sets if the old selection should be shown when there is a new temporary selection (pressed).
 void setStokePaint(int type, java.awt.Paint paint)
          Sets one of the stroke paints.
 void setStroke(int type, java.awt.Stroke stroke)
          Sets one of the strokes.
 void setStrokePaints(java.awt.Paint[] strokePaints)
          Sets the paints of the different strokes to draw around the corresponding date range.
 void setStrokes(java.awt.Stroke[] strokes)
          Sets the different strokes to draw around the corresponding date range.
 
Methods inherited from class com.miginfocom.calendar.decorators.AbstractDateGridDecorator
getDateGrid, getDateGridContainer
 
Methods inherited from class com.miginfocom.calendar.decorators.AbstractGridDecorator
compareTo, getGrid, getGridContainer, getInvalidEnd, getInvalidStart, getLayerIndex, hasInvalidCells, invalidateCells, processEvent, setCellsValid, setLayerIndex
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SelectionGridDecorator

public SelectionGridDecorator(DateArea dateArea,
                              int layerIndex)
Constructor. That's starts with not paints or strokes.

Parameters:
dateArea - The grid container to decorate. Not null.
layerIndex - The index at which to paint this "layer".

SelectionGridDecorator

public SelectionGridDecorator(DateArea dateArea,
                              int layerIndex,
                              java.awt.Paint[] paints,
                              int[] cellOutlineModes)
Constructor used when no strokes is to be used.

Parameters:
dateArea - The date area which grid to decorate. Uses the date area to listen for date range changes. Stored in a WeakReference
layerIndex - The index at which to paint this "layer".
paints - The different paints to paint in the background of the corresponding date range. Indexed after the modes in DateChangeEvent.XXX. Indexes are:
{MouseOver, Pressed, Selected, Selectable}. Both elements and the array can be null in which case nothing is painted. Must be of at least length 4, or null.
cellOutlineModes - How the area (polygon) around the date range to be painted should be positioned. One of:
Grid.SIZE_MODE_INSIDE - The polygon will not draw over the cell's surrounding grid.
Grid.SIZE_MODE_MIDDLE - The polygon will draw in the middle of the cell's surrounding grid.
Grid.SIZE_MODE_OUTSIDE - The polygon will draw over as much as possible of the cell's surrounding grid.
Grid.SIZE_MODE_UPPER_LEFT - The polygon will draw over as much as possible of the cell's upper and left surrounding grid lines but not over the grid lines to the right or below.
Indexed after the modes in DateChangeEvent.XXX. Idexes are:
{MouseOver, Pressed, Selected, Selectable}. Both elements and the array can be null in which case nothing is drawn.
If null or elements null Grid.SIZE_MODE_MIDDLE will be used.

SelectionGridDecorator

public SelectionGridDecorator(DateArea dateArea,
                              int layerIndex,
                              java.awt.Paint[] paints,
                              java.awt.Stroke[] strokes,
                              java.awt.Paint[] strokePaints,
                              int[] cellOutlineModes)
Constructor

Parameters:
dateArea - The date area which grid to decorate. Uses the date area to listen for date range changes. Stored in a WeakReference
layerIndex - The index at which to paint this "layer".
paints - The different paints to paint in the background of the corresponding date range. Indexed after the modes in DateChangeEvent.XXX. Indexes are:
{MouseOver, Pressed, Selected, Selectable}. Both elements and the array can be null in which case nothing is painted. Must be of at least length 4, or null.
strokes - The different strokes to draw around the corresponding date range. Indexed after the modes in DateChangeEvent.XXX. Idexes are:
{MouseOver, Pressed, Selected, Selectable}. Both elements and the array can be null in which case nothing is drawn. Must be of at least length 4, or null.
strokePaints - The paints of the different strokes to draw around the corresponding date range. Indexed after the modes in DateChangeEvent.XXX. Idexes are:
{MouseOver, Pressed, Selected, Selectable}. Both elements and the array can be null in which case nothing is drawn. Must be of at least length 4, or null.
cellOutlineModes - How the area (polygon) around the date range to be painted should be positioned. One of:
Grid.SIZE_MODE_INSIDE - The polygon will not draw over the cell's surrounding grid.
Grid.SIZE_MODE_MIDDLE - The polygon will draw in the middle of the cell's surrounding grid.
Grid.SIZE_MODE_OUTSIDE - The polygon will draw over as much as possible of the cell's surrounding grid.
Grid.SIZE_MODE_UPPER_LEFT - The polygon will draw over as much as possible of the cell's upper and left surrounding grid lines but not over the grid lines to the right or below.
Indexed after the modes in DateChangeEvent.XXX. Idexes are:
{MouseOver, Pressed, Selected, Selectable}. Both elements and the array can be null in which case nothing is drawn.
If null or elements null Grid.SIZE_MODE_MIDDLE will be used.
Must be of at least length 4, or null.
Method Detail

doPaint

public void doPaint(java.awt.Graphics2D g,
                    java.awt.Rectangle bounds)
Description copied from interface: Decorator
Paint what should be painted. Color, paints, fonts, hints and similar should be same as when called.

Specified by:
doPaint in interface Decorator
Parameters:
g - The graphics object to paint in
bounds - The bounds to stay within (a must). If width and/or height is 0 that dimension is not scaled to fit and should be ignored.

dispose

public void dispose()
Description copied from interface: Decorator
Clean up and deregister listeners. Should be called when a Decorator isn't needed any more.

Specified by:
dispose in interface Decorator
Overrides:
dispose in class AbstractGridDecorator

gridChanged

public void gridChanged(java.beans.PropertyChangeEvent e)
Description copied from class: AbstractGridDecorator
Called when the grid changes.

Specified by:
gridChanged in class AbstractGridDecorator
Parameters:
e - The event.

getDateArea

public DateArea getDateArea()
Might return null since the date area is kept in a WeakReference

Returns:
The datearea or null.

getPaints

public java.awt.Paint[] getPaints()
Returns the different paints used paint in the background of the corresponding date range. Indexed after the modes in DateChangeEvent.XXX. Idexes are:
{MouseOver, Pressed, Selected, Selectable}. Elements can be null but not the array.

Returns:
The paints used to draw the background.

setPaints

public void setPaints(java.awt.Paint[] paints)
Sets the different paints used paint in the background of the corresponding date range. Indexed after the modes in DateChangeEvent.XXX. Idexes are:
{MouseOver, Pressed, Selected, Selectable}. Both elements and the array can be null in which case nothing is painted.

Parameters:
paints - The paints used to paint the background. Must be of at least length 4, or null.

getPaint

public java.awt.Paint getPaint(int type)
Returns one of the paints.

Parameters:
type - The type to return. E.g. DateChangeEvent.MOUSE_OVER.

setPaint

public void setPaint(int type,
                     java.awt.Paint paint)
Sets one of the paints.

Parameters:
type - The type of paint to set. E.g. DateChangeEvent.MOUSE_OVER.
paint - The paint to set. Mighit be null.

getStrokes

public java.awt.Stroke[] getStrokes()
Returns the different strokes to draw around the corresponding date range. Indexed after the modes in DateChangeEvent.XXX. Idexes are:
{MouseOver, Pressed, Selected, Selectable}. Elements can be null but not the array.

Returns:
The strokes used to draw the outline.

setStrokes

public void setStrokes(java.awt.Stroke[] strokes)
Sets the different strokes to draw around the corresponding date range. Indexed after the modes in DateChangeEvent.XXX. Idexes are:
{MouseOver, Pressed, Selected, Selectable}. Both elements and the array can be null in which case nothing is drawn.

Parameters:
strokes - The strokes used to draw the outline. Must be of at least length 4, or null.

getStroke

public java.awt.Stroke getStroke(int type)
Returns one of the strokes.

Parameters:
type - The type to return. E.g. DateChangeEvent.MOUSE_OVER.

setStroke

public void setStroke(int type,
                      java.awt.Stroke stroke)
Sets one of the strokes.

Parameters:
type - The type to set. E.g. DateChangeEvent.MOUSE_OVER.
stroke - The stroke to set. Mighit be null.

getStrokePaints

public java.awt.Paint[] getStrokePaints()
Returns the paints of the different strokes to draw around the corresponding date range. Indexed after the modes in DateChangeEvent.XXX. Idexes are:
{MouseOver, Pressed, Selected, Selectable}. Elements can be null but not the array.

Returns:
The strokes' paint used to draw the outline.

setStrokePaints

public void setStrokePaints(java.awt.Paint[] strokePaints)
Sets the paints of the different strokes to draw around the corresponding date range. Indexed after the modes in DateChangeEvent.XXX. Idexes are:
{MouseOver, Pressed, Selected, Selectable}. Both elements and the array can be null in which case nothing is drawn.

Parameters:
strokePaints - The strokes' paint used to draw the outline. Must be of at least length 4, or null.

getStokePaint

public java.awt.Paint getStokePaint(int type)
Return one of the stroke paints.

Parameters:
type - The type of paint to set. E.g. DateChangeEvent.MOUSE_OVER.

setStokePaint

public void setStokePaint(int type,
                          java.awt.Paint paint)
Sets one of the stroke paints.

Parameters:
type - The type of paint to set. E.g. DateChangeEvent.MOUSE_OVER.
paint - The paint to set. Mighit be null.

getCellOutlineModes

public int[] getCellOutlineModes()
Returns how the area (polygon) around the date range to be painted should be positioned.

Returns:
The mode used to draw the outline. Elements can be null but not the array.
See Also:
setCellOutlineModes(int[])

isHideWhenNotExactCellDateRange

public boolean isHideWhenNotExactCellDateRange()
Property: If the selection should be hidden, i.e. not painted, if the selected date range is not exatctly matching the boundaries of the cells in the grid.

Returns:
The current value.

setHideWhenNotExactCellDateRange

public void setHideWhenNotExactCellDateRange(boolean hideWhenNotExactCellDateRange)
Property: If the selection should be hidden, i.e. not painted, if the selected date range is not exatctly matching the boundaries of the cells in the grid.

Parameters:
hideWhenNotExactCellDateRange - The new value.

setCellOutlineModes

public void setCellOutlineModes(int[] cellModes)
Sets how the area (polygon) around the date range to be painted should be positioned. One of:
Grid.SIZE_MODE_INSIDE - The polygon will not draw over the cell's surrounding grid.
Grid.SIZE_MODE_MIDDLE - The polygon will draw in the middle of the cell's surrounding grid.
Grid.SIZE_MODE_OUTSIDE - The polygon will draw over as much as possible of the cell's surrounding grid.
Grid.SIZE_MODE_UPPER_LEFT - The polygon will draw over as much as possible of the cell's upper and left surrounding grid lines but not over the grid lines to the right or below.

Indexed after the modes in DateChangeEvent.XXX. Idexes are:
{MouseOver, Pressed, Selected, Selectable}. Both elements and the array can be null in which case nothing is drawn.
If null or elements null Grid.SIZE_MODE_MIDDLE will be used.

Parameters:
cellModes - The strokes' paint used to draw the outline. Must be of at least length 4, or null.

getCellOutlineMode

public int getCellOutlineMode(int type)
Return one of the modes how the area (polygon) around the date range to be painted should be positioned

Parameters:
type - The type to set. E.g. DateChangeEvent.MOUSE_OVER.
See Also:
setCellOutlineModes(int[])

setCellOutlineMode

public void setCellOutlineMode(int type,
                               int mode)
Sets one of the modes how the area (polygon) around the date range to be painted should be positioned

Parameters:
type - The type to set. E.g. DateChangeEvent.MOUSE_OVER.
mode - The mode to set. Mighit be null.
See Also:
setCellOutlineModes(int[])

isShowSelectionWhenSelecting

public boolean isShowSelectionWhenSelecting()
Returns if the old selection should be shown when there is a new temporary selection (pressed).

Returns:
If the old selection should be shown when there is a new temporary selection (pressed).

setShowSelectionWhenSelecting

public void setShowSelectionWhenSelecting(boolean b)
Sets if the old selection should be shown when there is a new temporary selection (pressed).

Parameters:
b - If the old selection should be shown when there is a new temporary selection (pressed).

paintRange

protected void paintRange(java.awt.Graphics2D g2,
                          int paintRangeType)
Paints the outline, and possibly fills the outline of the indicated range type.

Parameters:
g2 - The object to draw in
paintRangeType - Type of range to paint. E.g. DateChangeEvent.PRESSED

paintRangePoly

protected void paintRangePoly(java.awt.Graphics2D g,
                              java.awt.Polygon fillPoly,
                              java.awt.Polygon drawPoly,
                              int rangeType)
Paint the poly gon

Parameters:
g - The object to draw in
fillPoly - The polygon to fill. Not null.
drawPoly - The polygon to draw outline for. Not null.
rangeType - The type, e.g. DateChangeEvent.MOUSE_OVER.

dateRangeChanged

public void dateRangeChanged(DateChangeEvent e)
Description copied from interface: DateChangeListener
Called when a date range changed.

Specified by:
dateRangeChanged in interface DateChangeListener
Parameters:
e - The event that explains what happened

repaintDateRange

protected void repaintDateRange(DateRangeI dateRange,
                                int type)
Marks the cells that overlaps dateRange in the grid as invalid IF there would be any visual change if they was repainted.

Parameters:
dateRange - The date range. Not null.
type - The type. E.g. DateChangeEvent.SELECTABLE.
See Also:
AbstractGridDecorator.invalidateCells(int, int), AbstractGridDecorator.getInvalidStart(), AbstractGridDecorator.getInvalidEnd()


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.