but hard to find examples and tutorials on draw2d. I have been working on SWT and JFace for a while, but totally a newbie on draw2d. How. GEF is the graphical framework developed on top of draw2d and SWT Tree. Here is Step by Step tutorial creation of graphical editor on a. GEF Tutorial. 搜索此网站. Navigation. GEF教程 · EditDomain · EditorPart · EditPart Draw2D. Comments. Sign in|Recent Site Activity|Report Abuse|Print.
|Published (Last):||10 July 2016|
|PDF File Size:||14.37 Mb|
|ePub File Size:||19.7 Mb|
|Price:||Free* [*Free Regsitration Required]|
It is packaged in Eclipse as a separate plug-in, org. Draw2D tuotrial hosted in a SWT canvas heavyweight control and manages the painting and mouse events that occur in the host canvas by delegating them to Draw2D figures.
Figures are draw2f to windows in a heavyweight graphics system. They can have arbitrary, nonrectangular shapes and can be nested in order to compose complex scenes or tutoriql controls.
Figures can be transparent or opaque, and can be ordered into layers, thus allowing parts of a diagram to be hidden or excluded from certain operations. Draw2D is a standalone graphics library that can be used by itself to create graphical views in Eclipse. A complete coverage of Draw2D in depth is beyond the scope of this book. A lightweight system is a graphics draww2d that is hosted inside a single heavyweight control.
The graphics objects in the lightweight system, known as figures in Draw2D, are treated as if they are normal windows. Tutoial can have focus and selection, get mouse events, have their own coordinate system, and have tutoriak cursor.
They each get a graphics context for rendering. The advantage of lightweight systems is that they are much more flexible than the native windowing system, which is generally composed of rectangular components. They allow you to create and manipulate arbitrarily shaped graphics objects. Because they simulate a heavyweight graphics system within a single heavyweight window, they allow you to create a graphically complex display without consuming a lot of system resources.
You can see the basic structure of a standalone Draw2D application in Example When you create a standalone Draw2D application, you need to make sure that your operating system is able to locate the SWT native library. For instance, on Microsoft Windows, make sure that the following file is added to your class path: A root figure is then added to the LightweightSystem.
The root figure is configured with a layout manager which controls the layout of any child figures that are subsequently added to it. Methods Everything that is visible in a Draw2D window tuutorial drawn on a figure. Tutorixl figure class contains a number of methods that provide the following functionality:. Registering or deregistering listeners on a figure; the figure will notify listeners of mouse events within the figure.
Structural events, for structural changes in the figures hierarchy, and for movement or resizing of the figure. Operations to manage the figure’s place in the figure hierarchy, including adding and removing children and accessing them or its parent figure.
Subclasses Draw2D provides many subclasses of figure that provide useful additional functionality. We describe some of these in the following sections. Shapes Subclasses of the Shape class contain non-rectangular figures that know how to fill themselves and provide a border of configurable width and line style, and include support for XOR drawing. Widgets Draw2D includes figures which allow you to create lightweight widgets that can be used when you need an input control within your Draw2D application.
These include various buttons, Checkbox, and the text entry figure, Label. Layers and panes These are figures designed to host child figures. They providing scaling, scrolling, and the ability to place figures into different layers. The graphics context Figures have a paint method that is called by the LightweightSystem when the figure needs to be rendered.
Each figure gets a graphical context, an instance of the Graphics class, that is passed as argument to the figure’s paint method.
The graphics context supports graphics operations, including drawing and filling shapes and drawing text. It also maintains the graphics state that influences these operations, such as the current font, background and foreground colors, etc. This analogous to many other graphics systems. It contains three main components:. It inherits some of the graphical environment of the hosting SWT Canvas, such as font, background, and foreground colors.
It tracks which figure has focus, which figure is being targeted by mouse events, and handles tooltip activation. It provides support for figures that want to capture the mouse. The update manager is responsible for painting and updating Draw2D figures.
The LightweightSystem calls the update manager’s performUpdate method when a paint request is received from the underlying SWT canvas. The update manager typically maintains a worklist of figures that are invalid or need repainting. The update manager tries to coalesce its work lists so that it can be as efficient as possible.
The default update manager, DeferredUpdateManager, allows updates to be performed asynchronously by queuing work on the Display’s user interface thread.
SWT Draw2D Example : 2D « SWT JFace Eclipse « Java
The main processes in a figure’s life cycle are painting and validating. Draw2D asks a figure to render itself by calling the figures paint methods. The paint method invokes three more specific paint methods:. Clipping is used to protect the border. Borders It is frequently necessary to provide a visual border to figures. The Draw2D package contains several classes, derived from the Border class, which provide a variety of border effects:.
Some Draw2D border types. The Insets class is used to represent the space within a figure that is allocated to the border. Notice that the border does not have to be symmetrical.
It can be occupy any combination of a figure’s edges, and can be a different size on any edge. The paint method clips the client area so that painting is constrained to the area of the figure inside the inset.
The border, when present, is the last part of the figure to be painted. Layouts LayoutManagers are used to manage the position and size of a figure’s child figures. They interrogate each child figure to obtain its preferred size, and then apply some layout algorithm to calculate the final size and placement of the child figures.
LayoutManagers also support constraints, which are data attached to each figure that gives additional guidance to the layout manager. The figure has accessor methods for its constraints, and the layout manager maintains a map of constraints for the figures it is managing.
The constraint accessors use the Object type for constraints since the type of the constraint depends on the layout manager being used. For instance, the XYLayout layout manager requires that the figures it manages have a constraint of type Rectangle, and the DelegatingLayout manager expects its figures to have a constraint which implements the Locator interface.
All Draw2D layout managers derive from the AbstractLayout abstract class. FlowLayout — Lays out its children into either rows or columns, which is configurable either draw2e using the constructor:.
The manager causes its children drxw2d wrap when the current row or column is full. There are also methods to control the alignment and tutoril of rows in both the major and minor axes. DelegatingLayout — Delegates the layout of its child figures to the child figures’ locators. The children must provide a Locator subclass as their constraint. XYLayout — Places its children tutoriql the location and dimensions specified for the child.
The child’s constraint must be a Rectangle object that specifies this information. Draw2D provides a scrollable pane via the ScrollPane class. To implement this functionality it futorial the ScrollPaneLayout, which manages the layout of the scroll bars and Viewport that comprise the ScrollPane.
In addition the Viewport uses the ViewportLayout manager to manage the viewport’s visible region and maintain the scroll position state. Layers Layers are transparent figures intended specifically for use in LayerPanes. They override the figure’s containsPoint and findFigureAt methods so that hit testing will “pass through” the layer. The FreeformLayer class adds additional specialization to Layer to provide a layer that can extend indefinitely in all four directions.
The term “Freeform”, when used in Draw2D class names, indicates that the class supports figures that tutorual expand in tjtorial directions — that is, they do not have a fixed size or origin, which also implies that the child figures can have negative coordinates. The ConnectionLayer class implements a FreeformLayer that is designed to contain connections. It Insures that any Connection figures added to the layer will have their connection router set correctly tutorual the tuforial connection router.
Similarly, when the layer’s connection router is changed, it will update the connection router of all its connection figures. LayerPanes are figures designed to contain layers they can only contain layers. The layers in a LayerPane are draq2d in a map whose key is typically a String. LayerPanes contain methods to add, insert, remove, and reorder the layers they contain.
Two subclasses of LayerPane provide additional flexibility.
The FreeformLayeredPane provides a set of layers that can expand in all directions. The Darw2d adds support for zooming. Finally, the ScalableLayeredPane provides a LayerPane that is scalable but is not free form but instead has a finite, fixed size. Locators Implementors of the Locator interface are used in Draw2D to position figures.
The interface consists of a single method:. Subclasses of ConnectionLocator are used for locating figures that are attached to a Connection. These can be used for placing arrowheads on the ends of connections or placing labels or other decorations or annotations on a Connection.
The locator ensures that the figure stays “attached” to the Connection in the designated location as the Connection is moved.
ArrowLocator — This locator is used to position decorations, such as arrowheads, on the drawd2 of connections. Any figure that implements RotatableDecoration can be located. Implementors of RotatableDecoration are given a position and a reference point so that they can rotate their visual representation based on the angle of the connection they are decorating.
ConnectionEndpointLocator — This locator is used to locate a figure near either the start or end of a connection. RelativeLocator — This tutodial is used to locate a figure using a 0 to 1 floating point value representing its affinity for the a weighting of the figure’s affinity for the upper left corner 0 or lower right corner 1 of a reference figure. This ttutorial is generally intended for calculating the placement of handles.