1 38 package com.gargoylesoftware.htmlunit.html; 39 40 import java.util.Map ; 41 import java.util.Iterator ; 42 43 51 public class HtmlLabel extends FocusableElement { 52 53 54 public static final String TAG_NAME = "label"; 55 56 62 public HtmlLabel( final HtmlPage page, final Map attributes ) { 63 super( page, attributes ); 64 } 65 66 69 public String getTagName() { 70 return TAG_NAME; 71 } 72 73 81 public final String getForAttribute() { 82 return getAttributeValue("for"); 83 } 84 85 86 94 public final String getAccessKeyAttribute() { 95 return getAttributeValue("accesskey"); 96 } 97 98 99 107 public final String getOnFocusAttribute() { 108 return getAttributeValue("onfocus"); 109 } 110 111 112 120 public final String getOnBlurAttribute() { 121 return getAttributeValue("onblur"); 122 } 123 124 125 128 public void blur() { 129 final FocusableElement element = getReferencedElement(); 130 if (element != null) { 131 element.blur(); 132 } 133 } 134 135 136 139 public void focus() { 140 final FocusableElement element = getReferencedElement(); 141 if (element != null) { 142 element.focus(); 143 } 144 } 145 146 147 private FocusableElement getReferencedElement() { 148 final String elementId = getAttributeValue("for"); 149 if (elementId.length() != 0) { 150 final HtmlElement element = getHtmlElementById(elementId); 151 if (element != null && element instanceof HtmlInput) { 152 return (FocusableElement) element; 153 } 154 } 155 else { 156 final Iterator childIterator = getChildIterator(); 157 while (childIterator.hasNext()) { 158 final DomNode element = (DomNode) childIterator.next(); 159 if (element instanceof HtmlInput) { 160 return (FocusableElement) element; 161 } 162 } 163 } 164 return null; 165 } 166 } 167 | Popular Tags |