Update Color constructors to use Device-less versions#2622
Update Color constructors to use Device-less versions#2622vogella merged 1 commit intoeclipse-platform:masterfrom
Conversation
There was a problem hiding this comment.
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, …)andnew Color(null, …)with device-lessnew Color(RGB)/new Color(r,g,b)patterns. - Updated helper methods to remove now-unneeded
Displayparameters 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 SWTColorinstances, butdispose()clearsfColorCachewithout 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.
| @@ -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()); | |||
There was a problem hiding this comment.
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
| 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); | ||
| } |
There was a problem hiding this comment.
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
| } | ||
|
|
||
| if (rgb != null) { | ||
| return new Color(display, rgb); | ||
| return new Color(rgb); | ||
| } |
There was a problem hiding this comment.
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
| if (fErrorMsgAreaBackground == null) { | ||
| fErrorMsgAreaBackground = new Color(getDisplay(), ERROR_BACKGROUND_RGB); | ||
| fErrorMsgAreaBackground = new Color(ERROR_BACKGROUND_RGB); | ||
| } | ||
| setBackground(fErrorMsgAreaBackground); |
There was a problem hiding this comment.
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
| // 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); |
There was a problem hiding this comment.
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
| Color c= fColors.get(rgb); | ||
| if (c == null) { | ||
| c= new Color(display, rgb); | ||
| c= new Color(rgb); | ||
| fColors.put(rgb, c); | ||
| } |
There was a problem hiding this comment.
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
| fStoppedColor = new Color(120, 120, 120); | ||
| } | ||
|
|
There was a problem hiding this comment.
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)); | ||
| } |
There was a problem hiding this comment.
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
| if (fErrorColor == null) { | ||
| fErrorColor= new Color(getDisplay(), fErrorRGB); | ||
| fErrorColor= new Color(fErrorRGB); | ||
| } | ||
| setForeground(fErrorColor); |
There was a problem hiding this comment.
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
| if (r != null) { | ||
| bg = new Color(display, r); | ||
| bg = new Color(r); | ||
| } |
There was a problem hiding this comment.
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
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
3a4d2b7 to
aca5ce4
Compare
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