KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > SClickable


1 /*
2  * $Id: SClickable.java,v 1.7 2005/05/26 13:18:08 neurolabs Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings;
15
16
17 /**
18  * An icon-text compound, where you can set an event by hand or which could be
19  * used as
20  *
21  * @author <a HREF="mailto:haaf@mercatis.de">Armin Haaf</a>
22  * @version $Revision: 1.7 $
23  */

24 public class SClickable
25         extends SAbstractClickable {
26
27     /**
28      * if this is set (!=null) this event is rendered as anchor. If it is null,
29      * the anchor in the AnchorRenderStack is rendered
30      */

31     private String JavaDoc event;
32
33     /**
34      * if this is set (!=null) this event is rendered as anchor. If it is null,
35      * the anchor in the AnchorRenderStack is rendered
36      */

37     private LowLevelEventListener requestTarget;
38
39     /**
40      * Creates a new <code>SClickable</code> instance with the specified text
41      * (left alligned) and no icon.
42      *
43      * @param text The text to be displayed by the label.
44      */

45     public SClickable(String JavaDoc text) {
46         this(text, null, SConstants.LEFT);
47     }
48
49     /**
50      * Creates a new <code>SClickable</code> instance with no text and no icon.
51      */

52     public SClickable() {
53         this((String JavaDoc) null);
54     }
55
56     /**
57      * Creates a new <code>SClickable</code> instance with the specified icon
58      * (left alligned) and no text.
59      *
60      * @param icon The image to be displayed by the label.
61      */

62     public SClickable(SIcon icon) {
63         this(icon, SConstants.LEFT);
64     }
65
66     /**
67      * Creates a new <code>SClickable</code> instance with the specified icon
68      * (alligned as specified) and no text.
69      *
70      * @param icon The image to be displayed by the clickable.
71      * @param horizontalAlignment One of the following constants defined in
72      * <code>SConstants</code>:
73      * <code>LEFT</code>, <code>CENTER</code>, <code>RIGHT</code>.
74      * @see SConstants
75      */

76     public SClickable(SIcon icon, int horizontalAlignment) {
77         this(null, icon, horizontalAlignment);
78     }
79
80     /**
81      * Creates a new <code>SClickable</code> instance with the specified icon
82      * and the specified text (left alligned).
83      *
84      * @param text The text to be displayed by the SClickable.
85      * @param icon The image to be displayed by the SClickable.
86      */

87     public SClickable(String JavaDoc text, SIcon icon) {
88         setText(text);
89         setIcon(icon);
90         setHorizontalAlignment(SConstants.LEFT);
91     }
92
93     /**
94      * Creates a new <code>SClickable</code> instance with the specified icon
95      * and the specified text (alligned as specified).
96      *
97      * @param text The text to be displayed by the SClickable.
98      * @param icon The image to be displayed by the SClickable.
99      * @param horizontalAlignment One of the following constants defined in
100      * <code>SConstants</code>:
101      * <code>LEFT</code>, <code>CENTER</code>, <code>RIGHT</code>.
102      * @see SConstants
103      */

104     public SClickable(String JavaDoc text, SIcon icon, int horizontalAlignment) {
105         setText(text);
106         setIcon(icon);
107         setHorizontalAlignment(horizontalAlignment);
108     }
109
110     /**
111      * Creates a new <code>SClickable</code> instance with the specified text
112      * (alligned as specified) and no icon.
113      *
114      * @param text The text to be displayed by the SClickable.
115      * @param horizontalAlignment One of the following constants defined in
116      * <code>SConstants</code>:
117      * <code>LEFT</code>, <code>CENTER</code>, <code>RIGHT</code>.
118      * @see SConstants
119      */

120     public SClickable(String JavaDoc text, int horizontalAlignment) {
121         this(text, null, horizontalAlignment);
122     }
123
124     public boolean isEpochCheckEnabled() {
125         return requestTarget == null ? true : requestTarget.isEpochCheckEnabled();
126     }
127
128     /**
129      * if this is set (!=null) this event is rendered as anchor. If it is null,
130      * the anchor in the AnchorRenderStack is rendered
131      */

132     public final void setEvent(String JavaDoc event, LowLevelEventListener requestTarget) {
133         setEvent(event);
134         setEventTarget(requestTarget);
135     }
136
137     /**
138      * if this is set (!=null) this event is rendered as anchor. If it is null,
139      * the anchor in the AnchorRenderStack is rendered
140      */

141     public void setEvent(String JavaDoc e) {
142         if (isDifferent(event, e)) {
143             event = e;
144             reload();
145         }
146     }
147
148     /**
149      * if this is set (!=null) this event is rendered as anchor. If it is null,
150      * the anchor in the AnchorRenderStack is rendered
151      */

152     public final String JavaDoc getEvent() {
153         return event;
154     }
155
156     /**
157      * sets the LowLevelEventListener for which to create a event.
158      */

159     public void setEventTarget(LowLevelEventListener t) {
160         if (isDifferent(requestTarget, t)) {
161             requestTarget = t;
162             reload();
163         }
164     }
165
166     /**
167      * if this is set (!=null) this event is rendered as anchor. If it is null,
168      * the anchor in the AnchorRenderStack is rendered
169      */

170     public final LowLevelEventListener getEventTarget() {
171         return requestTarget;
172     }
173
174     public SimpleURL getURL() {
175         if (getEvent() != null && getEventTarget() != null) {
176             RequestURL u = getRequestURL();
177             if (!isEpochCheckEnabled()) {
178                 u.setEpoch(null);
179                 u.setResource(null);
180             }
181
182             u.addParameter(getEventTarget(),
183                     getEvent());
184             return u;
185         } else {
186             return null;
187         }
188     }
189
190
191 }
192
193
194
Popular Tags