spring-richclient开发swing应用程序 3

冀望
2023-12-01

richclient-application-context.xml 上一节我们说到,这个文件是整个应用程序框架的核心,现在我们就来看这个文件。

1

 
  class="org.springframework.richclient.samples.petclinic.PetClinicLifecycleAdvisor">
  
    org/springframework/richclient/samples/petclinic/ui/commands-context.xml
  
  
    ownerManagerView
  
 

PetClinicLifecycleAdvisor这个类定义在应用程序加载的特定阶段,需要执行的一些函数,我们来看一下

public class PetClinicLifecycleAdvisor extends DefaultApplicationLifecycleAdvisor {

//在窗口打开之前,执行一个setup向导
    public void onPreWindowOpen(ApplicationWindowConfigurer configurer) {
        super.onPreWindowOpen(configurer);
        if (getApplicationServices().containsBean("setupWizard")) {
            SetupWizard setupWizard = (SetupWizard)getApplicationServices().getBean("setupWizard", SetupWizard.class);
            setupWizard.execute();
        }
        // comment out to hide the menubar, toolbar, or reduce window size...
        //configurer.setShowMenuBar(false);
        //configurer.setShowToolBar(false);
        //configurer.setInitialSize(new Dimension(640, 480));
    }

//在命令都被加载以后,执行一个loginCommand,相当于按了一下登陆按钮,才会出现登陆对话框。

    public void onCommandsCreated(ApplicationWindow window) {
        initializeDefaultPreferences();
       
        ActionCommand command = window.getCommandManager().getActionCommand("loginCommand");
        command.execute();
    }
   

//初始化应用程序选项,这是每一个应用程序启动都必须,加载的配置在richclient-preference-context.xml中

    private void initializeDefaultPreferences() {
        PreferenceStore ps = (PreferenceStore) getApplicationServices().getBean("preferenceStore");
        ps.setDefault(PetClinicAppearance.DIALOG_PAGE_TYPE, CompositeDialogPageType.TREE);
    }

}

2

 
  class="org.springframework.richclient.application.config.DefaultApplicationObjectConfigurer">
  
   
  
  
   
  
  
   
  
 

这个定义了一下需要用到的资源文件,包括文件,图标和语言文件。初学者或者从VB开发转过来的朋友要明白,把这些资源放在一个目录里面动态加载是可以提升降低程序的大小,提高程序性能的。

3

 
  class="org.springframework.context.event.SimpleApplicationEventMulticaster"/>

定义了事件分发的bean,用于将界面按钮的相应转给相应的command执行

4

   
        class="org.springframework.richclient.samples.petclinic.ui.binder.PetClinicBinderSelectionStrategy">
       
           

               
                   
                       
                            org.springframework.samples.petclinic.PetType
                   
                   
                        class="org.springframework.richclient.samples.petclinic.ui.binder.PetTypeBinder">
                       
                           
                       
                   
               
           

       
   

定义了一个select控件的数据绑定,就是在程序中添加宠物时用于选择宠物类型的。

5

 
  class="org.springframework.richclient.application.config.JGoodiesLooksConfigurer">
  
    
   
  
 

调用了jgoodies的一个皮肤

6

 
  class="org.springframework.context.support.ResourceBundleMessageSource">
  
   
     org.springframework.richclient.samples.petclinic.ui.messages
     org.springframework.richclient.samples.petclinic.ui.preference.messages
     org.springframework.richclient.application.messages
   
  
 
 
 
  class="org.springframework.context.support.ResourceMapFactoryBean">
  
   
     classpath:org/springframework/richclient/image/images.properties
     classpath:org/springframework/richclient/samples/petclinic/ui/images.properties
   
  
  
    images/
  
 
 
 
  class="org.springframework.richclient.image.DefaultImageSource">
  
   
  
  
    images/alert/error_obj.gif
  
 
 
 
  class="org.springframework.richclient.image.DefaultIconSource">
  
   
  
 

定义资源文件的地点,不用多说。

7

 
  class="org.springframework.richclient.form.builder.support.ChainedInterceptorFactory">
  
   
    
     
       255,245,245
     
    
    
    
    
     
      
     
    
   
  
   

为了让表单填写智能化用的三个interceptor。从名字就可以看出,

ColorValidationInterceptorFactory:错误显示灰色颜色

OverlayValidationInterceptorFactory

TextComponentPopupInterceptorFactory:文本框弹出提示

ComboBoxAutoCompletionInterceptorFactory组合框自动补完

8

 
  class="org.springframework.richclient.samples.petclinic.domain.PetClinicValidationRulesSource"/>

数据完整性验证,例如

return all(new Constraint[] {required(), maxLength(25), regexp("[a-zA-Z]*", "alphabetic")});

9

 
  class="org.springframework.richclient.application.support.DefaultViewDescriptor">
  
    org.springframework.richclient.samples.petclinic.ui.OwnerManagerView
  
  
   
    
     
    
   

  
 
 宠物主人管理的界面
 
  class="org.springframework.richclient.samples.petclinic.ui.NewOwnerWizard">
  
   
  
 
 添加宠物主人的向导
 
  class="org.springframework.richclient.application.support.DefaultViewDescriptor">
  
    org.springframework.richclient.samples.petclinic.ui.VetManagerView
  
  
   
    
     
    
   

  
 
 宠物管理界面


 
  class="org.springframework.richclient.application.setup.SetupWizard">
  
    /org/springframework/richclient/samples/petclinic/license.html
  
 

开始时后的安装向导



Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=470716


 类似资料: