Fixes Issue 759
setText() and setHTML() were previously the only way to set a DialogBox's
caption. These two methods were not documented properly and also had
misleading names. This patch adds specific documentation for setText()
and setHTML() on DialogBox and also adds two new methods setCaptionText()
and setCaptionHTML().
Found by: sandymac
Patch by: jlabanca
Review by: knorton
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1746 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/DialogBox.java b/user/src/com/google/gwt/user/client/ui/DialogBox.java
index 6244c58..a98cfde 100644
--- a/user/src/com/google/gwt/user/client/ui/DialogBox.java
+++ b/user/src/com/google/gwt/user/client/ui/DialogBox.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2007 Google Inc.
+ * Copyright 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
@@ -36,7 +36,8 @@
* {@example com.google.gwt.examples.DialogBoxExample}
* </p>
*/
-public class DialogBox extends PopupPanel implements HasHTML, MouseListener {
+public class DialogBox extends PopupPanel implements HasHTML, HasText,
+ MouseListener {
private HTML caption = new HTML();
private Widget child;
@@ -99,7 +100,7 @@
public String getText() {
return caption.getText();
}
-
+
@Override
public Widget getWidget() {
return child;
@@ -155,10 +156,44 @@
return true;
}
+ /**
+ * Sets the html inside the caption.
+ *
+ * @param html the caption html
+ */
+ public void setCaptionHTML(String html) {
+ setHTML(html);
+ }
+
+ /**
+ * Sets the text inside the caption.
+ *
+ * @param text the caption text
+ */
+ public void setCaptionText(String text) {
+ setText(text);
+ }
+
+ /**
+ * Sets the html string inside the caption.
+ *
+ * Use {@link #setWidget(Widget)} to set the contents inside the
+ * {@link DialogBox}.
+ *
+ * @param html the object's new HTML
+ */
public void setHTML(String html) {
caption.setHTML(html);
}
+ /**
+ * Sets the text inside the caption.
+ *
+ * Use {@link #setWidget(Widget)} to set the contents inside the
+ * {@link DialogBox}.
+ *
+ * @param text the object's new text
+ */
public void setText(String text) {
caption.setText(text);
}
diff --git a/user/test/com/google/gwt/user/client/ui/DialogBoxTest.java b/user/test/com/google/gwt/user/client/ui/DialogBoxTest.java
index 99a982b..158cd78 100644
--- a/user/test/com/google/gwt/user/client/ui/DialogBoxTest.java
+++ b/user/test/com/google/gwt/user/client/ui/DialogBoxTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2007 Google Inc.
+ * Copyright 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
@@ -24,7 +24,7 @@
public String getModuleName() {
return "com.google.gwt.user.User";
}
-
+
/**
* Test the accessors.
*/
@@ -40,4 +40,31 @@
box1.setWidget(null);
assertNull(box1.getWidget());
}
+
+ /**
+ * Test getters and setters for the caption.
+ */
+ public void testCaption() {
+ DialogBox dialogBox = new DialogBox();
+
+ // Set the caption as text
+ dialogBox.setText("text");
+ assertEquals("text", dialogBox.getText());
+ dialogBox.setText("<b>text</b>");
+ assertEquals("<b>text</b>", dialogBox.getText());
+
+ // Set the caption as html
+ dialogBox.setHTML("text");
+ assertEquals("text", dialogBox.getText());
+ assertEquals("text", dialogBox.getHTML());
+ dialogBox.setHTML("<b>text</b>");
+ assertEquals("text", dialogBox.getText());
+ assertEquals("<b>text</b>", dialogBox.getHTML());
+
+ // Set the caption as caption
+ dialogBox.setCaptionText("<b>text</b>");
+ assertEquals("<b>text</b>", dialogBox.getText());
+ dialogBox.setCaptionHTML("<b>text</b>");
+ assertEquals("text", dialogBox.getText());
+ }
}