1
2
3
4
5
6
7
8
9
10
11
12 package sk.uniba.euromath.plugin.views.outline;
13
14 import java.io.InputStream;
15
16 import org.eclipse.jface.resource.ImageRegistry;
17 import org.eclipse.jface.viewers.LabelProvider;
18 import org.eclipse.swt.graphics.Image;
19 import org.eclipse.swt.graphics.ImageData;
20
21 import sk.uniba.euromath.editor.EditorSite;
22 import sk.uniba.euromath.plugin.views.outline.items.OutlineItem;
23
24 /***
25 * Provides images and labels for outline items. Every node type has different
26 * image and label
27 *
28 * @author Tomáš Studva 2.11.2005
29 */
30
31 class OutlineItemsLabelProvider extends LabelProvider {
32
33 /***
34 * Image registry for image labels.
35 */
36 protected ImageRegistry registry;
37
38 /***
39 * Editor site instance.
40 */
41 private EditorSite editorSite;
42
43 /***
44 * Inverted images flag.
45 */
46 protected boolean inverted = true;
47
48 /***
49 * Constructor.
50 * @param site
51 *
52 * @param xmlAccess
53 */
54 public OutlineItemsLabelProvider(EditorSite site) {
55 super();
56 this.editorSite = site;
57 this.registry = new ImageRegistry();
58 createImages();
59 }
60
61 /***
62 * Adds image to registry.
63 *
64 * @param file
65 * @param key
66 * under which will be registered
67 */
68 private void addImage(String file, String key) {
69 InputStream stream = OutlineItemsLabelProvider.class
70 .getResourceAsStream(file);
71 ImageData data = new ImageData(stream);
72 this.registry.put(key,
73 new Image(null, data, data.getTransparencyMask()));
74
75 }
76
77 /***
78 * Creates needed images by this provider.
79 */
80 private void createImages() {
81 addImage(OutlineConsts.ATTR_FILE, OutlineConsts.ATTR_KEY);
82 addImage(OutlineConsts.ATTR_FILE_INV, OutlineConsts.ATTR_KEY_INV);
83 addImage(OutlineConsts.CDAT_FILE, OutlineConsts.CDAT_KEY);
84 addImage(OutlineConsts.CDAT_FILE_INV, OutlineConsts.CDAT_KEY_INV);
85 addImage(OutlineConsts.COMM_FILE, OutlineConsts.COMM_KEY);
86 addImage(OutlineConsts.COMM_FILE_INV, OutlineConsts.COMM_KEY_INV);
87 addImage(OutlineConsts.ELEM_FILE, OutlineConsts.ELEM_KEY);
88 addImage(OutlineConsts.ELEM_FILE_INV, OutlineConsts.ELEM_KEY_INV);
89 addImage(OutlineConsts.ENTI_FILE, OutlineConsts.ENTI_KEY);
90 addImage(OutlineConsts.ENTI_FILE_INV, OutlineConsts.ENTI_KEY_INV);
91 addImage(OutlineConsts.INST_FILE, OutlineConsts.INST_KEY);
92 addImage(OutlineConsts.INST_FILE_INV, OutlineConsts.INST_KEY_INV);
93 addImage(OutlineConsts.TEXT_FILE, OutlineConsts.TEXT_KEY);
94 addImage(OutlineConsts.TEXT_FILE_INV, OutlineConsts.TEXT_KEY_INV);
95 }
96
97
98
99
100
101
102 @Override
103 public void dispose() {
104 this.registry = null;
105 super.dispose();
106 }
107
108 /***
109 * Returns image for obj. Depends on image key and inverted flag. Images of
110 * not visualized nodes have inverted image.
111 *
112 * @param obj
113 * must be instance of outline item
114 */
115 @Override
116 public Image getImage(Object obj) {
117 assert (obj instanceof OutlineItem);
118
119 OutlineItem item = (OutlineItem) obj;
120 String imageKey = item.getImageKey();
121 if (imageKey == null)
122 return null;
123
124 if (this.inverted) {
125 String id = this.editorSite.getXMLAccess().getIDManager().getIDNull(item.getModel());
126
127 if (!this.editorSite.getVisualizedIds().contains(id)) {
128 imageKey += OutlineConsts.KEY_INVERTED;
129 }
130 }
131 return this.registry.get(imageKey);
132 }
133
134 /***
135 * Getter for image registry.
136 *
137 * @return image registry holding images registered under keys from
138 * OutlineConsts.
139 */
140 public ImageRegistry getImageRegistry() {
141 return this.registry;
142 }
143
144 /***
145 * Returns text, label for object.
146 */
147 @Override
148 public String getText(Object obj) {
149 return obj.toString();
150 }
151
152 /***
153 * @param b
154 */
155 public void setWithInvertedImages(boolean b) {
156 this.inverted = b;
157 }
158
159 }