MiG InfoCom MiG Calendar JavaBeans Guide User Manual

Page 43

Advertising
background image

MiG InfoCom AB

repaint them selves accordingly. This is a very powerful
design that makes fast and resource effective user
interactions possible with almost no restrictions.

There are quite a few Decorators in the framework, some of
them are abstract with helper functionality that can be
extended and used. See the JavaDoc for each class for how
to use it. AbstractGridDecorator is a good place to start.
Extend that to implement a generic Decorator. Note that
you will have to provide a reference to a GridContainer,
which can be DateArea or AbstractGridHeader.

All decorators should contain a layer index and in its
Comparable interface compare that layer index to the layer
index of another Decorator. The code normally looks like
this:

public int compareTo(Object o)

{
return getLayerIndex() - ((Decorator) o).getLayerIndex();

}

To add your custom decorator call addDecorator(..) on the
DefaultDateArea or AbstractGridHeader depending on
where you want your Decorator (i.e. if you are decorating
the date area or a header). Most Header classes are actually
descendants from AbstractGridHeader so they can have
decorators.

To for instance create a Decorator that paints the
background light blue between two date/times in the date
area it this simple:

Decorator decorator = new AbstractGridDecorator(dateArea, 20) {

public void doPaint(Graphics2D g2, Rectangle bounds)

{

DateGrid dateGrid = (DateGrid) getGrid();

DateRangeI dr = new DateRange(System.currentTimeMillis(),

DateRangeI.RANGE_TYPE_HOUR, 2, null, null);

Rectangle[] rects = dateGrid.getBoundsForDateRange(dr,

Grid.SIZE_MODE_INSIDE);

g2.setColor(new Color(240, 240, 255));

for (int i = 0; i < rects.length; i++)

g2.fill(rects[i]);

MiG Calendar JavaBeans Guide

Page 43 / 45

Advertising