Skip to content

Use the shared color blend helper from SWT #4486

Open

Description

@vogella

Blending two RGB values by a ratio is implemented over a dozen times in platform.ui, each with its own parameter type and rounding.
Following the discussion in #4489, SWT now provides the shared helper: RGB.blend(RGB other, double weight) and RGBA.blend(RGBA other, double weight) (eclipse-platform/eclipse.platform.swt#3732, @since 3.136).
The weight is the share of other, from 0 (the receiver) to 1 (other), and channels are rounded to the nearest integer.

Work to do in platform.ui, once SWT 3.136 is in the target platform:

  • Raise the org.eclipse.swt lower bound to 3.136 in each touched bundle's MANIFEST.MF.
  • Replace the private copies with RGB.blend:
Bundle Copy Replacement
jface PopupDialog.blend(bg, fg, factor) bg.blend(fg, factor)
jface.databinding SWTUtil.mix(rgb1, rgb2, ratio) rgb2.blend(rgb1, ratio)
jface.text Colors.blend(bg, fg, factor), projection SourceViewerInformationControl.blend bg.blend(fg, factor)
jface.text OverviewRuler.interpolate(fg, bg, scale), DiffPainter.interpolate fg.blend(bg, scale)
ui.editors SourceViewerInformationControl.blend(bg, fg, factor) bg.blend(fg, factor)
ui.workbench ShowViewDialog.blend(c1, c2, ratio) c2.blend(c1, ratio / 100.0)
ui.workbench HeapStatus.blend(fg, bg) (40% foreground) bg.getRGB().blend(fg.getRGB(), 0.4)
e4 renderers CTabRendering.blend(c1, c2, ratio) c2.blend(c1, ratio / 100.0)
  • Keep the public API and let it delegate: FormColors.blend(c1, c2, ratio) and ColorUtil.blend(c1, c2, ratio) become c2.blend(c1, ratio / 100.0), and ColorUtil.blend(val1, val2) becomes val1.blend(val2, 0.5).

The copies truncate while RGB.blend rounds, so a migrated color can differ by one per channel.
Tests that compare exact RGB values need adjusting rather than a rounding shim.

Copies in other repositories (Compare in eclipse.platform, JDT UI, PDE, GEF Classic's FigureUtilities) can follow the same way.

Activity

  1. ptziegler commented on Oct 13, 2026

    @ptziegler
    Contributor

    Not just the Platform uses such a helper method . Having a "central" blend function would be very much appreciated. I'm not sure if JFaceColors is the best place to put it, because it doesn't really fit the description:

    JFaceColors is the class that stores references to all of the colors used by JFace.

    But I also don't see a better place to put it.

  2. laeubi commented on Oct 14, 2026

    @laeubi
    Contributor

    2. But I also don't see a better place to put it.

    See my comment here I think it makes much sense to add this to SWT directly instead especially as your claim

    Not just the Platform uses such a helper method

  3. vogella commented on Oct 14, 2026

    @vogella
    ContributorAuthor
  4. changed the title [-]Provide a shared color blend helper in JFace[/-] [+]Use the shared color blend helper from SWT[/+] on Oct 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions