PDA

View Full Version : [BUG] Fix extra padding in ButtonBar



negge
23 Jun 2008, 9:13 PM
Right now padding is applied to the right of every button in the button bar, irrespective of how many buttons are in the bar. This patch applies the padding on the left to every button that is added after the first button. In addition, it also allows the user to specify the size of the padding and the cell spacing on the <TABLE> of the ButtonBar.


--- user/src/com/extjs/gxt/ui/client/widget/button/ButtonBar.java (revision 508)
+++ user/src/com/extjs/gxt/ui/client/widget/button/ButtonBar.java (working copy)
@@ -9,6 +9,7 @@

import com.extjs.gxt.ui.client.Events;
import com.extjs.gxt.ui.client.XDOM;
+import com.extjs.gxt.ui.client.Style;
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.core.El;
import com.extjs.gxt.ui.client.event.BaseEvent;
@@ -79,6 +80,8 @@
private HorizontalAlignment buttonAlign = HorizontalAlignment.LEFT;
private Button buttonPressed;
private El inner;
+ private int cellSpacing = Style.DEFAULT;
+ private String padding = "4px";
private Listener listener = new Listener() {
public void handleEvent(BaseEvent be) {
if (be instanceof ButtonEvent) {
@@ -153,6 +156,20 @@
}

/**
+ * @return the cellSpacing
+ */
+ public int getCellSpacing() {
+ return cellSpacing;
+ }
+
+ /**
+ * @return the padding
+ */
+ public String getPadding() {
+ return padding;
+ }
+
+ /**
* Inserts a button at the specified location. Fires the <i>BeforeAdd</i>
* event before inserting, then fires the <i>Add</i> event after the widget
* has been inserted.
@@ -164,7 +181,9 @@
@Override
public boolean insert(Button button, int index) {
TableData data = new TableData();
- data.setStyle("paddingRight: 4px;");
+ if (index>0) {
+ data.setStyle("paddingLeft: " + padding);
+ }
if (button instanceof FillButton) {
data.setWidth("100%");
}
@@ -214,6 +233,26 @@
this.buttonWidth = buttonWidth;
}

+ /**
+ * Sets the bar's cell spacing
+ *
+ * @param cellSpacing the cell spacing
+ */
+ public void setCellSpacing(int cellSpacing) {
+ assertPreRender();
+ this.cellSpacing = cellSpacing;
+ }
+
+ /**
+ * Sets the padding between adjacent buttons
+ *
+ * @param padding the padding
+ */
+ public void setPadding(String padding) {
+ assertPreRender();
+ this.padding = padding;
+ }
+
protected void onButtonPressed(ButtonEvent be) {
Button btn = be.button;
buttonPressed = btn;
@@ -252,7 +291,11 @@

StringBuffer sb = new StringBuffer();
sb.append("<div class=x-panel-btn-ct>");
- sb.append("<table width=100%><tr><td class=inner-cell align=" + align + "></td></tr></table>");
+ sb.append("<table width=100%");
+ if (cellSpacing != Style.DEFAULT) {
+ sb.append(" cellspacing=" + cellSpacing);
+ }
+ sb.append("><tr><td class=inner-cell align=" + align + "></td></tr></table>");

setElement(XDOM.create(sb.toString()), target, index);Nathan