`

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


就可以了,不信?自己测试看看
分享到:
评论

相关推荐

    GEF/Draw2D入门例子

    GEF/Draw2D入门例子 主要是Draw2d的几个入门的例子和入门的书籍 对eclipse中图形的绘画讲解

    draw2d 绘制图形教程

    draw2d 绘制图形教程 draw2d 绘制图形教程draw2d 绘制图形教程 draw2d 绘制图形教程

    Draw2d js图形库

    Draw2d js图形库,画各种流程图,非常强大的javascript类图库。

    eclipse draw2d实例大全 源码

    eclipse draw2d实例大全 org.eclipse.draw2d.examples.cg org.eclipse.draw2d.examples.connections org.eclipse.draw2d.examples.graph org.eclipse.draw2d.examples.hittest org.eclipse.draw2d.examples.images ...

    Draw2D快速入门精简教程

    网上的Draw2D的参考资料实在是太少了,对于新手来说太不友好了,所以,我总结了一份只有10来页的PPT做为新手的快速入门教程。

    Java中如何使用Draw2D和SWT绘图

    如果您想以图形形式描绘将展示的数据,那么Draw2D是一个好工具。可以使用Draw2D编写自己的用来绘制图形的Java代码,这有助于您将精力集中于缩放代码和绘制代码上,把其他与绘制相关的工作留给Draw2D和SWT。您还可以...

    Draw2D 使用例子

    GEF Draw2D 使用例子,可以直接运行的

    Draw2d Programmer Guide

    eclipse Draw2d Programmer Guide

    Draw2d API (html版)

    Draw2d API Draw2d是一个宿主在SWT Composite控件中的轻量级的构件(widge)系统。一个Draw2d应用程序由一个 SWT Composite控件, 一个轻量级系统, 以及其内容(figures)组成。

    Draw2D documents and samples

    Draw2D:eclipse Draw2D documents and samples.

    draw2d/gef入门例子

    GEF的例子GEF的例子GEF的例子GEF的例子GEF的例子GEF的例子GEF的例子GEF的例子GEF的例子GEF的例子GEF的例子GEF的例子GEF的例子GEF的例子GEF的例子GEF的例子GEF的例子

    draw2d 示例代码

    eclipse draw2d 示例代码 码很全的。。。。

    Draw2d画线例子

    用Draw2d绘制曲线图形,在eclipse环境下运行

    Draw2d 教程 很详细

    Draw2d教程,网上的,我收集了一下。 写的很详细

    draw2d精讲

    Draw2d是SWT的轻量级组件系统,Draw2d的实例由SWT组件、LightweightSystem和Draw2d的IFigure实例集合组成。

    Draw2D教程

    Draw2D教程,介绍了Draw2D的基本知识,对学习Draw2D有所帮助

    swt总结draw2d绘图

    swt总结draw2d绘图

    org.eclipse.draw2d_3.1.0.jar

    org.eclipse.draw2d_3.1.0.jarorg.eclipse.draw2d_3.1.0.jarorg.eclipse.draw2d_3.1.0.jarorg.eclipse.draw2d_3.1.0.jar

    使用Draw2d做的流程图工具

    使用Draw2d做的流程图工具

    draw2d_Demo_code

    draw2d_Demo_code

Global site tag (gtag.js) - Google Analytics