Before getting start, you must learn something about Draw2d and GEF.

1.1.1        What is Draw2d

Draw2d is a lightweight toolkit of graphical components called figures. Lightweight means that a figure is simply a java object, with no corresponding resource in the operating system. Figures can be composed via a parent-child relationship. Every figure has a rectangular bounds inside which it, and its children, paint.

如果有SWT/JFace开发经验,那么可以把Draw2d SWT/JFace看成等同的图形显示的实现方式。Draw2d其实很简单,就是一个java的图形显示。

 

上图就是用Draw2d绘制的GEF显示图形,利用Draw2d提供的布局方式(与SWT的布局方式类似)和组件,可以构建出更加复杂的界面组件。

1.1.2        What is GEF

Draw2d focuses on efficient painting and layout of figures. The GEF plug-in adds editing on top of Draw2d. The purpose of this framework is to:

1.       Facilitate the display of any model graphically using draw2d figures

2.       Support interactions from mouse, keyboard, or the Workbench

3.       Provide common components related to the above

The diagram below shows a high-level view of GEF.  GEF can be loosely defined as the region in the middle. The framework provides the link between an application's model and view. It also provides input handlers, such as tools and actions, that turn events into requests. Requests and Commands are used to encapsulate interactions and their effects on the model.

GEF是个基于MVC的图形编辑框架。GEF负责处理用户请求并把处理结果以图形化的方式返回给用户。So, 就这么简单。

从上图中可以看出,要构建一个GEF应用,须构建ModelControllerView三部分。本文的以下部分将结合泊位管理的需求,阐述MVC各部分的开发。