Skip to content

Commit 13a45ab

Browse files
committed
Streamline ImageDescriptor implementations and avoid getImageData()
ImageDescriptor.getImageData() is deprecated and sub-classes are advised to stop re-implementing it and instead implement getImageData(int). The still existing implementations just replicate the default implementation and therefore can just be removed. Additionally the custom and internal 'ImageImageDescriptor' and '(Abstract)OverlayIcon' classes are replaced with implementations provided by standard JFace.
1 parent 30affe0 commit 13a45ab

File tree

6 files changed

+15
-244
lines changed

6 files changed

+15
-244
lines changed

ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/views/actions/EditorImageDescriptor.java

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2005 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
66
* which accompanies this distribution, and is available at
77
* https://www.eclipse.org/legal/epl-2.0/
88
*
99
* SPDX-License-Identifier: EPL-2.0
10-
*
10+
*
1111
* Contributors:
1212
* IBM Corporation - initial API and implementation
1313
*******************************************************************************/
1414
package org.eclipse.ant.internal.ui.views.actions;
1515

1616
import org.eclipse.jface.resource.ImageDescriptor;
17-
import org.eclipse.swt.graphics.Image;
1817
import org.eclipse.swt.graphics.ImageData;
1918
import org.eclipse.swt.program.Program;
2019
import org.eclipse.ui.ISharedImages;
@@ -36,11 +35,9 @@ public EditorImageDescriptor(Program program) {
3635

3736
@Override
3837
public boolean equals(Object o) {
39-
if (!(o instanceof EditorImageDescriptor)) {
38+
if (!(o instanceof EditorImageDescriptor other)) {
4039
return false;
4140
}
42-
EditorImageDescriptor other = (EditorImageDescriptor) o;
43-
4441
// See if there is a name - compare it if so and compare the programs if not
4542
String otherName = other.program.getName();
4643
if (otherName == null) {
@@ -49,22 +46,14 @@ public boolean equals(Object o) {
4946
return otherName.equals(program.getName());
5047
}
5148

52-
/**
53-
* Returns an SWT Image that is described by the information in this descriptor. Each call returns a new Image.
54-
*/
55-
public Image getImage() {
56-
return createImage();
57-
}
58-
5949
@Override
60-
public ImageData getImageData() {
61-
62-
ImageData defaultImage = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FILE).getImageData();
50+
public ImageData getImageData(int zoom) {
51+
ImageData defaultImage = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FILE).getImageData(zoom);
6352
if (defaultImage == null) {
6453
return null;
6554
}
6655
ImageData data = null;
67-
if (program == null || ((data = program.getImageData()) == null)) {
56+
if (program == null || ((data = program.getImageData(zoom)) == null)) {
6857
return defaultImage;
6958
}
7059

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/DebugElementHelper.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2013 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -76,12 +76,7 @@ public static ImageDescriptor getImageDescriptor(Object object, IDebugModelPrese
7676

7777
public static ImageDescriptor getImageDescriptor(Image image) {
7878
if (image != null) {
79-
ImageDescriptor descriptor = fgImages.get(image);
80-
if (descriptor == null) {
81-
descriptor = new ImageImageDescriptor(image);
82-
fgImages.put(image, descriptor);
83-
}
84-
return descriptor;
79+
return fgImages.computeIfAbsent(image, ImageDescriptor::createFromImage);
8580
}
8681
return null;
8782
}

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/ImageImageDescriptor.java

Lines changed: 0 additions & 48 deletions
This file was deleted.

ua/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/util/AbstractOverlayIcon.java

Lines changed: 0 additions & 122 deletions
This file was deleted.

ua/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/util/OverlayIcon.java

Lines changed: 0 additions & 42 deletions
This file was deleted.

ua/org.eclipse.help.ui/src/org/eclipse/help/ui/internal/views/AllTopicsPart.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2000, 2016 IBM Corporation and others.
2+
* Copyright (c) 2000, 2025 IBM Corporation and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -22,9 +22,10 @@
2222
import org.eclipse.help.internal.toc.Toc;
2323
import org.eclipse.help.ui.internal.HelpUIResources;
2424
import org.eclipse.help.ui.internal.IHelpUIConstants;
25-
import org.eclipse.help.ui.internal.util.OverlayIcon;
2625
import org.eclipse.jface.action.IToolBarManager;
2726
import org.eclipse.jface.resource.ImageDescriptor;
27+
import org.eclipse.jface.viewers.DecorationOverlayIcon;
28+
import org.eclipse.jface.viewers.IDecoration;
2829
import org.eclipse.jface.viewers.ITreeContentProvider;
2930
import org.eclipse.jface.viewers.ITreeViewerListener;
3031
import org.eclipse.jface.viewers.LabelProvider;
@@ -159,8 +160,8 @@ private boolean isNotEmpty(ITopic topic) {
159160
}
160161

161162
private boolean isNotEmpty(ITopic[] topics) {
162-
for (int i = 0; i < topics.length; i++) {
163-
if (isNotEmpty(topics[i]))
163+
for (ITopic topic : topics) {
164+
if (isNotEmpty(topic))
164165
return true;
165166
}
166167
return false;
@@ -205,8 +206,7 @@ private void initializeImages() {
205206
.getImageDescriptor(IHelpUIConstants.IMAGE_CONTAINER);
206207
ImageDescriptor ovr = HelpUIResources
207208
.getImageDescriptor(IHelpUIConstants.IMAGE_DOC_OVR);
208-
ImageDescriptor desc = new OverlayIcon(base,
209-
new ImageDescriptor[][] { { ovr } });
209+
ImageDescriptor desc = new DecorationOverlayIcon(base, ovr, IDecoration.TOP_RIGHT);
210210
containerWithTopicImage = desc.createImage();
211211
}
212212

@@ -239,8 +239,7 @@ protected String getHref(IHelpResource res) {
239239

240240
public void selectReveal(String href) {
241241
IToc[] tocs = HelpSystem.getTocs();
242-
for (int i = 0; i < tocs.length; i++) {
243-
IToc toc = tocs[i];
242+
for (IToc toc : tocs) {
244243
ITopic topic = toc.getTopic(href);
245244
if (topic != null) {
246245
selectReveal(topic);

0 commit comments

Comments
 (0)