Changeset 9627

Show
Ignore:
Timestamp:
04/17/08 21:00:52 (5 years ago)
Author:
ewigkeit
Message:

lang/java/sabotter: ImageRegistryを使うように変更。ついでにスペルミスも修正。

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/java/sabotter/trunk/src/jp/xet/eclipse/sabotter/views/LabelProcessor.java

    r9597 r9627  
    99import java.text.SimpleDateFormat; 
    1010import java.util.Date; 
    11 import java.util.HashMap; 
    1211import java.util.Locale; 
    13 import java.util.Map; 
    1412 
    1513import jp.xet.eclipse.sabotter.SabotterPlugin; 
     
    2119import org.apache.commons.httpclient.HttpMethod; 
    2220import org.apache.commons.httpclient.methods.GetMethod; 
     21import org.eclipse.jface.resource.ImageRegistry; 
    2322import org.eclipse.swt.SWT; 
    2423import org.eclipse.swt.graphics.Color; 
     
    3332/** 
    3433 * 表示文字列等の加工(色づけ等)クラス。 
     34 *  
    3535 * @author daisuke 
    3636 */ 
    3737public class LabelProcessor { 
    38          
     38 
    3939        private TwitterManager manager; 
    4040 
     
    4848 
    4949        /** アイコン画像のキャッシュ */ 
    50         private Map<String, Image> cashe = new HashMap<String, Image>(); 
    51          
     50        private ImageRegistry cache = new ImageRegistry(); 
     51 
    5252        /** プリファレンス */ 
    5353        SabotterPreference pref = SabotterPlugin.getPreference(); 
     
    5555        /** 
    5656         * コンストラクタ。 
     57         *  
    5758         * @param manager 
    5859         * @category instance creation 
     
    6465        /** 
    6566         * 表示する名前を取得する。 
     67         *  
    6668         * @param status 
    6769         * @return 名前 
     
    8284        /** 
    8385         * 表示するメッセージを取得する。 
     86         *  
    8487         * @param status 
    8588         * @return メッセージ 
     
    9194        /** 
    9295         * 表示する日時を取得する。 
     96         *  
    9397         * @param status 
    9498         * @return 日時 
     
    107111        /** 
    108112         * 表示するアイコンを取得する 
     113         *  
    109114         * @param status 
    110115         * @return アイコン 
    111116         */ 
    112117        public Image getImage(Status status) { 
    113                 Image image = null; 
    114118                if (status == null) { 
    115                         return image; 
     119                        return null; 
    116120                } 
    117121                String url = encode(status.getUser().getProfileImageURL().toString()); 
    118                 if (cashe.get(url) == null) { 
     122                if (cache.get(url) == null) { 
    119123                        HttpClient client = new HttpClient(); 
    120124 
     
    126130                        } 
    127131 
     132                        Image tmpImage = null; 
     133 
    128134                        try { 
    129135                                HttpMethod method = new GetMethod(url); 
    130136                                client.executeMethod(method); 
    131137                                InputStream is = method.getResponseBodyAsStream(); 
    132                                 image = new Image(null, is); 
    133                                 cashe.put(url, image); 
     138                                tmpImage = new Image(null, is); 
     139                                cache.put(url, processImage(tmpImage)); 
    134140                        } catch (HttpException e) { 
    135141                                SabotterPlugin.handleException(e); 
     
    139145                                SabotterPlugin.handleException(e, SabotterPlugin.LOG 
    140146                                                | SabotterPlugin.STACKTRACE); 
     147                        } finally { 
     148                                if ((tmpImage != null) && !tmpImage.isDisposed()) { 
     149                                        tmpImage.dispose(); 
     150                                } 
    141151                        } 
    142                 } else { 
    143                         image = cashe.get(url); 
    144                 } 
    145  
    146                 return processImage(image); 
     152                } 
     153 
     154                return cache.get(url); 
    147155        } 
    148156 
    149157        /** 
    150158         * APIから取得したURLのエンコーディングを行う。(本来はAPI側で処理されているべきなんだが) 
     159         *  
    151160         * @param url 
    152161         * @return エンコーディング結果。 
     
    168177        /** 
    169178         * 画像を設定の通りに加工する。 
     179         *  
    170180         * @param image 
    171181         * @return 加工された画像 
     
    215225        /** 
    216226         * 背景色を取得する。 
     227         *  
    217228         * @param status 
    218229         * @return 背景色 
     
    233244        /** 
    234245         * 文字色を取得する。 
     246         *  
    235247         * @param status 
    236248         * @return 文字色 
     
    246258        /** 
    247259         * フォントを取得する。 
     260         *  
    248261         * @param status 
    249262         * @return フォント 
    250263         */ 
    251264        public Font getFont(Status status) { 
    252                 if(manager.isUnread(status)) { 
     265                if (manager.isUnread(status)) { 
    253266                        // なんか微妙だな。。 
    254267                        return new Font(null, new FontData("", 9, SWT.BOLD));