spring-richclient开发swing应用程序 3

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

1

 <bean id="petclinicLifecycleAdvisor"
  class="org.springframework.richclient.samples.petclinic.PetClinicLifecycleAdvisor">
  <property name="windowCommandBarDefinitions">
   <value>org/springframework/richclient/samples/petclinic/ui/commands-context.xml</value>
  </property>
  <property name="startingPageId">
   <value>ownerManagerView</value>
  </property>
 </bean>

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

 <bean id="applicationObjectConfigurer"
  class="org.springframework.richclient.application.config.DefaultApplicationObjectConfigurer">
  <constructor-arg index="0">
   <ref bean="messageSource"/>
  </constructor-arg>
  <constructor-arg index="1">
   <ref bean="imageSource"/>
  </constructor-arg>
  <constructor-arg index="2">
   <ref bean="iconSource"/>
  </constructor-arg>
 </bean>

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

3

 <bean id="applicationEventMulticaster"
  class="org.springframework.context.event.SimpleApplicationEventMulticaster"/>

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

4

    <bean id="binderSelectionStrategy"
        class="org.springframework.richclient.samples.petclinic.ui.binder.PetClinicBinderSelectionStrategy">
        <property name="bindersForPropertyTypes">
            <map>
<!--                <entry>
                    <key>
                        <value type="java.lang.Class">java.util.Date</value>
                    </key>
                    <bean
                        class="org.springframework.richclient.samples.petclinic.ui.binder.CustomDatePickerBinder"/>
                </entry>-->
                <entry>
                    <key>
                        <value type="java.lang.Class">
                            org.springframework.samples.petclinic.PetType</value>
                    </key>
                    <bean
                        class="org.springframework.richclient.samples.petclinic.ui.binder.PetTypeBinder">
                        <property name="clinic">
                            <ref bean="clinic"/>
                        </property>
                    </bean>
                </entry>
            </map>
        </property>
    </bean>

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

5

 <bean id="lookAndFeelConfigurer"
  class="org.springframework.richclient.application.config.JGoodiesLooksConfigurer">
  <property name="popupDropShadowEnabled" value="false" />
  <property name="theme"> 
   <bean class="com.jgoodies.looks.plastic.theme.ExperienceBlue"/>
  </property>
 </bean>

调用了jgoodies的一个皮肤

6

 <bean id="messageSource"
  class="org.springframework.context.support.ResourceBundleMessageSource">
  <property name="basenames">
   <list>
    <value>org.springframework.richclient.samples.petclinic.ui.messages</value>
    <value>org.springframework.richclient.samples.petclinic.ui.preference.messages</value>
    <value>org.springframework.richclient.application.messages</value>
   </list>
  </property>
 </bean>
 
 <bean id="imageResourcesFactory"
  class="org.springframework.context.support.ResourceMapFactoryBean">
  <property name="locations">
   <list>
    <value>classpath:org/springframework/richclient/image/images.properties</value>
    <value>classpath:org/springframework/richclient/samples/petclinic/ui/images.properties</value>
   </list>
  </property>
  <property name="resourceBasePath">
   <value>images/</value>
  </property>
 </bean>
 
 <bean id="imageSource"
  class="org.springframework.richclient.image.DefaultImageSource">
  <constructor-arg index="0">
   <ref bean="imageResourcesFactory"/>
  </constructor-arg>
  <property name="brokenImageIndicator">
   <value>images/alert/error_obj.gif</value>
  </property>
 </bean>
 
 <bean id="iconSource"
  class="org.springframework.richclient.image.DefaultIconSource">
  <constructor-arg index="0">
   <ref bean="imageSource"/>
  </constructor-arg>
 </bean>

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

7

 <bean id="formComponentInterceptorFactory"
  class="org.springframework.richclient.form.builder.support.ChainedInterceptorFactory">
  <property name="interceptorFactories">
   <list>
    <bean class="org.springframework.richclient.form.builder.support.ColorValidationInterceptorFactory">
     <property name="errorColor">
      <value>255,245,245</value>
     </property>
    </bean>
    <bean class="org.springframework.richclient.form.builder.support.OverlayValidationInterceptorFactory"/>
    <bean class="org.springframework.richclient.text.TextComponentPopupInterceptorFactory"/>
    <bean class="org.springframework.richclient.list.ComboBoxAutoCompletionInterceptorFactory">
     <property name="messageSource">
      <ref bean="messageSource"/>
     </property>
    </bean>
   </list>
  </property>
 </bean> 

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

ColorValidationInterceptorFactory:错误显示灰色颜色

OverlayValidationInterceptorFactory

TextComponentPopupInterceptorFactory:文本框弹出提示

ComboBoxAutoCompletionInterceptorFactory组合框自动补完

8

 <bean id="rulesSource"
  class="org.springframework.richclient.samples.petclinic.domain.PetClinicValidationRulesSource"/>

数据完整性验证,例如

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

9

 <bean id="ownerManagerView"
  class="org.springframework.richclient.application.support.DefaultViewDescriptor">
  <property name="viewClass">
   <value>org.springframework.richclient.samples.petclinic.ui.OwnerManagerView</value>
  </property>
  <property name="viewProperties">
   <map>
    <entry key="clinic">
     <ref bean="clinic"/>
    </entry>
   </map>
  </property>
 </bean>
 宠物主人管理的界面
 <bean id="newOwnerWizard"
  class="org.springframework.richclient.samples.petclinic.ui.NewOwnerWizard">
  <property name="clinic">
   <ref bean="clinic"/>
  </property>
 </bean>
 添加宠物主人的向导
 <bean id="vetManagerView"
  class="org.springframework.richclient.application.support.DefaultViewDescriptor">
  <property name="viewClass">
   <value>org.springframework.richclient.samples.petclinic.ui.VetManagerView</value>
  </property>
  <property name="viewProperties">
   <map>
    <entry key="clinic">
     <ref bean="clinic"/>
    </entry>
   </map>
  </property>
 </bean>
 宠物管理界面


 <bean id="setupWizard"
  class="org.springframework.richclient.application.setup.SetupWizard">
  <property name="licenseTextLocation">
   <value>/org/springframework/richclient/samples/petclinic/license.html</value>
  </property>
 </bean>

开始时后的安装向导

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值