beautypg.com

Decorators – MiG InfoCom MiG Calendar Getting Started Guide User Manual

Page 28

background image

MiG InfoCom AB

any interactions on it, see the

AShape Tutorial

for information

on how to do this.
If all we want to do is fill blue rectangles there is a faster

way, the #2 in the list above. It might be used to paint a

great number of read only activities with extreme speed.

// Setting a new renderer as defined below.
container.getDateArea().setActivityViewRenderer(new BlueRectangleRenderer());

// add outside a method declaration in your class
static class BlueRectangleRenderer implements ActivityViewRenderer
{
private final Insets REPAINT_MARGIN = new Insets(1, 1, 1, 1);

public void paint(Graphics2D g2, Rectangle bounds, TimeSpanList actViewList)
{
Paint oldPaint = g2.getPaint();
g2.setColor(Color.BLUE);
Rectangle clip = g2.getClipBounds();

for (int ix = 0, ixSz = actViewList.size(); ix < ixSz; ix++) {
ActivityView actView = (ActivityView) actViewList.get(ix);

Rectangle[] actBnds = actView.getBounds();
if (actBnds != null) {
for (int i = 0; i < actBnds.length; i++) {
Rectangle actBnd = actBnds[i];
if(actBnd != null && clip.intersects(actBnd)) {
g2.fill(actBnd); // The actual paint code! Exchange for something better...
}
}
}
}
g2.setPaint(oldPaint);
}

public Insets getRepaintMargin()
{
return REPAINT_MARGIN;
}
}

You now have the basics for changing the

AShape

s for you

own, and even for implementing you own proprietary paint

algorithm.
In the demo source that was installed with the component

you can look at

AShapeCreator

source code. It contains

some example

AShape

s.

Decorators

The Basics
You have already used a couple of decorators above, but

MiG Calendar Getting Started Guide

Page 28 / 31