001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020: package com.salmonllc.html;
021:
022: /////////////////////////
023: //$Archive: /SOFIA/SourceCode/com/salmonllc/html/HtmlButton.java $
024: //$Author: Dan $
025: //$Revision: 17 $
026: //$Modtime: 9/30/04 5:50p $
027: /////////////////////////
028:
029: import com.salmonllc.properties.*;
030:
031: /**
032: * This class will generate an html button. The button will execute some javascript when clicked.
033: */
034: public class HtmlButton extends HtmlComponent {
035: String _dispName = "";
036: String _onClick = "";
037: private String _fontTagStart = null;
038: private String _fontTagEnd = null;
039: private String _theme;
040: private boolean _enabled = true;
041: private String _buttonBgColor = null;
042: private String _buttonFontStyle = null;
043: private Integer _tabIndex;
044: private String _accessKey;
045: private String _onDoubleClick = null;
046: private String _onMouseDown = null;
047:
048: /**
049: * @return Returns the onDoubleClick.
050: */
051: public String getOnDoubleClick() {
052: return _onDoubleClick;
053: }
054:
055: /**
056: * @param onDoubleClick The onDoubleClick to set.
057: */
058: public void setOnDoubleClick(String onDoubleClick) {
059: _onDoubleClick = onDoubleClick;
060: }
061:
062: /**
063: * Constructs a new Button.
064: * @param name Each component on a page must have a unique name.
065: * @param dispName The text to appear on the button.
066: * @param onClick The javascript to execute when the button is clicked.
067: * @param p A Props object that will be used to initialize any properties in the object.
068: */
069: public HtmlButton(String name, String dispName, String onClick,
070: HtmlPage p) {
071: this (name, dispName, onClick, null, p);
072: }
073:
074: /**
075: * Constructs a new Button.
076: * @param name Each component on a page must have a unique name.
077: * @param dispName The text to appear on the button.
078: * @param onClick The javascript to execute when the button is clicked.
079: * @param theme The theme to use for loading properties.
080: * @param p A Props object that will be used to initialize any properties in the object.
081: */
082: public HtmlButton(String name, String dispName, String onClick,
083: String theme, HtmlPage p) {
084: super (name, p);
085: _dispName = dispName;
086: _onClick = onClick;
087: setTheme(theme);
088: }
089:
090: public void generateHTML(java.io.PrintWriter p, int rowNo)
091: throws Exception {
092: if (!getVisible())
093: return;
094:
095: String style = null;
096: if (_buttonBgColor != null || _buttonFontStyle != null) {
097: style = " style=\"";
098: if (_buttonBgColor != null)
099: style += "background-color:" + _buttonBgColor + ";";
100: if (_buttonFontStyle != null)
101: style += _buttonFontStyle;
102: style += "\"";
103: }
104: String out = "<INPUT TYPE=\"BUTTON\" name=\"" + getFullName()
105: + "\" value=\"" + _dispName + "\"";
106: if (_onClick != null)
107: out += " onClick=\"" + _onClick + "\"";
108: if (_class != null && !_class.trim().equals(""))
109: out += " class=\"" + _class + "\"";
110: if ((!_enabled) && useDisabledAttribute())
111: out += " disabled=\"" + true + "\"";
112: if (_tabIndex != null)
113: out += " tabindex=\"" + _tabIndex + "\"";
114: if (_accessKey != null)
115: out += " accesskey=\"" + _accessKey + "\"";
116: if (style != null)
117: out += style;
118: if (_onDoubleClick != null)
119: out += " ondblclick=\"" + _onDoubleClick + "\"";
120: if (_onMouseDown != null)
121: out += " onMouseDown=\"" + _onMouseDown + "\"";
122: out += ">";
123:
124: if (_fontTagStart != null)
125: out = _fontTagStart + out + _fontTagEnd;
126:
127: p.println(out);
128: }
129:
130: /**
131: * This method returns the text that will be displayed on the button in the browser.
132: * @return java.lang.String
133: */
134: public String getDisplayName() {
135: return _dispName;
136: }
137:
138: /**
139: * This method gets the end font tag for the component.
140: */
141: public String getFontEndTag() {
142: return _fontTagEnd;
143: }
144:
145: /**
146: * This method gets the start font tag for the component.
147: */
148: public String getFontStartTag() {
149: return _fontTagStart;
150: }
151:
152: /**
153: * This method gets the javascript that will be executed when the button is clicked.
154: */
155: public String getOnClick() {
156: return _onClick;
157: }
158:
159: /**
160: * This method returns the property theme for the component.
161: */
162: public String getTheme() {
163: return _theme;
164: }
165:
166: /**
167: * This method sets the text that will appear on the button in the browser.
168: */
169: public void setDisplayName(String name) {
170: _dispName = name;
171: }
172:
173: /**
174: * This method sets the end font tag for the component.
175: */
176: public void setFontEndTag(String value) {
177: _fontTagEnd = value;
178: }
179:
180: /**
181: * This method sets the start font tag for the component.
182: */
183: public void setFontStartTag(String value) {
184: _fontTagStart = value;
185: }
186:
187: /**
188: * This method sets the javascript that will be executed when the button is clicked.
189: */
190: public void setOnClick(String onClick) {
191: _onClick = onClick;
192: }
193:
194: /**
195: * This method sets the property theme for the component.
196: * @param theme The theme to use.
197: */
198: public void setTheme(String theme) {
199: Props props = getPage().getPageProperties();
200: _fontTagStart = props.getThemeProperty(theme, Props.FONT_BUTTON
201: + Props.TAG_START);
202: _fontTagEnd = props.getThemeProperty(theme, Props.FONT_BUTTON
203: + Props.TAG_END);
204: _buttonBgColor = props.getThemeProperty(theme,
205: Props.BUTTON_BG_COLOR);
206: _buttonFontStyle = props.getThemeProperty(theme,
207: Props.BUTTON_FONT_STYLE);
208: _class = props
209: .getThemeProperty(theme, Props.BUTTON_STYLE_CLASS);
210: _theme = theme;
211: }
212:
213: public boolean getEnabled() {
214: return _enabled;
215: }
216:
217: public void setEnabled(boolean enabled) {
218: _enabled = enabled;
219: }
220:
221: /**
222: * Returns the background color for the button
223: */
224: public String getButtonBgColor() {
225: return _buttonBgColor;
226: }
227:
228: /**
229: * Sets the background color for the button
230: */
231: public void setButtonBgColor(String buttonBgColor) {
232: _buttonBgColor = buttonBgColor;
233: }
234:
235: /**
236: * Gets the foreground font style for a button
237: */
238: public String getButtonFontStyle() {
239: return _buttonFontStyle;
240: }
241:
242: /**
243: * Sets the foreground font style for a button
244: */
245:
246: public void setButtonFontStyle(String buttonFontStyle) {
247: _buttonFontStyle = buttonFontStyle;
248: }
249:
250: /**
251: * @returns the access key html attribute
252: */
253: public String getAccessKey() {
254: return _accessKey;
255: }
256:
257: /**
258: * @returns the tab index html attribute
259: */
260: public int getTabIndex() {
261: if (_tabIndex == null)
262: return -1;
263: return _tabIndex.intValue();
264: }
265:
266: /**
267: * @param sets the access key html attribute
268: */
269: public void setAccessKey(String string) {
270: _accessKey = string;
271: }
272:
273: /**
274: * @param sets the tab index html attribute. You can also pass TAB_INDEX_DEFAULT to use the default tab index for the component or TAB_INDEX_NONE to keep this component from being tabbed to
275: */
276: public void setTabIndex(int val) {
277: if (val == -1)
278: _tabIndex = null;
279: else
280: _tabIndex = new Integer(val);
281: }
282:
283: /**
284: * @return Returns the onMouseDown.
285: */
286: public String getOnMouseDown() {
287: return _onMouseDown;
288: }
289:
290: /**
291: * @param onMouseDown The onMouseDown to set.
292: */
293: public void setOnMouseDown(String onMouseDown) {
294: _onMouseDown = onMouseDown;
295: }
296: }
|