1
|
|
package com.tirsen.angkor.widget;
|
2
|
|
|
3
|
|
import com.tirsen.angkor.Debug;
|
4
|
|
import com.tirsen.angkor.RenderContext;
|
5
|
|
import com.tirsen.angkor.View;
|
6
|
|
import com.tirsen.angkor.Component;
|
7
|
|
import com.tirsen.angkor.event.Action;
|
8
|
|
import com.tirsen.angkor.event.ActionListener;
|
9
|
|
import com.tirsen.angkor.event.ActionSource;
|
10
|
|
import com.tirsen.angkor.event.ActionSourceHelper;
|
11
|
|
import org.apache.log4j.Category;
|
12
|
|
|
13
|
|
import java.io.IOException;
|
14
|
|
|
15
|
|
/**
|
16
|
|
* @author $Author: tirsen $
|
17
|
|
* @version $Revision: 1.6 $
|
18
|
|
* <BR>
|
19
|
|
* $Id: ImageMap.java,v 1.6 2002/10/13 19:59:23 tirsen Exp $
|
20
|
|
*/
|
21
|
|
public class ImageMap extends Container
|
22
|
|
{
|
23
|
|
private static final Category logger = Category.getInstance(Debug.LOGGER_NAME);
|
24
|
|
|
25
|
0
|
public void add(int index, View element)
|
26
|
|
{
|
27
|
0
|
if (element instanceof Area)
|
28
|
0
|
super.add(index, element);
|
29
|
|
else
|
30
|
0
|
throw new IllegalArgumentException("A image-map can only contain ImageMap.Areas");
|
31
|
|
}
|
32
|
|
|
33
|
|
public static class Area extends Component implements ActionSource
|
34
|
|
{
|
35
|
|
private ActionSourceHelper actionSourceHelper = new ActionSourceHelper(this);
|
36
|
|
private int x1,y1,x2,y2;
|
37
|
|
|
38
|
0
|
public Area(Action action, int x1, int y1, int x2, int y2)
|
39
|
|
{
|
40
|
0
|
actionSourceHelper.setAction(action);
|
41
|
0
|
this.x1 = x1;
|
42
|
0
|
this.y1 = y1;
|
43
|
0
|
this.x2 = x2;
|
44
|
0
|
this.y2 = y2;
|
45
|
|
}
|
46
|
|
|
47
|
0
|
public String getAlt()
|
48
|
|
{
|
49
|
0
|
if (getAction() == null)
|
50
|
0
|
return null;
|
51
|
|
else
|
52
|
0
|
return (String) getAction().getValue(Action.NAME);
|
53
|
|
}
|
54
|
|
|
55
|
0
|
public void render(RenderContext context) throws IOException
|
56
|
|
{
|
57
|
0
|
logger.debug(">>> Area.render");
|
58
|
0
|
context.emptyTag("area href=\"" + context.getRequestPath() + "?" + uniqueId(context) + "=clicked\" " +
|
59
|
|
((getAlt() == null) ? "" : ("alt=\"" + getAlt() + "\" ")) +
|
60
|
|
"coords=\"" + x1 + "," + y1 + "," + x2 + "," + y2 + "\"");
|
61
|
0
|
context.registerParsingComponent(this);
|
62
|
0
|
logger.debug("<<< Area.render");
|
63
|
|
}
|
64
|
|
|
65
|
0
|
public boolean isParsing()
|
66
|
|
{
|
67
|
0
|
return true;
|
68
|
|
}
|
69
|
|
|
70
|
0
|
public void parse(RenderContext context)
|
71
|
|
{
|
72
|
0
|
super.parse(context);
|
73
|
0
|
if (context.getRequestParameter(getId()) != null)
|
74
|
|
{
|
75
|
0
|
actionSourceHelper.signalActionEvent(context);
|
76
|
|
}
|
77
|
|
}
|
78
|
|
|
79
|
0
|
public void removeActionListener(ActionListener listener)
|
80
|
|
{
|
81
|
0
|
actionSourceHelper.removeActionListener(listener);
|
82
|
|
}
|
83
|
|
|
84
|
0
|
public void addActionListener(ActionListener listener)
|
85
|
|
{
|
86
|
0
|
actionSourceHelper.addActionListener(listener);
|
87
|
|
}
|
88
|
|
|
89
|
0
|
public void setAction(Action action)
|
90
|
|
{
|
91
|
0
|
actionSourceHelper.setAction(action);
|
92
|
|
}
|
93
|
|
|
94
|
0
|
public Action getAction()
|
95
|
|
{
|
96
|
0
|
return actionSourceHelper.getAction();
|
97
|
|
}
|
98
|
|
|
99
|
0
|
public void signalActionEvent()
|
100
|
|
{
|
101
|
0
|
actionSourceHelper.signalActionEvent();
|
102
|
|
}
|
103
|
|
}
|
104
|
|
|
105
|
0
|
public void render(RenderContext context) throws IOException
|
106
|
|
{
|
107
|
0
|
logger.debug(">>> ImageMap.render");
|
108
|
0
|
context.startTag("map name=\"" + uniqueId(context) + "\"");
|
109
|
0
|
renderChildren(context);
|
110
|
0
|
context.endTag("map");
|
111
|
0
|
logger.debug("<<< ImageMap.render");
|
112
|
|
}
|
113
|
|
}
|
114
|
|
|