Skip to content

Commit e5c260e

Browse files
committed
Migrate off deprecated ImageData methods
1 parent edf706e commit e5c260e

File tree

23 files changed

+180
-191
lines changed

23 files changed

+180
-191
lines changed

examples/org.eclipse.swt.examples.launcher/src/org/eclipse/swt/examples/launcher/LauncherPlugin.java

+28-28
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class LauncherPlugin extends AbstractUIPlugin {
5959
LAUNCH_ITEMS_XML_ATTRIB_ENABLED = "enabled",
6060
LAUNCH_ITEMS_XML_ATTRIB_CATEGORY = "category",
6161
LAUNCH_ITEMS_XML_VALUE_TRUE = "true",
62-
LAUNCH_ITEMS_XML_VALUE_FALSE = "false";
62+
LAUNCH_ITEMS_XML_VALUE_FALSE = "false";
6363

6464
static final int
6565
liClosedFolder = 0,
@@ -84,7 +84,7 @@ public void start(BundleContext context) throws Exception {
8484
super.start(context);
8585
resourceBundle = Platform.getResourceBundle(getBundle());
8686
}
87-
87+
8888
/**
8989
* Clean up
9090
*/
@@ -107,7 +107,7 @@ public static LauncherPlugin getDefault() {
107107
public static void initResources() {
108108
if (images == null) {
109109
images = new Image[imageLocations.length];
110-
110+
111111
for (int i = 0; i < imageLocations.length; ++i) {
112112
images[i] = getImageFromPlugin(plugin.getBundle(), imageLocations[i]);
113113
if (images[i] == null) {
@@ -116,7 +116,7 @@ public static void initResources() {
116116
throw new IllegalStateException();
117117
}
118118
}
119-
}
119+
}
120120
}
121121

122122
/**
@@ -133,7 +133,7 @@ public static void freeResources() {
133133

134134
/**
135135
* Log an error to the ILog for this plugin
136-
*
136+
*
137137
* @param message the localized error message text
138138
* @param exception the associated exception, or null
139139
*/
@@ -154,7 +154,7 @@ public static String getResourceString(String key) {
154154
return key;
155155
} catch (NullPointerException e) {
156156
return "!" + key + "!";
157-
}
157+
}
158158
}
159159

