Eclipse rcp/rap 开发经验总结(10) -Rap不同系统间的差异和处理方式

 

平常进行 rap 程序开发一般都是在 win 下面完成 , 然后在 tomcat 下面测试 , 但是程序最终发布一般都是在 linux  aix 上面 , 这个时候就有能会出现一下问题,下面 2 个问题是我们把在开发中真是出现的问题,与大家一起分享下 ;

1、   图片路径

这个是最常用的方法,就是在 rap 中加载图片进行显示,刚开始我们使用的是如下代码

 

public static String getRoot() {
        String path = null ;
        try {
     path = FileLocator.toFileURL (Platform.getBundle (Activator. PLUGIN_ID ).getEntry( "" )).getPath();
     path = path.substring(path.indexOf( "/" ) + 1, path.length());
        }
        catch (Exception e) {
           log .error( "getRoot method :" , e);
        }
        return path;
    }

 

来获得系统的跟路径 . 但是当程序在移植到 linux 和 aix 上面的时候发现图片路径全部失效 . 可以使用如下方式进行寻址来获得图片。

/**
     * 获取图片
     * @param fileName
     *            图片的名称
     * @return 先从缓存对象中查找,若有直接返回,若没有,则将图片加载到缓存中,在从缓存中将图片传给调用着
     */

    public static Image getImage(String fileName) {
        Bundle bundle = Platform.getBundle ( "TelecomUI" );
        URL url = bundle.getEntry( "icons" );
        try {
            url = Platform.asLocalURL (url) ;
        }
        catch (Exception e) {
        }
        Image image = registry .get(fileName);
        if ( null != image) {
            return image;
        }
        else {
            URL fullPathString = bundle.getEntry( "icons/" + fileName);
            ImageDescriptor des = ImageDescriptor.createFromURL (fullPathString);
            registry .put(fileName, des);
            return ImageDescriptor.createFromURL (fullPathString).createImage();
        }
    } 

 

 

 

2、   获得屏幕的分辨率

因为需要把一些弹出的组件居中显示 , 这个时候就需要获得系统的分辨率

刚开始我们使用的方法如下;

screenH = Toolkit.getDefaultToolkit().getScreenSize ().height;
        screenW = Toolkit.getDefaultToolkit().getScreenSize ().width; 

 

 

上面这段代码在 window 下面是没有问题的 , 可是到了 linux aix 下面就报错了 , 找不到

sun.awt.X11.XToolkit

 

可以采用如下方式来获得屏幕的分辨率     

DisPlay.getDefault().getClientArea();

 

 

3、   其他如果有发现不兼容会陆续补充

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值