org.liyifeng.html.Td Maven / Gradle / Ivy
The newest version!
package org.liyifeng.html;
/**
* @author liyifeng
* date 2016年6月28日 下午5:06:05
*/
public class Td extends AbstractHtmlTag {
private Integer colspan;
private Integer rowspan;
private Object text;
private Integer width;
/**
*
* @param text td内容
* @param rowspan 跨行
* @param colspan 跨列
*/
public Td(Object text, Integer rowspan, Integer colspan) {
super();
this.text = text;
if (rowspan != null) {
this.rowspan = rowspan;
}
if (colspan != null) {
this.colspan = colspan;
}
}
/**
* @param text td内容
*/
public Td(Object text) {
super();
this.text = text;
}
/**
*/
public Td() {
super();
}
/**
*
* @param key css样式名
* @param val css样式值
*/
public void addStyle(String key, String val) {
styleMap.put(key, val);
}
/**
*
* @param key css样式名
* @param val css样式值
* @return this
*/
public Td appendStyle(String key, String val) {
styleMap.put(key, val);
return this;
}
/*
*
* @see com.anxinyisheng.html.IHtml#toHtml()
*/
@Override
public String html() {
StringBuilder sb = new StringBuilder();
sb.append("");
if (text != null) {
sb.append(text);
}
sb.append(" ");
return sb.toString();
}
/**
*
* @return html
*/
@Override
public String toString() {
return html();
}
/**
*
* @param colspan 跨N列
* @return this
*/
public Td colspan(Integer colspan) {
this.colspan = colspan;
return this;
}
/**
*
* @param rowspan 跨N行
* @return this
*/
public Td rowspan(Integer rowspan) {
this.rowspan = rowspan;
return this;
}
@Override
public void clearStyle() {
colspan = null;
rowspan = null;
super.clearStyle();
}
@Override
public void clearElement() {
text = null;
}
@Override
public Td style(String styleKey, String styleVal) {
styleMap.put(styleKey, styleVal);
return this;
}
@Override
public String text() {
return text == null ? "" : text.toString();
}
public Integer colspan() {
return colspan;
}
public Integer rowspan() {
return rowspan;
}
public void width(Integer width) {
this.width = width;
}
public Integer width() {
return this.width;
}
}