Eclipse RCP Application System Development Method and Practice 2-custom application window attributes (for your reference only)

Source: Internet
Author: User
Tags bmp image
Document directory
  • 5.1.4 customize application window properties
[Switch] eclipse RCP Application System Development Method and Practice 2 -- customize application window attributes

 

5.1.4 The application main interface generated by the custom application window property wizard does not meet the requirements and has many problems. For example, the main interface is not automatically centered during running and the main interface size is not fixed.
The text in the title bar of the Main Window should be "university fund calculation system ". Are there any differences between the title bars in Figure 5-3 and figure 5-4? Of course, as shown in Figure 5-3, the title bar of the interface is a beautiful arc
The title bar of the interface shown in Figure 5-4 is not. In this case, you need to reset the settings. 1. Some initialization work is often required before the main interface of the pop-up screen application is displayed, that is, the startup time may be a little longer. If there is no prompt, the user
May be confused, and the pop-up screen can better solve this problem. Prepare a 24-bit BMP image. Make sure that the image size cannot exceed 500mm × 300mm. Copy the image
Replace the original splash.bmp file in the project folder. 2. do not save the window status to applicationworkbenchadvisor. the statement in Java's initialize () method: Er er. setsaveandrestore (true); changed to: explorer. setsaveandrestore (false); As mentioned above, if it is set to true, the window state will be saved every time the application exits. this parameter is not required and has a slight impact on performance, so it is set to false. 3. Customize the window style and then customize the main window. As mentioned earlier, you can customize the window style in the prewindowopen () method of applicationworkbenchwindowadvisor. java. Modify the window style as follows. Cn.edu. jfcs. APP/
Applicationworkbenchwindowadvisor. Java public void prewindowopen () {iworkbenchwindowconfigurer
Cycler = getwindowcycler (); // The window is set to 800x600 cycler. setinitialsize (New
Point (800,600); // The toolbar receiver is not displayed for the moment. setshowcoolbar (false); // display the status bar worker er. setshowstatusline (true); // The window only displays the minimize and close buttons. setshellstyle (SWT. min
| SWT. Close); // set the window title configurer. settitle ("university funding calculation system");} After performing the previous step, we will find configurer. setshellstyle (SWT. Min
|
SWT. Close) a small light bulb with a Red Cross occurs next to the code, which means there is a problem with this line of code, because the SWT. min constant is used and the corresponding class is not imported. Solution
The method is very simple. Just click the light bulb and import the package as prompted.
Org. Eclipse. SWT. SWT, which is also a very considerate feature of Eclipse. Now let's run it. The main interface of the program has changed a lot. The "university fund Calculation System" in the last code in the program is a custom constant. There are many similar custom constants in a system, such as the name of the sample piece and
And so on, and these constants may need to be used in more than one place. A good way is to create an interface file and place the definition of all constants in this interface file. This allows unified management and maintenance.
Convenience. To modify the value of a constant, you only need to modify it in the interface file. To implement this operation, create a new package cn.edu. jfcs. sys and create an interface class under the package.
Iappconstants. Java, the code is similar to the following form. Package cn.edu. jfcs. sys; public interface iappconstants {public static final
String application_title = "university funding calculation system";} Now you only need
Prewindowopen () method in applicationworkbenchwindowadvisor. Java
Configurer. settitle ("university fund calculation system") is changed
Extends er. settitle (iappconstants. Application _
Title. Remember to import the cn.edu. jfcs. SYS. iappconstants class.
Constant definitions will be added to this interface file in the future. To avoid unnecessary troubles, we recommend that you copy the iappconstants. Java class with the source code in this book to your project.
4. Window auto center window center requires manual programming. before writing it, you must first think about where the code is stored? Or in the prewindowopen () method
? Of course not. prewindowopen () is the component of the Configuration window, that is, the component of the window itself, while the center is the position of the defined window, obviously not the component of the window.
Postwindowopen () can be used to handle events that require a ready-made window. Right-click the code editing view and choose source> override/implement from the shortcut menu.
Methods ...] Command to display "override/implement
In the methods dialog box, select the postwindowopen () method. By default, the postwindowopen () method is inserted at the cursor position. This is
Eclipse is a very considerate function and is expected to be used by readers. The code for rewriting this method is as follows: cn.edu. jfcs. APP/
Applicationworkbenchwindowadvisor. Java public void
Postwindowopen () {// set window auto center shell
Shell = getwindowcycler (). getwindow (). getshell (); rectangle
Screensize = display. getdefault (). getclientarea (); rectangle
Framesize = shell. getbounds (); shell. setlocation (screensize. Width
-Framesize. width)/2, (screensize. Height
-Framesize. height)/2);} This method uses the default display object to set the screen width and height, and obtains the width and height of the current window through the shell object. The two values are subtracted and divided by 2, respectively, in the upper left corner of the window (X
,Y
) Coordinates. Do not forget to import related classes and check whether the window is automatically centered after running. 5. Set the arc appearance of the view title bar. You must like the arc title bar on the page 5-3. This style of title bar involves the workbench UI attribute (Org. Eclipse. UI
Preference): show_traditional_style_tabs. You can set it in three ways. (1) Hard coding is implemented by writing code directly. Open the applicationworkbenchadvisor. Java file and modify the initialize () method code as follows: cn.edu. jfcs. APP/applicationworkbenchadvisor. Java public void initialize (iworkbenchconfigurer
Extends ER) {super. initialize (extends ER); extends er. setsaveandrestore (false); platformui. getpreferencestore (). setvalue (iworkbenchpreferenceconstants. show_traditional_style_tabs,
False);} There are many related attributes. For details, see the iworkbenchpreferenceconstants interface file. The method is to press and hold
CTRL: move the mouse over iworkbenchpreferenceconstants.
And iworkbenchpreferenceconstants are underlined. Click the left mouse button. This is also true for other eclipse methods. Here
First, we will briefly introduce several common attributes. Table 5-4 iworkbenchpreferenceconstants common attributes
Gender name Description of Ownership
Editor_minimum_characters However, when many editors overlap, set the shortest length of the editor title text. The default value is 8 characters.
Show_progress_on_startup Set whether to display the progress bar at startup. The default value is false.
Dock_perspective_bar Set the position of the title bar of the perspective. The default value is top_right. You can also set it to top_left or left.
Show_text_on_perspective_bar Set whether the Perspective View displays the title text. The default value is true.
Show_intro Whether the welcome screen is displayed at startup. The default value is true.
Some people may like to display the welcome screen every time they start, they can add platformui. getpreferencestore (). setvalue (iworkbenchpreferenceconstants. show_intro,
True );
(2) You can create an Initialization Configuration File by modifying the default configuration file of the product, and use the default configuration file name plugin_customization.ini. Click mouse on the project name
Right-click and choose new> file. In File
Enter plugin_mizmization.ini, click Finish, and enter the following content. # Set the arc appearance of the view title bar org. Eclipse. UI/show_traditional_style_tabs = false # The editor title bar prompts the shortest length of the text org. Eclipse. UI/
Editor_minimum_characters = 12 (3) custom configuration file if you do not like the default configuration file, you can change the configuration file name (this method is used in this book). The procedure is as follows. ① Double-click the pludin. xml file and click the "extensions" page. 2. Expand org. Eclipse. Core. runtime. Products, right-click jfcs (product), and choose new> property ]. ③ Enter the property name preferencecustomization in the text box after name in extension element details.
(The attribute name cannot be changed). Enter apppref. ini in the text box after the value (which can be any name), as shown in Figure 5-10. To view
Org. Eclipse. Core. runtime. Products
Org. Eclipse. Core. runtime. Products name, and then click Open extension point on the right
Description, eclipse will open the property description about the products extension point, as shown in 5-11. Note that the default file for this attribute is exactly what we mentioned above.
Plugin_customization.ini. Figure 5-10 Add attribute settings view 5-11 Org. eclipse. core. runtime. products extension POint Description ④ right-click the project name, choose new> file, and enter apppref after file name. INI, click the finish button, and enter the configuration content. Here, I would like to remind you that if you have made a lot of settings and the runtime does not seem to take effect, this is because eclipse caches the old configuration information. Solution
Method: select "run"> "run…" in the System menu ...], In the "run" dialog box, click "Eclipse"
Application, and then click "jfcs" and check "clean workspace data before ".
Launching, do not check ask
For confirmation before cleaning ". This ensures that each running is the latest result, as shown in Figure 5-12. Figure 5-12 running Setting Dialog Box
Show_intro
Special. If you use the ini configuration file, no matter whether you use the default configuration file or custom configuration file, after the product is packaged and released (not running in the eclipse environment), it only appears at the first startup.
Welcome to the screen, because eclipse will modify showintro = false for the org. Eclipse. UI. prefs file in the workspace directory at the end of the runtime.
No welcome screen will appear during the following startup. If you want a welcome screen to appear when the program starts, you need to use hard encoding!
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.