001package com.hfg.html; 002 003 004import java.util.Hashtable; 005 006//------------------------------------------------------------------------------ 007/** 008 * Base class for most html form elements. 009 * 010 * @author J. Alex Taylor, hairyfatguy.com 011 */ 012//------------------------------------------------------------------------------ 013// com.hfg XML/HTML Coding Library 014// 015// This library is free software; you can redistribute it and/or 016// modify it under the terms of the GNU Lesser General Public 017// License as published by the Free Software Foundation; either 018// version 2.1 of the License, or (at your option) any later version. 019// 020// This library is distributed in the hope that it will be useful, 021// but WITHOUT ANY WARRANTY; without even the implied warranty of 022// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 023// Lesser General Public License for more details. 024// 025// You should have received a copy of the GNU Lesser General Public 026// License along with this library; if not, write to the Free Software 027// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 028// 029// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 030// jataylor@hairyfatguy.com 031//------------------------------------------------------------------------------ 032 033abstract public class HTMLTagWithFormEvents extends HTMLTagWithCoreEvents 034{ 035 //########################################################################### 036 // CONSTRUCTORS 037 //########################################################################### 038 039 //-------------------------------------------------------------------------- 040 public HTMLTagWithFormEvents(String inName) 041 { 042 super(inName); 043 } 044 045 //-------------------------------------------------------------------------- 046 public HTMLTagWithFormEvents(String inName, Hashtable<String, String> inAttributes) 047 { 048 super(inName, inAttributes); 049 } 050 051 //-------------------------------------------------------------------------- 052 public HTMLTagWithFormEvents(String inName, Hashtable inAttributes, String inContent) 053 { 054 super(inName, inAttributes, inContent); 055 } 056 057 //########################################################################### 058 // PUBLIC METHODS 059 //########################################################################### 060 061 // Form Events 062 063 //-------------------------------------------------------------------------- 064 public HTMLTagWithFormEvents setOnBlur(String inValue) 065 { 066 setAttribute(HTML.ONBLUR, inValue); 067 return this; 068 } 069 070 //--------------------------------------------------------------------------- 071 public HTMLTagWithFormEvents appendToOnBlur(String inValue) 072 { 073 appendToEventHandler(HTML.ONBLUR, inValue); 074 return this; 075 } 076 077 //-------------------------------------------------------------------------- 078 public String getOnBlur() 079 { 080 return getAttributeValue(HTML.ONBLUR); 081 } 082 083 084 //-------------------------------------------------------------------------- 085 public HTMLTagWithFormEvents setOnChange(String inValue) 086 { 087 setAttribute(HTML.ONCHANGE, inValue); 088 return this; 089 } 090 091 //--------------------------------------------------------------------------- 092 public HTMLTagWithFormEvents appendToOnChange(String inValue) 093 { 094 appendToEventHandler(HTML.ONCHANGE, inValue); 095 return this; 096 } 097 098 //-------------------------------------------------------------------------- 099 public String getOnChange() 100 { 101 return getAttributeValue(HTML.ONCHANGE); 102 } 103 104 105 //-------------------------------------------------------------------------- 106 public HTMLTagWithFormEvents setOnFocus(String inValue) 107 { 108 setAttribute(HTML.ONFOCUS, inValue); 109 return this; 110 } 111 112 //--------------------------------------------------------------------------- 113 public HTMLTagWithFormEvents appendToOnFocus(String inValue) 114 { 115 appendToEventHandler(HTML.ONFOCUS, inValue); 116 return this; 117 } 118 119 //-------------------------------------------------------------------------- 120 public String getOnFocus() 121 { 122 return getAttributeValue(HTML.ONFOCUS); 123 } 124 125 //########################################################################### 126 // PRIVATE METHODS 127 //########################################################################### 128 129 //-------------------------------------------------------------------------- 130 private void appendToEventHandler(String inEventAttr, String inValue) 131 { 132 String oldValue = getAttributeValue(inEventAttr); 133 if (oldValue != null) 134 { 135 inValue = oldValue + (oldValue.endsWith(";") ? " ": "; ") + inValue; 136 } 137 setAttribute(inEventAttr, inValue); 138 } 139}