Draw2d Label
2011-04-17 10:49
120 查看
在Draw2d中,IFigure对象代表图形,IFigure对象还能包含其他的IFigure对象,所有的IFigure对象组合成用户指定的图形
通常用户可以继承Figure类实现自己的图形。Figure实现了IFigure接口
我下面写了个实例,实现了一个Figure,并设置边框为 LineBorder(边框类似为连线),而且还给它加了颜色,好像是淡绿色,对颜色没啥研究,另外还添加了以个Label作为显示的Figure,并设置为Label的现实文字和文字对齐方式,以及Figure的布局
package com.heming.table.editor.figure;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FlowLayout;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.swt.graphics.Image;
/**
* Figure功能
* @author 何明
*
*/
public class KCGCommonFigure extends Figure {
//在Figure中添加标签(标签也是Figure)
protected Label label = new Label();
public KCGCommonFigure(String fieldLabel, Image typeIcon){
//设置背景色
setBackgroundColor(ColorConstants.tooltipBackground);
//设置前景色
setForegroundColor(ColorConstants.tooltipForeground);
//设置Figure的边框,并给边框加上颜色
setBorder(new LineBorder(ColorConstants.cyan));
//设置label中文字的对齐方式
label.setTextAlignment(PositionConstants.LEFT);
//设置label的图标
label.setIcon(typeIcon);
//设置Figure的布局方式
setLayoutManager(new FlowLayout());
//把label添加到Figure中
add(label);
//设置label的显示文字
setLabelText(fieldLabel);
}
private void setLabelText(String fieldLabel) {
label.setText(fieldLabel);
}
}
接下来就是测试了
在写这篇文章之前,写了个HelloWorld,咱们就拿它来测试了
只需要将
IFigure label = new Label("Hello World");
lws.setContents(label);
换成
KCGCommonFigure figure = new KCGCommonFigure("Figure Demo",SWTResourceManager.getImage("icons/methpub_obj.gif"));
lws.setContents(figure);
通常用户可以继承Figure类实现自己的图形。Figure实现了IFigure接口
我下面写了个实例,实现了一个Figure,并设置边框为 LineBorder(边框类似为连线),而且还给它加了颜色,好像是淡绿色,对颜色没啥研究,另外还添加了以个Label作为显示的Figure,并设置为Label的现实文字和文字对齐方式,以及Figure的布局
package com.heming.table.editor.figure;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.FlowLayout;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.LineBorder;
import org.eclipse.draw2d.PositionConstants;
import org.eclipse.swt.graphics.Image;
/**
* Figure功能
* @author 何明
*
*/
public class KCGCommonFigure extends Figure {
//在Figure中添加标签(标签也是Figure)
protected Label label = new Label();
public KCGCommonFigure(String fieldLabel, Image typeIcon){
//设置背景色
setBackgroundColor(ColorConstants.tooltipBackground);
//设置前景色
setForegroundColor(ColorConstants.tooltipForeground);
//设置Figure的边框,并给边框加上颜色
setBorder(new LineBorder(ColorConstants.cyan));
//设置label中文字的对齐方式
label.setTextAlignment(PositionConstants.LEFT);
//设置label的图标
label.setIcon(typeIcon);
//设置Figure的布局方式
setLayoutManager(new FlowLayout());
//把label添加到Figure中
add(label);
//设置label的显示文字
setLabelText(fieldLabel);
}
private void setLabelText(String fieldLabel) {
label.setText(fieldLabel);
}
}
接下来就是测试了
在写这篇文章之前,写了个HelloWorld,咱们就拿它来测试了
只需要将
IFigure label = new Label("Hello World");
lws.setContents(label);
换成
KCGCommonFigure figure = new KCGCommonFigure("Figure Demo",SWTResourceManager.getImage("icons/methpub_obj.gif"));
lws.setContents(figure);
相关文章推荐
- [Web Chart系列之五] 2. 实战draw2d 之Label 放大,缩小的问题(raphael的text类似问题)
- [Web Chart系列之五] 2. 实战draw2d 之Label 放大,缩小的问题(raphael的text类似问题)
- [Web Chart系列之五] 4. 实战draw2d(Raphael)之取消Chrome中Label Text 全部选中
- [Web Chart系列之五] 4. 实战draw2d(Raphael)之取消Chrome中Label Text 全部选中
- Draw2D--1. 设计思想和相关模式
- Draw2d中如何控制ToolTip的持续时间
- Draw2D 教程(五)
- Draw2D、GEF、GMF和EMF的解释
- Draw2d中的布局管理器Layout比较
- Draw2D--2. 图形元素(Figure)类设计层次(2)
- Draw2D、GEF、GMF和EMF的解释
- jQuery插件HighCharts绘制2D带Label的折线图效果示例【附demo源码下载】
- cocos2dx v3.x box2d DrawDebugData 后置问题
- Draw2D--2. 图形元素(Figure)类设计层次(3)
- Draw2D 教程(三)
- Draw2D简介
- Layer Draw Label
- [Web Chart系列之五] 3. 实战draw2d 之图形填充色(纯色 or 渐变)
- Draw2D 教程(四)
- Draw2d 入门