1
|
|
/*
|
2
|
|
* Angkor Web Framework
|
3
|
|
*
|
4
|
|
* Distributable under LGPL license.
|
5
|
|
* See terms of license at gnu.org.
|
6
|
|
*/
|
7
|
|
|
8
|
|
package com.tirsen.angkor.widget;
|
9
|
|
|
10
|
|
import com.tirsen.angkor.RenderContext;
|
11
|
|
import com.tirsen.angkor.Component;
|
12
|
|
import com.tirsen.angkor.event.Action;
|
13
|
|
import com.tirsen.angkor.event.ActionListener;
|
14
|
|
import com.tirsen.angkor.event.ActionSource;
|
15
|
|
import com.tirsen.angkor.event.ActionSourceHelper;
|
16
|
|
|
17
|
|
import java.io.IOException;
|
18
|
|
|
19
|
|
/**
|
20
|
|
* <!-- $Id: ImageButton.java,v 1.4 2002/10/13 19:59:23 tirsen Exp $ -->
|
21
|
|
* <!-- $Author: tirsen $ -->
|
22
|
|
*
|
23
|
|
* @author Jon Tirs´n (tirsen@users.sourceforge.net)
|
24
|
|
* @version $Revision: 1.4 $
|
25
|
|
*/
|
26
|
|
public class ImageButton extends Component implements ActionSource
|
27
|
|
{
|
28
|
|
private ActionSourceHelper actionSourceHelper = new ActionSourceHelper(this);
|
29
|
|
private String imageURL;
|
30
|
|
|
31
|
0
|
public ImageButton(String id)
|
32
|
|
{
|
33
|
0
|
super(id);
|
34
|
|
}
|
35
|
|
|
36
|
0
|
public ImageButton()
|
37
|
|
{
|
38
|
|
}
|
39
|
|
|
40
|
0
|
public ImageButton(Action action)
|
41
|
|
{
|
42
|
0
|
setAction(action);
|
43
|
|
}
|
44
|
|
|
45
|
0
|
public void setAction(Action action)
|
46
|
|
{
|
47
|
0
|
actionSourceHelper.setAction(action);
|
48
|
|
}
|
49
|
|
|
50
|
0
|
public Action getAction()
|
51
|
|
{
|
52
|
0
|
return actionSourceHelper.getAction();
|
53
|
|
}
|
54
|
|
|
55
|
0
|
public void addActionListener(ActionListener listener)
|
56
|
|
{
|
57
|
0
|
actionSourceHelper.addActionListener(listener);
|
58
|
|
}
|
59
|
|
|
60
|
0
|
public void removeActionListener(ActionListener listener)
|
61
|
|
{
|
62
|
0
|
actionSourceHelper.removeActionListener(listener);
|
63
|
|
}
|
64
|
|
|
65
|
0
|
public void signalActionEvent()
|
66
|
|
{
|
67
|
0
|
actionSourceHelper.signalActionEvent();
|
68
|
|
}
|
69
|
|
|
70
|
0
|
public void setImageURL(String label)
|
71
|
|
{
|
72
|
0
|
this.imageURL = label;
|
73
|
|
}
|
74
|
|
|
75
|
0
|
public boolean isParsing()
|
76
|
|
{
|
77
|
0
|
return true;
|
78
|
|
}
|
79
|
|
|
80
|
0
|
public String getImageURL()
|
81
|
|
{
|
82
|
0
|
String resultingImageURL = null;
|
83
|
|
|
84
|
0
|
if (imageURL != null)
|
85
|
|
{
|
86
|
0
|
resultingImageURL = imageURL;
|
87
|
|
}
|
88
|
|
else
|
89
|
|
{
|
90
|
0
|
if (getAction() != null) resultingImageURL = (String) getAction().getValue(Action.IMAGE_URL);
|
91
|
|
}
|
92
|
|
|
93
|
0
|
return resultingImageURL;
|
94
|
|
}
|
95
|
|
|
96
|
0
|
public String toString()
|
97
|
|
{
|
98
|
0
|
return getClass().getName() + "[" + getAction() + "]";
|
99
|
|
}
|
100
|
|
|
101
|
0
|
public void render(RenderContext context) throws IOException
|
102
|
|
{
|
103
|
0
|
if (isVisible())
|
104
|
|
{
|
105
|
0
|
context.startTag("INPUT name=\"" + uniqueId(context) + "\" border=\"0\" type=\"image\" src=\"" + getImageURL() + "\"");
|
106
|
0
|
context.registerParsingComponent(this);
|
107
|
|
}
|
108
|
|
}
|
109
|
|
|
110
|
0
|
public void parse(RenderContext context)
|
111
|
|
{
|
112
|
0
|
super.parse(context);
|
113
|
0
|
if (context.getRequestParameter(getId() + ".x") != null)
|
114
|
|
{
|
115
|
0
|
actionSourceHelper.signalActionEvent(context);
|
116
|
|
}
|
117
|
|
}
|
118
|
|
}
|
119
|
|
|