1 package net.mograsim.logic.ui;
3 import java.util.function.Consumer;
4 import java.util.function.Supplier;
6 import org.eclipse.swt.graphics.Color;
7 import org.eclipse.swt.graphics.Device;
9 import net.haspamelodica.swt.helper.gcs.GeneralGC;
10 import net.mograsim.preferences.ColorDefinition;
11 import net.mograsim.preferences.ColorManager;
13 public class ColorHelper
15 public static void executeWithDifferentForeground(GeneralGC gc, ColorDefinition col, Runnable exec)
17 executeWithDifferentColor(gc.getDevice(), col, gc::getForeground, gc::setForeground, exec);
20 public static void executeWithDifferentBackground(GeneralGC gc, ColorDefinition col, Runnable exec)
22 executeWithDifferentColor(gc.getDevice(), col, gc::getBackground, gc::setBackground, exec);
25 private static void executeWithDifferentColor(Device device, ColorDefinition col, Supplier<Color> getColor, Consumer<Color> setColor,
28 ColorManager cm = ColorManager.current();
29 Color oldColor = getColor.get();
30 Color newColor = cm.toColor(device, col);
31 setColor.accept(newColor);
33 setColor.accept(oldColor);
39 throw new UnsupportedOperationException("No instances of ColorHelper");