Jexi Design (8) Creating a GUI using SWT

zhaozj2021-02-16  93

At present, the structure of the Document class has been perfect. Since editing document involves the interface, write the GUI first.

It has always been more troubles with Java interface. The early AWT is too slow. Now I have used it. Swing I haven't used it, but the speed is too much, and finally I find SWT is a good local library, fast enough, fast, And the effects are the same as the local platform (because it is called platform related API), it is not carefully seen that it is Java.

However, take into account portability, I decided to divide the Frame into platforms and related two layers, so there is sufficient flexibility, and the SWT can be replaced with SWING or other GUI libraries, or transplanted to Linux, only the change platform is required. Interface (such as Font in Windows uses the logfont structure, this is not in Linux), the upper abstract GUI interface is not changed, the core jexi.core. * Is only intended to deal with the abstract GUI, and how to implement it without the bottom GUI.

In order to abstract the GUI interface, it is defined:

Color, Font, Graphics, Frame, View, ...

The abstract interface or abstract class, the corresponding platform related specific classes are:

SWTCOLOR, SWTFONT, SWTGRAPHICS, SWTFRAME, SWTVIEW, ...

In order to deal the upper client only and the abstract interface, use the Abstract Factory Singleton Adapter and other modes, as shown:

The advantage is that flexibility is greatly enhanced, but Factory is not only responsible for creating products, but also caching to improve efficiency (to know that these GUI operations like creating fonts are very time-time), the disadvantage is to introduce more classes.

For example, Font:

Since the abstract class FontFactory is a Singleton, I wrote a hard coded inside:

Private static fontfactory instance = new swtfontfactory ();

This is the only place to have a coupling, but if SWTFOctFactory is replaced with SwingFontFactory, it only needs to be changed:

Private static fontfactory installation = new swingfontfactory ();

Re-compiled.

A basic interface is already running, as shown below:

The next step is to increase the editing function, the file read and write, test, and strive to release a beta version next week! :)

转载请注明原文地址:https://www.9cbs.com/read-11593.html

New Post(0)