View Javadoc

1   /*
2    * $Id: URIExplorerLabelDecorator.java,v 1.3 2005/05/31 22:04:32 jlerner Exp $
3    *
4    * Copyright (c) 1999-2004, BBN Technologies, LLC.
5    * All rights reserved.
6    * http://www.daml.org/legal/opensource/bbn_license.html
7    */
8    
9   package com.bbn.swede.view.uriexplorer.ui;
10  
11  import org.eclipse.jface.resource.CompositeImageDescriptor;
12  import org.eclipse.jface.viewers.ILabelDecorator;
13  import org.eclipse.jface.viewers.LabelProvider;
14  import org.eclipse.swt.graphics.Image;
15  import org.eclipse.swt.graphics.Point;
16  
17  import com.bbn.swede.core.IOWLLibrary;
18  import com.bbn.swede.core.libraries.Libraries;
19  
20  /***
21   * This is a class which implements the Decorator pattern for label 
22   * providers, tailored to the functioning of the URIExplorer.  
23   * 
24   * @author aperezlo
25   */
26  public class URIExplorerLabelDecorator extends LabelProvider implements ILabelDecorator
27  {
28     
29     /*** 
30      * Used to decorate images shown in the URI Explorer.  Currently does nothing.
31      * 
32      * @see org.eclipse.jface.viewers.ILabelDecorator#decorateImage(org.eclipse.swt.graphics.Image, java.lang.Object)
33      */
34     public Image decorateImage(Image image, Object element)
35     {
36        Image toReturn = image;
37  
38  //      if(element instanceof IOWLLibrary)
39  //      {
40  //         if(Libraries.isDueForRefresh(((IOWLLibrary) element).getLibrary()))
41  //         {
42  //            ISharedImages si = JavaUI.getSharedImages();
43  //            BottomRightImageAnnotator bria = 
44  //               new BottomRightImageAnnotator(image, si.getImage(ISharedImages.IMG_FIELD_DEFAULT)); 
45  //            toReturn = bria.createImage();
46  //         }
47  //      }
48        
49        return toReturn;
50     }
51  
52     /*** 
53      * Used to decorate text labels.  Currently alters the names of 
54      * labels for libraries that are due to be refreshed as specified 
55      * in the Library preferences.
56      * 
57      * @see org.eclipse.jface.viewers.ILabelDecorator#decorateText(java.lang.String, java.lang.Object)
58      */
59     public String decorateText(String text, Object element)
60     {
61        String toReturn = text;
62        if(element instanceof IOWLLibrary)
63        {
64           if(Libraries.isDueForRefresh(((IOWLLibrary) element).getLibrary()))
65           {
66              toReturn += " (due for refresh)";
67           }
68        }
69        return toReturn;
70     }
71     
72     
73     /***
74      * This class will draw a decorator image atop a main image
75      * and was written for the label decorator.  Unfortunately, 
76      * no good decorator artwork was available, and so the class
77      * is currently not used.  
78      *  
79      * @author aperezlo
80      */
81     private final class BottomRightImageAnnotator extends CompositeImageDescriptor
82     {
83        private Image _mainImage;
84        private Image _annotationImage;
85        
86        public BottomRightImageAnnotator(Image main, Image annotation)
87        {
88           _mainImage = main;
89           _annotationImage = annotation;
90        }
91        
92        protected void drawCompositeImage(int width, int height)
93        {
94           Point center = new Point((width / 2) - 1, (height / 2) - 1);
95           
96           drawImage(_mainImage.getImageData(), 0, 0);
97           drawImage(_annotationImage.getImageData(), center.x, center.y);
98  //         drawImage(_annotationImage.getImageData(), 0, 0);
99        }
100 
101       protected Point getSize()
102       {
103          return new Point(_mainImage.getBounds().width, _mainImage.getBounds().height);
104       }
105    }
106 }