组件的开发一个圆角边框的开发示例
package snowrain.webframework.web.border;
import java.util.List;
import java.util.Properties;
import java.util.ArrayList;
import snowrain.webframework.web.*;
import snowrain.webframework.xsd.XsdElement;
/**
* 一个圆角边框
* @author snowrain
* @version 1.0
*/
public class BorderContent extends WebObject {
public static String Path = "borderContent/";
private static String Skin = "yellow";
private String ContentBackGroundColor = "#fbfdf0";
/**
* 构造函数
*/
public BorderContent() {
}
/**
* 构造函数
* @param path String 图象路径
* @param skin String Skin名
* @param bgColor String 背景颜色
*/
public BorderContent(String path, String skin, String bgColor) {
Path = path;
Skin = skin;
ContentBackGroundColor = bgColor;
}
/**
* 构造函数
* @param path String 图象路径
* @param skin String Skin名
*/
public BorderContent(String path, String skin) {
Path = path;
Skin = skin;
}
/**
* 构造函数
* @param skin String Skin名
*/
public BorderContent(String skin) {
Skin = skin;
}
/**
* 返回用到的CSS文件名
* @return String
*/
public static String getCssFile() {
return Path + Skin + "/border.css";
}
/**
* 设置路径
* @param path String
*/
public static void setPath(String path) {
Path = path;
}
/**
* 用于从XML读入参数停息
* @param prop Properties
*/
public void parameterFromProperties(Properties prop) {
super.parameterFromProperties(prop);
Path = prop.getProperty("Path");
Skin = prop.getProperty("Skin");
ContentBackGroundColor = prop.getProperty("ContentBackGroundColor");
}
/**
* 提供克隆方法
* @return WebObject
*/
public WebObject cloneWebObject() {
return this;
}
/**
* 返回下面部分的内容
* @return String
*/
public String getFooter() {
if (!isInit) {
init();
}
String imagePath = (Path.endsWith("/") ? Path : (Path + "/")) + Skin +
"/";
String str = "";
str += " </td>\n";
str += " <td valign=\"top\" width=\"7\" background=\"" +
imagePath + "middleRight.gif\"><img src=\"" +
imagePath +
"middleRight.gif\" width=\"7\" height=\"21\"></td>\n";
str += " </tr>\n";
str += " </table>\n";
str += " </td>\n";
str += " </tr>\n";
str += " <tr>\n";
str += " <td valign=\"top\">\n";
str += " <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
str += " <tr>\n";
str += " <td width=\"10\"><img src=\"" + imagePath +
"bottomLeft.gif\" width=\"10\" height=\"11\"></td>\n";
str += " <td width=\"*\" background=\"" + imagePath +
"bottomMiddle.gif\"><img src=\"" + imagePath +
"bottomMiddle.gif\" width=\"2\" height=\"11\"></td>\n";
str += " <td width=\"9\"><img src=\"" + imagePath +
"bottomRight.gif\" width=\"9\" height=\"11\"></td>\n";
str += " </tr>\n";
str += " </table>\n";
str += " </td>\n";
str += " </tr>\n";
str += "</table>\n";
return str;
}
/**
* 返回上面部分的内容
* @return String
*/
public String getHeader() {
if (!isInit) {
init();
}
String imagePath = (Path.endsWith("/") ? Path : (Path + "/")) + Skin +
"/";
String str = "";
str +=
"<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">\n";
str += " <tr>\n";
str += " <td valign=\"top\">\n";
str += " <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
str += " <tr>\n";
str += " <td width=\"9\"><img src=\"" + imagePath +
"topLeft.gif\" width=\"9\" height=\"8\"></td>\n";
str += " <td width=\"*\" background=\"" + imagePath +
"topMiddle.gif\"><img src=\"" + imagePath +
"topMiddle.gif\" width=\"4\" height=\"8\"></td>\n";
str += " <td width=\"9\"><img src=\"" + imagePath +
"topRight.gif\" width=\"9\" height=\"8\"></td>\n";
str += " </tr>\n";
str += " </table>\n";
str += " </td>\n";
str += " </tr>\n";
str += " <tr>\n";
str += " <td valign=\"top\">\n";
str += " <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n";
str += " <tr>\n";
str += " <td valign=\"top\" width=\"6\" background=\"" +
imagePath + "middleLeft.gif\"><img src=\"" +
imagePath +
"middleLeft.gif\" width=\"6\" height=\"20\"></td>\n";
str += " <td width=\"*\" bgcolor=\"" + ContentBackGroundColor +
"\">\n";
return str;
}
/**
* 提供从XML读入参数的方式
* @param prop Properties
*/
public void parameterToProperties(Properties prop) {
super.parameterToProperties(prop);
if (Path != null) {
prop.setProperty("Path", Path);
}
if (Skin != null) {
prop.setProperty("Skin", Skin);
}
if (ContentBackGroundColor != null) {
prop.setProperty("ContentBackGroundColor", ContentBackGroundColor);
}
}
/**
* 如果检测到没有添加内容,则自动添加一个空格进去
*/
public void init() {
super.init();
this.addWebText(" ");
}
/**
* 用于生成Xml Schema
* @return List
*/
public List getParameterList() {
ArrayList al = new ArrayList();
al.add(new XsdElement("Path", "string", 0, 1));
al.add(new XsdElement("Skin", "string", 0, 1));
al.add(new XsdElement("ContentBackGroundColor", "string", 0, 1));
return al;
}
}