Fixes CustomButton to follow the new style naming pattern.
Patch by: rdayal
Review by: jgw
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@1112 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/user/client/ui/CustomButton.java b/user/src/com/google/gwt/user/client/ui/CustomButton.java
index 3694fa4..acda760 100644
--- a/user/src/com/google/gwt/user/client/ui/CustomButton.java
+++ b/user/src/com/google/gwt/user/client/ui/CustomButton.java
@@ -28,7 +28,8 @@
* hovering is assigned the CSS modifier <i>down-hovering</i>. So, if the
* button's overall style name is <i>gwt-PushButton</i> then when showing the
* <code>down-hovering</code> face, the button's style is <i>
- * gwt-PushButton-down-hovering</i>.
+ * gwt-PushButton-down-hovering</i>. The overall style name can be used to
+ * change the style of the button irrespective of the current face.
*
* <p>
* Each button face can be assigned is own image, text, or html contents. If no
@@ -263,11 +264,6 @@
private static final int DOWN_DISABLED = DOWN | DISABLED_ATTRIBUTE;
/**
- * Base style name. By default gwt-CustomButton.
- */
- private String baseStyleName;
-
- /**
* The button's current face element.
*/
private Element curFaceElement;
@@ -454,17 +450,6 @@
return getCurrentFace().getHTML();
}
- /**
- * Gets the style name associated with the object. The actual CSS style name
- * for the button will be this name + "-" + current face name.
- *
- * @return the object's style name
- * @see #setStyleName(String)
- */
- public final String getStyleName() {
- return baseStyleName;
- }
-
public int getTabIndex() {
return FocusPanel.impl.getTabIndex(getElement());
}
@@ -564,26 +549,6 @@
getCurrentFace().setHTML(html);
}
- /**
- * Sets the style name associated with the object. The actual CSS style name
- * for the button will be this name + "-" + current face name.
- *
- * @param styleName the object's style name
- * @see #setStyleName(String)
- */
- public final void setStyleName(String styleName) {
- if (styleName == null) {
- throw new IllegalStateException("Cannot set the base style name to null");
- }
- if (curFace != null) {
- super.removeStyleName(getCSSStyleName());
- baseStyleName = styleName;
- super.addStyleName(getCSSStyleName());
- } else {
- baseStyleName = styleName;
- }
- }
-
public void setTabIndex(int index) {
FocusPanel.impl.setTabIndex(getElement(), index);
}
@@ -714,7 +679,7 @@
* @return the modified style name
*/
private String getCSSStyleName() {
- return baseStyleName + "-" + curFace.getName();
+ return getStyleName() + "-" + curFace.getName();
}
private Face getFaceFromID(int id) {
diff --git a/user/test/com/google/gwt/user/client/ui/CustomButtonTest.java b/user/test/com/google/gwt/user/client/ui/CustomButtonTest.java
index 8fe9e38..c016748 100644
--- a/user/test/com/google/gwt/user/client/ui/CustomButtonTest.java
+++ b/user/test/com/google/gwt/user/client/ui/CustomButtonTest.java
@@ -56,8 +56,8 @@
Map.Entry entry = (Entry) entries.next();
Face f = (Face) entry.getValue();
b.setCurrentFace(f);
- assertTrue(DOM.getElementProperty(b.getElement(), "className").indexOf(
- "random-" + f.getName()) >= 0);
+ assertEquals("random random-" + f.getName(), DOM.getElementProperty(
+ b.getElement(), "className").trim());
}
entries = faces.entrySet().iterator();
@@ -69,6 +69,7 @@
b.setCurrentFace(f);
String computedStyleName = DOM.getElementProperty(b.getElement(),
"className");
+ assertTrue(computedStyleName.indexOf("random") == 0);
assertTrue(computedStyleName.indexOf("random-" + f.getName()) >= 0);
assertTrue(computedStyleName.indexOf("fobar") >= 0);
}