com.miginfocom.calendar.decorators
Class CellLabelDecorator

java.lang.Object
  extended by com.miginfocom.calendar.decorators.AbstractGridDecorator
      extended by com.miginfocom.calendar.decorators.GridCellDecorator
          extended by com.miginfocom.calendar.decorators.CellLabelDecorator
All Implemented Interfaces:
Decorator, GridDecorator, java.lang.Comparable
Direct Known Subclasses:
ThemeCellLabelDecorator

public class CellLabelDecorator
extends GridCellDecorator

Default painter that paints all cells alike. Override paintCell(java.awt.Graphics2D, int, int, java.awt.Rectangle) and changes some properties (E.g. font, foreground paint) and then call super.paintCell(..) and subsequent cells will be painted with those properties instead.

The strings to draw are cached for every cell since they are unlikely to change. Only formatted for the first paint. See getLabelString(com.miginfocom.util.dates.ImmutableDateRange, boolean).

Notice that it is possible to have a special look for the cell that spans the current time. See for instance setNowFont(java.awt.Font).


Field Summary
 
Fields inherited from class com.miginfocom.calendar.decorators.GridCellDecorator
placeRect
 
Constructor Summary
CellLabelDecorator(DateGridContainer gridContainer, int layerIndex)
          Default constructor.
CellLabelDecorator(DateGridContainer gridContainer, int layerIndex, PlaceRect placeRect, DateFormatList dateFormat, java.awt.Font font, java.awt.Paint fgPaint, AtRefRangeNumber alignX, AtRefRangeNumber alignY, int ulWidth, boolean antiAlias, java.awt.Paint bgPaint)
          Deprecated. Use the version which has an Object hint as anti alias.
CellLabelDecorator(DateGridContainer gridContainer, int layerIndex, PlaceRect placeRect, DateFormatList dateFormat, java.awt.Font font, java.awt.Paint fgPaint, AtRefRangeNumber alignX, AtRefRangeNumber alignY, int ulWidth, int antiAliasHint, java.awt.Paint bgPaint)
          Constructor.
 
Method Summary
 void cleanStringLabelCache()
          Cleans the sting label cache.
 AtRefRangeNumber getAlignX()
          Returns the horizontal alignment.
 AtRefRangeNumber getAlignY()
          Returns the vertical alignment.
 java.awt.Paint getBackground()
          Returns the background paint.
 javax.swing.border.Border getBorder()
          Returns the border.
 int getCellModulo()
          Returns the modulo for the cells to paint.
 DateFormatList getDateFormat()
          Returns the date format.
 DateGrid getDateGrid()
          Returns the date grid or null if it's not available.
 DateGridContainer getDateGridContainer()
          Returns the date grid container or null not available anymore.
 DateFormatList getFirstDateFormat()
          Property: Date format for the "first" of something, e.g.
 int getFirstInField()
          Property: If getFirstDateFormat() is != this is the Calendar field that is used to know what's "first".
 java.awt.Font getFont()
          Returns the font.
 java.awt.Paint getForeground()
          Returns the foreground paint.
protected  java.lang.String getLabelString(ImmutableDateRange dateRange, boolean isNow)
          Returns the label to draw for a cell that spans dateRange.
 java.awt.Dimension getMinimumCellSize()
          Return the minimum cell size to paint a label for.
 java.awt.Paint getNowBackground()
          Returns the background paint for cells that overlaps the "now" time from System.currentTimeMillis()..
 javax.swing.border.Border getNowBorder()
          Returns the border for cells that overlaps the "now" time from System.currentTimeMillis().
 DateFormatList getNowDateFormat()
          Returns the date format for cells that overlaps the "now" time from System.currentTimeMillis()..
 java.awt.Font getNowFont()
          Returns the font for cells that overlaps the "now" time from System.currentTimeMillis()..
 java.awt.Paint getNowForeground()
          Returns the foreground paint for cells that overlaps the "now" time from System.currentTimeMillis()..
 PlaceRect getNowPlaceRect()
          Optional correction to the cell rectangle.
 java.lang.Integer getNowRangeType()
          Property: The range type to round the "now" date to.
 java.awt.Paint getNowShadowForeground()
          The color that is used to draw the label shadow for "now" cell(s).
 java.awt.Point getNowShadowOffset()
          The offset that is used do displace the shadow for "now" cell(s).
 java.awt.Paint getShadowForeground()
          The color that is used to draw the label shadow.
 java.awt.Point getShadowOffset()
          The offset that is used do displace the shadow.
 int getTextAntiAlias()
          Property: The anti aliasing hint used when drawing the label.
 int getUlWidth()
          Returns the underline width.
 void gridChanged(java.beans.PropertyChangeEvent e)
          Called when the grid changes.
protected  void invalidateDateRange(ImmutableDateRange dateRange)
          Marks the cells that overlaps dateRange in the grid as invalid.
 boolean isAntiAlias()
          Deprecated. Use getTextAntiAlias()
protected  void paintCell(java.awt.Graphics2D g2, int r, int c, java.awt.Rectangle b)
          Paints the cell, or part thereof.
protected  void postPaint()
          Called after the last cell has been painted.
protected  boolean prePaint()
          Called before the first cell is painted.
 void setAlignX(AtRefRangeNumber alignX)
          Sets the horizontal alignment.
 void setAlignY(AtRefRangeNumber alignY)
          Sets the vertical alignment.
 void setAntiAlias(boolean antiAlias)
          Deprecated. Use setTextAntiAlias(int)
 void setBackground(java.awt.Paint p)
          Sets the background paint.
 void setBorder(javax.swing.border.Border b)
          Sets the border.
 void setCellModulo(int cellModulo)
          Sets the modulo for the cells to paint.
 void setDateFormat(DateFormatList df)
          Sets the date format for the label.
 void setFirstDateFormat(DateFormatList format)
          Property: Date format for the "first" of something, e.g.
 void setFirstInField(int calField)
          Property: If getFirstDateFormat() is != this is the Calendar field that is used to know what's "first".
 void setFont(java.awt.Font font)
          Set the font.
 void setForeground(java.awt.Paint fgPaint)
          Sets the foreground paint.
 void setMinimumCellSize(java.awt.Dimension minCellSize)
          Sets the minimum cell size to paint a label for.
 void setNowBackground(java.awt.Paint p)
          Sets the background paint for cells that overlaps the "now" time from System.currentTimeMillis()..
 void setNowBorder(javax.swing.border.Border b)
          Sets the border for cells that overlaps the "now" time from System.currentTimeMillis()..
 void setNowDateFormat(DateFormatList df)
          Sets the date format for the label for cells that overlaps the "now" time from System.currentTimeMillis()..
 void setNowFont(java.awt.Font f)
          Set the font for cells that overlaps the "now" time from System.currentTimeMillis()..
 void setNowForeground(java.awt.Paint p)
          Sets the foreground paint for cells that overlaps the "now" time from System.currentTimeMillis()..
 void setNowPlaceRect(PlaceRect rect)
          Optional correction to the cell rectangle.
 void setNowRangeType(java.lang.Integer rangeType)
          Property: The range type to round the "now" date to.
 void setNowShadowForeground(java.awt.Paint p)
          The color that is used to draw the label shadow for "now" cell(s).
 void setNowShadowOffset(java.awt.Point p)
          The offset that is used do displace the shadow for "now" cell(s).
 void setShadowForeground(java.awt.Paint p)
          The color that is used to draw the label shadow.
 void setShadowOffset(java.awt.Point p)
          The offset that is used do displace the shadow.
 void setTextAntiAlias(int hint)
          Property: The anti aliasing hint used when drawing the label.
 void setUlWidth(int ulWidth)
          Sets the underline width.
 boolean useStringLabelCache()
          Returns if the strings for every cell should be cached.
 
Methods inherited from class com.miginfocom.calendar.decorators.GridCellDecorator
createCellRects, doPaint, getPlaceRect, getSizeMode, setPlaceRect, setSizeMode
 
Methods inherited from class com.miginfocom.calendar.decorators.AbstractGridDecorator
compareTo, dispose, 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

CellLabelDecorator

public CellLabelDecorator(DateGridContainer gridContainer,
                          int layerIndex)
Default constructor.

Parameters:
gridContainer - The grid container to decorate. Not null.
layerIndex - A number to indicate the order in which to paint something. Lower if painted before. I.e. under.

CellLabelDecorator

public CellLabelDecorator(DateGridContainer gridContainer,
                          int layerIndex,
                          PlaceRect placeRect,
                          DateFormatList dateFormat,
                          java.awt.Font font,
                          java.awt.Paint fgPaint,
                          AtRefRangeNumber alignX,
                          AtRefRangeNumber alignY,
                          int ulWidth,
                          boolean antiAlias,
                          java.awt.Paint bgPaint)
Deprecated. Use the version which has an Object hint as anti alias.

Constructor.

Parameters:
gridContainer - The grid container to decorate. Not null.
layerIndex - A number to indicate the order in which to paint something. Lower if painted before. I.e. under.
placeRect - The rectangle within the cell to paint/draw label for.
dateFormat - The date format used for getting the label. Can be null. Remember to set correct Locale.
font - The font used to paint the label. Can be null.
fgPaint - The label paint. Both can be null.
alignX - Where within the relative rectangle the label should be painted. Can be null.
alignY - Where within the relative rectangle the label should be painted. Can be null.
ulWidth - The underline width. If 0 no underline.
antiAlias - If text anti aliasing should be turned on when drawing strings.
bgPaint - The background paint. Both can be null.

CellLabelDecorator

public CellLabelDecorator(DateGridContainer gridContainer,
                          int layerIndex,
                          PlaceRect placeRect,
                          DateFormatList dateFormat,
                          java.awt.Font font,
                          java.awt.Paint fgPaint,
                          AtRefRangeNumber alignX,
                          AtRefRangeNumber alignY,
                          int ulWidth,
                          int antiAliasHint,
                          java.awt.Paint bgPaint)
Constructor.

Parameters:
gridContainer - The grid container to decorate. Not null.
layerIndex - A number to indicate the order in which to paint something. Lower if painted before. I.e. under.
placeRect - The rectangle within the cell to paint/draw label for.
dateFormat - The date format used for getting the label. Can be null. Remember to set correct Locale.
font - The font used to paint the label. Can be null.
fgPaint - The label paint. Both can be null.
alignX - Where within the relative rectangle the label should be painted. Can be null.
alignY - Where within the relative rectangle the label should be painted. Can be null.
ulWidth - The underline width. If 0 no underline.
antiAliasHint - The anti aliasing hint. E.g. GfxUtil.AA_HINT_LCD_GASP.
bgPaint - The background paint. Both can be null.
Method Detail

paintCell

protected void paintCell(java.awt.Graphics2D g2,
                         int r,
                         int c,
                         java.awt.Rectangle b)
Description copied from class: GridCellDecorator
Paints the cell, or part thereof.

Specified by:
paintCell in class GridCellDecorator
Parameters:
g2 - The object to paint in. Paint may be changed and not restored for every call.
r - The row beeing painted.
c - The column beeing painted
b - The bounds of the cell, or part there of, to be painted.

prePaint

protected boolean prePaint()
Description copied from class: GridCellDecorator
Called before the first cell is painted. Possible to do setup.

Specified by:
prePaint in class GridCellDecorator
Returns:
If the paint should continue. If false GridCellDecorator.paintCell(java.awt.Graphics2D, int, int, java.awt.Rectangle) will not be called this round. GridCellDecorator.postPaint() will be called though.

postPaint

protected void postPaint()
Description copied from class: GridCellDecorator
Called after the last cell has been painted. Possible to dispose of resources.

Specified by:
postPaint in class GridCellDecorator

getCellModulo

public int getCellModulo()
Returns the modulo for the cells to paint. Calculated in the primary dimension. E.g. "2" will paint every second cell.

Returns:
The modulo for the cells to paint. Calculated in the primary dimension.

setCellModulo

public void setCellModulo(int cellModulo)
Sets the modulo for the cells to paint. Calculated in the primary dimension. E.g. "4" will paint every fourth cell.

Parameters:
cellModulo - The modulo for the cells to paint. Calculated in the primary dimension.

getMinimumCellSize

public java.awt.Dimension getMinimumCellSize()
Return the minimum cell size to paint a label for. Smaller in any dimension will not paint.

Returns:
The minimum cell size to paint a label for. Smaller in any dimension will not paint. May be null.

setMinimumCellSize

public void setMinimumCellSize(java.awt.Dimension minCellSize)
Sets the minimum cell size to paint a label for. Smaller in any dimension will not paint.

Parameters:
minCellSize - The minimum cell size to paint a label for. Smaller in any dimension will not paint. May be null.

getAlignX

public AtRefRangeNumber getAlignX()
Returns the horizontal alignment.

Returns:
The horizontal alignment. May be null.

setAlignX

public void setAlignX(AtRefRangeNumber alignX)
Sets the horizontal alignment.

Parameters:
alignX - The horizontal alignment. May be null.

getAlignY

public AtRefRangeNumber getAlignY()
Returns the vertical alignment.

Returns:
The vertical alignment. May be null.

setAlignY

public void setAlignY(AtRefRangeNumber alignY)
Sets the vertical alignment.

Parameters:
alignY - The vertical alignment. May be null.

getBorder

public javax.swing.border.Border getBorder()
Returns the border.

Returns:
The border. May be null.

setBorder

public void setBorder(javax.swing.border.Border b)
Sets the border.

Parameters:
b - The border. May be null.

getNowBorder

public javax.swing.border.Border getNowBorder()
Returns the border for cells that overlaps the "now" time from System.currentTimeMillis().

Returns:
The border. May be null.

setNowBorder

public void setNowBorder(javax.swing.border.Border b)
Sets the border for cells that overlaps the "now" time from System.currentTimeMillis()..

Parameters:
b - The border. May be null in which case no special value for now is used.

getNowPlaceRect

public PlaceRect getNowPlaceRect()
Optional correction to the cell rectangle. For instance to make the today cell bigger or smaller.

Returns:
The current value. null is default.
Since:
6.5

setNowPlaceRect

public void setNowPlaceRect(PlaceRect rect)
Optional correction to the cell rectangle. For instance to make the today cell bigger or smaller.

Parameters:
rect - The new value. null is default.
Since:
6.5

getBackground

public java.awt.Paint getBackground()
Returns the background paint.

Returns:
The background paint. May be null.

setBackground

public void setBackground(java.awt.Paint p)
Sets the background paint.

Parameters:
p - The background paint. May be null.

getNowBackground

public java.awt.Paint getNowBackground()
Returns the background paint for cells that overlaps the "now" time from System.currentTimeMillis()..

Returns:
The background paint. May be null.

setNowBackground

public void setNowBackground(java.awt.Paint p)
Sets the background paint for cells that overlaps the "now" time from System.currentTimeMillis()..

Parameters:
p - The background paint. May be null in which case no special value for now is used.

getForeground

public java.awt.Paint getForeground()
Returns the foreground paint.

Returns:
The foreground paint. May be null.

setForeground

public void setForeground(java.awt.Paint fgPaint)
Sets the foreground paint.

Parameters:
fgPaint - The foreground paint. May be null.

getNowForeground

public java.awt.Paint getNowForeground()
Returns the foreground paint for cells that overlaps the "now" time from System.currentTimeMillis()..

Returns:
The foreground paint. May be null.

setNowForeground

public void setNowForeground(java.awt.Paint p)
Sets the foreground paint for cells that overlaps the "now" time from System.currentTimeMillis()..

Parameters:
p - The foreground paint. May be null in which case no special value for now is used.

getDateFormat

public DateFormatList getDateFormat()
Returns the date format.

Returns:
The date format. May be null.

setDateFormat

public void setDateFormat(DateFormatList df)
Sets the date format for the label.

Parameters:
df - The date format for the label. May be null. Remember to set correct Locale.

getNowDateFormat

public DateFormatList getNowDateFormat()
Returns the date format for cells that overlaps the "now" time from System.currentTimeMillis()..

Returns:
The date format. May be null.

setNowDateFormat

public void setNowDateFormat(DateFormatList df)
Sets the date format for the label for cells that overlaps the "now" time from System.currentTimeMillis()..

Parameters:
df - The date format for the label. May be null in which case no special value for now is used. Remember to set correct Locale.

getFont

public java.awt.Font getFont()
Returns the font.

Returns:
The font. May be null.

setFont

public void setFont(java.awt.Font font)
Set the font.

Parameters:
font - The font. May be null.

getNowFont

public java.awt.Font getNowFont()
Returns the font for cells that overlaps the "now" time from System.currentTimeMillis()..

Returns:
The font. May be null.

setNowFont

public void setNowFont(java.awt.Font f)
Set the font for cells that overlaps the "now" time from System.currentTimeMillis()..

Parameters:
f - The font. May be null in which case no special value for now is used.

getUlWidth

public int getUlWidth()
Returns the underline width. 0 means none.

Returns:
The underline width.

setUlWidth

public void setUlWidth(int ulWidth)
Sets the underline width. 0 means none.

Parameters:
ulWidth - The underline width.

isAntiAlias

public boolean isAntiAlias()
Deprecated. Use getTextAntiAlias()

Returns whether to anti alias the label. Note that this only reflects if it is forced off. Default returns true.

Returns:
Whether to anti alias the label

setAntiAlias

public void setAntiAlias(boolean antiAlias)
Deprecated. Use setTextAntiAlias(int)

Sets whether to anti alias the label

Parameters:
antiAlias - Whether to anti alias the label

getTextAntiAlias

public int getTextAntiAlias()
Property: The anti aliasing hint used when drawing the label. For instance GfxUtil.AA_HINT_ON.

Returns:
The current hint.
See Also:
GfxUtil.AA_HINT_ON

setTextAntiAlias

public void setTextAntiAlias(int hint)
Property: The anti aliasing hint used when drawing the label.

