diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ColorsAndFontsPreferencePage.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ColorsAndFontsPreferencePage.java index ce48e8432231..dbc41e8bfd1a 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ColorsAndFontsPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/themes/ColorsAndFontsPreferencePage.java @@ -63,6 +63,7 @@ import org.eclipse.swt.graphics.FontMetrics; import org.eclipse.swt.graphics.GC; import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.ImageGcDrawer; import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.layout.FillLayout; @@ -333,10 +334,6 @@ private class PresentationLabelProvider extends LabelProvider implements IFontPr private final HashMap images = new HashMap<>(); - private int imageSize = -1; - - private int usableImageSize = -1; - private static final int REFRESH_INTERVAL_IN_MS = 300; private final Runnable updateControlsAndRefreshTreeRunnable = () -> { @@ -440,25 +437,20 @@ public Image getImage(Object element) { c = display.getSystemColor(SWT.COLOR_WHITE); foregroundColor = display.getSystemColor(DEFINITION_NOT_AVAIL_COLOR); } + final Color gcBackgroundcolor = c; + final Color gcForegroundColor = foregroundColor; Image image = images.get(c); if (image == null) { - ensureImageSize(); - image = new Image(display, imageSize, imageSize); - - GC gc = new GC(image); - gc.setBackground(tree.getViewer().getControl().getBackground()); - gc.setForeground(tree.getViewer().getControl().getBackground()); - gc.drawRectangle(0, 0, imageSize - 1, imageSize - 1); - - gc.setForeground(foregroundColor); - gc.setBackground(c); - - int offset = (imageSize - usableImageSize) / 2; - gc.drawRectangle(offset, offset, usableImageSize - offset, usableImageSize - offset); - gc.fillRectangle(offset + 1, offset + 1, usableImageSize - offset - 1, - usableImageSize - offset - 1); - gc.dispose(); - + ImageGcDrawer imageGcDrawer = (gc, imageWidth, imageHeight) -> { + gc.setForeground(tree.getViewer().getControl().getBackground()); + gc.drawRectangle(0, 0, imageWidth - 1, imageHeight - 1); + + gc.setForeground(gcForegroundColor); + gc.setBackground(gcBackgroundcolor); + gc.fillRectangle(2, 2, 11, 11); + gc.drawRectangle(2, 2, 11, 11); + }; + image = new Image(display, imageGcDrawer, 16, 16); images.put(c, image); } return image; @@ -470,13 +462,6 @@ public Image getImage(Object element) { } } - private void ensureImageSize() { - if (imageSize == -1) { - imageSize = tree.getViewer().getTree().getItemHeight(); - usableImageSize = Math.max(1, imageSize - 4); - } - } - @Override public String getText(Object element) { if (element instanceof IHierarchalThemeElementDefinition themeElement) {