zoukankan      html  css  js  c++  java
  • Eclipse rap 富客户端开发总结(10) : Rap不同系统间的差异和处理方式

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

    1、   图片路径

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

    [java] view plain copy
     
     print?
    1. public static String getRoot() {  
    2.         String path = null ;  
    3.         try {  
    4.      path = FileLocator.toFileURL (Platform.getBundle (Activator. PLUGIN_ID ).getEntry( "" )).getPath();  
    5.      path = path.substring(path.indexOf( "/" ) + 1, path.length());  
    6.         }  
    7.         catch (Exception e) {  
    8.            log .error( "getRoot method :" , e);  
    9.         }  
    10.         return path;  
    11.     }  

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

    [java] view plain copy
     
     print?
    1. /** 
    2.      * 获取图片 
    3.      * @param fileName 
    4.      *            图片的名称 
    5.      * @return 先从缓存对象中查找,若有直接返回,若没有,则将图片加载到缓存中,在从缓存中将图片传给调用着 
    6.      */  
    7.   
    8.     public static Image getImage(String fileName) {  
    9.         Bundle bundle = Platform.getBundle ( "TelecomUI" );  
    10.         URL url = bundle.getEntry( "icons" );  
    11.         try {  
    12.             url = Platform.asLocalURL (url) ;  
    13.         }  
    14.         catch (Exception e) {  
    15.         }  
    16.         Image image = registry .get(fileName);  
    17.         if ( null != image) {  
    18.             return image;  
    19.         }  
    20.         else {  
    21.             URL fullPathString = bundle.getEntry( "icons/" + fileName);  
    22.             ImageDescriptor des = ImageDescriptor.createFromURL (fullPathString);  
    23.             registry .put(fileName, des);  
    24.             return ImageDescriptor.createFromURL (fullPathString).createImage();  
    25.         }  
    26.     }   

    2、   获得屏幕的分辨率

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

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

    [java] view plain copy
     
     print?
    1. screenH = Toolkit.getDefaultToolkit().getScreenSize ().height;  
    2.         screenW = Toolkit.getDefaultToolkit().getScreenSize ().width;   

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

    sun.awt.X11.XToolkit 类

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

    DisPlay.getDefault().getClientArea();

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

  • 相关阅读:
    yield* 表达式
    Set 对象和WeakSet对象
    洗牌算法
    filter() 方法创建一个新数组
    UTF8文件带BOM引起的问题
    ios的白屏坑
    css的字体样式怎么写
    npm全局安装失效修复
    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)解决方案
    linux下nginx的安装及配置
  • 原文地址:https://www.cnblogs.com/dengyungao/p/7503634.html
Copyright © 2011-2022 走看看