5.1.4 Custom application window property of the wizard-generated application's main interface and does not meet the requirements, there are many problems, such as the main interface, the runtime does not automatically center, the main interface, there is no fixed size, the main window's title bar text should be "college funds measurement system. " Look at the plug 5-3, Figure 5-4 is not different from the title bar? Of course, as shown in Figure 5-3, the title bar of the interface is very beautiful arc-shaped, while Figure 5-4 shows the title bar of the interface is not. And so on, need to re-set.
1. Splash screen displays the main interface screen applications often need to do some initialization before processing, that is, start-up time might be slightly longer, without any prompts, the user may feel confused, splash screen images can better solve this problem. Prepare a 24bit color BMP format images, pay attention to image size should not exceed 500mm × 300mm. The picture copied to the project folder splash.bmp replace the original files.
2. Does not save the window state will ApplicationWorkbenchAdvisor.java the initialize () method in the statement: configurer.setSaveAndRestore (true);
Revised to: configurer.setSaveAndRestore (false);
Previously said, is set to true, each application will be saved when you exit the window state, where it was not necessary and a slight impact on performance, it is set to false.
3. Custom Window style custom main window again. As already described, in the ApplicationWorkbenchWindowAdvisor.java the preWindowOpen () method of custom window style, now amended as follows.
cn.edu.jfcs.app / ApplicationWorkbenchWindowAdvisor.java
public void preWindowOpen () (
IWorkbenchWindowConfigurer configurer = getWindowConfigurer ();
/ / Window is set to 800x600
configurer.setInitialSize (new Point (800, 600));
/ / Temporarily not show the toolbar
/ / Display status bar
/ / Window show only minimize the Close button
configurer.setShellStyle (SWT.MIN | SWT.CLOSE);
/ / Set Window Title
configurer.setTitle ( "college funds calculation system");
Implementation-step operation, we will find configurer.setShellStyle (SWT.MIN | SWT.CLOSE) appears next to a phrase code red pork on a skewer with a small light bulb, which means that the line of code in question, it is because the use of SWT.MIN constants without importing the corresponding class. Solution is simple, just right click the small light bulb, according to the pop-up prompts to import packages import org.eclipse.swt.SWT can be, this is a very intimate little Eclipse features. Now run to see the program main interface has been greatly changed.
Program in the last sentence of the code in the "college funds calculation system" is a custom constant. There are a lot like a system of custom constants, such as the picture name, the name of the view, etc., and these constants may need to use more than one place to. A good way is to create an interface file will be placed on the definition of all the constants to the interface file, so can a unified management, and easy maintenance. If you want to modify a constant value, only need to modify the interface file on it. The following to achieve this treatment, create a new package cn.edu.jfcs.sys, in the package under the new interface class IAppConstants.java, code similar to the following form.
public interface IAppConstants (
public static final String APPLICATION_TITLE = "college funds calculation system";
Now only need to ApplicationWorkbenchWindowAdvisor.java in preWindowOpen () method configurer.setTitle ( "college funds calculation system") was revised to configurer.setTitle (IAppConstants.APPLICATION_ TITLE) can be. Remember to import cn.edu.jfcs.sys.IAppConstants class.
After the interface file will be continuously added to the constant definitions. In order to avoid unnecessary troubles, it is recommended practice when the first readers of this book comes with source code IAppConstants.java class directly copied into their own projects.
4. Auto center window, the window centered need to manually programmed, write code to be placed before the come to think where? Or on preWindowOpen () method do? Certainly not, preWindowOpen () is the configuration window, the composition of elements, namely, the formation of the window itself, the composition of components, door to it is defined in the location of the window, clearly do not constitute a part of the window elements. postWindowOpen () can perform this task, because postWindowOpen () is mainly used to deal with those who need a ready-made window event handling can be carried out.
In the code editor view, right-click pop-up shortcut menu, select 【Source】 → 【Override / Implement Methods ...】 command, the pop-up "Override / Implement Methods" dialog box, check the postWindowOpen () method, the default will be insert the cursor postWindowOpen () method. This is a very intimate Eclipse features, hope proficient readers. To rewrite the code of the method is as follows:
cn.edu.jfcs.app / ApplicationWorkbenchWindowAdvisor.java
public void postWindowOpen () (
/ / Set the window auto-centered
Shell shell = getWindowConfigurer (). 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 by default Display object to set the screen width and height, through the Shell object to obtain the current window's width and height, respectively, subtract the two and then divided by 2, calculated the window upper-left corner (x, y) coordinates. Do not forget to import the relevant classes, and then running the window to see whether they are automatically centered.
5. To set the view title bar of the arc-shaped appearance I am sure you all like the interface as shown in Figure 5-3, the title bar of the arc-shaped, the title bar of this style involves workbench UI properties (org.eclipse.ui Preference): SHOW_TRADITIONAL_STYLE_TABS. Can be set in three ways.
(1) hard-coded to achieve hard-coded implementation is achieved by direct writing code. Open ApplicationWorkbenchAdvisor.java file, modify the initialize () method code is as follows:
cn.edu.jfcs.app / ApplicationWorkbenchAdvisor.java
public void initialize (IWorkbenchConfigurer configurer) (
PlatformUI.getPreferenceStore (). SetValue (IWorkbenchPreferenceConstants.
Many properties related to the specific interface file can be viewed IWorkbenchPreferenceConstants. Method is to press 【Ctrl】 key, move the mouse to IWorkbenchPreferenceConstants above, IWorkbenchPreferenceConstants the following will appear underlined, click the left mouse button can be. For Eclipse same is true of other ways to operate. Here to briefly highlight a number of common properties.
Table 5-4 IWorkbenchPreferenceConstants Common Attribute name Attribute Description
But many editors EDITOR_MINIMUM_CHARACTERS overlap, set the title text editor, the shortest length. The default is 8 characters
SHOW_PROGRESS_ON_STARTUP to set whether to display the progress bar at startup. The default value is false
DOCK_PERSPECTIVE_BAR set the title bar parking location perspective. The default value is TOP_RIGHT, also can be set to TOP_LEFT, LEFT
SHOW_TEXT_ON_PERSPECTIVE_BAR set perspective whether to display the text. The default value is true
SHOW_INTRO startup whether to display the Welcome screen. The default value is true
There may be some people like to display the Welcome screen each time you start, you can initialize () method by adding:
PlatformUI.getPreferenceStore (). SetValue (IWorkbenchPreferenceConstants.SHOW_INTRO, true);
(2) modify the product's default configuration file you can create an initialization configuration file, use the default configuration file name plugin_customization.ini. In the project name, click the right mouse button and select 【New】 → 【File】, in the File name entered after the plugin_customization.ini, click 【Finish】 button, enter the following.
# Set the view title bar of the arc-shaped appearance of
org.eclipse.ui / SHOW_TRADITIONAL_STYLE_TABS = false
# Text editor prompts the shortest length of the title bar
org.eclipse.ui / EDITOR_MINIMUM_CHARACTERS = 12
(3) Custom configuration file if you do not like the default configuration file can change the configuration file name (in this book using this method), specific steps are as follows.
Pludin.xml ① Double-click the file, and then click "Extensions" page.
② Expand org.eclipse.core.runtime.products, in jfcs (Product) Right-click and select 【New】 → 【property】.
③ In the Extension Element Details under the name of the text box after the property name preferenceCustomization
(Property name can not be changed), value after the text box AppPref.ini (can be any name), specifically as shown in Figure 5-10. To see what is available org.eclipse.core.runtime.products configuration properties, only need to click org.eclipse.core.runtime.products name, and then click the right of Open extension point description, Eclipse will open the Products extension point on the property description, as shown in Figure 5-11. Noted that the properties of the default file is the previously mentioned plugin_customization.ini.
Figure 5-10 Add attribute to set the view
Figure 5-11 org.eclipse.core.runtime.products extension points described in the project name ④ Click the right mouse button and select 【New】 → 【File】, in the File name entered after the AppPref.ini, click 【Finish】 button , enter the configuration content.
Caution here that, if done a lot of settings, while the run-time does not seem to take effect, this is because the Eclipse caching the old configuration information. Workaround: Select the system menu Run】 【→】 【Run ..., pop-up "Run" dialog box, first click the "Eclipse Application", and then click "jfcs", check "Clean workspace data before launching", do not hook Select "Ask for confirmation before cleaning". This will ensure that each run are the latest results, set the screen shown in Figure 5-12.
Figure 5-12 Run Settings dialog box
SHOW_INTRO is rather special. If you use the ini configuration file the way, regardless of the default configuration file or a custom configuration file, after the release of product packaging (not Eclipse environment to run) only appears when you first start the Welcome screen, it is because Eclipse will run the end of modification Space directory org.eclipse.ui.prefs files showIntro = false, it will not appear next time you start the Welcome screen. If you want the program every time you start the Welcome screen appears when they need to take a hard-coded way!