Convert AWT Application to SWT / JFace

I am currently playing with the idea of ​​converting a small / medium sized project from AWT to SWT, although Swing is still not quite right. I was thinking about converting the main window into a bridge object SWT_AWT, but I have no idea how the semantics for this work. After that, I plan to update the dialog for the dialogue, but not necessarily for one version. Is it possible?

Has someone done such a conversion and can give me some advice? Maybe even a textbook is out there somewhere? Maybe even a tool that can automate parts of this? I tried searching the Internet, but to no avail.

Update: One more thing: this is currently a netbeans project. Maybe help or not, I don’t know.

+3
source share
4 answers

We have done this quite a few times. But just because we are moving from a Swing application to an Eclipse RCP application is not because we like to mess with things. This project will really let you know if you separated your controller / model code from your view code.

One suggestion is not to try to convert everything all at once. You will get a bunch of mixed code that doesn't work at all. You can start by converting portals. I would consider a portal anything in Tab, Dialog or Window, essentially autonomous. If you have a window that opens, create the window in SWT, but make it the contents of the existing AWT / Swing. This should be pretty straight forward and allow you to get used to (I really hope they weren't drunk and had good reason for this), a way to create and map parent / child controls.

One of them can happen with transparent components. Swing, with the exception of the "window" class, is all displayed in Java. This makes it easy to visualize things the way you want them to. There are some limitations in SWT:

  • Borders. If you use SWT.BORDER, you are stuck in any color that uses its own component. It is best to use a PaintListener and display your own borders if you want them to be in a different style or color.
  • Transparent labels, progress indicators. I could not get shortcuts or progress bars to get a transparent background. If you want them to take the parent color or pattern, you will need to display the text and other controls yourself.
  • Controls SWT has composites and controls. Think of the controls as the main built-in controls that make all API calls. They cannot be subclasses, which makes work difficult.
  • Tables will provide you the most trouble. Make sure everything is stable before trying to convert JTable to Table or TableViewer. You will spend some time on them, especially if you have custom editors and viewers.

I have not investigated why SWT was designed the way it was. I guess that was a good reason. It would be great if someone had a blog or protection, so I don't need to look for it. As soon as it is published, I will delete these lines, since they are not relevant to the issue.

Adding

I want to add that since you have an existing product, I assume that it works. The best advice I can give you is to never allow your code to enter a state that it cannot compile and run. If you work on the conversion and everything you check is always up and running (despite the visual differences between SWT / AWT / Swing), you will save yourself a lot of headaches in the long run. The worst thing you can do is try to solve all this at once and get the code in an unstable state for several weeks.

+3
source

I would suggest importing it into a WindowBuilder project, since WindowBuilder gives you the ability to analyze existing code and create a mock GUI, then convert the components to SWT or Swing.

+1
source

If you are thinking of using a combination of SWT and Swing in the same application, this Eclipse Corner Article will be very helpful.

+1
source

We are preparing the same step: Swing to SWT / JFace. First, we try to identify bottlenecks: redefine special components obtained from JComponent using SWT / JFace, look for a JIDE dock replacement (we want to use SWT / JFace rather than RCP to avoid too much hassle). The worst thing we are already introducing is that in Swing you can create components and add them later to the parent. With SWT, this is not possible: the parent component must be passed as a reference to the constructor of the child component. This will require significant refactoring in the Swing application before using SWT.

Honestly, we evaluate conversion as a very difficult change, because we expect a time when nothing can be compiled as quite long. We try to reduce this time by preparing everything as best as possible, but we will see how good it is.

Update April 6, 2011:

Now we have redesigned our Swing application to always create components with our parent (as in SWT). Our subclasses JFrame and JDialog received refactoring to have an instance of JDialog to make it easier to switch to SWT Shell . In parallel, we are rewriting complex components in SWT.

0
source

Source: https://habr.com/ru/post/1388717/


All Articles