1 package com.tirsen.angkor.widget;
2
3 import com.tirsen.angkor.RenderContext;
4 import com.tirsen.angkor.Component;
5 import com.tirsen.angkor.event.Action;
6 import com.tirsen.angkor.event.ActionListener;
7 import com.tirsen.angkor.event.ActionSource;
8 import com.tirsen.angkor.event.ActionSourceHelper;
9
10 import java.io.IOException;
11
12 /***
13 * @author $Author: tirsen $
14 * @version $Revision: 1.6 $
15 * <BR>
16 * $Id: Button.java,v 1.6 2002/10/13 19:59:22 tirsen Exp $
17 */
18 public class Button extends Component implements ActionSource
19 {
20 private ActionSourceHelper actionSourceHelper = new ActionSourceHelper(this);
21 private String label;
22
23 public Button(String id)
24 {
25 super(id);
26 }
27
28 public Button()
29 {
30 }
31
32 public Button(Action action)
33 {
34 actionSourceHelper.setAction(action);
35 }
36
37 public void setAction(Action action)
38 {
39 actionSourceHelper.setAction(action);
40 }
41
42 public Action getAction()
43 {
44 return actionSourceHelper.getAction();
45 }
46
47 public void addActionListener(ActionListener listener)
48 {
49 actionSourceHelper.addActionListener(listener);
50 }
51
52 public void removeActionListener(ActionListener listener)
53 {
54 actionSourceHelper.removeActionListener(listener);
55 }
56
57 public void signalActionEvent()
58 {
59 actionSourceHelper.signalActionEvent();
60 }
61
62 public void setLabel(String label)
63 {
64 this.label = label;
65 }
66
67 public boolean isParsing()
68 {
69 return true;
70 }
71
72 public void parse(RenderContext context)
73 {
74 super.parse(context);
75 if (context.getRequestParameter(getId()) != null)
76 {
77 actionSourceHelper.signalActionEvent(context);
78 }
79 }
80
81 public String getLabel()
82 {
83 String actualLabel = null;
84
85 if (label != null)
86 {
87 actualLabel = label;
88 }
89 else
90 {
91 if (getAction() != null) actualLabel = (String) getAction().getValue(Action.NAME);
92 }
93
94 return actualLabel;
95 }
96
97 public void render(RenderContext context) throws IOException
98 {
99 if (isVisible())
100 {
101 context.startTag("INPUT name=\"" + uniqueId(context) + "\" type=\"submit\" value=\"" + getLabel() + "\"");
102 context.getApplication().registerParsingComponent(this);
103 }
104 }
105
106 public String toString()
107 {
108 return getClass().getName() + "[" + label + "]";
109 }
110 }
This page was automatically generated by Maven