1 13 package info.magnolia.cms.gui.control; 14 15 import org.apache.commons.lang.StringUtils; 16 17 18 22 public class Button extends ControlSuper { 23 24 27 private static final String HTML_PRE_DIVIDED = "<table cellpadding=0 cellspacing=0 border=0><tr><td>"; 29 private String label; 30 31 private String iconSrc; 32 33 private String onclick; 34 35 private int state = BUTTONSTATE_NORMAL; 36 37 private int buttonType = BUTTONTYPE_PUSHBUTTON; 38 39 private String pushButtonTag = "span"; 41 private boolean small; 42 43 public Button() { 44 } 45 46 public Button(String name, String value) { 47 super(name, value); 48 } 49 50 public void setLabel(String s) { 51 this.label = s; 52 } 53 54 public String getLabel() { 55 if (this.label != null) { 56 return this.label; 57 } 58 59 return this.getValue(); 60 } 61 62 66 public void setIconSrc(String s) { 67 this.iconSrc = s; 68 } 69 70 public String getIconSrc() { 71 if (iconSrc == null) { 72 return StringUtils.EMPTY; 73 } 74 75 return "<img SRC=\"" + this.iconSrc + "\" />"; } 78 79 public void setOnclick(String s) { 80 this.onclick = s; 81 } 82 83 public String getOnclick() { 84 return this.onclick; 85 } 86 87 public void setHtmlPre() { 88 if (super.getHtmlPre(null) == null) { 89 if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) { 90 this.setHtmlPre(StringUtils.EMPTY); 91 } 92 else { 93 this.setHtmlPre(HTML_PRE_DIVIDED); 94 } 95 } 96 } 97 98 public void setHtmlInter() { 99 if (super.getHtmlInter(null) == null) { 100 if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) { 101 this.setHtmlInter(StringUtils.EMPTY); 102 } 103 else { 104 this.setHtmlInter("</td><td>"); } 106 } 107 } 108 109 public void setHtmlPost() { 110 if (super.getHtmlPost(null) == null) { 111 if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) { 112 this.setHtmlPost(StringUtils.EMPTY); 113 } 114 else { 115 this.setHtmlPost("</td></tr></table>"); } 117 } 118 } 119 120 public void setSmall(boolean b) { 121 this.small = b; 122 } 123 124 public boolean getSmall() { 125 return this.small; 126 } 127 128 public void setPushButtonTag(String s) { 129 this.pushButtonTag = s; 130 } 131 132 public String getPushButtonTag() { 133 return this.pushButtonTag; 134 } 135 136 public String getHtml() { 137 StringBuffer html = new StringBuffer (); 138 this.setHtmlPre(); 139 this.setHtmlInter(); 140 this.setHtmlPost(); 141 html.append(this.getHtmlPre()); 142 if (this.getButtonType() == BUTTONTYPE_PUSHBUTTON) { 143 html.append(this.getHtmlPushbutton()); 144 } 145 else { 146 html.append(this.getHtmlDividedbutton()); 147 } 148 html.append(this.getHtmlPost()); 149 return html.toString(); 150 } 151 152 public String getHtmlDividedbutton() { 153 StringBuffer html = new StringBuffer (); 154 String buttonType; 155 if (this.getButtonType() == BUTTONTYPE_RADIO) { 156 buttonType = "radio"; } 158 else { 159 buttonType = "checkbox"; } 161 html.append("<input type=\"" + buttonType + "\""); html.append(" name=\"" + this.getName() + "\""); html.append(" value=\"" + this.getValue() + "\""); html.append(" id=\"" + this.getId() + "\""); if (StringUtils.isNotEmpty(this.getOnclick())) { 166 html.append(" onclick=\"" + this.getOnclick() + "\""); } 168 if (this.getState() == BUTTONSTATE_PUSHED) { 169 html.append(" checked"); } 171 html.append(this.getHtmlCssClass()); 172 html.append(this.getHtmlCssStyles()); 173 html.append(" />"); if (this.getSaveInfo()) { 175 html.append(this.getHtmlSaveInfo()); 176 } 177 html.append(this.getHtmlInter()); 178 html.append("<a HREF=\"javascript:mgnlShiftDividedButton('" + this.getId() + "');"); if (StringUtils.isNotEmpty(this.getOnclick())) { 180 html.append(this.getOnclick()); 181 } 182 html.append("\" " + this.getHtmlCssClass() + ">"); 184 html.append(this.getLabel()); 185 html.append(this.getIconSrc()); 186 187 html.append("</a>"); return html.toString(); 189 } 190 191 public String getHtmlPushbutton() { 192 StringBuffer html = new StringBuffer (); 193 html.append("<" + this.getPushButtonTag()); if (StringUtils.isEmpty(this.getCssClass())) { 195 if (this.getSmall()) { 196 this.setCssClass(CSSCLASS_CONTROLBUTTONSMALL); 197 } 198 else { 199 this.setCssClass(CSSCLASS_CONTROLBUTTON); 200 } 201 } 202 if (this.getState() == BUTTONSTATE_PUSHED) { 203 this.setCssClass(this.getCssClass() + "_PUSHED"); } 205 html.append(" onclick=\"mgnlShiftPushButtonClick(this);"); 207 if (StringUtils.isNotEmpty(this.getOnclick())) { 208 html.append(this.getOnclick()); 209 } 210 html.append("\""); 212 html.append(" onmousedown=\"mgnlShiftPushButtonDown(this);\""); html.append(" onmouseout=\"mgnlShiftPushButtonOut(this);\""); html.append(this.getHtmlId()); 215 html.append(this.getHtmlCssClass()); 216 html.append(this.getHtmlCssStyles()); 217 html.append(">"); 219 html.append(this.getIconSrc()); 220 html.append(this.getLabel()); 221 html.append("</" + this.getPushButtonTag() + ">"); return html.toString(); 223 } 224 225 public void setState(int i) { 226 this.state = i; 227 } 228 229 public int getState() { 230 return this.state; 231 } 232 233 public void setButtonType(int i) { 234 this.buttonType = i; 235 } 236 237 public int getButtonType() { 238 return this.buttonType; 239 } 240 241 245 public void setLabelNbspPadding(int i) { 246 } 248 } 249 | Popular Tags |