Skip to content

Update Color constructors to use Device-less versions#2622

Merged
vogella merged 1 commit intoeclipse-platform:masterfrom
vogella:fix-color-constructors
Apr 15, 2026
Merged

Update Color constructors to use Device-less versions#2622
vogella merged 1 commit intoeclipse-platform:masterfrom
vogella:fix-color-constructors

Conversation

@vogella
Copy link
Copy Markdown
Contributor

@vogella vogella commented Apr 14, 2026

Updated all Color constructors in the repo which used the outdated constructor taking a Device/Display argument, as they are now deprecated in SWT. Removed unused Display/Device imports and parameters where applicable.

See: eclipse-platform/eclipse.platform.swt#3232

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 14, 2026

Test Results

    54 files  ±0      54 suites  ±0   37m 13s ⏱️ + 1m 20s
 4 558 tests ±0   4 535 ✅ ±0   23 💤 ±0  0 ❌ ±0 
12 270 runs  ±0  12 111 ✅ ±0  159 💤 ±0  0 ❌ ±0 

Results for commit aca5ce4. ± Comparison against base commit aa3bfa8.

♻️ This comment has been updated with latest results.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates SWT Color allocations across multiple UI bundles/examples/tests to use the newer device-less constructors, aligning the codebase with SWT’s deprecation of Color(Device/Display, …) constructors (per eclipse.platform.swt#3232).

Changes:

  • Replaced new Color(display/device, …) and new Color(null, …) with device-less new Color(RGB) / new Color(r,g,b) patterns.
  • Updated helper methods to remove now-unneeded Display parameters and removed related imports/usages.
  • Adjusted internal color cache helpers to use the new constructor signatures.

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
ua/org.eclipse.ui.intro/src/org/eclipse/ui/internal/intro/impl/presentations/IntroLaunchBar.java Drop Display dependency for Color creation in launch bar styling.
ua/org.eclipse.ui.cheatsheets/src/org/eclipse/ui/internal/cheatsheets/views/CheatSheetPage.java Convert page color computations to device-less Color constructors.
team/examples/org.eclipse.compare.examples.xml/src/org/eclipse/compare/examples/xml/ui/MessageLine.java Update lazy error color allocation to device-less constructor.
team/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java Update internal RGB→Color caching helper and call sites to device-less constructors.
debug/org.eclipse.unittest.ui/src/org/eclipse/unittest/internal/ui/UnitTestProgressBar.java Replace per-widget colors with device-less constructors.
debug/org.eclipse.ui.console/src/org/eclipse/ui/internal/console/ansi/utils/ColorCache.java Update static color cache to device-less constructor.
debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/TreeModelLabelProvider.java Update label-provider RGB→Color cache to device-less constructor.
debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/breadcrumb/BreadcrumbItemDropDown.java Update blended color allocation to device-less constructor.
debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/AsynchronousViewer.java Update viewer RGB→Color cache to device-less constructor.
debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/ColorManager.java Remove Display usage and allocate cached colors via device-less constructor.
debug/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/TextConsoleViewerTest.java Update test colors to device-less constructors.
debug/org.eclipse.debug.examples.ui/src/org/eclipse/debug/examples/ui/pda/DebugUIPlugin.java Update plugin color cache to device-less constructor and remove Display import.
ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/MessageLine.java Update error background color allocation to device-less constructor.
ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/preferences/AntPreviewerUpdater.java Remove Display parameter from color creation helper and use device-less constructor.
ant/org.eclipse.ant.ui/Ant Tools Support/org/eclipse/ant/internal/ui/ColorManager.java Update synchronized color allocation to device-less constructor and remove Display import.
Comments suppressed due to low confidence (1)

debug/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/viewers/model/TreeModelLabelProvider.java:205

  • getColor() allocates SWT Color instances, but dispose() clears fColorCache without disposing its values (images/fonts are disposed). Please dispose cached colors on dispose to avoid SWT resource leaks.
	public Color getColor(RGB rgb) {
		if (rgb == null) {
			return null;
		}
		Color color = fColorCache.get(rgb);
		if (color == null) {
			color = new Color(rgb);
			fColorCache.put(rgb, color);
		}
		return color;
	}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 162 to +184
@@ -175,26 +175,26 @@ private void computeColors(Display display) {
} else if (FormColors.testTwoPrimaryColors(rgb, 240, 256)) {
rgb = FormColors.blend(rgb, black, 30);
}
introColor = new Color(display, rgb);
inactiveColor2 = new Color(display, rgb);
introColor = new Color(rgb);
inactiveColor2 = new Color(rgb);
}
rgb = inactiveColor2.getRGB();
rgb = FormColors.blend(rgb, backgroundColor.getRGB(), 40);
inactiveColor1 = new Color(display, rgb);
activeColor = new Color(display, backgroundColor.getRGB());
inactiveColor1 = new Color(rgb);
activeColor = new Color(backgroundColor.getRGB());
Copy link
Copy Markdown
Contributor Author

@vogella vogella Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Device-less Color instances (created without a Device/Display argument) are plain Java objects backed by RGBA values and do not hold native OS handles. Explicit disposal is therefore not required. See the SWT deprecation of device-based constructors: eclipse-platform/eclipse.platform.swt#3232

