org.sgx.j2s.html
Class HTMLUtils

Package class diagram package HTMLUtils
java.lang.Object
  extended by org.sgx.j2s.html.HTMLUtils

public class HTMLUtils
extends java.lang.Object

usefull html utilities


Field Summary
private static java.lang.String CHILDREN_ATTR_NAME
           
private static java.lang.String PARENT_ATTR_NAME
           
private static java.lang.String STYLE_ATTR_NAME
           
private static java.lang.String TAGNAME_ATTR_NAME
           
 
Constructor Summary
HTMLUtils()
           
 
Method Summary
static void addEventListener_(java.lang.Object element, java.lang.String eventName, java.lang.Runnable _handler, java.lang.Object context)
           
static boolean addEventListener_simple(java.lang.Object object, java.lang.String evt, java.lang.Object func, boolean capture)
          Add an event listener to an object
static void addEventListener(java.lang.Object element, java.lang.String eventName, java.lang.Runnable handler)
          safe context and compatible way of register events with a runnable handler
static Element createButton(Element parent, java.lang.String label, java.lang.Runnable clickHandler)
           
static Element createElement(Element parent, java.lang.String tagname, java.lang.Object... attrs)
           
static Element createElementRec(java.lang.Object obj)
          recursively creates markup from js object like shown :
static Element createLabel(Element parent, java.lang.String text)
           
static HTMLTable createTable(java.lang.Object tableObj, int rowCount, int columnCount)
           
static java.lang.String getAttribute(Element el, java.lang.String name)
           
static Element getChildren(Element parent, int childindex)
           
static Document getDocument()
           
static Navigator getNavigator()
           
static boolean isBrowserIE()
           
static boolean isValidAttribute(java.lang.String name)
           
static Event normalizeJsEvent(java.lang.Object e)
          Gets an event with all needed properties
static java.lang.String printEvent(Event e)
          prints a normalized event
static void printIn(Element parent, java.lang.String s)
           
static boolean removeEventListener(java.lang.Object object, java.lang.String evt, java.lang.Object func, boolean capture)
          Removes an event listener
static boolean setAttribute(Element el, java.lang.String name, java.lang.Object val)
          this is a slow but safe implementation. native setAttribute can throw very native exceptions (event uncacheable by firebug) when attr names are invalid
static void setAttributes(Element el, java.lang.Object... attrs)
           
static void setStyle(Element el, java.lang.String name, java.lang.String value)
           
static void setStyles(Element el, java.lang.String... attrs)
          you must pass the javascript property name instead the css name.
static HTMLTableCell tableGetCell(Element table, int row, int column)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHILDREN_ATTR_NAME

private static final java.lang.String CHILDREN_ATTR_NAME
See Also:
Constant Field Values

PARENT_ATTR_NAME

private static final java.lang.String PARENT_ATTR_NAME
See Also:
Constant Field Values

TAGNAME_ATTR_NAME

private static final java.lang.String TAGNAME_ATTR_NAME
See Also:
Constant Field Values

STYLE_ATTR_NAME

private static final java.lang.String STYLE_ATTR_NAME
See Also:
Constant Field Values
Constructor Detail

HTMLUtils

public HTMLUtils()
Method Detail

isValidAttribute

public static boolean isValidAttribute(java.lang.String name)

setAttribute

public static boolean setAttribute(Element el,
                                   java.lang.String name,
                                   java.lang.Object val)
this is a slow but safe implementation. native setAttribute can throw very native exceptions (event uncacheable by firebug) when attr names are invalid


getAttribute

public static java.lang.String getAttribute(Element el,
                                            java.lang.String name)

setAttributes

public static void setAttributes(Element el,
                                 java.lang.Object... attrs)

createElementRec

public static Element createElementRec(java.lang.Object obj)
recursively creates markup from js object like shown :

See Also:
org.sgx.j2s.htmlWidgets.test.HTMLUtilsTest.createElementRecTest()

createElement

public static Element createElement(Element parent,
                                    java.lang.String tagname,
                                    java.lang.Object... attrs)

getChildren

public static Element getChildren(Element parent,
                                  int childindex)

createTable

public static HTMLTable createTable(java.lang.Object tableObj,
                                    int rowCount,
                                    int columnCount)

tableGetCell

public static HTMLTableCell tableGetCell(Element table,
                                         int row,
                                         int column)

createLabel

public static Element createLabel(Element parent,
                                  java.lang.String text)

setStyles

public static void setStyles(Element el,
                             java.lang.String... attrs)
you must pass the javascript property name instead the css name. For example, "backgroundImage" instead of "background-image"


setStyle

public static void setStyle(Element el,
                            java.lang.String name,
                            java.lang.String value)

createButton

public static Element createButton(Element parent,
                                   java.lang.String label,
                                   java.lang.Runnable clickHandler)

printEvent

public static java.lang.String printEvent(Event e)
prints a normalized event


removeEventListener

public static boolean removeEventListener(java.lang.Object object,
                                          java.lang.String evt,
                                          java.lang.Object func,
                                          boolean capture)
Removes an event listener

Parameters:
object -
evt - event
func - function
capture -
Returns:
boolean

addEventListener_

public static void addEventListener_(java.lang.Object element,
                                     java.lang.String eventName,
                                     java.lang.Runnable _handler,
                                     java.lang.Object context)
Parameters:
element -
eventName -
handler, - you can pass an AbstractRunnable and override AbstractRunnable:getParamCount() method for indicating runnable param count.
context -

addEventListener

public static void addEventListener(java.lang.Object element,
                                    java.lang.String eventName,
                                    java.lang.Runnable handler)
safe context and compatible way of register events with a runnable handler

Parameters:
element -
eventName -
handler -

addEventListener_simple

public static boolean addEventListener_simple(java.lang.Object object,
                                              java.lang.String evt,
                                              java.lang.Object func,
                                              boolean capture)
Add an event listener to an object

Parameters:
object -
evt - event
func - function
capture -
Returns:
boolean true if event listener was sucessfully registered.

normalizeJsEvent

public static Event normalizeJsEvent(java.lang.Object e)
Gets an event with all needed properties

Parameters:
e - event
Returns:
event object

getDocument

public static Document getDocument()

printIn

public static void printIn(Element parent,
                           java.lang.String s)

isBrowserIE

public static boolean isBrowserIE()

getNavigator

public static Navigator getNavigator()