160160
/**
@@ -174,7 +174,7 @@ public static String getResourceString(String key, Object[] args) {
174174

175175
/**
176176
* Constructs a list of available programs from registered extensions.
177-
*
177+
*
178178
* @return an ItemTreeNode representing the root of a tree of items (the root is not to be displayed)
179179
*/
180180
public static ItemTreeNode getLaunchItemTree() {
@@ -186,41 +186,41 @@ public static ItemTreeNode getLaunchItemTree() {
186186
// retrieve all configuration elements registered at our launchItems extension-point
187187
IConfigurationElement[] configurationElements =
188188
extensionRegistry.getConfigurationElementsFor(LAUNCH_ITEMS_POINT_ID);
189-
189+
190190
if (configurationElements == null || configurationElements.length == 0) {
191191
logError(getResourceString("error.CouldNotFindRegisteredExtensions"), null);
192192
return categoryTree;
193193
}
194-
194+
195195
/* Collect all launch categories -- coalesce those with same ID */
196196
HashMap<String, ItemTreeNode> idMap = new HashMap<>();
197197
for (IConfigurationElement ce: configurationElements) {
198198
final String ceName = ce.getName();
199199
final String attribId = getItemAttribute(ce, LAUNCH_ITEMS_XML_ATTRIB_ID, null);
200-
200+
201201
if (idMap.containsKey(attribId)) continue;
202202
if (ceName.equalsIgnoreCase(LAUNCH_ITEMS_XML_CATEGORY)) {
203-
final String attribName = getItemName(ce);
203+
final String attribName = getItemName(ce);
204204
ItemDescriptor theDescriptor = new ItemDescriptor(attribId, attribName,
205205
getItemDescription(ce), null, null, null, null, ce);
206206
idMap.put(attribId, new ItemTreeNode(theDescriptor));
207207
}
208208
}
209-
209+
210210
/* Generate launch category hierarchy */
211211
Set<String> tempIdSet = new HashSet<>(); // used to prevent duplicates from being entered into the tree
212212
for (IConfigurationElement ce : configurationElements) {
213213
final String ceName = ce.getName();
214214
final String attribId = getItemAttribute(ce, LAUNCH_ITEMS_XML_ATTRIB_ID, null);
215-
215+
216216
if (tempIdSet.contains(attribId)) continue;
217217
if (ceName.equalsIgnoreCase(LAUNCH_ITEMS_XML_CATEGORY)) {
218218
final ItemTreeNode theNode = idMap.get(attribId);
219219
addItemByCategory(ce, categoryTree, theNode, idMap);
220220
tempIdSet.add(attribId);
221221
}
222222
}
223-
223+
224224
/* Generate program tree */
225225
for (IConfigurationElement ce : configurationElements) {
226226
final String ceName = ce.getName();
@@ -230,11 +230,11 @@ public static ItemTreeNode getLaunchItemTree() {
230230
if (ceName.equalsIgnoreCase(LAUNCH_ITEMS_XML_CATEGORY)) {
231231
// ignore
232232
} else if (ceName.equalsIgnoreCase(LAUNCH_ITEMS_XML_ITEM)) {
233-
final String enabled = getItemAttribute(ce, LAUNCH_ITEMS_XML_ATTRIB_ENABLED,
233+
final String enabled = getItemAttribute(ce, LAUNCH_ITEMS_XML_ATTRIB_ENABLED,
234234
LAUNCH_ITEMS_XML_VALUE_TRUE);
235235
if (enabled.equalsIgnoreCase(LAUNCH_ITEMS_XML_VALUE_FALSE)) continue;
236-
ItemDescriptor theDescriptor = createItemDescriptor(ce, attribId);
237-
236+
ItemDescriptor theDescriptor = createItemDescriptor(ce, attribId);
237+
238238
if (theDescriptor != null) {
239239
final ItemTreeNode theNode = new ItemTreeNode(theDescriptor);
240240
addItemByCategory(ce, categoryTree, theNode, idMap);
@@ -245,28 +245,28 @@ public static ItemTreeNode getLaunchItemTree() {
245245
return categoryTree;
246246
}
247247

248-
248+
249249
/**
250250
* Adds an item to the category tree.
251251
*/
252252
private static void addItemByCategory(IConfigurationElement ce, ItemTreeNode root,
253253
ItemTreeNode theNode, HashMap<String, ItemTreeNode> idMap) {
254254
final String attribCategory = getItemAttribute(ce, LAUNCH_ITEMS_XML_ATTRIB_CATEGORY, null);
255-
255+
256256
// locate the parent node
257257
ItemTreeNode parentNode = null;
258258
if (attribCategory != null) {
259259
parentNode = idMap.get(attribCategory);
260260
}
261261
if (parentNode == null) parentNode = root;
262-
262+
263263
// add the item
264264
parentNode.addSortedNode(theNode);
265265
}
266266

267267
/**
268268
* Creates an ItemDescriptor from an XML definition.
269-
*
269+
*
270270
* @param ce the IConfigurationElement describing the item
271271
* @param attribId the attribute id
272272
* @return a new ItemDescriptor, or null if an error occurs
@@ -279,7 +279,7 @@ private static ItemDescriptor createItemDescriptor(IConfigurationElement ce, Str
279279
IConfigurationElement viewCE = getItemElement(ce, LAUNCH_ITEMS_XML_VIEW);
280280
if (viewCE != null) {
281281
//Item is a view
282-
final String attribView = getItemAttribute(viewCE, LAUNCH_ITEMS_XML_VIEW_VIEWID, null);
282+
final String attribView = getItemAttribute(viewCE, LAUNCH_ITEMS_XML_VIEW_VIEWID, null);
283283
if (attribView == null) {
284284
logError(getResourceString("error.IncompleteViewLaunchItem",
285285
new Object[] { attribId } ), null);
@@ -310,7 +310,7 @@ private static ItemDescriptor createItemDescriptor(IConfigurationElement ce, Str
310310

311311
/**
312312
* Returns the first instance of a particular child XML element.
313-
*
313+
*
314314
* @param ce the IConfigurationElement parent
315315
* @param element the name of the element to fetch
316316
* @return the element's IConfigurationElement, or null if not found
@@ -322,7 +322,7 @@ private static IConfigurationElement getItemElement(IConfigurationElement ce, St
322322

323323
/**
324324
* Returns the value of an XML attribute for an item.
325-
*
325+
*
326326
* @param ce the IConfigurationElement describing the item
327327
* @param attribute the attribute to fetch
328328
* @param defaultValue the value to return if the attribute is not found
@@ -335,7 +335,7 @@ private static String getItemAttribute(IConfigurationElement ce, String attribut
335335

336336
/**
337337
* Returns the description string given the IConfigurationElement for an item.
338-
*
338+
*
339339
* @param ce the IConfigurationElement describing the item
340340
* @return a newline-delimited string that describes this item, or null if none
341341
*/
@@ -346,7 +346,7 @@ private static String getItemDescription(IConfigurationElement ce) {
346346

347347
/**
348348
* Returns the name of an item.
349-
*
349+
*
350350
* @param ce the IConfigurationElement describing the item
351351
* @return the attribute value
352352
*/
@@ -358,7 +358,7 @@ private static String getItemName(IConfigurationElement ce) {
358358

359359
/**
360360
* Returns the icon for an item.
361-
*
361+
*
362362
* @param ce the IConfigurationElement describing the item
363363
* @return an icon
364364
*/
@@ -392,7 +392,7 @@ private static Image getImageFromPlugin(Bundle bundle, String iconPath) {
392392
URL installUrl = bundle.getEntry("/");
393393
URL url = new URL(installUrl, iconPath);
394394
is = url.openConnection().getInputStream();
395-
ImageData source = new ImageData(is);
395+
ImageData source = ImageData.load(is);
396396
ImageData mask = source.getTransparencyMask();
397397
Image image = new Image(null, source, mask);
398398
return image;

examples/org.eclipse.swt.examples.ole.win32/src/org/eclipse/swt/examples/ole/win32/OlePlugin.java

+16-10
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,22 @@
1414
package org.eclipse.swt.examples.ole.win32;
1515

1616

17-
import java.io.*;
18-
import java.net.*;
19-
import java.text.*;
20-
import java.util.*;
17+
import java.io.InputStream;
18+
import java.net.URL;
19+
import java.text.MessageFormat;
20+
import java.util.MissingResourceException;
21+
import java.util.ResourceBundle;
2122

22-
import org.eclipse.core.runtime.*;
23-
import org.eclipse.swt.*;
24-
import org.eclipse.swt.graphics.*;
25-
import org.eclipse.ui.plugin.*;
26-
import org.osgi.framework.*;
23+
import org.eclipse.core.runtime.IStatus;
24+
import org.eclipse.core.runtime.Platform;
25+
import org.eclipse.core.runtime.Status;
26+
import org.eclipse.swt.SWT;
27+
import org.eclipse.swt.graphics.Font;
28+
import org.eclipse.swt.graphics.Image;
29+
import org.eclipse.swt.graphics.ImageData;
30+
import org.eclipse.ui.plugin.AbstractUIPlugin;
31+
import org.osgi.framework.Bundle;
32+
import org.osgi.framework.BundleContext;
2733

2834
/**
2935
* The main plugin class to be used in the desktop.
@@ -174,7 +180,7 @@ public static void freeResources() {
174180
private static Image getImageFromPlugin(Bundle bundle, String iconPath) {
175181
URL installUrl = bundle.getEntry("/");
176182
try (InputStream is = new URL(installUrl, iconPath).openConnection().getInputStream()) {
177-
ImageData source = new ImageData(is);
183+
ImageData source = ImageData.load(is);
178184
ImageData mask = source.getTransparencyMask();
179185
Image image = new Image(null, source, mask);
180186
return image;

examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/browserexample/BrowserExample.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ void initResources() {
324324
images = new Image[imageLocations.length];
325325
for (int i = 0; i < imageLocations.length; ++i) {
326326
try (InputStream sourceStream = clazz.getResourceAsStream(imageLocations[i])) {
327-
ImageData source = new ImageData(sourceStream);
327+
ImageData source = ImageData.load(sourceStream);
328328
ImageData mask = source.getTransparencyMask();
329329
images[i] = new Image(null, source, mask);
330330
}

examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/ControlExample.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ void initResources() {
204204

205205
for (int i = 0; i < imageLocations.length; ++i) {
206206
try (InputStream sourceStream = clazz.getResourceAsStream(imageLocations[i])) {
207-
ImageData source = new ImageData(sourceStream);
207+
ImageData source = ImageData.load(sourceStream);
208208
if (imageTypes[i] == SWT.ICON) {
209209
ImageData mask = source.getTransparencyMask();
210210
images[i] = new Image(null, source, mask);

examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/controlexample/StyledTextTab.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ class StyledTextTab extends ScrollableTab {
7575
Image createBitmapImage(Display display, String name) {
7676
try (InputStream sourceStream = ControlExample.class.getResourceAsStream(name + ".bmp");
7777
InputStream maskStream = ControlExample.class.getResourceAsStream(name + "_mask.bmp")) {
78-
ImageData source = new ImageData(sourceStream);
79-
ImageData mask = new ImageData(maskStream);
78+
ImageData source = ImageData.load(sourceStream);
79+
ImageData mask = ImageData.load(maskStream);
8080
Image result = new Image(display, source, mask);
8181
return result;
8282
} catch (IOException e) {

examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/fileviewer/IconCache.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void freeResources() {
130130
*/
131131
private Image createStockImage(Display display, String path) {
132132
try (InputStream stream = IconCache.class.getResourceAsStream (path)) {
133-
ImageData imageData = new ImageData (stream);
133+
ImageData imageData = ImageData.load(stream);
134134
ImageData mask = imageData.getTransparencyMask ();
135135
Image result = new Image (display, imageData, mask);
136136
return result;

examples/org.eclipse.swt.examples/src/org/eclipse/swt/examples/hoverhelp/HoverHelp.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public Shell open(Display display) {
8888

8989
for (int i = 0; i < imageLocations.length; ++i) {
9090
try (InputStream stream = clazz.getResourceAsStream(imageLocations[i])) {
91-
ImageData source = new ImageData(stream);
91+
ImageData source = ImageData.load(stream);
9292
ImageData mask = source.getTransparencyMask();
9393
images[i] = new Image(display, source, mask);
9494
} catch (IOException e) {

0 commit comments

Comments
 (0)