Example 5 : Image Map with DirectLink Actions
This example shows, how to add DirectLink actions to a DynamicImage
- This is the same stuff as in the previous examples. But here some DirectLink actions are added to the areas
Note
This is static documentation. The image below is just a screenshot.
You can see this example live

MapDirectLink.html
<h3><span jwcid="@Insert" value="ognl:notice">Click the shapes to see the action....</span></h3>
<img jwcid="@sotacs:DynamicImage" hasMap="ognl:true" listener="listener:listenToMapHits"
parameters="ognl:{100, 80, 150}"
height="200" width="200" painter="painter:paintme" />
MapDirectLink.java
public abstract class MapDirectLink extends BasePage{
@InitialValue("literal:Click the shapes to see the action....")
public abstract void setNotice(String msg);
public void listenToMapHits(IRequestCycle cycle, String arg){
setNotice(arg + " was invoked");
}
public void paintme(Graphics2D g2d, IPainterContext context){
// Enable antialiasing for shapes
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
//white background
g2d.setColor(Color.WHITE);
g2d.fillRect(0,0, context.getWidth(), context.getHeight());
//draw the time string
g2d.setColor(Color.BLACK);
g2d.drawString("produced " + new Date(), 0, 180);
//draw a green triangle
g2d.setColor(Color.GREEN);
Polygon triangle = new Polygon(new int[]{130, 150, 170}, new int[]{0, 60, 0},3);
g2d.fill(triangle);
//and declare the image map area
MapArea area = new PolygonMapArea(triangle);
area.setTooltip("This is a green triangle");
area.setDirectLinkArgument("Green Triangle");
context.addMapArea(area);
//draw a black circle
g2d.setColor(Color.BLACK);
g2d.fillOval(0, 0, 60, 60);
//... and declare the image map area
area = new CircleMapArea(30,30,30);
area.setTooltip("This is a black circle");
area.setDirectLinkArgument("Black Circle");
context.addMapArea(area);
//draw the 3 bars
Color[] colors = new Color[]{Color.RED, Color.BLUE, Color.BLUE.darker()};
Rectangle[] bars = new Rectangle[3];
for (int i = 0; i < 3; i++) {
int value = (Integer)context.getParameters()[i];
g2d.setColor(colors[i]);
bars[i] = new Rectangle(0, 80 + 30 * i, value, 20);
g2d.fill(bars[i]);
//... and declare the image map area
area = new RectangleMapArea(bars[i]);
area.setTooltip("results of 200" + i);
area.setDirectLinkArgument("Bar Results of 200" + i);
context.addMapArea(area);
}
}
}
