001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings;
014:
015: /**
016: * A basic icon-text compound
017: * where you can set an event by hand or which could be
018: * used as a base class to extend from.
019: *
020: * @author <a href="mailto:haaf@mercatis.de">Armin Haaf</a>
021: */
022: public class SClickable extends SAbstractClickable {
023:
024: /**
025: * if this is set (!=null) this event is rendered as anchor. If it is null,
026: * the anchor in the AnchorRenderStack is rendered
027: */
028: private String event;
029:
030: /**
031: * if this is set (!=null) this event is rendered as anchor. If it is null,
032: * the anchor in the AnchorRenderStack is rendered
033: */
034: private LowLevelEventListener requestTarget;
035:
036: /**
037: * Creates a new <code>SClickable</code> instance with the specified text
038: * (left alligned) and no icon.
039: *
040: * @param text The text to be displayed by the label.
041: */
042: public SClickable(String text) {
043: this (text, null, SConstants.LEFT);
044: }
045:
046: /**
047: * Creates a new <code>SClickable</code> instance with no text and no icon.
048: */
049: public SClickable() {
050: this ((String) null);
051: }
052:
053: /**
054: * Creates a new <code>SClickable</code> instance with the specified icon
055: * (left alligned) and no text.
056: *
057: * @param icon The image to be displayed by the label.
058: */
059: public SClickable(SIcon icon) {
060: this (icon, SConstants.LEFT);
061: }
062:
063: /**
064: * Creates a new <code>SClickable</code> instance with the specified icon
065: * (alligned as specified) and no text.
066: *
067: * @param icon The image to be displayed by the clickable.
068: * @param horizontalAlignment One of the following constants defined in
069: * <code>SConstants</code>:
070: * <code>LEFT</code>, <code>CENTER</code>, <code>RIGHT</code>.
071: * @see SConstants
072: */
073: public SClickable(SIcon icon, int horizontalAlignment) {
074: this (null, icon, horizontalAlignment);
075: }
076:
077: /**
078: * Creates a new <code>SClickable</code> instance with the specified icon
079: * and the specified text (left alligned).
080: *
081: * @param text The text to be displayed by the SClickable.
082: * @param icon The image to be displayed by the SClickable.
083: */
084: public SClickable(String text, SIcon icon) {
085: setText(text);
086: setIcon(icon);
087: setHorizontalAlignment(SConstants.LEFT);
088: }
089:
090: /**
091: * Creates a new <code>SClickable</code> instance with the specified icon
092: * and the specified text (alligned as specified).
093: *
094: * @param text The text to be displayed by the SClickable.
095: * @param icon The image to be displayed by the SClickable.
096: * @param horizontalAlignment One of the following constants defined in
097: * <code>SConstants</code>:
098: * <code>LEFT</code>, <code>CENTER</code>, <code>RIGHT</code>.
099: * @see SConstants
100: */
101: public SClickable(String text, SIcon icon, int horizontalAlignment) {
102: setText(text);
103: setIcon(icon);
104: setHorizontalAlignment(horizontalAlignment);
105: }
106:
107: /**
108: * Creates a new <code>SClickable</code> instance with the specified text
109: * (alligned as specified) and no icon.
110: *
111: * @param text The text to be displayed by the SClickable.
112: * @param horizontalAlignment One of the following constants defined in
113: * <code>SConstants</code>:
114: * <code>LEFT</code>, <code>CENTER</code>, <code>RIGHT</code>.
115: * @see SConstants
116: */
117: public SClickable(String text, int horizontalAlignment) {
118: this (text, null, horizontalAlignment);
119: }
120:
121: public boolean isEpochCheckEnabled() {
122: return requestTarget == null ? true : requestTarget
123: .isEpochCheckEnabled();
124: }
125:
126: /**
127: * if this is set (!=null) this event is rendered as anchor. If it is null,
128: * the anchor in the AnchorRenderStack is rendered
129: */
130: public final void setEvent(String event,
131: LowLevelEventListener requestTarget) {
132: setEvent(event);
133: setEventTarget(requestTarget);
134: }
135:
136: /**
137: * if this is set (!=null) this event is rendered as anchor. If it is null,
138: * the anchor in the AnchorRenderStack is rendered
139: */
140: public void setEvent(String e) {
141: if (isDifferent(event, e)) {
142: event = e;
143: reload();
144: }
145: }
146:
147: /**
148: * if this is set (!=null) this event is rendered as anchor. If it is null,
149: * the anchor in the AnchorRenderStack is rendered
150: */
151: public final String getEvent() {
152: return event;
153: }
154:
155: /**
156: * sets the LowLevelEventListener for which to create a event.
157: */
158: public void setEventTarget(LowLevelEventListener t) {
159: if (isDifferent(requestTarget, t)) {
160: requestTarget = t;
161: reload();
162: }
163: }
164:
165: /**
166: * if this is set (!=null) this event is rendered as anchor. If it is null,
167: * the anchor in the AnchorRenderStack is rendered
168: */
169: public final LowLevelEventListener getEventTarget() {
170: return requestTarget;
171: }
172:
173: public SimpleURL getURL() {
174: if (getEvent() != null && getEventTarget() != null) {
175: RequestURL u = getRequestURL();
176: if (!isEpochCheckEnabled()) {
177: u.setEventEpoch(null);
178: u.setResource(null);
179: }
180:
181: u.addParameter(getEventTarget(), getEvent());
182: return u;
183: } else {
184: return null;
185: }
186: }
187:
188: }
|