Revision: 7401
Author: [email protected]
Date: Thu Jan 14 12:01:09 2010
Log: Adding setAltText/getAltText methods to Image widget.
Patch by: bobbrose
Review by: jlabanca
Issue: 1333
http://code.google.com/p/google-web-toolkit/source/detail?r=7401
Modified:
/trunk/user/src/com/google/gwt/user/client/ui/Image.java
/trunk/user/test/com/google/gwt/user/client/ui/ImageTest.java
=======================================
--- /trunk/user/src/com/google/gwt/user/client/ui/Image.java Fri Nov 20
16:10:50 2009
+++ /trunk/user/src/com/google/gwt/user/client/ui/Image.java Thu Jan 14
12:01:09 2010
@@ -532,6 +532,15 @@
public void addMouseWheelListener(MouseWheelListener listener) {
ListenerWrapper.WrappedMouseWheelListener.add(this, listener);
}
+
+ /**
+ * Gets the alternate text for the image.
+ *
+ * @return the alternate text for the image
+ */
+ public String getAltText() {
+ return state.getImageElement(this).getAlt();
+ }
/**
* Gets the height of the image. When the image is in the unclipped
state, the
@@ -638,6 +647,16 @@
public void removeMouseWheelListener(MouseWheelListener listener) {
ListenerWrapper.WrappedMouseWheelListener.remove(this, listener);
}
+
+ /**
+ * Sets the alternate text of the image for user agents that can't
render the
+ * image.
+ *
+ * @param altText the alternate text to set to
+ */
+ public void setAltText(String altText) {
+ state.getImageElement(this).setAlt(altText);
+ }
/**
* Sets the url and the visibility rectangle for the image at the same
time,
=======================================
--- /trunk/user/test/com/google/gwt/user/client/ui/ImageTest.java Fri Nov
20 16:10:50 2009
+++ /trunk/user/test/com/google/gwt/user/client/ui/ImageTest.java Thu Jan
14 12:01:09 2010
@@ -119,6 +119,17 @@
public String getModuleName() {
return "com.google.gwt.user.UserTest";
}
+
+ public void testAltText() {
+ final String altText = "this is an image";
+ final Image image = new Image("image.png", 12, 12, 12, 12);
+
+ assertEquals("", image.getAltText());
+ image.setAltText(altText);
+ assertEquals(altText, image.getAltText());
+ image.setAltText("");
+ assertEquals("", image.getAltText());
+ }
/**
* Tests the transition from the clipped state to the unclipped state.
@@ -433,7 +444,7 @@
RootPanel.get().add(image);
}
-
+
public void testResourceConstructor() {
Bundle b = GWT.create(Bundle.class);
Image image = new Image(b.prettyPiccy());
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors