下面来简单描述一下这个工程中对应的View——视图。由于对应的图形元素(Figure)都很简单,这里没有用单独的类来描述图形元素,而是使用GEF或者Draw2D中内置的几种Figure:Ellipse(椭圆)、RectangleFigure(矩形)和PolylineConnection(连接线)。这些Figure都将作为RootFigure的children,安放在RootFigure上。这里ShapeDragram对应的图形为FreeformLayer(一个可以扩展的Layer)。
我们来把上面得model和view关联起来:
a) Connection <-->PolylineConnection
b) EllipticalShape <-->Ellipse
c) RectangularShape <-->RectangleFigure
d) ShapeDiagram <--> FreeformLayer
这里简单讲解一下 Connection 对应的图形元素 PolylineConnection 。 PolylineConnection 是一种基于线条的连接,是最常用的连接之一,它的主要特点有:
a) 连接线有实线、虚线、点线等之分,同时还可以设定颜色、宽度
b) 有双向连接和单向连接之分,通过设定源和目的箭头装饰
setTargetDecoration(new PolygonDecoration())
当然,不设定则默认为无箭头的连接
c) 连接可以弯曲,由 Bendpoint 负责
d) 可以设置连接路径,比如使用最短路径连接还是弯曲连接
setConnectionRouter(ConnectionRouter cr)
常见的 ConnectionRouter 为 BendpointConnectionRouter, FanRouter,
ConnectionRouter.NullConnectionRouter,ManhattanConnectionRouter, ShortestPathConnectionRouter (详细见 org.eclipse.draw2d 类包 API )
PolylineConnection 和 ConnectionLayer 中均有此方法,注意相互设置的影响,一般以 ConnectionLayer 设置的优先
ManhattanConnectionRouter :
ShortestPathConnectionRouter :
ConnectionRouter.NullConnectionRouter :