Comment on lines 362 to 370
protected Color getColor(RGB rgb) {
if (rgb == null) {
return null;
}
Color color = fColorCache.get(rgb);
if (color == null) {
color = new Color(getControl().getDisplay(), rgb);
color = new Color(rgb);
fColorCache.put(rgb, color);
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Device-less Color instances (created without a Device/Display argument) are plain Java objects backed by RGBA values and do not hold native OS handles. Explicit disposal is therefore not required. See the SWT deprecation of device-based constructors: eclipse-platform/eclipse.platform.swt#3232

Comment on lines 155 to 159
}

if (rgb != null) {
return new Color(display, rgb);
return new Color(rgb);
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Device-less Color instances (created without a Device/Display argument) are plain Java objects backed by RGBA values and do not hold native OS handles. Explicit disposal is therefore not required. See the SWT deprecation of device-based constructors: eclipse-platform/eclipse.platform.swt#3232

Comment on lines 75 to 78
if (fErrorMsgAreaBackground == null) {
fErrorMsgAreaBackground = new Color(getDisplay(), ERROR_BACKGROUND_RGB);
fErrorMsgAreaBackground = new Color(ERROR_BACKGROUND_RGB);
}
setBackground(fErrorMsgAreaBackground);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Device-less Color instances (created without a Device/Display argument) are plain Java objects backed by RGBA values and do not hold native OS handles. Explicit disposal is therefore not required. See the SWT deprecation of device-based constructors: eclipse-platform/eclipse.platform.swt#3232

Comment on lines 190 to +197
// Create new colors, they will get disposed
RGB rgb = background.getRGB();
activeColor = new Color(display, rgb );
activeColor = new Color(rgb);
rgb = FormColors.blend(rgb, white, 85);
inactiveColor1 = new Color(display, rgb);
inactiveColor1 = new Color(rgb);
rgb = FormColors.blend(rgb, white, 85);
inactiveColor2 = new Color(display, rgb );
introColor = new Color(display, rgb );
inactiveColor2 = new Color(rgb);
introColor = new Color(rgb);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Device-less Color instances (created without a Device/Display argument) are plain Java objects backed by RGBA values and do not hold native OS handles. Explicit disposal is therefore not required. See the SWT deprecation of device-based constructors: eclipse-platform/eclipse.platform.swt#3232

Comment on lines 4816 to 4820
Color c= fColors.get(rgb);
if (c == null) {
c= new Color(display, rgb);
c= new Color(rgb);
fColors.put(rgb, c);
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Device-less Color instances (created without a Device/Display argument) are plain Java objects backed by RGBA values and do not hold native OS handles. Explicit disposal is therefore not required. See the SWT deprecation of device-based constructors: eclipse-platform/eclipse.platform.swt#3232

Comment on lines +62 to 64
fStoppedColor = new Color(120, 120, 120);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Device-less Color instances (created without a Device/Display argument) are plain Java objects backed by RGBA values and do not hold native OS handles. Explicit disposal is therefore not required. See the SWT deprecation of device-based constructors: eclipse-platform/eclipse.platform.swt#3232

public static Color get(RGB rgb) {
return CACHE.computeIfAbsent(rgb, color -> new Color(null, color));
return CACHE.computeIfAbsent(rgb, color -> new Color(color));
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Device-less Color instances (created without a Device/Display argument) are plain Java objects backed by RGBA values and do not hold native OS handles. Explicit disposal is therefore not required. See the SWT deprecation of device-based constructors: eclipse-platform/eclipse.platform.swt#3232

Comment on lines 116 to 119
if (fErrorColor == null) {
fErrorColor= new Color(getDisplay(), fErrorRGB);
fErrorColor= new Color(fErrorRGB);
}
setForeground(fErrorColor);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Device-less Color instances (created without a Device/Display argument) are plain Java objects backed by RGBA values and do not hold native OS handles. Explicit disposal is therefore not required. See the SWT deprecation of device-based constructors: eclipse-platform/eclipse.platform.swt#3232

Comment on lines 334 to 336
if (r != null) {
bg = new Color(display, r);
bg = new Color(r);
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Device-less Color instances (created without a Device/Display argument) are plain Java objects backed by RGBA values and do not hold native OS handles. Explicit disposal is therefore not required. See the SWT deprecation of device-based constructors: eclipse-platform/eclipse.platform.swt#3232

@vogella vogella marked this pull request as ready for review April 15, 2026 07:00
Updated all Color constructors in the repo which used the outdated
constructor taking a Device/Display argument, as they are now
deprecated in SWT. Removed unused Display/Device imports and
parameters where applicable.

See: eclipse-platform/eclipse.platform.swt#3232
@vogella vogella force-pushed the fix-color-constructors branch from 3a4d2b7 to aca5ce4 Compare April 15, 2026 09:13
@vogella vogella merged commit 9b8c4e4 into eclipse-platform:master Apr 15, 2026
18 checks passed
@vogella vogella deleted the fix-color-constructors branch April 15, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants