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: import com.salmonllc.html.events.ValueChangedEvent;
023:
024: import com.salmonllc.properties.Props;
025:
026: import com.salmonllc.util.Util;
027:
028: /////////////////////////
029: //$Archive: /SOFIA/SourceCode/com/salmonllc/html/HtmlTextEdit.java $
030: //$Author: Srufle $
031: //$Revision: 29 $
032: //$Modtime: 8/06/04 3:11p $
033: /////////////////////////
034: import java.util.Hashtable;
035:
036: /**
037: * This class is used for text input field.
038: */
039: public class HtmlTextEdit extends HtmlFormComponent {
040: private Boolean _readOnly;
041: private Integer _tabIndex;
042: private String _accessKey;
043: private String _fontTagEnd;
044: private String _fontTagStart;
045: private String _onChange;
046: private String _onFocus;
047: private String _onKeyUp;
048: private String _onLoseFocus;
049: private String _style;
050: private int _maxLength = 10;
051: private int _size = 10;
052:
053: /**
054: * Constructs a new HTMLTextEdit component.
055: *
056: * @param name The name of the component
057: * @param p The page the component will be placed in.
058: */
059: public HtmlTextEdit(String name, com.salmonllc.html.HtmlPage p) {
060: this (name, null, p);
061: }
062:
063: /**
064: * Constructs a new HTMLTextEdit component.
065: *
066: * @param name The name of the component
067: * @param theme The theme to use for loading properties
068: * @param p The page the component will be placed in.
069: */
070: public HtmlTextEdit(String name, String theme,
071: com.salmonllc.html.HtmlPage p) {
072: super (name, p);
073: setTheme(theme);
074: }
075:
076: /**
077: * DOCUMENT ME!
078: *
079: * @param string the access key html attribute
080: */
081: public void setAccessKey(String string) {
082: _accessKey = string;
083: }
084:
085: /**
086: * DOCUMENT ME!
087: *
088: * @return the access key html attribute
089: */
090: public String getAccessKey() {
091: return _accessKey;
092: }
093:
094: /**
095: * This method sets the end font tag for the component.
096: *
097: * @param value DOCUMENT ME!
098: */
099: public void setFontEndTag(String value) {
100: _fontTagEnd = value;
101: }
102:
103: /**
104: * This method gets the end font tag for the component.
105: *
106: * @return DOCUMENT ME!
107: */
108: public String getFontEndTag() {
109: return _fontTagEnd;
110: }
111:
112: /**
113: * This method sets the start font tag for the component.
114: *
115: * @param value DOCUMENT ME!
116: */
117: public void setFontStartTag(String value) {
118: _fontTagStart = value;
119: }
120:
121: /**
122: * This method gets the start font tag for the component.
123: *
124: * @return DOCUMENT ME!
125: */
126: public String getFontStartTag() {
127: return _fontTagStart;
128: }
129:
130: /**
131: * This method sets the maximum length for the text in the component.
132: *
133: * @param maxLength DOCUMENT ME!
134: */
135: public void setMaxLength(int maxLength) {
136: _maxLength = maxLength;
137: }
138:
139: /**
140: * This method gets the maximum length for the text in the component.
141: *
142: * @return DOCUMENT ME!
143: */
144: public int getMaxLength() {
145: return _maxLength;
146: }
147:
148: /**
149: * This method sets the javascript to be executed when the value of the text in the component changes.
150: *
151: * @param value DOCUMENT ME!
152: */
153: public void setOnChange(String value) {
154: _onChange = value;
155: }
156:
157: /**
158: * This method gets the javascript to be executed when the value of the text in the component changes.
159: *
160: * @return DOCUMENT ME!
161: */
162: public String getOnChange() {
163: return _onChange;
164: }
165:
166: /**
167: * This method sets the javascript to be executed when the component gains focus.
168: *
169: * @param value DOCUMENT ME!
170: */
171: public void setOnFocus(String value) {
172: _onFocus = value;
173: }
174:
175: /**
176: * This method gets the javascript to be executed when the component gets focus.
177: *
178: * @return DOCUMENT ME!
179: */
180: public String getOnFocus() {
181: return _onFocus;
182: }
183:
184: /**
185: * This method sets the javascript to be executed when a keyboard key is release.
186: *
187: * @param value DOCUMENT ME!
188: */
189: public void setOnKeyUp(String value) {
190: _onKeyUp = value;
191: }
192:
193: /**
194: * This method sets the javascript to be executed when the component loses focus.
195: *
196: * @param value DOCUMENT ME!
197: */
198: public void setOnLoseFocus(String value) {
199: _onLoseFocus = value;
200: }
201:
202: /**
203: * This method gets the javascript to be executed when the component loses focus.
204: *
205: * @return DOCUMENT ME!
206: */
207: public String getOnLoseFocus() {
208: return _onLoseFocus;
209: }
210:
211: /**
212: * DOCUMENT ME!
213: *
214: * @param val the read only html attribute
215: */
216: public void setReadOnly(boolean val) {
217: if (val == false) {
218: _readOnly = null;
219: } else {
220: _readOnly = Boolean.TRUE;
221: }
222: }
223:
224: /**
225: * DOCUMENT ME!
226: *
227: * @return the read only html attribute
228: */
229: public boolean getReadOnly() {
230: if (_readOnly == null) {
231: return false;
232: }
233:
234: return _readOnly.booleanValue();
235: }
236:
237: /**
238: * This method sets the display size for the component in characters.
239: *
240: * @param size DOCUMENT ME!
241: */
242: public void setSize(int size) {
243: _size = size;
244: }
245:
246: /**
247: * This method gets the display size for the component in characters.
248: *
249: * @return DOCUMENT ME!
250: */
251: public int getSize() {
252: return _size;
253: }
254:
255: /**
256: * DOCUMENT ME!
257: *
258: * @param string
259: */
260: public void setStyle(String string) {
261: _style = string;
262: }
263:
264: /**
265: * DOCUMENT ME!
266: *
267: * @return
268: */
269: public String getStyle() {
270: return _style;
271: }
272:
273: /**
274: * DOCUMENT ME!
275: *
276: * @param val 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
277: */
278: public void setTabIndex(int val) {
279: if (val == -1) {
280: _tabIndex = null;
281: } else {
282: _tabIndex = new Integer(val);
283: }
284: }
285:
286: /**
287: * DOCUMENT ME!
288: *
289: * @return the tab index html attribute
290: */
291: public int getTabIndex() {
292: if (_tabIndex == null) {
293: return -1;
294: }
295:
296: return _tabIndex.intValue();
297: }
298:
299: /**
300: * This method sets the property theme for the component.
301: *
302: * @param theme The theme to use.
303: */
304: public void setTheme(String theme) {
305: super .setTheme(theme);
306:
307: Props props = getPage().getPageProperties();
308: _fontTagStart = props.getThemeProperty(theme,
309: Props.FONT_TEXT_EDIT + Props.TAG_START);
310: _fontTagEnd = props.getThemeProperty(theme,
311: Props.FONT_TEXT_EDIT + Props.TAG_END);
312: }
313:
314: public void generateHTML(java.io.PrintWriter p, int rowNo)
315: throws Exception {
316: if (!_visible) {
317: return;
318: }
319:
320: processLocaleInfo();
321:
322: String name = getFullName();
323:
324: if (rowNo > -1) {
325: name += ("_" + rowNo);
326: }
327:
328: String tag = "<INPUT TYPE=\"TEXT\" NAME=\"" + name + "\"";
329:
330: if (_onKeyUp != null) {
331: tag += (" onKeyUp=\"" + _onKeyUp + "\"");
332: }
333:
334: if (!getEnabled()) {
335: if (useDisabledAttribute()) {
336: tag += " DISABLED=\"true\"";
337: } else {
338: String out = getValue(rowNo, true);
339:
340: if (out != null) {
341: out = fixSpecialHTMLCharacters(out);
342: } else {
343: out = "";
344: }
345:
346: // Code added in an attempt to remove unsightly ' ' in the HtmlTelephonecomponent and
347: // HtmlSSNComponent.
348: // The premise is that the ' ' was introduced to provide for the case when the field
349: // is disabled and when the string is empty or null
350: // The IF statement is introduced to do as much without impacting non-null and non-empty strings
351: if ((out == null)
352: || ((out != null) && (out.equals("")))) {
353: out += " ";
354: }
355:
356: if (_disabledFontStartTag != null) {
357: p.print(_disabledFontStartTag + out
358: + _disabledFontEndTag);
359: } else {
360: p.print(out);
361: }
362:
363: return;
364: }
365: }
366:
367: if (_maxLength > -1) {
368: tag += (" MAXLENGTH=\"" + _maxLength + "\"");
369: }
370:
371: if (_size > -1) {
372: int size = _size;
373:
374: if ((getPage().getBrowserType() == HtmlPage.BROWSER_NETSCAPE)
375: && (getPage().getBrowserVersion() == 4)) {
376: size = (int) (size * .60);
377: }
378:
379: if (size < 1) {
380: size = 1;
381: }
382:
383: tag += (" SIZE=\"" + size + "\"");
384: }
385:
386: String value = getValue(rowNo, true);
387:
388: if (value != null) {
389: tag += (" VALUE=\"" + fixSpecialHTMLCharacters(value) + "\"");
390: }
391:
392: if (_onChange != null) {
393: tag += (" onChange=\"" + _onChange + "\"");
394: }
395:
396: if (_onFocus != null) {
397: tag += (" onFocus=\"" + _onFocus + "\"");
398: }
399:
400: if (_onLoseFocus != null) {
401: tag += (" onBlur=\"" + _onLoseFocus + "\"");
402: }
403:
404: if (_class != null) {
405: tag += (" class=\"" + _class + "\"");
406: }
407:
408: if (_tabIndex != null) {
409: tag += (" tabindex=\"" + _tabIndex + "\"");
410: }
411:
412: if (Util.isFilled(getStyle())) {
413: tag += (" style=\"" + getStyle() + "\"");
414: }
415:
416: if (_accessKey != null) {
417: tag += (" accesskey=\"" + _accessKey + "\"");
418: }
419:
420: if (_readOnly != null) {
421: tag += (" readonly=\"" + _readOnly + "\"");
422: }
423:
424: tag += ">";
425:
426: if (_fontTagStart != null) {
427: //tag = _fontTagStart + tag + _fontTagEnd;
428: }
429:
430: if (_generateNewline) {
431: p.println(tag);
432: } else {
433: p.print(tag);
434: }
435:
436: writeFocusScript(p, rowNo);
437: }
438:
439: public boolean processParms(Hashtable parms, int rowNo)
440: throws Exception {
441: // fc: 07/17/02 Commented out the below lines as they are no longer required,
442: // since a better approach is to check to see if the field is contained in
443: // the form when submitted. see other change below
444: // if (!getVisible() || !getEnabled())
445: // return false;
446: String oldValue = _value;
447:
448: String name = getFullName();
449:
450: if (rowNo > -1) {
451: name += ("_" + rowNo);
452:
453: if (_dsBuff != null) {
454: oldValue = _dsBuff.getFormattedString(rowNo, _dsColNo);
455: }
456: } else {
457: if (_dsBuff != null) {
458: oldValue = _dsBuff.getFormattedString(_dsColNo);
459: }
460: }
461:
462: //fc: 07/17/02 Added check to see if component exists in form if not
463: // then do not process.
464: if (parms.containsKey(name)) {
465: String val[] = (String[]) parms.get(name);
466:
467: if (val != null) {
468: _value = val[0].trim();
469:
470: if (_value.equals("")) {
471: _value = null;
472: }
473: } else {
474: _value = null;
475: }
476:
477: convertValue();
478:
479: if (!valuesEqual(oldValue, _value)) {
480: ValueChangedEvent e = new ValueChangedEvent(getPage(),
481: this , getName(), getFullName(), oldValue,
482: _value, rowNo, _dsColNo, _dsBuff);
483: addEvent(e);
484: }
485: }
486:
487: return false;
488: }
489: }
|