Draw2d入门系列(二、 图形Figure的功能)

在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);


就可以了,不信?自己测试看看
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值