锁定老帖子 主题:利用GEF制作表格系统(模型设计)
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-02-27
模型设计1、建立通用模型,实现模型属性变化的跟踪 public class AbstractNode implements Cloneable,IPropertySource, Serializable { … private static final long serialVersionUID=10000100L;
private PropertyChangeSupport listeners = new PropertyChangeSupport(this); public void addPropertyChangeListener(PropertyChangeListener listener){ listeners.addPropertyChangeListener(listener); } public void firePropertyChange(String propName,Object oldValue,Object newValue){ listeners.firePropertyChange(propName,oldValue,newValue); } public void removePropertyChange(PropertyChangeListener listener){ listeners.removePropertyChangeListener(listener); } … } 2、建立画布模型,增加子元素列表,实现子元素变化的追踪 public class DiagramNode extends AbstractNode{ public static final String P_CHILDREN ="_children"; protected List children=new ArrayList(); public void setChildren(List children){ if(children != null){ this.children=children; }else{ this.children=new ArrayList(); } this.firePropertyChange(P_CHILDREN, null, children); } public List getChildren(){ return this.children; } public void addChild(Object child){ children.add(child); firePropertyChange(P_CHILDREN, null, null); } public void addChild(int index,Object child){ if(index == -1){ this.children.add(child); }else{ this.children.add(index, child); } firePropertyChange(P_CHILDREN,null,null); } public void removeChild(Object child){ children.remove(child); firePropertyChange(P_CHILDREN,null,null); } public void moveChild(int index,AbstractNode child){ children.remove(child); children.add(index, child); firePropertyChange(P_CHILDREN,null,null); } } 3、建立表格模型,增加子元素列表,实现对子元素变化的追踪;建立表格间距等属性的编辑和追踪管理 public class TableNode extends AbstractNode { public static final String P_CHILDREN ="_children"; public static final String P_GRIDMANAGER="_gmanaer"; public static final String P_CHILDCHANGE="_change"; public static final String P_TABLEHSPACE="_hspace"; public static final String P_TABLEVSPACE="_vspace"; public static final String P_MARGINWIDTH="_hmargin"; public static final String P_MARGINHEIGHT="_vmargin"; public static final String P_TABLEBGCOLOR="_bgcolor"; public static final String P_OPERATE="_operate";
protected List children=new ArrayList(); private boolean border=true; private GridLayout grid; private int widthHint = 20; private int heightHint = 20; private int rows=0; private String operate="row"; private boolean childChange=false;
private String bgColor="255:255:255"; public TableNode(){ super(); constraint.width=widthHint*4; constraint.height=40; } public void setChildren(List children){ if(children != null){ this.children=children; }else{ this.children=new ArrayList(); } this.firePropertyChange(P_CHILDREN, null, children); } public List getChildren(){ return this.children; } public void addChild(Object child){ children.add(child); firePropertyChange(P_CHILDREN, null, null);
} public void addChild(int index,Object child){ if(index == -1){
this.children.add(child); }else{ this.children.add(index, child); } firePropertyChange(P_CHILDREN,null,null); }
public void removeChild(Object child){ children.remove(child); firePropertyChange(P_CHILDREN,null,null); } public void moveChild(int index,AbstractNode child){ children.remove(child); children.add(index, child); firePropertyChange(P_CHILDREN,null,null); } public GridLayout getGrid() { if(grid==null){ grid = new GridLayout(); grid.numColumns=4; } return grid; } public void setGrid(GridLayout grid) { this.grid = grid; this.firePropertyChange(P_GRIDMANAGER, null, grid); } public boolean isBorder() { return border; } public void setBorder(boolean border) { this.border = border; } public int getWidthHint() { return widthHint; } public void setWidthHint(int widthHint) { this.widthHint = widthHint; } public int getHeightHint() { return heightHint; } public void setHeightHint(int heightHint) { this.heightHint = heightHint; } public int getRows() { return rows; } public void setRows(int rows) { this.rows = rows; } public String getOperate() { return operate; } public void setOperate(String operate) { this.operate = operate; } public boolean isChildChange() { return childChange; } public void setChildChange(boolean childChange) { this.childChange = childChange; this.firePropertyChange(P_CHILDCHANGE, null, null); } //表格属性 public int getTableHorizontalSpace(){ GridLayout grid=getGrid(); return grid.horizontalSpacing; } public void setTableHorizontalSpace(String ss){ GridLayout grid=getGrid(); int delta=Integer.parseInt(ss)-grid.horizontalSpacing; if(delta != 0){ grid.horizontalSpacing=Integer.parseInt(ss); this.firePropertyChange(P_GRIDMANAGER,null,"hspace:"+delta); } }
public int getTableVerticalSpace(){ GridLayout grid=getGrid(); return grid.verticalSpacing; } public void setTableVerticalSpace(String ss){ GridLayout grid=getGrid(); int delta=Integer.parseInt(ss) - grid.verticalSpacing ; if(delta != 0){ grid.verticalSpacing=Integer.parseInt(ss); this.firePropertyChange(P_GRIDMANAGER,null,"vspace:"+delta); } }
public int getTableHorizontalMargin(){ GridLayout grid=getGrid(); return grid.marginWidth; } public void setTableHorizontalMargin(String ss){ GridLayout grid=getGrid(); int delta=Integer.parseInt(ss) - grid.marginWidth; if(delta !=0 ){ grid.marginWidth=Integer.parseInt(ss); this.firePropertyChange(P_GRIDMANAGER,null, margin:"+delta); } }
public int getTableVerticalMargin(){ GridLayout grid=getGrid(); return grid.marginHeight; } public void setTableVerticalMargin(String ss){ GridLayout grid=getGrid(); int delta=Integer.parseInt(ss) - grid.marginHeight; if(delta != 0){ grid.marginHeight=Integer.parseInt(ss); this.firePropertyChange(P_GRIDMANAGER, null, "vmargin:"+delta); } } public Color getBgColor() { if(this.bgColor ==null){ return new Color(null,255,255,255); }else{ String[] rgb=bgColor.split(":"); return new Color(null,Integer.parseInt(rgb[0]),Integer.parseInt(rgb[1]),Integer.parseInt(rgb[2])); }
} public void setBgColor(Color bgColor) { this.bgColor = bgColor.getRed()+":"+bgColor.getGreen()+":"+bgColor.getBlue(); this.firePropertyChange(P_TABLEBGCOLOR, null, null); }
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
浏览 2827 次