KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > dbforms > taglib > TagSupportWithScriptHandler


1 /*
2  * $Header: /cvsroot/jdbforms/dbforms/src/org/dbforms/taglib/TagSupportWithScriptHandler.java,v 1.15 2004/08/18 12:26:08 hkollmann Exp $
3  * $Revision: 1.15 $
4  * $Date: 2004/08/18 12:26:08 $
5  *
6  * DbForms - a Rapid Application Development Framework
7  * Copyright (C) 2001 Joachim Peer <joepeer@excite.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22  */

23
24 package org.dbforms.taglib;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 import org.dbforms.config.DbFormsConfig;
30 import org.dbforms.config.DbFormsConfigRegistry;
31
32 import org.dbforms.util.Util;
33
34 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
35
36
37
38 /**
39  * <p>
40  * Base class for TagSupport that render form data-elements capable of
41  * including JavaScript event handlers and/or CSS Style attributes.
42  * </p>
43  *
44  * <p>
45  * the html/css releated properties and methods where originally done by Don
46  * Clasen for Apache Groups's Jakarta-Struts project.
47  * </p>
48  */

49 public abstract class TagSupportWithScriptHandler extends BodyTagSupport JavaDoc {
50    private static Log logCat = LogFactory.getLog(DbBaseHandlerTag.class.getName());
51
52    /** DOCUMENT ME! */
53    private String JavaDoc accessKey = null;
54
55    // Focus Events
56

57    /** Component lost focus event. */
58    private String JavaDoc onBlur = null;
59
60    /** Content changed after component lost focus event. */
61    private String JavaDoc onChange = null;
62
63    // Mouse Events
64

65    /** Mouse click event. */
66    private String JavaDoc onClick = null;
67
68    /** Mouse double click event. */
69    private String JavaDoc onDblClick = null;
70
71    /** Component has received focus event. */
72    private String JavaDoc onFocus = null;
73
74    // Keyboard Events
75

76    /** Key down in component event. */
77    private String JavaDoc onKeyDown = null;
78
79    /** Key down and up together in component event. */
80    private String JavaDoc onKeyPress = null;
81
82    /** Key released in component event. */
83    private String JavaDoc onKeyUp = null;
84
85    /** Mouse pressed on component event. */
86    private String JavaDoc onMouseDown = null;
87
88    /** Mouse moved over component event. */
89    private String JavaDoc onMouseMove = null;
90
91    /** Mouse exit component event. */
92    private String JavaDoc onMouseOut = null;
93
94    /** Mouse over component event. */
95    private String JavaDoc onMouseOver = null;
96
97    /** Mouse released on component event. */
98    private String JavaDoc onMouseUp = null;
99
100    // Text Events
101

102    /** Text selected in component event. */
103    private String JavaDoc onSelect = null;
104
105    // CSS Style Support
106

107    /** Style attribute associated with component. */
108    private String JavaDoc style = null;
109
110    /** Named Style class associated with component. */
111    private String JavaDoc styleClass = null;
112
113    /** Tab index value. */
114    private String JavaDoc tabIndex = null;
115
116    /** Title (Tool Tip/Hint) attribute */
117    private String JavaDoc title = null;
118
119    // Navigation Management
120

121    /**
122     * Sets the accessKey character.
123     *
124     * @param accessKey DOCUMENT ME!
125     */

126    public void setAccessKey(String JavaDoc accessKey) {
127       this.accessKey = accessKey;
128    }
129
130
131    /**
132     * Returns the accessKey character.
133     *
134     * @return DOCUMENT ME!
135     */

136    public String JavaDoc getAccessKey() {
137       return (this.accessKey);
138    }
139
140
141    /**
142     * DOCUMENT ME!
143     *
144     * @return DOCUMENT ME!
145     */

146    public DbFormsConfig getConfig() {
147       try {
148          return DbFormsConfigRegistry.instance()
149                                      .lookup();
150       } catch (Exception JavaDoc e) {
151          logCat.error("getConfig", e);
152
153          return null;
154       }
155    }
156
157
158    // Focus Events
159

160    /**
161     * Sets the onBlur event handler.
162     *
163     * @param onBlur DOCUMENT ME!
164     */

165    public void setOnBlur(String JavaDoc onBlur) {
166       this.onBlur = onBlur;
167    }
168
169
170    /**
171     * Returns the onBlur event handler.
172     *
173     * @return DOCUMENT ME!
174     */

175    public String JavaDoc getOnBlur() {
176       return onBlur;
177    }
178
179
180    // Text Events
181

182    /**
183     * Sets the onChange event handler.
184     *
185     * @param onChange DOCUMENT ME!
186     */

187    public void setOnChange(String JavaDoc onChange) {
188       this.onChange = onChange;
189    }
190
191
192    /**
193     * Returns the onChange event handler.
194     *
195     * @return DOCUMENT ME!
196     */

197    public String JavaDoc getOnChange() {
198       return onChange;
199    }
200
201
202    // Mouse Events
203

204    /**
205     * Sets the onClick event handler.
206     *
207     * @param onClick DOCUMENT ME!
208     */

209    public void setOnClick(String JavaDoc onClick) {
210       this.onClick = onClick;
211    }
212
213
214    /**
215     * Returns the onClick event handler.
216     *
217     * @return DOCUMENT ME!
218     */

219    public String JavaDoc getOnClick() {
220       return onClick;
221    }
222
223
224    /**
225     * Sets the onDblClick event handler.
226     *
227     * @param onDblClick DOCUMENT ME!
228     */

229    public void setOnDblClick(String JavaDoc onDblClick) {
230       this.onDblClick = onDblClick;
231    }
232
233
234    /**
235     * Returns the onDblClick event handler.
236     *
237     * @return DOCUMENT ME!
238     */

239    public String JavaDoc getOnDblClick() {
240       return onDblClick;
241    }
242
243
244    /**
245     * Sets the onFocus event handler.
246     *
247     * @param onFocus DOCUMENT ME!
248     */

249    public void setOnFocus(String JavaDoc onFocus) {
250       this.onFocus = onFocus;
251    }
252
253
254    /**
255     * Returns the onFocus event handler.
256     *
257     * @return DOCUMENT ME!
258     */

259    public String JavaDoc getOnFocus() {
260       return onFocus;
261    }
262
263
264    // Keyboard Events
265

266    /**
267     * Sets the onKeyDown event handler.
268     *
269     * @param onKeyDown DOCUMENT ME!
270     */

271    public void setOnKeyDown(String JavaDoc onKeyDown) {
272       this.onKeyDown = onKeyDown;
273    }
274
275
276    /**
277     * Returns the onKeyDown event handler.
278     *
279     * @return DOCUMENT ME!
280     */

281    public String JavaDoc getOnKeyDown() {
282       return onKeyDown;
283    }
284
285
286    /**
287     * Sets the onKeyPress event handler.
288     *
289     * @param onKeyPress DOCUMENT ME!
290     */

291    public void setOnKeyPress(String JavaDoc onKeyPress) {
292       this.onKeyPress = onKeyPress;
293    }
294
295
296    /**
297     * Returns the onKeyPress event handler.
298     *
299     * @return DOCUMENT ME!
300     */

301    public String JavaDoc getOnKeyPress() {
302       return onKeyPress;
303    }
304
305
306    /**
307     * Sets the onKeyUp event handler.
308     *
309     * @param onKeyUp DOCUMENT ME!
310     */

311    public void setOnKeyUp(String JavaDoc onKeyUp) {
312       this.onKeyUp = onKeyUp;
313    }
314
315
316    /**
317     * Returns the onKeyUp event handler.
318     *
319     * @return DOCUMENT ME!
320     */

321    public String JavaDoc getOnKeyUp() {
322       return onKeyUp;
323    }
324
325
326    /**
327     * Sets the onMouseDown event handler.
328     *
329     * @param onMouseDown DOCUMENT ME!
330     */

331    public void setOnMouseDown(String JavaDoc onMouseDown) {
332       this.onMouseDown = onMouseDown;
333    }
334
335
336    /**
337     * Returns the onMouseDown event handler.
338     *
339     * @return DOCUMENT ME!
340     */

341    public String JavaDoc getOnMouseDown() {
342       return onMouseDown;
343    }
344
345
346    /**
347     * Sets the onMouseMove event handler.
348     *
349     * @param onMouseMove DOCUMENT ME!
350     */

351    public void setOnMouseMove(String JavaDoc onMouseMove) {
352       this.onMouseMove = onMouseMove;
353    }
354
355
356    /**
357     * Returns the onMouseMove event handler.
358     *
359     * @return DOCUMENT ME!
360     */

361    public String JavaDoc getOnMouseMove() {
362       return onMouseMove;
363    }
364
365
366    /**
367     * Sets the onMouseOut event handler.
368     *
369     * @param onMouseOut DOCUMENT ME!
370     */

371    public void setOnMouseOut(String JavaDoc onMouseOut) {
372       this.onMouseOut = onMouseOut;
373    }
374
375
376    /**
377     * Returns the onMouseOut event handler.
378     *
379     * @return DOCUMENT ME!
380     */

381    public String JavaDoc getOnMouseOut() {
382       return onMouseOut;
383    }
384
385
386    /**
387     * Sets the onMouseOver event handler.
388     *
389     * @param onMouseOver DOCUMENT ME!
390     */

391    public void setOnMouseOver(String JavaDoc onMouseOver) {
392       this.onMouseOver = onMouseOver;
393    }
394
395
396    /**
397     * Returns the onMouseOver event handler.
398     *
399     * @return DOCUMENT ME!
400     */

401    public String JavaDoc getOnMouseOver() {
402       return onMouseOver;
403    }
404
405
406    /**
407     * Sets the onMouseUp event handler.
408     *
409     * @param onMouseUp DOCUMENT ME!
410     */

411    public void setOnMouseUp(String JavaDoc onMouseUp) {
412       this.onMouseUp = onMouseUp;
413    }
414
415
416    /**
417     * Returns the onMouseUp event handler.
418     *
419     * @return DOCUMENT ME!
420     */

421    public String JavaDoc getOnMouseUp() {
422       return onMouseUp;
423    }
424
425
426    /**
427     * Sets the onSelect event handler.
428     *
429     * @param onSelect DOCUMENT ME!
430     */

431    public void setOnSelect(String JavaDoc onSelect) {
432       this.onSelect = onSelect;
433    }
434
435
436    /**
437     * Returns the onSelect event handler.
438     *
439     * @return DOCUMENT ME!
440     */

441    public String JavaDoc getOnSelect() {
442       return onSelect;
443    }
444
445
446    // CSS Style Support
447

448    /**
449     * Sets the style attribute.
450     *
451     * @param style DOCUMENT ME!
452     */

453    public void setStyle(String JavaDoc style) {
454       this.style = style;
455    }
456
457
458    /**
459     * Returns the style attribute.
460     *
461     * @return DOCUMENT ME!
462     */

463    public String JavaDoc getStyle() {
464       return style;
465    }
466
467
468    /**
469     * Sets the style class attribute.
470     *
471     * @param styleClass DOCUMENT ME!
472     */

473    public void setStyleClass(String JavaDoc styleClass) {
474       this.styleClass = styleClass;
475    }
476
477
478    /**
479     * Returns the style class attribute.
480     *
481     * @return DOCUMENT ME!
482     */

483    public String JavaDoc getStyleClass() {
484       return styleClass;
485    }
486
487
488    /**
489     * Sets the tabIndex value.
490     *
491     * @param tabIndex DOCUMENT ME!
492     */

493    public void setTabIndex(String JavaDoc tabIndex) {
494       this.tabIndex = tabIndex;
495    }
496
497
498    /**
499     * Returns the tabIndex value.
500     *
501     * @return DOCUMENT ME!
502     */

503    public String JavaDoc getTabIndex() {
504       return (this.tabIndex);
505    }
506
507
508    /**
509     * Sets the title attribute.
510     *
511     * @param title DOCUMENT ME!
512     */

513    public void setTitle(String JavaDoc title) {
514       this.title = title;
515    }
516
517
518    /**
519     * Returns the title attribute.
520     *
521     * @return DOCUMENT ME!
522     */

523    public String JavaDoc getTitle() {
524       return title;
525    }
526
527
528    /**
529     * reset tag state
530     *
531     * @see javax.servlet.jsp.tagext.TryCatchFinally#doFinally()
532     */

533    public void doFinally() {
534       accessKey = null;
535       tabIndex = null;
536       onClick = null;
537       onDblClick = null;
538       onMouseOver = null;
539       onMouseOut = null;
540       onMouseMove = null;
541       onMouseDown = null;
542       onMouseUp = null;
543       onKeyDown = null;
544       onKeyUp = null;
545       onKeyPress = null;
546       onSelect = null;
547       onChange = null;
548       onBlur = null;
549       onFocus = null;
550       style = null;
551       styleClass = null;
552       title = null;
553    }
554
555
556    /**
557     * Prepares the event handlers for inclusion in the component's HTML tag.
558     *
559     * @return The prepared String for inclusion in the HTML tag.
560     */

561    protected String JavaDoc prepareEventHandlers() {
562       StringBuffer JavaDoc handlers = new StringBuffer JavaDoc();
563       prepareIdEvents(handlers); // Fossato, 20011008
564
prepareMouseEvents(handlers);
565       prepareKeyEvents(handlers);
566       prepareTextEvents(handlers);
567       prepareFocusEvents(handlers);
568
569       return handlers.toString();
570    }
571
572
573    /**
574     * Prepares the style attributes for inclusion in the component's HTML tag.
575     *
576     * @return The prepared String for inclusion in the HTML tag.
577     */

578    protected String JavaDoc prepareStyles() {
579       StringBuffer JavaDoc styles = new StringBuffer JavaDoc();
580
581       if (!Util.isNull(getStyleClass())) {
582          styles.append(" class=\"");
583          styles.append(getStyleClass());
584          styles.append("\"");
585       }
586
587       if (!Util.isNull(getStyle())) {
588          styles.append(" style=\"");
589          styles.append(getStyle());
590          styles.append("\"");
591       }
592
593       if (!Util.isNull(getTitle())) {
594          styles.append(" title=\"");
595          styles.append(getTitle());
596          styles.append("\"");
597       }
598
599       return styles.toString();
600    }
601
602
603    /**
604     * Prepares the focus event handlers, appending them to the the given
605     * StringBuffer.
606     *
607     * @param handlers The StringBuffer that output will be appended to.
608     */

609    private void prepareFocusEvents(StringBuffer JavaDoc handlers) {
610       if (onBlur != null) {
611          handlers.append(" onBlur=\"");
612          handlers.append(onBlur);
613          handlers.append("\"");
614       }
615
616       if (onFocus != null) {
617          handlers.append(" onFocus=\"");
618          handlers.append(onFocus);
619          handlers.append("\"");
620       }
621    }
622
623
624    // -------------------------------------------------------- Private Methods
625

626    /**
627     * Prepares the id handlers, appending them to the the given StringBuffer.
628     *
629     * @param handlers The StringBuffer that output will be appended to.
630     */

631    private void prepareIdEvents(StringBuffer JavaDoc handlers) { // Fossato, 20011008
632

633       if (id != null) {
634          handlers.append(" id=\"")
635                  .append(id)
636                  .append("\"");
637       }
638    }
639
640
641    /**
642     * Prepares the keyboard event handlers, appending them to the the given
643     * StringBuffer.
644     *
645     * @param handlers The StringBuffer that output will be appended to.
646     */

647    private void prepareKeyEvents(StringBuffer JavaDoc handlers) {
648       if (onKeyDown != null) {
649          handlers.append(" onKeyDown=\"");
650          handlers.append(onKeyDown);
651          handlers.append("\"");
652       }
653
654       if (onKeyUp != null) {
655          handlers.append(" onKeyUp=\"");
656          handlers.append(onKeyUp);
657          handlers.append("\"");
658       }
659
660       if (onKeyPress != null) {
661          handlers.append(" onKeyPress=\"");
662          handlers.append(onKeyPress);
663          handlers.append("\"");
664       }
665    }
666
667
668    /**
669     * Prepares the mouse event handlers, appending them to the the given
670     * StringBuffer.
671     *
672     * @param handlers The StringBuffer that output will be appended to.
673     */

674    private void prepareMouseEvents(StringBuffer JavaDoc handlers) {
675       if (onClick != null) {
676          handlers.append(" onClick=\"");
677          handlers.append(onClick);
678          handlers.append("\"");
679       }
680
681       if (onDblClick != null) {
682          handlers.append(" onDblClick=\"");
683          handlers.append(onDblClick);
684          handlers.append("\"");
685       }
686
687       if (onMouseOver != null) {
688          handlers.append(" onMouseOver=\"");
689          handlers.append(onMouseOver);
690          handlers.append("\"");
691       }
692
693       if (onMouseOut != null) {
694          handlers.append(" onMouseOut=\"");
695          handlers.append(onMouseOut);
696          handlers.append("\"");
697       }
698
699       if (onMouseMove != null) {
700          handlers.append(" onMouseMove=\"");
701          handlers.append(onMouseMove);
702          handlers.append("\"");
703       }
704
705       if (onMouseDown != null) {
706          handlers.append(" onMouseDown=\"");
707          handlers.append(onMouseDown);
708          handlers.append("\"");
709       }
710
711       if (onMouseUp != null) {
712          handlers.append(" onMouseUp=\"");
713          handlers.append(onMouseUp);
714          handlers.append("\"");
715       }
716    }
717
718
719    /**
720     * Prepares the text event handlers, appending them to the the given
721     * StringBuffer.
722     *
723     * @param handlers The StringBuffer that output will be appended to.
724     */

725    private void prepareTextEvents(StringBuffer JavaDoc handlers) {
726       if (onSelect != null) {
727          handlers.append(" onSelect=\"");
728          handlers.append(onSelect);
729          handlers.append("\"");
730       }
731
732       if (onChange != null) {
733          handlers.append(" onChange=\"");
734          handlers.append(onChange);
735          handlers.append("\"");
736       }
737    }
738 }
739
Popular Tags