|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.Widget
com.google.gwt.user.client.ui.Image
public class Image
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.
If an image transitions between clipped mode and unclipped mode, any
Element
-specific attributes added by the user (including style
attributes, style names, and style modifiers), except for event listeners,
will be lost.
public class ImageExample implements EntryPoint { private Label lbl = new Label(); private Button btn = new Button("Clip this image"); private Button btn2 = new Button("Restore image"); public void onModuleLoad() { // Create an image, not yet referencing a URL. We make it final so that we // can manipulate the image object within the ClickHandlers for the buttons. final Image image = new Image(); // Hook up a load listener, so that we can be informed if the image fails // to load. image.addLoadListener(new LoadListener() { public void onError(Widget sender) { lbl.setText("An error occurred while loading."); } public void onLoad(Widget sender) { } }); // Point the image at a real URL. image.setUrl("http://www.google.com/images/logo.gif"); // When the user clicks this button, we want to clip the image. btn.addClickListener(new ClickListener() { public void onClick(Widget sender) { image.setVisibleRect(70, 0, 47, 110); } }); btn.setWidth("120px"); // When the user clicks this button, we want to restore the image to its // unclipped state. btn2.addClickListener(new ClickListener() { public void onClick(Widget sender) { image.setUrl("http://www.google.com/images/logo.gif"); } }); btn2.setWidth("120px"); // Add the image, label, and clip/restore buttons to the root panel. VerticalPanel panel = new VerticalPanel(); panel.add(lbl); panel.add(image); HorizontalPanel buttonPanel = new HorizontalPanel(); buttonPanel.add(btn); buttonPanel.add(btn2); panel.add(buttonPanel); RootPanel.get().add(panel); } }
Constructor Summary | |
---|---|
Image()
Creates an empty image. |
|
Image(java.lang.String url)
Creates an image with a specified URL. |
|
Image(java.lang.String url,
int left,
int top,
int width,
int height)
Creates a clipped image with a specified URL and visibility rectangle. |
Method Summary | |
---|---|
void |
addClickListener(ClickListener listener)
Adds a listener interface to receive click events. |
void |
addLoadListener(LoadListener listener)
Adds a listener interface to receive load events. |
void |
addMouseListener(MouseListener listener)
Adds a listener interface to receive mouse events. |
void |
addMouseWheelListener(MouseWheelListener listener)
Adds a listener interface to receive mouse events. |
int |
getHeight()
Gets the height of the image. |
int |
getOriginLeft()
Gets the horizontal co-ordinate of the upper-left vertex of the image's visibility rectangle. |
int |
getOriginTop()
Gets the vertical co-ordinate of the upper-left vertex of the image's visibility rectangle. |
java.lang.String |
getUrl()
Gets the URL of the image. |
int |
getWidth()
Gets the width of the image. |
void |
onBrowserEvent(Event event)
Fired whenever a browser event is received. |
static void |
prefetch(java.lang.String url)
Causes the browser to pre-fetch the image at a given URL. |
void |
removeClickListener(ClickListener listener)
Removes a previously added listener interface. |
void |
removeLoadListener(LoadListener listener)
Removes a previously added listener interface. |
void |
removeMouseListener(MouseListener listener)
Removes a previously added listener interface. |
void |
removeMouseWheelListener(MouseWheelListener listener)
Removes a previously added listener interface. |
void |
setUrl(java.lang.String url)
Sets the URL of the image to be displayed. |
void |
setUrlAndVisibleRect(java.lang.String url,
int left,
int top,
int width,
int height)
Sets the url and the visibility rectangle for the image at the same time. |
void |
setVisibleRect(int left,
int top,
int width,
int height)
Sets the visibility rectangle of an image. |
Methods inherited from class com.google.gwt.user.client.ui.Widget |
---|
doAttachChildren, doDetachChildren, getParent, isAttached, onAttach, onDetach, onLoad, onUnload, removeFromParent, setElement |
Methods inherited from class com.google.gwt.user.client.ui.UIObject |
---|
addStyleDependentName, addStyleName, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, removeStyleDependentName, removeStyleName, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkEvents, toString, unsinkEvents |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Image()
public Image(java.lang.String url)
url
- the URL of the image to be displayedpublic Image(java.lang.String url, int left, int top, int width, int height)
url
- the URL of the image to be displayedleft
- the horizontal co-ordinate of the upper-left vertex of the
visibility rectangletop
- the vertical co-ordinate of the upper-left vertex of the
visibility rectanglewidth
- the width of the visibility rectangleheight
- the height of the visibility rectangleMethod Detail |
---|
public static void prefetch(java.lang.String url)
url
- the URL of the image to be prefetchedpublic void addClickListener(ClickListener listener)
SourcesClickEvents
addClickListener
in interface SourcesClickEvents
listener
- the listener interface to addpublic void addLoadListener(LoadListener listener)
SourcesLoadEvents
addLoadListener
in interface SourcesLoadEvents
listener
- the listener interface to addpublic void addMouseListener(MouseListener listener)
SourcesMouseEvents
addMouseListener
in interface SourcesMouseEvents
listener
- the listener interface to addpublic void addMouseWheelListener(MouseWheelListener listener)
SourcesMouseWheelEvents
addMouseWheelListener
in interface SourcesMouseWheelEvents
listener
- the listener interface to addpublic int getHeight()
public int getOriginLeft()
public int getOriginTop()
public java.lang.String getUrl()
public int getWidth()
public void onBrowserEvent(Event event)
EventListener
onBrowserEvent
in interface EventListener
onBrowserEvent
in class Widget
event
- the event receivedpublic void removeClickListener(ClickListener listener)
SourcesClickEvents
removeClickListener
in interface SourcesClickEvents
listener
- the listener interface to removepublic void removeLoadListener(LoadListener listener)
SourcesLoadEvents
removeLoadListener
in interface SourcesLoadEvents
listener
- the listener interface to removepublic void removeMouseListener(MouseListener listener)
SourcesMouseEvents
removeMouseListener
in interface SourcesMouseEvents
listener
- the listener interface to removepublic void removeMouseWheelListener(MouseWheelListener listener)
SourcesMouseWheelEvents
removeMouseWheelListener
in interface SourcesMouseWheelEvents
listener
- the listener interface to removepublic void setUrl(java.lang.String url)
url
- the image URLpublic void setUrlAndVisibleRect(java.lang.String url, int left, int top, int width, int height)
url
- the image URLleft
- the horizontal coordinate of the upper-left vertex of the
visibility rectangletop
- the vertical coordinate of the upper-left vertex of the
visibility rectanglewidth
- the width of the visibility rectangleheight
- the height of the visibility rectanglepublic void setVisibleRect(int left, int top, int width, int height)
left
- the horizontal coordinate of the upper-left vertex of the
visibility rectangletop
- the vertical coordinate of the upper-left vertex of the
visibility rectanglewidth
- the width of the visibility rectangleheight
- the height of the visibility rectangle
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |