001: /*
002: * de.jwic.controls.ButtonControl
003: * $Id: ButtonControl.java,v 1.6 2007/03/28 08:54:24 lordsam Exp $
004: */
005: package de.jwic.controls;
006:
007: import de.jwic.base.IControlContainer;
008: import de.jwic.base.ImageRef;
009:
010: /**
011: * Represents the <button> html element. A button displays text and/or
012: * an image.
013: *
014: * @author Florian Lippisch
015: * @version $Revision: 1.6 $
016: */
017: public class ButtonControl extends SelectableControl {
018:
019: private static final long serialVersionUID = 1L;
020:
021: public final static String ICON_DIS_SUFIX = "_dis";
022:
023: private String title = null;
024: private ImageRef iconEnabled = null;
025: private ImageRef iconDisabled = null;
026: private int result = 0;
027: private boolean submitButton = false;
028: private String iconInfo = null;
029: private String confirmMsg = "";
030:
031: /**
032: * @param container
033: */
034: public ButtonControl(IControlContainer container) {
035: super (container);
036: init();
037: }
038:
039: /**
040: * @param container
041: * @param name
042: */
043: public ButtonControl(IControlContainer container, String name) {
044: super (container, name);
045: init();
046: }
047:
048: /* (non-Javadoc)
049: * @see de.jwic.base.Control#init()
050: */
051: private void init() {
052: if (title == null) {
053: title = getName();
054: }
055: }
056:
057: /* (non-Javadoc)
058: * @see de.jwic.base.Control#actionPerformed(java.lang.String, java.lang.String)
059: */
060: public void actionPerformed(String actionId, String parameter) {
061:
062: click();
063:
064: }
065:
066: /**
067: * @return Returns the title.
068: */
069: public String getTitle() {
070: return title;
071: }
072:
073: /**
074: * @param title The title to set.
075: */
076: public void setTitle(String title) {
077: this .title = title;
078: setRequireRedraw(true);
079: }
080:
081: /**
082: * @return Returns the iconID.
083: * @deprecated use iconEnabled property
084: */
085: public String getIconEnID() {
086: return iconEnabled != null ? iconEnabled.getPath() : null;
087: }
088:
089: /**
090: * @param iconID The iconID to set.
091: * @deprecated use iconEnabled property
092: */
093: public void setIconEnID(String iconID) {
094: this .iconEnabled = new ImageRef(iconID);
095: }
096:
097: /**
098: * @return Returns the iconDisID.
099: * @deprecated use iconDisabled property.
100: */
101: public String getIconDisID() {
102: return iconDisabled != null ? iconDisabled.getPath() : null;
103: }
104:
105: /**
106: * @param iconDisID The iconDisID to set.
107: * @deprecated use iconDisabled property
108: */
109: public void setIconDisID(String iconDisID) {
110: this .iconDisabled = new ImageRef(iconDisID);
111: }
112:
113: /**
114: * @return the complete url for the icon to display
115: * @deprecated use getIcon()
116: */
117: public String getIconUrl() {
118: String relativeUrl = getIconEnID();
119:
120: if (!isEnabled()) {
121: if (null != getIconDisID())
122: relativeUrl = getIconDisID();
123: }
124:
125: return relativeUrl;
126: }
127:
128: /**
129: * Returns the icon for the button depending on the state.
130: * @return
131: */
132: public ImageRef getIcon() {
133: if (!isEnabled()) {
134: return iconDisabled != null ? iconDisabled : iconEnabled;
135: } else {
136: return iconEnabled;
137: }
138: }
139:
140: /**
141: * Returns true if an icon is specified.
142: * @return
143: */
144: public boolean hasIcon() {
145: return iconEnabled != null;
146: }
147:
148: /**
149: * @return Returns the result.
150: */
151: public int getResult() {
152: return result;
153: }
154:
155: /**
156: * @param result The result to set.
157: */
158: public void setResult(int result) {
159: this .result = result;
160: }
161:
162: /**
163: * Returns true if the button should behave like a submit button.
164: * @return boolean
165: */
166: public boolean isSubmitButton() {
167: return submitButton;
168: }
169:
170: /**
171: * Set to true if the button should be of the type submit.
172: * @param submitButton The submitButton to set.
173: */
174: public void setSubmitButton(boolean submitButton) {
175: this .submitButton = submitButton;
176: }
177:
178: /**
179: * @return Returns the iconInfo.
180: */
181: public String getIconInfo() {
182: return iconInfo;
183: }
184:
185: /**
186: * @param iconInfo The iconInfo to set.
187: */
188: public void setIconInfo(String iconInfo) {
189: this .iconInfo = iconInfo;
190: }
191:
192: /**
193: * @return Returns the confirmMsg.
194: */
195: public String getConfirmMsg() {
196: return confirmMsg;
197: }
198:
199: /**
200: * @param confirmMsg The confirmMsg to set.
201: */
202: public void setConfirmMsg(String confirmMsg) {
203: this .confirmMsg = confirmMsg;
204: }
205:
206: /**
207: * Set the width of the button as css style.
208: * The width value is now handled as an int as it is specified within the IHTMLElement
209: * interface.
210: * @param width The width to set.
211: * @deprecated
212: */
213: public void setWidth(String width) {
214: if (width.endsWith("px")) {
215: setWidth(Integer.parseInt(width.substring(0,
216: width.length() - 2)));
217: } else {
218: setWidth(Integer.parseInt(width));
219: }
220: }
221:
222: /**
223: * @return the iconDisabled
224: */
225: public ImageRef getIconDisabled() {
226: return iconDisabled;
227: }
228:
229: /**
230: * @param iconDisabled the iconDisabled to set
231: */
232: public void setIconDisabled(ImageRef iconDisabled) {
233: this .iconDisabled = iconDisabled;
234: }
235:
236: /**
237: * @return the iconEnabled
238: */
239: public ImageRef getIconEnabled() {
240: return iconEnabled;
241: }
242:
243: /**
244: * @param iconEnabled the iconEnabled to set
245: */
246: public void setIconEnabled(ImageRef iconEnabled) {
247: this.iconEnabled = iconEnabled;
248: }
249: }
|