Migrating GUI

Sometimes, we may come across purely coded visual components and depending on our proficiency in the Swing and AWT code, a change in this kind of user interface may become a challenge. IntelliJ provides a tool that can convert hand-coded GUI and forms created in other designers to its form format. This way it is possible to normalize the visual elements of different projects and make it easy to maintain the code even for those who don't have much proficiency in Swing/AWT code.

To make it possible to extract a form format from any GUI, we need to use the Snapshot feature. IntelliJ will analyze the user interface that is running and will take some snapshots of it, then it will traverse the tree components of the snapshot and create the form in its own format.

In the Chapter 5 folder, there is a file named Find.java. I didn't create this file, I just found it over the internet, so I don't have any idea about its code; I just want to convert it to the IntelliJ format. Copy the file Find.java to the package org.example.desktop, right-click anywhere inside it, and select Run "Find.main()" or simply press Ctrl + Shift + F10.

We need to run the application to capture the snapshot; however, we need to configure it before we run it, so close the Find dialog. Notice that a configuration was created for this file; Navigate to Run | Run/Debug, and click on Edit Configurations....

Expand the node Applications and click on Find; in the right panel, check the checkbox Enable capturing form snapshots, then click on OK. Now, right-click on the package org.example.desktop and select New | Form Snapshot; when asked if you want to run the application, click on Yes. In our case, we just have one dialog; but, if you are working in an application with more than one dialog, open the dialog that you want to take the snapshot of, and click on OK in the dialog that IntelliJ will show you. The following screenshot shows the Create Form Snapshot window:

Migrating GUI

In the Create Form Snapshot window, select the first node; this will grant that all components of the Find dialog will be extracted. Name the new form as FindForm and click on Create Snapshot. IntelliJ will tell us that it can't understand the GroupLayout element and say that its components will be ignored; click on the Yes button. After some time, you will see that a message with a timeout error will return to us.

Despite being a good idea, IntelliJ's snapshot tool can't extract the elements of a GUI all the time; it will sometimes fail.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.147.77