|
1 | 1 | /*******************************************************************************
|
2 |
| - * Copyright (c) 2000, 2023 IBM Corporation and others. |
| 2 | + * Copyright (c) 2000, 2024 IBM Corporation and others. |
3 | 3 | *
|
4 | 4 | * This program and the accompanying materials
|
5 | 5 | * are made available under the terms of the Eclipse Public License 2.0
|
@@ -205,25 +205,47 @@ public static ImageDescriptor createFromURLSupplier(boolean useMissingImage, Sup
|
205 | 205 | }
|
206 | 206 |
|
207 | 207 | /**
|
208 |
| - * Convenient method to create an ImageDescriptor from an URI |
| 208 | + * Convenient method to create an ImageDescriptor from an URI. |
209 | 209 | *
|
210 |
| - * Delegates to ImageDescriptor createFromURL |
| 210 | + * Delegates to {@link ImageDescriptor#createFromURL(URL)}. <em>Important</em> |
| 211 | + * This method should only be used when it's guaranteed that the given |
| 212 | + * {@link URI} is also a valid {@link URL}, in order to avoid the |
| 213 | + * {@link MalformedURLException} thrown by {@link URI#toURL()}. |
| 214 | + * |
| 215 | + * If the URI is {@code null} or not a valid {@link URL}, then an image from |
| 216 | + * {@link #getMissingImageDescriptor()} will be returned. |
211 | 217 | *
|
212 | 218 | * @param uriIconPath The URI of the image file.
|
213 | 219 | * @return a new image descriptor
|
214 | 220 | *
|
215 |
| - * @since 3.19 |
| 221 | + * @since 3.36 |
216 | 222 | */
|
217 |
| - public ImageDescriptor imageDescriptorFromURI(URI uriIconPath) { |
| 223 | + public static ImageDescriptor createFromURI(URI uriIconPath) { |
218 | 224 | try {
|
219 |
| - return ImageDescriptor.createFromURL(new URL(uriIconPath.toString())); |
220 |
| - } catch (MalformedURLException | NullPointerException e) { |
| 225 | + return ImageDescriptor.createFromURL(uriIconPath != null ? uriIconPath.toURL() : null); |
| 226 | + } catch (MalformedURLException e) { |
221 | 227 | // return the missing image placeholder to indicate
|
222 | 228 | // the incorrect call without interfering with the user flow
|
223 | 229 | return getMissingImageDescriptor();
|
224 | 230 | }
|
225 | 231 | }
|
226 | 232 |
|
| 233 | + /** |
| 234 | + * Convenient method to create an ImageDescriptor from an URI |
| 235 | + * |
| 236 | + * Delegates to ImageDescriptor createFromURL |
| 237 | + * |
| 238 | + * @param uriIconPath The URI of the image file. |
| 239 | + * @return a new image descriptor |
| 240 | + * |
| 241 | + * @since 3.19 |
| 242 | + * @deprecated Use {@link #createFromURI(URI)} instead. |
| 243 | + */ |
| 244 | + @Deprecated(since = "3.36", forRemoval = true) |
| 245 | + public ImageDescriptor imageDescriptorFromURI(URI uriIconPath) { |
| 246 | + return createFromURI(uriIconPath); |
| 247 | + } |
| 248 | + |
227 | 249 | @Override
|
228 | 250 | public Object createResource(Device device) throws DeviceResourceException {
|
229 | 251 | Image result = createImage(false, device);
|
|
0 commit comments