001package com.hfg.html; 002 003import com.hfg.css.CssUtil; 004import com.hfg.xml.XMLNode; 005 006//------------------------------------------------------------------------------ 007/** 008 * Represents an option group (<optgroup>) tag. 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 033public class OptGroup extends HTMLTag 034{ 035 036 //########################################################################## 037 // PRIVATE FIELDS 038 //########################################################################## 039 040 041 //########################################################################## 042 // CONSTRUCTORS 043 //########################################################################## 044 045 //-------------------------------------------------------------------------- 046 public OptGroup() 047 { 048 super(HTML.OPTGROUP); 049 } 050 051 //-------------------------------------------------------------------------- 052 public OptGroup(String inLabel) 053 { 054 super(HTML.OPTGROUP); 055 setLabel(inLabel); 056 } 057 058 //-------------------------------------------------------------------------- 059 public OptGroup(XMLNode inXMLNode) 060 { 061 this(); 062 initFromXMLNode(inXMLNode); 063 } 064 065 //########################################################################## 066 // PUBLIC METHODS 067 //########################################################################## 068 069 //-------------------------------------------------------------------------- 070 public Option addOption(String inText) 071 { 072 Option option = new Option(inText); 073 addSubtag(option); 074 075 return option; 076 } 077 078 //-------------------------------------------------------------------------- 079 public Option addOption(String inText, String inValue) 080 { 081 Option option = new Option(inText, inValue); 082 addSubtag(option); 083 084 return option; 085 } 086 087 //-------------------------------------------------------------------------- 088 public Option addOption(String inText, boolean inSelected) 089 { 090 Option option = new Option(inText, inSelected); 091 addSubtag(option); 092 093 return option; 094 } 095 096 //-------------------------------------------------------------------------- 097 public Option addOption(String inText, String inValue, boolean inSelected) 098 { 099 Option option = new Option(inText, inValue, inSelected); 100 addSubtag(option); 101 102 return option; 103 } 104 105 //-------------------------------------------------------------------------- 106 public OptGroup setLabel(String inValue) 107 { 108 setAttribute(HTML.LABEL, inValue); 109 return this; 110 } 111 112 //-------------------------------------------------------------------------- 113 public String getLabel() 114 { 115 return getAttributeValue(HTML.LABEL); 116 } 117 118 //-------------------------------------------------------------------------- 119 public OptGroup setDisabled(boolean inValue) 120 { 121 if (inValue) 122 { 123 setAttribute(HTML.DISABLED, "1"); 124 } 125 else 126 { 127 removeAttribute(HTML.DISABLED); 128 } 129 130 return this; 131 } 132 133 //-------------------------------------------------------------------------- 134 public boolean isDisabled() 135 { 136 return hasAttribute(HTML.DISABLED); 137 } 138 139 //-------------------------------------------------------------------------- 140 @Override 141 public OptGroup setClass(String inValue) 142 { 143 setAttribute(HTML.CLASS, inValue); 144 return this; 145 } 146 147 148 //-------------------------------------------------------------------------- 149 @Override 150 public OptGroup setId(String inValue) 151 { 152 setAttribute(HTML.ID, inValue); 153 return this; 154 } 155 156 //-------------------------------------------------------------------------- 157 @Override 158 public OptGroup setStyle(CharSequence inValue) 159 { 160 setAttribute(HTML.STYLE, inValue); 161 162 return this; 163 } 164 165 //-------------------------------------------------------------------------- 166 @Override 167 public OptGroup addStyle(String inValue) 168 { 169 CssUtil.addStyle(this, inValue); 170 return this; 171 } 172 173}