Parameters:
hint - The new hint.
See Also:
GfxUtil.AA_HINT_ON

getNowRangeType

public java.lang.Integer getNowRangeType()
Property: The range type to round the "now" date to. Can for instance be set to DateRangeI.RANGE_TYPE_MONTH to make all the cells in a month be cosidered "now" and get the "now" font/background/foreground.

Returns:
The current range type or null if not set. E.g. DateRangeI.RANGE_TYPE_MONTH.

setNowRangeType

public void setNowRangeType(java.lang.Integer rangeType)
Property: The range type to round the "now" date to. Can for instance be set to DateRangeI.RANGE_TYPE_MONTH to make all the cells in a month be cosidered "now" and get the "now" font/background/foreground.

Parameters:
rangeType - E.g. DateRangeI.RANGE_TYPE_MONTH. null for no rounding.

getDateGridContainer

public DateGridContainer getDateGridContainer()
Returns the date grid container or null not available anymore.

Returns:
The date grid container

getDateGrid

public DateGrid getDateGrid()
Returns the date grid or null if it's not available.

Returns:
The date grid

getFirstDateFormat

public DateFormatList getFirstDateFormat()
Property: Date format for the "first" of something, e.g. first day of the month.

Returns:
Date format for the "first" of something, e.g. first day of the month.

setFirstDateFormat

public void setFirstDateFormat(DateFormatList format)
Property: Date format for the "first" of something, e.g. first day of the month.

Parameters:
format - Date format for the "first" of something, e.g. first day of the month.

getFirstInField

public int getFirstInField()
Property: If getFirstDateFormat() is != this is the Calendar field that is used to know what's "first".

Returns:
The range type. E.g. Calendar.DAY_OF_MONTH.

setFirstInField

public void setFirstInField(int calField)
Property: If getFirstDateFormat() is != this is the Calendar field that is used to know what's "first".

Parameters:
calField - The range type. E.g. Calendar.DAY_OF_MONTH.

getShadowForeground

public java.awt.Paint getShadowForeground()
The color that is used to draw the label shadow.

Returns:
The current value. null by default which means no shadow.
Since:
6.5

setShadowForeground

public void setShadowForeground(java.awt.Paint p)
The color that is used to draw the label shadow.

Parameters:
p - The new value. null by default which means no shadow.
Since:
6.5

getShadowOffset

public java.awt.Point getShadowOffset()
The offset that is used do displace the shadow.

Returns:
The current value. Point(0, 1) by default. Returns a clone, free to use.
Since:
6.5

setShadowOffset

public void setShadowOffset(java.awt.Point p)
The offset that is used do displace the shadow.

Parameters:
p - The new value. Point(0, 1) by default.
Since:
6.5

getNowShadowForeground

public java.awt.Paint getNowShadowForeground()
The color that is used to draw the label shadow for "now" cell(s).

Returns:
The current value. null by default which means no shadow.
Since:
6.5

setNowShadowForeground

public void setNowShadowForeground(java.awt.Paint p)
The color that is used to draw the label shadow for "now" cell(s).

Parameters:
p - The new value. null by default which means no shadow.
Since:
6.5

getNowShadowOffset

public java.awt.Point getNowShadowOffset()
The offset that is used do displace the shadow for "now" cell(s).

Returns:
The current value. Point(0, 1) by default. Returns a clone, free to use.
Since:
6.5

setNowShadowOffset

public void setNowShadowOffset(java.awt.Point p)
The offset that is used do displace the shadow for "now" cell(s).

Parameters:
p - The new value. Point(0, 1) by default.
Since:
6.5

getLabelString

protected java.lang.String getLabelString(ImmutableDateRange dateRange,
                                          boolean isNow)
Returns the label to draw for a cell that spans dateRange. Can be overridden to paint custom strings.

Parameters:
dateRange - The date range that the cell spans
isNow - If dateRange is overlapping "current time".
Returns:
The String to draw in the cell. Never null but if "" no label will be painted.

gridChanged

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

Overrides:
gridChanged in class GridCellDecorator
Parameters:
e - The event.

useStringLabelCache

public boolean useStringLabelCache()
Returns if the strings for every cell should be cached. Override and return false to never cache or call cleanStringLabelCache() to clean it if date format changes.

Returns:
If the strings for every cell should be cached.

cleanStringLabelCache

public void cleanStringLabelCache()
Cleans the sting label cache.


invalidateDateRange

protected void invalidateDateRange(ImmutableDateRange dateRange)
Marks the cells that overlaps dateRange in the grid as invalid.

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


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.