关键代码在
//构建一个可用的图形画布
setFigureCanvas(new FigureCanvas(shell));
//通过子类实现抽象方法getContents,设置可视图形
getFigureCanvas().setContents(contents = getContents());
//ContentsTrackXXX方法缺省设置为false,当改变图形大小时,追踪其高度与宽度
getFigureCanvas().getViewport().setContentsTracksHeight(true);
getFigureCanvas().getViewport().setContentsTracksWidth(true);
getFigureCanvas().setLayoutData(new GridData(GridData.FILL_BOTH));
//通过重写该方法实现与shell的关联操作
hookShell();
sizeShell();
____________________使用abstractExample________________________________
/**
* 重写AbstractExample#getContents()
* org.eclipse.draw2d.FlowLayout
* 在container中加入多种shape,并在container上使用FlowLayout布局
*/
protected IFigure getContents() {
Figure container = new Figure();
container.setBorder(new LineBorder());
container.setLayoutManager(layout = new FlowLayout());
Shape shape;
shape = new Ellipse();
shape.setBackgroundColor(ColorConstants.blue);
shape.setSize(60,40);
container.add(shape);
shape = new RectangleFigure();
shape.setBackgroundColor(ColorConstants.red);
shape.setSize(30,70);
container.add(shape);
shape = new RoundedRectangle();
shape.setBackgroundColor(ColorConstants.yellow);
shape.setSize(90,30);
container.add(shape);
shape = new RectangleFigure();
shape.setBackgroundColor(ColorConstants.gray);
shape.setSize(50,80);
container.add(shape);
shape = new Ellipse();
shape.setBackgroundColor(ColorConstants.green);
shape.setSize(50,50);
container.add(shape);
shape = new Triangle();
shape.setBackgroundColor(ColorConstants.black);
shape.setSize(50,50);
container.add(shape);
shape = new RoundedRectangle();
shape.setBackgroundColor(ColorConstants.cyan);
shape.setSize(50,50);
container.add(shape);
shape = new RectangleFigure();
shape.setBackgroundColor(ColorConstants.darkGreen);
shape.setSize(50,50);
container.add(shape);
shape = new Triangle();
shape.setBackgroundColor(ColorConstants.orange);
shape.setSize(50,50);
container.add(shape);
shape = new Ellipse();
shape.setBackgroundColor(ColorConstants.red);
shape.setSize(50,50);
container.add(shape);
shape = new RoundedRectangle();
shape.setBackgroundColor(ColorConstants.yellow);
shape.setSize(50,50);
container.add(shape);
return container;
}
/**
* @see org.eclipse.draw2d.examples.AbstractExample#hookShell()
*/
protected void hookShell() {
Composite composite = new Composite(shell, 0);
composite.setLayoutData(new GridData(GridData.FILL_VERTICAL));
composite.setLayout(new GridLayout());
final Button horizontal = new Button(composite, SWT.CHECK);
horizontal.setText("Horizontal");
horizontal.setSelection(true);
horizontal.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
layout.setHorizontal(!layout.isHorizontal());
contents.revalidate();
shell.layout(true);
}
});
{
Group major = new Group(composite, 0);
major.setLayout(new FillLayout(SWT.VERTICAL));
major.setText("Major Axis");
Button left = new Button(major, SWT.RADIO);
left.setText("Top/Left");
left.setSelection(true);
left.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
layout.setMajorAlignment(FlowLayout.ALIGN_LEFTTOP);
contents.revalidate();
}
});
Button center = new Button(major, SWT.RADIO);
center.setText("Middle/Center");
center.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
layout.setMajorAlignment(FlowLayout.ALIGN_CENTER);
contents.revalidate();
}
});
Button right = new Button(major, SWT.RADIO);
right.setText("Buttom/Right");
right.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
layout.setMajorAlignment(FlowLayout.ALIGN_RIGHTBOTTOM);
contents.revalidate();
}
});
final Scale spacing = new Scale(major, 0);
spacing.setMinimum(0);
spacing.setMaximum(20);
spacing.setSelection(5);
spacing.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
layout.setMajorSpacing(spacing.getSelection());
contents.revalidate();
}
});
Label spacingLabel = new Label(major, SWT.CENTER);
spacingLabel.setText("Spacing");
}
{
Group minor = new Group(composite, 0);
minor.setLayout(new FillLayout(SWT.VERTICAL));
minor.setText("minor axis");
Button left = new Button(minor, SWT.RADIO);
left.setText("Top/Left");
left.setSelection(true);
left.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
layout.setMinorAlignment(FlowLayout.ALIGN_LEFTTOP);
contents.revalidate();
}
});
Button center = new Button(minor, SWT.RADIO);
center.setText("Middle/Center");
center.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
layout.setMinorAlignment(FlowLayout.ALIGN_CENTER);
contents.revalidate();
}
});
Button right = new Button(minor, SWT.RADIO);
right.setText("Buttom/Right");
right.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
layout.setMinorAlignment(FlowLayout.ALIGN_RIGHTBOTTOM);
contents.revalidate();
}
});
final Scale spacing = new Scale(minor, 0);
spacing.setMinimum(0);
spacing.setMaximum(20);
spacing.setSelection(5);
spacing.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
layout.setMinorSpacing(spacing.getSelection());
contents.revalidate();
}
});
Label spacingLabel = new Label(minor, SWT.CENTER);
spacingLabel.setText("Spacing");
}
}
结果
- 大小: 18.6 KB
- 大小: 6.3 KB
- 大小: 19.2 KB
分享到:
相关推荐
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 ...
GEF Draw2D 使用例子,可以直接运行的
Draw2d js图形库,画各种流程图,非常强大的javascript类图库。
如果您想以图形形式描绘将展示的数据,那么Draw2D是一个好工具。可以使用Draw2D编写自己的用来绘制图形的Java代码,这有助于您将精力集中于缩放代码和绘制代码上,把其他与绘制相关的工作留给Draw2D和SWT。您还可以...
draw2d 绘制图形教程 draw2d 绘制图形教程draw2d 绘制图形教程 draw2d 绘制图形教程
Draw2d API Draw2d是一个宿主在SWT Composite控件中的轻量级的构件(widge)系统。一个Draw2d应用程序由一个 SWT Composite控件, 一个轻量级系统, 以及其内容(figures)组成。
Draw2D:eclipse Draw2D documents and samples.
源码实现用gef 和draw2d画类图和连线,代码相对来说简单易懂,易于扩展
eclipse Draw2d Programmer Guide
Draw2D教程,介绍了Draw2D的基本知识,对学习Draw2D有所帮助
网上的Draw2D的参考资料实在是太少了,对于新手来说太不友好了,所以,我总结了一份只有10来页的PPT做为新手的快速入门教程。
Draw2d教程,网上的,我收集了一下。 写的很详细
使用Draw2d做的流程图工具
GEF/Draw2D入门例子 主要是Draw2d的几个入门的例子和入门的书籍 对eclipse中图形的绘画讲解
swt总结draw2d绘图
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是SWT的轻量级组件系统,Draw2d的实例由SWT组件、LightweightSystem和Draw2d的IFigure实例集合组成。
eclipse draw2d 示例代码 码很全的。。。。
draw2d_Demo_code
用Draw2d绘制曲线图形,在eclipse环境下运行