|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.gwt.user.client.DOM
public class DOM
This class provides a set of static methods that allow you to manipulate the
browser's Document Object Model (DOM). It contains methods for manipulating
both elements
and
events
.
Constructor Summary | |
---|---|
DOM()
|
Method Summary | |
---|---|
static void |
addEventPreview(EventPreview preview)
Adds an event preview to the preview stack. |
static void |
appendChild(Element parent,
Element child)
Appends one element to another's list of children. |
static boolean |
compare(Element elem1,
Element elem2)
Compares two elements for equality (note that reference equality is not sufficient to determine equality among elements on most browsers). |
static Element |
createAnchor()
Creates an HTML A element. |
static Element |
createButton()
Creates an HTML BUTTON element. |
static Element |
createCaption()
Creates an HTML CAPTION element. |
static Element |
createCol()
Creates an HTML COL element. |
static Element |
createColGroup()
Creates an HTML COLGROUP element. |
static Element |
createDiv()
Creates an HTML DIV element. |
static Element |
createElement(java.lang.String tagName)
Creates an HTML element. |
static Element |
createFieldSet()
Creates an HTML FIELDSET element. |
static Element |
createForm()
Creates an HTML FORM element. |
static Element |
createIFrame()
Creates an HTML IFRAME element. |
static Element |
createImg()
Creates an HTML IMG element. |
static Element |
createInputCheck()
Creates an HTML INPUT type='CHECK' element. |
static Element |
createInputPassword()
Creates an HTML INPUT type='PASSWORD' element. |
static Element |
createInputRadio(java.lang.String name)
Creates an HTML INPUT type='RADIO' element. |
static Element |
createInputText()
Creates an HTML INPUT type='TEXT' element. |
static Element |
createLabel()
Creates an HTML LABEL element. |
static Element |
createLegend()
Creates an HTML LEGEND element. |
static Element |
createOptions()
Creates an HTML OPTIONS element. |
static Element |
createSelect()
Creates a single-selection HTML SELECT element. |
static Element |
createSelect(boolean multiple)
Creates an HTML SELECT element. |
static Element |
createSpan()
Creates an HTML SPAN element. |
static Element |
createTable()
Creates an HTML TABLE element. |
static Element |
createTBody()
Creates an HTML TBODY element. |
static Element |
createTD()
Creates an HTML TD element. |
static Element |
createTextArea()
Creates an HTML TEXTAREA element. |
static Element |
createTFoot()
Creates an HTML TFOOT element. |
static Element |
createTH()
Creates an HTML TH element. |
static Element |
createTHead()
Creates an HTML THEAD element. |
static Element |
createTR()
Creates an HTML TR element. |
static void |
eventCancelBubble(Event evt,
boolean cancel)
Cancels bubbling for the given event. |
static boolean |
eventGetAltKey(Event evt)
Gets whether the ALT key was depressed when the given event occurred. |
static int |
eventGetButton(Event evt)
Gets the mouse buttons that were depressed when the given event occurred. |
static int |
eventGetClientX(Event evt)
Gets the mouse x-position within the browser window's client area. |
static int |
eventGetClientY(Event evt)
Gets the mouse y-position within the browser window's client area. |
static boolean |
eventGetCtrlKey(Event evt)
Gets whether the CTRL key was depressed when the given event occurred. |
static Event |
eventGetCurrentEvent()
Gets the current event that is being fired. |
static Element |
eventGetCurrentTarget(Event evt)
Gets the current target element of the given event. |
static Element |
eventGetFromElement(Event evt)
Gets the element from which the mouse pointer was moved (only valid for Event.ONMOUSEOVER ). |
static int |
eventGetKeyCode(Event evt)
Gets the key code associated with this event. |
static boolean |
eventGetMetaKey(Event evt)
Gets whether the META key was depressed when the given event occurred. |
static int |
eventGetMouseWheelVelocityY(Event evt)
Gets the velocity of the mouse wheel associated with the event along the Y axis. |
static boolean |
eventGetRepeat(Event evt)
Gets the key-repeat state of this event. |
static int |
eventGetScreenX(Event evt)
Gets the mouse x-position on the user's display. |
static int |
eventGetScreenY(Event evt)
Gets the mouse y-position on the user's display. |
static boolean |
eventGetShiftKey(Event evt)
Gets whether the shift key was depressed when the given event occurred. |
static Element |
eventGetTarget(Event evt)
Returns the element that was the actual target of the given event. |
static Element |
eventGetToElement(Event evt)
Gets the element to which the mouse pointer was moved (only valid for Event.ONMOUSEOUT ). |
static int |
eventGetType(Event evt)
Gets the enumerated type of this event (as defined in Event ). |
static java.lang.String |
eventGetTypeString(Event evt)
Gets the type of the given event as a string. |
static void |
eventPreventDefault(Event evt)
Prevents the browser from taking its default action for the given event. |
static void |
eventSetKeyCode(Event evt,
char key)
Sets the key code associated with the given keyboard event. |
static java.lang.String |
eventToString(Event evt)
Returns a stringized version of the event. |
static int |
getAbsoluteLeft(Element elem)
Gets an element's absolute left coordinate in the document's coordinate system. |
static int |
getAbsoluteTop(Element elem)
Gets an element's absolute top coordinate in the document's coordinate system. |
static java.lang.String |
getAttribute(Element elem,
java.lang.String attr)
Deprecated. Use the more appropriately named getElementProperty(Element, String) instead. |
static boolean |
getBooleanAttribute(Element elem,
java.lang.String attr)
Deprecated. Use the more appropriately named getElementPropertyBoolean(Element, String) instead. |
static Element |
getCaptureElement()
Gets the element that currently has mouse capture. |
static Element |
getChild(Element parent,
int index)
Gets an element's n-th child element. |
static int |
getChildCount(Element parent)
Gets the number of child elements present in a given parent element. |
static int |
getChildIndex(Element parent,
Element child)
Gets the index of a given child element within its parent. |
static java.lang.String |
getElementAttribute(Element elem,
java.lang.String attr)
Gets the named attribute from the element. |
static Element |
getElementById(java.lang.String id)
Gets the element associated with the given unique id within the entire document. |
static java.lang.String |
getElementProperty(Element elem,
java.lang.String prop)
Gets any named property from an element, as a string. |
static boolean |
getElementPropertyBoolean(Element elem,
java.lang.String prop)
Gets any named property from an element, as a boolean. |
static int |
getElementPropertyInt(Element elem,
java.lang.String prop)
Gets any named property from an element, as an int. |
static int |
getEventsSunk(Element elem)
Gets the current set of events sunk by a given element. |
static Element |
getFirstChild(Element elem)
Gets the first child element of the given element. |
static java.lang.String |
getImgSrc(Element img)
Gets the src attribute of an img element. |
static java.lang.String |
getInnerHTML(Element elem)
Gets an HTML representation of an element's children. |
static java.lang.String |
getInnerText(Element elem)
Gets the text contained within an element. |
static int |
getIntAttribute(Element elem,
java.lang.String attr)
Deprecated. Use the more appropriately named getElementPropertyInt(Element, String) instead. |
static int |
getIntStyleAttribute(Element elem,
java.lang.String attr)
Gets an integer attribute on a given element's style. |
static Element |
getNextSibling(Element elem)
Gets an element's next sibling element. |
static Element |
getParent(Element elem)
Gets an element's parent element. |
static java.lang.String |
getStyleAttribute(Element elem,
java.lang.String attr)
Gets an attribute of the given element's style. |
static void |
insertBefore(Element parent,
Element child,
Element before)
Inserts an element as a child of the given parent element, before another child of that parent. |
static void |
insertChild(Element parent,
Element child,
int index)
Inserts an element as a child of the given parent element. |
static void |
insertListItem(Element select,
java.lang.String item,
java.lang.String value,
int index)
Creates an <option> element and inserts it as a child
of the specified <select> element. |
static boolean |
isOrHasChild(Element parent,
Element child)
Determine whether one element is equal to, or the child of, another. |
static void |
releaseCapture(Element elem)
Releases mouse capture on the given element. |
static void |
removeChild(Element parent,
Element child)
Removes a child element from the given parent element. |
static void |
removeElementAttribute(Element elem,
java.lang.String attr)
Removes the named attribute from the given element. |
static void |
removeEventPreview(EventPreview preview)
Removes an element from the preview stack. |
static void |
scrollIntoView(Element elem)
Scrolls the given element into view. |
static void |
setAttribute(Element elem,
java.lang.String attr,
java.lang.String value)
Deprecated. Use the more appropriately named setElementProperty(Element, String, String) instead. |
static void |
setBooleanAttribute(Element elem,
java.lang.String attr,
boolean value)
Deprecated. Use the more appropriately named setElementPropertyBoolean(Element, String, boolean) instead. |
static void |
setCapture(Element elem)
Sets mouse-capture on the given element. |
static void |
setElementAttribute(Element elem,
java.lang.String attr,
java.lang.String value)
Sets an attribute on a given element. |
static void |
setElementProperty(Element elem,
java.lang.String prop,
java.lang.String value)
Sets a property on the given element. |
static void |
setElementPropertyBoolean(Element elem,
java.lang.String prop,
boolean value)
Sets a boolean property on the given element. |
static void |
setElementPropertyInt(Element elem,
java.lang.String prop,
int value)
Sets an int property on the given element. |
static void |
setEventListener(Element elem,
EventListener listener)
Sets the EventListener to receive events for the given element. |
static void |
setImgSrc(Element img,
java.lang.String src)
Sets the src attribute of an img element. |
static void |
setInnerHTML(Element elem,
java.lang.String html)
Sets the HTML contained within an element. |
static void |
setInnerText(Element elem,
java.lang.String text)
Sets the text contained within an element. |
static void |
setIntAttribute(Element elem,
java.lang.String attr,
int value)
Deprecated. Use the more appropriately named setElementPropertyInt(Element, String, int) instead. |
static void |
setIntStyleAttribute(Element elem,
java.lang.String attr,
int value)
Sets an integer attribute on the given element's style. |
static void |
setOptionText(Element select,
java.lang.String text,
int index)
Sets the option text of the given select object. |
static void |
setStyleAttribute(Element elem,
java.lang.String attr,
java.lang.String value)
Sets an attribute on the given element's style. |
static void |
sinkEvents(Element elem,
int eventBits)
Sets the current set of events sunk by a given element. |
static java.lang.String |
toString(Element elem)
Returns a stringized version of the element. |
static int |
windowGetClientHeight()
Gets the height of the browser window's client area excluding the scroll bar. |
static int |
windowGetClientWidth()
Gets the width of the browser window's client area excluding the vertical scroll bar. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DOM()
Method Detail |
---|
public static void addEventPreview(EventPreview preview)
preview
- the event preview to be added to the stack.public static void appendChild(Element parent, Element child)
parent
- the parent elementchild
- its new childpublic static boolean compare(Element elem1, Element elem2)
elem1
- the first element to be comparedelem2
- the second element to be compared
true
if they are in fact the same elementisOrHasChild(Element, Element)
public static Element createAnchor()
public static Element createButton()
public static Element createCaption()
public static Element createCol()
public static Element createColGroup()
public static Element createDiv()
public static Element createElement(java.lang.String tagName)
tagName
- the HTML tag of the element to be created
public static Element createFieldSet()
public static Element createForm()
public static Element createIFrame()
public static Element createImg()
public static Element createInputCheck()
public static Element createInputPassword()
public static Element createInputRadio(java.lang.String name)
name
- the name of the group with which this radio button will be
associated
public static Element createInputText()
public static Element createLabel()
public static Element createLegend()
public static Element createOptions()
public static Element createSelect()
createSelect(false)
public static Element createSelect(boolean multiple)
multiple
- true if multiple selection of options is allowed
public static Element createSpan()
public static Element createTable()
public static Element createTBody()
public static Element createTD()
public static Element createTextArea()
public static Element createTFoot()
public static Element createTH()
public static Element createTHead()
public static Element createTR()
public static void eventCancelBubble(Event evt, boolean cancel)
evt
- the event on which to cancel bubblingcancel
- true
to cancel bubblingpublic static boolean eventGetAltKey(Event evt)
evt
- the event to be tested
true
if ALT was depressed when the event occurredpublic static int eventGetButton(Event evt)
evt
- the event to be tested
Event.BUTTON_LEFT
,
Event.BUTTON_MIDDLE
, and Event.BUTTON_RIGHT
public static int eventGetClientX(Event evt)
evt
- the event to be tested
public static int eventGetClientY(Event evt)
evt
- the event to be tested
public static boolean eventGetCtrlKey(Event evt)
evt
- the event to be tested
true
if CTRL was depressed when the event occurredpublic static Event eventGetCurrentEvent()
public static Element eventGetCurrentTarget(Event evt)
evt
- the event
eventGetTarget(Event)
public static Element eventGetFromElement(Event evt)
Event.ONMOUSEOVER
).
evt
- the event to be tested
public static int eventGetKeyCode(Event evt)
For Event.ONKEYPRESS
, this method returns the Unicode value of the
character generated. For Event.ONKEYDOWN
and Event.ONKEYUP
,
it returns the code associated with the physical key.
evt
- the event to be tested
KeyboardListener
public static boolean eventGetMetaKey(Event evt)
evt
- the event to be tested
true
if META was depressed when the event occurredpublic static int eventGetMouseWheelVelocityY(Event evt)
The velocity of the event is an artifical measurement for relative comparisons of wheel activity. It is affected by some non-browser factors, including choice of input hardware and mouse acceleration settings. The sign of the velocity measurement agrees with the screen coordinate system; negative values are towards the origin and positive values are away from the origin. Standard scrolling speed is approximately ten units per event.
evt
- the event to be examined.
public static boolean eventGetRepeat(Event evt)
evt
- the event to be tested
true
if this key event was an auto-repeatpublic static int eventGetScreenX(Event evt)
evt
- the event to be tested
public static int eventGetScreenY(Event evt)
evt
- the event to be tested
public static boolean eventGetShiftKey(Event evt)
evt
- the event to be tested
true
if shift was depressed when the event occurredpublic static Element eventGetTarget(Event evt)
evt
- the event to be tested
public static Element eventGetToElement(Event evt)
Event.ONMOUSEOUT
).
evt
- the event to be tested
public static int eventGetType(Event evt)
Event
).
evt
- the event to be tested
public static java.lang.String eventGetTypeString(Event evt)
evt
- the event to be tested
public static void eventPreventDefault(Event evt)
evt
- the event whose default action is to be preventedpublic static void eventSetKeyCode(Event evt, char key)
evt
- the event whose key code is to be setkey
- the new key codepublic static java.lang.String eventToString(Event evt)
evt
- the event to stringize
public static int getAbsoluteLeft(Element elem)
elem
- the element to be measured
public static int getAbsoluteTop(Element elem)
elem
- the element to be measured
public static java.lang.String getAttribute(Element elem, java.lang.String attr)
getElementProperty(Element, String)
instead.
elem
- the element whose attribute is to be retrievedattr
- the name of the attribute
public static boolean getBooleanAttribute(Element elem, java.lang.String attr)
getElementPropertyBoolean(Element, String)
instead.
elem
- the element whose attribute is to be setattr
- the name of the attribute to be set
public static Element getCaptureElement()
null
if none
existspublic static Element getChild(Element parent, int index)
parent
- the element whose child is to be retrievedindex
- the index of the child element
public static int getChildCount(Element parent)
parent
- the element whose children are to be counted
public static int getChildIndex(Element parent, Element child)
parent
- the parent elementchild
- the child element
-1
if it is
not a child of the given parentpublic static java.lang.String getElementAttribute(Element elem, java.lang.String attr)
elem
- the element whose property is to be retrievedattr
- the name of the attribute
public static Element getElementById(java.lang.String id)
id
- the id whose associated element is to be retrieved
null
if none is foundpublic static java.lang.String getElementProperty(Element elem, java.lang.String prop)
elem
- the element whose property is to be retrievedprop
- the name of the property
public static boolean getElementPropertyBoolean(Element elem, java.lang.String prop)
elem
- the element whose property is to be retrievedprop
- the name of the property
public static int getElementPropertyInt(Element elem, java.lang.String prop)
elem
- the element whose property is to be retrievedprop
- the name of the property
public static int getEventsSunk(Element elem)
elem
- the element whose events are to be retrieved
Event
)public static Element getFirstChild(Element elem)
elem
- the element whose child is to be retrieved
public static java.lang.String getImgSrc(Element img)
setImgSrc(Element, String)
so that it always returns the correct
url.
img
- a non-null img whose src attribute is to be read.
public static java.lang.String getInnerHTML(Element elem)
elem
- the element whose HTML is to be retrieved
public static java.lang.String getInnerText(Element elem)
elem
- the element whose inner text is to be retrieved
public static int getIntAttribute(Element elem, java.lang.String attr)
getElementPropertyInt(Element, String)
instead.
elem
- the element whose attribute is to be retrievedattr
- the name of the attribute to be retrieved
public static int getIntStyleAttribute(Element elem, java.lang.String attr)
elem
- the element whose style attribute is to be retrievedattr
- the name of the attribute to be retrieved
public static Element getNextSibling(Element elem)
elem
- the element whose sibling is to be retrieved
public static Element getParent(Element elem)
elem
- the element whose parent is to be retrieved
public static java.lang.String getStyleAttribute(Element elem, java.lang.String attr)
elem
- the element whose style attribute is to be retrievedattr
- the name of the style attribute to be retrieved
public static void insertBefore(Element parent, Element child, Element before)
parent
- the parent elementchild
- the child element to add to parent
before
- an existing child element of parent
before
which child
will be insertedpublic static void insertChild(Element parent, Element child, int index)
parent
- the parent elementchild
- the child element to add to parent
index
- the index before which the child will be inserted (any value
greater than the number of existing children will cause the child
to be appended)public static void insertListItem(Element select, java.lang.String item, java.lang.String value, int index)
<option>
element and inserts it as a child
of the specified <select>
element. If the index is
less than zero, or greater than or equal to the length of the list, then
the option element will be appended to the end of the list.
select
- the <select>
elementitem
- the text of the new item; cannot be null
value
- the value
attribute for the new
<option>
; cannot be null
index
- the index at which to insert the childpublic static boolean isOrHasChild(Element parent, Element child)
parent
- the potential parent elementchild
- the potential child element
true
if the relationship holdscompare(Element, Element)
public static void releaseCapture(Element elem)
elem
- the element to release capturesetCapture(Element)
public static void removeChild(Element parent, Element child)
parent
- the parent elementchild
- the child element to be removedpublic static void removeElementAttribute(Element elem, java.lang.String attr)
elem
- the element whose attribute is to be removedattr
- the name of the element to removepublic static void removeEventPreview(EventPreview preview)
preview
- the event preview to be removed from the stackpublic static void scrollIntoView(Element elem)
This method crawls up the DOM hierarchy, adjusting the scrollLeft and scrollTop properties of each scrollable element to ensure that the specified element is completely in view. It adjusts each scroll position by the minimum amount necessary.
elem
- the element to be made visiblepublic static void setAttribute(Element elem, java.lang.String attr, java.lang.String value)
setElementProperty(Element, String, String)
instead.
elem
- the element whose attribute is to be setattr
- the name of the attribute to be setvalue
- the new attribute valuepublic static void setBooleanAttribute(Element elem, java.lang.String attr, boolean value)
setElementPropertyBoolean(Element, String, boolean)
instead.
elem
- the element whose attribute is to be setattr
- the name of the attribute to be setvalue
- the attribute's new boolean valuepublic static void setCapture(Element elem)
releaseCapture(Element)
is called on it.
elem
- the element on which to set mouse capturepublic static void setElementAttribute(Element elem, java.lang.String attr, java.lang.String value)
elem
- element whose attribute is to be setattr
- the name of the attributevalue
- the value to which the attribute should be setpublic static void setElementProperty(Element elem, java.lang.String prop, java.lang.String value)
elem
- the element whose property is to be setprop
- the name of the property to be setvalue
- the new property valuepublic static void setElementPropertyBoolean(Element elem, java.lang.String prop, boolean value)
elem
- the element whose property is to be setprop
- the name of the property to be setvalue
- the new property value as a booleanpublic static void setElementPropertyInt(Element elem, java.lang.String prop, int value)
elem
- the element whose property is to be setprop
- the name of the property to be setvalue
- the new property value as an intpublic static void setEventListener(Element elem, EventListener listener)
EventListener
to receive events for the given element.
Only one such listener may exist for a single element.
elem
- the element whose listener is to be setlistener
- the listener to receive events
public static void setImgSrc(Element img, java.lang.String src)
img
- a non-null img whose src attribute will be set.src
- a non-null url for the imgpublic static void setInnerHTML(Element elem, java.lang.String html)
elem
- the element whose inner HTML is to be sethtml
- the new htmlpublic static void setInnerText(Element elem, java.lang.String text)
elem
- the element whose inner text is to be settext
- the new textpublic static void setIntAttribute(Element elem, java.lang.String attr, int value)
setElementPropertyInt(Element, String, int)
instead.
elem
- the element whose attribute is to be setattr
- the name of the attribute to be setvalue
- the attribute's new integer valuepublic static void setIntStyleAttribute(Element elem, java.lang.String attr, int value)
elem
- the element whose style attribute is to be setattr
- the name of the style attribute to be setvalue
- the style attribute's new integer valuepublic static void setOptionText(Element select, java.lang.String text, int index)
select
- the select object whose option text is being settext
- the text to setindex
- the index of the option whose text should be setpublic static void setStyleAttribute(Element elem, java.lang.String attr, java.lang.String value)
elem
- the element whose style attribute is to be setattr
- the name of the style attribute to be setvalue
- the style attribute's new valuepublic static void sinkEvents(Element elem, int eventBits)
EventListener
specified on any of the
element's parents.
elem
- the element whose events are to be retrievedeventBits
- a bitfield describing the events sunk on this element (its
possible values are described in Event
)public static java.lang.String toString(Element elem)
elem
- the element to stringize
public static int windowGetClientHeight()
public static int windowGetClientWidth()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |