A widget that displays the image at a given URL.
The image can be in 'unclipped' mode (the default) or 'clipped' mode. In clipped mode, a viewport is overlaid on top of the image so that a subset of the image will be displayed. In unclipped mode, there is no viewport - the entire image will be visible. Whether an image is in clipped or unclipped mode depends on how the image is constructed, and how it is transformed after construction. Methods will operate differently depending on the mode that the image is in. These differences are detailed in the documentation for each method.
Here is an example of how to use this widget:
function doGet() {
var app = UiApp.createApplication();
// The very first Google Doodle!
app.add(app.createImage("http://www.google.com/logos/googleburn.jpg"));
// Just the man in the middle
app.add(app.createImage("http://www.google.com/logos/googleburn.jpg", 118, 0, 50, 106));
return app;
}
Due to browser-specific HTML constructions needed to achieve the clipping effect, certain CSS attributes, such as padding and background, may not work as expected when an image is in clipped mode. These limitations can usually be easily worked around by encapsulating the image in a container widget that can itself be styled.
Internally, UiApp widgets are built on top of the Google Web Toolkit, and it can sometimes be helpful to look at the GWT documentation directly. You can find the Image documentation here.
Methods
Method | Return type | Brief description |
---|---|---|
addClickHandler(handler) | Image | Add a handler for click events. |
addErrorHandler(handler) | Image | Add a handler for error events (failed loads). |
addLoadHandler(handler) | Image | Add a handler for load events. |
addMouseDownHandler(handler) | Image | Add a handler for mouse down events. |
addMouseMoveHandler(handler) | Image | Add a handler for mouse move events. |
addMouseOutHandler(handler) | Image | Add a handler for mouse out events. |
addMouseOverHandler(handler) | Image | Add a handler for mouse move events. |
addMouseUpHandler(handler) | Image | Add a handler for mouse up events. |
addMouseWheelHandler(handler) | Image | Add a handler for mouse wheel events. |
addStyleDependentName(styleName) | Image | Sets the dependent style name of this Image . |
addStyleName(styleName) | Image | Adds a style name to this Image . |
getId() | String | Returns the id that has been assigned to this object. |
getTag() | String | Gets the text tag of this Image . |
getType() | String | Gets the type of this object. |
setHeight(height) | Image | Sets the height of this Image . |
setId(id) | Image | Sets the id of this Image . |
setPixelSize(width, height) | Image | Sets the size of this Image in pixels. |
setSize(width, height) | Image | Sets the size of this Image . |
setStyleAttribute(attribute, value) | Image | Sets one of this Image 's style attributes to a new value. |
setStyleAttributes(attributes) | Image | Sets this Image 's style attributes. |
setStyleName(styleName) | Image | Sets the style name of this Image . |
setStylePrimaryName(styleName) | Image | Sets the primary style name of this Image . |
setTag(tag) | Image | Sets the text tag of this Image . |
setTitle(title) | Image | Sets the hover title of this Image . |
setUrl(url) | Image | Sets the URL of the image to be displayed. |
setUrlAndVisibleRect(url, left, top, width, height) | Image | Sets the url and the visibility rectangle for the image at the same time. |
setVisible(visible) | Image | Sets whether this Image is visible. |
setVisibleRect(left, top, width, height) | Image | Sets the visibility rectangle of an image. |
setWidth(width) | Image | Sets the width of this Image . |
Detailed documentation
addClickHandler(handler)
Add a handler for click events.
Note that you can have multiple handlers for the same event on the same widget. They will be
called in the order that they were added to the widget, although
ServerHandler
s may
appear to happen simultaneously.
The handler passes back some information to the server about what happened. This information can be accessed as follows:
function doGet() {
var app = UiApp.createApplication();
var button = app.createButton("a button");
var handler = app.createServerHandler("handlerFunction");
button.addClickHandler(handler);
app.add(button);
return app;
}
function handlerFunction(eventInfo) {
var parameter = eventInfo.parameter;
// the type of event, in this case "click".
var eventType = parameter.eventType;
// the id of the widget that fired this event.
var source = parameter.source;
// mouse x and y position relative to the widget that fired the event.
var x = parameter.x;
var y = parameter.y;
// mouse x and y position within the browser window's client area.
var clientX = parameter.clientX;
var clientY = parameter.clientY;
// mouse x and y position within the user's display.
var screenX = parameter.screenX;
var screenY = parameter.screenY;
// the mouse button used. Left is 1, right is 2, and middle is 4.
var button = parameter.button;
// whether the various modifier keys were also pressed (true or false)
var shift = parameter.shift;
var alt = parameter.alt;
var ctrl = parameter.ctrl;
var meta = parameter.meta;
}
In addition, the values of certain widgets can be sent up with the event as well, as "callback
elements." See the documentation of
ServerHandler
for more information.Parameters
Name | Type | Description |
---|---|---|
handler | Handler | the handler to execute when the event occurs. This can be a
ClientHandler or a
ServerHandler . |
Return
addErrorHandler(handler)
Add a handler for error events (failed loads).
The handler passes back some information to the server about what happened. This information can be accessed as follows:
function doGet() {
var app = UiApp.createApplication();
var image = app.createImage("some image url");
var handler = app.createServerHandler("handlerFunction");
image.addErrorHandler(handler);
app.add(image);
return app;
}
function handlerFunction(eventInfo) {
var parameter = eventInfo.parameter;
// the type of event, in this case "error".
var eventType = parameter.eventType;
// the id of the widget that fired this event.
var source = parameter.source;
}
In addition, the values of certain widgets can be sent up with the event as well, as "callback
elements." See the documentation of
ServerHandler
for more information.Parameters
Name | Type | Description |
---|---|---|
handler | Handler | the handler to execute when the event occurs. This can be a
ClientHandler or a
ServerHandler . |
Return
addLoadHandler(handler)
Add a handler for load events.
The handler passes back some information to the server about what happened. This information can be accessed as follows:
function doGet() {
var app = UiApp.createApplication();
var image = app.createImage("some image url");
var handler = app.createServerHandler("handlerFunction");
image.addLoadHandler(handler);
app.add(image);
return app;
}
function handlerFunction(eventInfo) {
var parameter = eventInfo.parameter;
// the type of event, in this case "load".
var eventType = parameter.eventType;
// the id of the widget that fired this event.
var source = parameter.source;
}
In addition, the values of certain widgets can be sent up with the event as well, as "callback
elements." See the documentation of
ServerHandler
for more information.Parameters
Name | Type | Description |
---|---|---|
handler | Handler | the handler to execute when the event occurs. This can be a
ClientHandler or a
ServerHandler . |
Return
addMouseDownHandler(handler)
Add a handler for mouse down events.
Note that you can have multiple handlers for the same event on the same widget. They will be
called in the order that they were added to the widget, although
ServerHandler
s may
appear to happen simultaneously.
The handler passes back some information to the server about what happened. This information can be accessed as follows:
function doGet() {
var app = UiApp.createApplication();
var button = app.createButton("a button");
var handler = app.createServerHandler("handlerFunction");
button.addMouseDownHandler(handler);
app.add(button);
return app;
}
function handlerFunction(eventInfo) {
var parameter = eventInfo.parameter;
// the type of event, in this case "mousedown".
var eventType = parameter.eventType;
// the id of the widget that fired this event.
var source = parameter.source;
// mouse x and y position relative to the widget that fired the event.
var x = parameter.x;
var y = parameter.y;
// mouse x and y position within the browser window's client area.
var clientX = parameter.clientX;
var clientY = parameter.clientY;
// mouse x and y position within the user's display.
var screenX = parameter.screenX;
var screenY = parameter.screenY;
// the mouse button used. Left is 1, right is 2, and middle is 4.
var button = parameter.button;
// whether the various modifier keys were also pressed (true or false)
var shift = parameter.shift;
var alt = parameter.alt;
var ctrl = parameter.ctrl;
var meta = parameter.meta;
}
In addition, the values of certain widgets can be sent up with the event as well, as "callback
elements." See the documentation of
ServerHandler
for more information.Parameters
Name | Type | Description |
---|---|---|
handler | Handler | the handler to execute when the event occurs. This can be a
ClientHandler or a
ServerHandler . |
Return
addMouseMoveHandler(handler)
Add a handler for mouse move events.
Note that you can have multiple handlers for the same event on the same widget. They will be
called in the order that they were added to the widget, although
ServerHandler
s may
appear to happen simultaneously.
The handler passes back some information to the server about what happened. This information can be accessed as follows:
function doGet() {
var app = UiApp.createApplication();
var button = app.createButton("a button");
var handler = app.createServerHandler("handlerFunction");
button.addMouseMoveHandler(handler);
app.add(button);
return app;
}
function handlerFunction(eventInfo) {
var parameter = eventInfo.parameter;
// the type of event, in this case "mousemove".
var eventType = parameter.eventType;
// the id of the widget that fired this event.
var source = parameter.source;
// mouse x and y position relative to the widget that fired the event.
var x = parameter.x;
var y = parameter.y;
// mouse x and y position within the browser window's client area.
var clientX = parameter.clientX;
var clientY = parameter.clientY;
// mouse x and y position within the user's display.
var screenX = parameter.screenX;
var screenY = parameter.screenY;
// the mouse button used. Left is 1, right is 2, and middle is 4.
var button = parameter.button;
// whether the various modifier keys were also pressed (true or false)
var shift = parameter.shift;
var alt = parameter.alt;
var ctrl = parameter.ctrl;
var meta = parameter.meta;
}
In addition, the values of certain widgets can be sent up with the event as well, as "callback
elements." See the documentation of
ServerHandler
for more information.Parameters
Name | Type | Description |
---|---|---|
handler | Handler | the handler to execute when the event occurs. This can be a
ClientHandler or a
ServerHandler . |
Return
addMouseOutHandler(handler)
Add a handler for mouse out events.
Note that you can have multiple handlers for the same event on the same widget. They will be
called in the order that they were added to the widget, although
ServerHandler
s may
appear to happen simultaneously.
The handler passes back some information to the server about what happened. This information can be accessed as follows:
function doGet() {
var app = UiApp.createApplication();
var button = app.createButton("a button");
var handler = app.createServerHandler("handlerFunction");
button.addMouseOutHandler(handler);
app.add(button);
return app;
}
function handlerFunction(eventInfo) {
var parameter = eventInfo.parameter;
// the type of event, in this case "mouseout".
var eventType = parameter.eventType;
// the id of the widget that fired this event.
var source = parameter.source;
// mouse x and y position relative to the widget that fired the event.
var x = parameter.x;
var y = parameter.y;
// mouse x and y position within the browser window's client area.
var clientX = parameter.clientX;
var clientY = parameter.clientY;
// mouse x and y position within the user's display.
var screenX = parameter.screenX;
var screenY = parameter.screenY;
// the mouse button used. Left is 1, right is 2, and middle is 4.
var button = parameter.button;
// whether the various modifier keys were also pressed (true or false)
var shift = parameter.shift;
var alt = parameter.alt;
var ctrl = parameter.ctrl;
var meta = parameter.meta;
}
In addition, the values of certain widgets can be sent up with the event as well, as "callback
elements." See the documentation of
ServerHandler
for more information.Parameters
Name | Type | Description |
---|---|---|
handler | Handler | the handler to execute when the event occurs. This can be a
ClientHandler or a
ServerHandler . |
Return
addMouseOverHandler(handler)
Add a handler for mouse move events.
Note that you can have multiple handlers for the same event on the same widget. They will be
called in the order that they were added to the widget, although
ServerHandler
s may
appear to happen simultaneously.
The handler passes back some information to the server about what happened. This information can be accessed as follows:
function doGet() {
var app = UiApp.createApplication();
var button = app.createButton("a button");
var handler = app.createServerHandler("handlerFunction");
button.addMouseOverHandler(handler);
app.add(button);
return app;
}
function handlerFunction(eventInfo) {
var parameter = eventInfo.parameter;
// the type of event, in this case "mousover".
var eventType = parameter.eventType;
// the id of the widget that fired this event.
var source = parameter.source;
// mouse x and y position relative to the widget that fired the event.
var x = parameter.x;
var y = parameter.y;
// mouse x and y position within the browser window's client area.
var clientX = parameter.clientX;
var clientY = parameter.clientY;
// mouse x and y position within the user's display.
var screenX = parameter.screenX;
var screenY = parameter.screenY;
// the mouse button used. Left is 1, right is 2, and middle is 4.
var button = parameter.button;
// whether the various modifier keys were also pressed (true or false)
var shift = parameter.shift;
var alt = parameter.alt;
var ctrl = parameter.ctrl;
var meta = parameter.meta;
}
In addition, the values of certain widgets can be sent up with the event as well, as "callback
elements." See the documentation of
ServerHandler
for more information.Parameters
Name | Type | Description |
---|---|---|
handler | Handler | the handler to execute when the event occurs. This can be a
ClientHandler or a
ServerHandler . |
Return
addMouseUpHandler(handler)
Add a handler for mouse up events.
Note that you can have multiple handlers for the same event on the same widget. They will be
called in the order that they were added to the widget, although
ServerHandler
s may
appear to happen simultaneously.
The handler passes back some information to the server about what happened. This information can be accessed as follows:
function doGet() {
var app = UiApp.createApplication();
var button = app.createButton("a button");
var handler = app.createServerHandler("handlerFunction");
button.addMouseUpHandler(handler);
app.add(button);
return app;
}
function handlerFunction(eventInfo) {
var parameter = eventInfo.parameter;
// the type of event, in this case "mouseup".
var eventType = parameter.eventType;
// the id of the widget that fired this event.
var source = parameter.source;
// mouse x and y position relative to the widget that fired the event.
var x = parameter.x;
var y = parameter.y;
// mouse x and y position within the browser window's client area.
var clientX = parameter.clientX;
var clientY = parameter.clientY;
// mouse x and y position within the user's display.
var screenX = parameter.screenX;
var screenY = parameter.screenY;
// the mouse button used. Left is 1, right is 2, and middle is 4.
var button = parameter.button;
// whether the various modifier keys were also pressed (true or false)
var shift = parameter.shift;
var alt = parameter.alt;
var ctrl = parameter.ctrl;
var meta = parameter.meta;
}
In addition, the values of certain widgets can be sent up with the event as well, as "callback
elements." See the documentation of
ServerHandler
for more information.Parameters
Name | Type | Description |
---|---|---|
handler | Handler | the handler to execute when the event occurs. This can be a
ClientHandler or a
ServerHandler . |
Return
addMouseWheelHandler(handler)
Add a handler for mouse wheel events.
Note that you can have multiple handlers for the same event on the same widget. They will be
called in the order that they were added to the widget, although
ServerHandler
s may
appear to happen simultaneously.
The handler passes back some information to the server about what happened. This information can be accessed as follows:
function doGet() {
var app = UiApp.createApplication();
var button = app.createButton("a button");
var handler = app.createServerHandler("handlerFunction");
button.addMouseWheelHandler(handler);
app.add(button);
return app;
}
function handlerFunction(eventInfo) {
var parameter = eventInfo.parameter;
// the type of event, in this case "mousewheel".
var eventType = parameter.eventType;
// the id of the widget that fired this event.
var source = parameter.source;
// mouse x and y position relative to the widget that fired the event.
var x = parameter.x;
var y = parameter.y;
// mouse x and y position within the browser window's client area.
var clientX = parameter.clientX;
var clientY = parameter.clientY;
// mouse x and y position within the user's display.
var screenX = parameter.screenX;
var screenY = parameter.screenY;
// the mouse button used. Left is 1, right is 2, and middle is 4.
var button = parameter.button;
// whether the various modifier keys were also pressed (true or false)
var shift = parameter.shift;
var alt = parameter.alt;
var ctrl = parameter.ctrl;
var meta = parameter.meta;
}
In addition, the values of certain widgets can be sent up with the event as well, as "callback
elements." See the documentation of
ServerHandler
for more information.Parameters
Name | Type | Description |
---|---|---|
handler | Handler | the handler to execute when the event occurs. This can be a
ClientHandler or a
ServerHandler . |
Return
addStyleDependentName(styleName)
Sets the dependent style name of this Image
.
This is useful for debugging but is otherwise of minimal use since there is no way to use custom stylesheets in UiApp.
Parameters
Name | Type | Description |
---|---|---|
styleName | String | the new style name. |
Return
addStyleName(styleName)
Adds a style name to this Image
.
This is useful for debugging but is otherwise of minimal use since there is no way to use custom stylesheets in UiApp.
Parameters
Name | Type | Description |
---|---|---|
styleName | String | the new style name. |
Return
getId()
Returns the id that has been assigned to this object.
This can be used in conjunction with app.getElementById() to retrieve a reference to this object.
Return
String
— the id that has been assigned to this object
getType()
Gets the type of this object.
Return
String
— the object type
setHeight(height)
Sets the height of this Image
.
Parameters
Name | Type | Description |
---|---|---|
height | String | the new height in any CSS unit such as "10px" or "50%". |
Return
setId(id)
Sets the id of this Image
.
Parameters
Name | Type | Description |
---|---|---|
id | String | the new id, which can be used to retrieve the Image from
app.getElementById(id). |
Return
setPixelSize(width, height)
Sets the size of this Image
in pixels.
Parameters
Name | Type | Description |
---|---|---|
width | Integer | the new width in pixels. |
height | Integer | the new height in pixels. |
Return
setSize(width, height)
Sets the size of this Image
.
Parameters
Name | Type | Description |
---|---|---|
width | String | the new width in any CSS unit such as "10px" or "50%". |
height | String | the new height in any CSS unit such as "10px" or "50%". |
Return
setStyleAttribute(attribute, value)
Sets one of this Image
's style attributes to a new value. Valid attributes are
listed here; the values for each attribute are
the same as those available in CSS style sheets.
// Change the widget's background to black and text color to green.
widget.setStyleAttribute("background", "black")
.setStyleAttribute("color", "green");
Parameters
Name | Type | Description |
---|---|---|
attribute | String | the CSS attribute, in camel-case ("fontSize", not "font-size"), as listed here |
value | String | the CSS value |
Return
setStyleAttributes(attributes)
Sets this Image
's style attributes. This is a convenience method that is equivalent
to calling setStyleAttribute with every key/value pair in the attributes object. Valid
attributes are listed here; the values for each
attribute are the same as those available in CSS style sheets.
// Change the widget's background to black and text color to green.
widget.setStyleAttributes({background: "black", color: "green"});
Parameters
Name | Type | Description |
---|---|---|
attributes | Object | an object of key/value pairs for the CSS attributes and values to set; valid attributes are listed here |
Return
setStyleName(styleName)
Sets the style name of this Image
.
This is useful for debugging but is otherwise of minimal use since there is no way to use custom stylesheets in UiApp.
Parameters
Name | Type | Description |
---|---|---|
styleName | String | the new style name. |
Return
setStylePrimaryName(styleName)
Sets the primary style name of this Image
.
This is useful for debugging but is otherwise of minimal use since there is no way to use custom stylesheets in UiApp.
Parameters
Name | Type | Description |
---|---|---|
styleName | String | the new style name. |
Return
setTag(tag)
Sets the text tag of this Image
.
Parameters
Name | Type | Description |
---|---|---|
tag | String | the new text tag, which can be anything you wish to store with the widget. |
Return
setTitle(title)
Sets the hover title of this Image
.
Not all browsers will show this.
Parameters
Name | Type | Description |
---|---|---|
title | String | the hover title. |
Return
setUrl(url)
Sets the URL of the image to be displayed.
If the image is in the clipped state, a call to this method will cause a transition of the image to the unclipped state. Regardless of whether or not the image is in the clipped or unclipped state, a load event will be fired.
Parameters
Name | Type | Description |
---|---|---|
url | String | the new image url. |
Return
setUrlAndVisibleRect(url, left, top, width, height)
Sets the url and the visibility rectangle for the image at the same time.
A single load event will be fired if either the incoming url or visiblity rectangle coordinates differ from the image's current url or current visibility rectangle coordinates. If the image is currently in the unclipped state, a call to this method will cause a transition to the clipped state.
Parameters
Name | Type | Description |
---|---|---|
url | String | the new image url. |
left | Integer | the the horizontal coordinate of the upper-left vertex of the visibility rectangle, in pixels. |
top | Integer | the the vertical coordinate of the upper-left vertex of the visibility rectangle, in pixels. |
width | Integer | the width of the visibility rectangle. |
height | Integer | the height of the visibility rectangle. |
Return
setVisible(visible)
Sets whether this Image
is visible.
Parameters
Name | Type | Description |
---|---|---|
visible | Boolean | whether this Image should be visible or not. |
Return
setVisibleRect(left, top, width, height)
Sets the visibility rectangle of an image.
The visibility rectangle is declared relative to the the rectangle which encompasses the entire image, which has an upper-left vertex of (0,0). Provided that any of the left, top, width, and height parameters are different than the those values that are currently set for the image, a load event will be fired. If the image is in the unclipped state, a call to this method will cause a transition of the image to the clipped state. This transition will cause a load event to fire.
Parameters
Name | Type | Description |
---|---|---|
left | Integer | the the horizontal coordinate of the upper-left vertex of the visibility rectangle, in pixels. |
top | Integer | the the vertical coordinate of the upper-left vertex of the visibility rectangle, in pixels. |
width | Integer | the width of the visibility rectangle. |
height | Integer | the height of the visibility rectangle. |
Return
setWidth(width)
Sets the width of this Image
.
Parameters
Name | Type | Description |
---|---|---|
width | String | the new width in any CSS unit such as "10px" or "50%". |