项目开发中遇到一些和Draw2d图形有关的问题,以前总是胡乱用用这次决心好好看看了。从例子学习。没有理论只有代码学习。 :arrow: 代码参考org.eclipse.draw2d.examples包
例1:
[img]/upload/attachment/120225/35fc2b5a-fb08-347a-8e36-29813dcdd52f.gif[/img]
主要类——属性与方法:
org.eclipse.draw2d.FigureCanvas--图形画布
父类:org.eclipse.swt.widgets.Canvas
爷爷类:Composite
以上关系可以看明白
FigureCanvas canvas = new FigureCanvas(shell);等价于
Compositecanvas = new Composite(shell);
canvas.setContents(new Label("Hello World"));
以下是setContents方法的实现
[img]/upload/attachment/120227/10f50c66-9f61-3ba4-8e3b-e87a09548026.gif[/img]
getViewport()方法活的一个Viewport实例,Viewport我大致叫为可视窗口
Viewport继承Figure实现PropertyChangeListener接口,可以暂时猜测为是根图形
setContents在Viewport中的实现:
[img]/upload/attachment/120233/004859a0-98cc-34e0-a3d9-dffc5f1420c4.gif[/img]
从上可以看出可视窗口与图形关联,猜测图形把引用交付给可视窗口,可视窗口再被显示出来
new Label("Hello World")
类:org.eclipse.draw2d.Label通过setContents方法了解到,Label同样基层与Figure类
Label构造函数:
Label() Construct an empty Label.
Label(String s) Construct a Label with passed String as its text.
Label(String s, Image i)
Construct a Label with passed String as text and passed Image as its icon.
第一练习结束,结果:
[img]/upload/attachment/120240/9f1d73db-009a-3c32-9409-8b0d80195bb5.gif[/img]
例1:
[img]/upload/attachment/120225/35fc2b5a-fb08-347a-8e36-29813dcdd52f.gif[/img]
主要类——属性与方法:
org.eclipse.draw2d.FigureCanvas--图形画布
父类:org.eclipse.swt.widgets.Canvas
爷爷类:Composite
以上关系可以看明白
FigureCanvas canvas = new FigureCanvas(shell);等价于
Compositecanvas = new Composite(shell);
canvas.setContents(new Label("Hello World"));
以下是setContents方法的实现
[img]/upload/attachment/120227/10f50c66-9f61-3ba4-8e3b-e87a09548026.gif[/img]
getViewport()方法活的一个Viewport实例,Viewport我大致叫为可视窗口
Viewport继承Figure实现PropertyChangeListener接口,可以暂时猜测为是根图形
setContents在Viewport中的实现:
[img]/upload/attachment/120233/004859a0-98cc-34e0-a3d9-dffc5f1420c4.gif[/img]
从上可以看出可视窗口与图形关联,猜测图形把引用交付给可视窗口,可视窗口再被显示出来
new Label("Hello World")
类:org.eclipse.draw2d.Label通过setContents方法了解到,Label同样基层与Figure类
Label构造函数:
Label() Construct an empty Label.
Label(String s) Construct a Label with passed String as its text.
Label(String s, Image i)
Construct a Label with passed String as text and passed Image as its icon.
第一练习结束,结果:
[img]/upload/attachment/120240/9f1d73db-009a-3c32-9409-8b0d80195bb5.gif[/img]