001package com.hfg.html.custom; 002 003import java.util.List; 004 005import com.hfg.css.CSS; 006import com.hfg.css.CSSDeclaration; 007import com.hfg.css.CSSProperty; 008import com.hfg.css.CSSRule; 009import com.hfg.graphics.units.GfxSize; 010import com.hfg.graphics.units.GfxUnits; 011import com.hfg.html.HTMLTag; 012import com.hfg.html.HTMLTagWithCoreEvents; 013import com.hfg.html.Span; 014import com.hfg.util.StringUtil; 015 016//------------------------------------------------------------------------------ 017/** 018 Container for things like a custom tri-state plus its label. Clicking on the label 019 invokes the click() on the specified inner tag. 020 <div> 021 @author J. Alex Taylor, hairyfatguy.com 022 </div> 023 */ 024//------------------------------------------------------------------------------ 025// com.hfg XML/HTML Coding Library 026// 027// This library is free software; you can redistribute it and/or 028// modify it under the terms of the GNU Lesser General Public 029// License as published by the Free Software Foundation; either 030// version 2.1 of the License, or (at your option) any later version. 031// 032// This library is distributed in the hope that it will be useful, 033// but WITHOUT ANY WARRANTY; without even the implied warranty of 034// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 035// Lesser General Public License for more details. 036// 037// You should have received a copy of the GNU Lesser General Public 038// License along with this library; if not, write to the Free Software 039// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 040// 041// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 042// jataylor@hairyfatguy.com 043//------------------------------------------------------------------------------ 044 045public class ClickLabelSpan extends Span 046{ 047 private HTMLTag mHTMLTag; 048 049 //########################################################################## 050 // CONSTRUCTORS 051 //########################################################################## 052 053 //-------------------------------------------------------------------------- 054 public ClickLabelSpan(HTMLTagWithCoreEvents inHTMLTag, String inLabel) 055 { 056 super(); 057 058 mHTMLTag = inHTMLTag; 059 addSubtag(inHTMLTag.appendToOnClick("event.cancelBubble=true;")); 060 addSpan(inLabel).setStyle("margin-left: 5px;"); 061 appendToOnClick("this.children[0].click();"); 062 } 063 064 //-------------------------------------------------------------------------- 065 public ClickLabelSpan(HTMLTagWithCoreEvents inHTMLTag, HTMLTag inLabel) 066 { 067 super(); 068 069 mHTMLTag = inHTMLTag; 070 addSubtag(inHTMLTag.appendToOnClick("event.cancelBubble=true;")); 071 072 // Check to see if a margin was already specified on the label 073 boolean paddingPresent = false; 074 String existingStyle = inLabel.getStyle(); 075 if (StringUtil.isSet(existingStyle)) 076 { 077 List<CSSDeclaration> cssDeclarations = CSSDeclaration.parse(existingStyle); 078 for (CSSDeclaration cssDeclaration : cssDeclarations) 079 { 080 if (cssDeclaration.getProperty().equals(CSSProperty.margin_left)) 081 { 082 GfxSize gfxSize = GfxSize.allocate(cssDeclaration.getValue(), GfxUnits.pixels); 083 if (gfxSize.toInt(GfxUnits.pixels) > 5) 084 { 085 paddingPresent = true; 086 } 087 break; 088 } 089 } 090 } 091 092 if (! paddingPresent) 093 { 094 inLabel.addStyle("margin-left: 5px;"); 095 } 096 097 addSubtag(inLabel); 098 appendToOnClick("this.children[0].click();"); 099 } 100 101 //########################################################################## 102 // PUBLIC METHODS 103 //########################################################################## 104 105 //-------------------------------------------------------------------------- 106 @Override 107 public ClickLabelSpan addClass(String inValue) 108 { 109 return (ClickLabelSpan) super.addClass(inValue); 110 } 111 112 //-------------------------------------------------------------------------- 113 @Override 114 public ClickLabelSpan addStyle(String inValue) 115 { 116 return (ClickLabelSpan) super.addStyle(inValue); 117 } 118}