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;
8 import net.haspamelodica.swt.helper.gcs.GeneralGC;
9 import net.mograsim.preferences.ColorDefinition;
10 import net.mograsim.preferences.ColorManager;
12 public class ColorHelper
14 public static void executeWithDifferentForeground(GeneralGC gc, ColorDefinition col, Runnable exec)
16 executeWithDifferentColor(col, gc::getForeground, gc::setForeground, exec);
19 public static void executeWithDifferentBackground(GeneralGC gc, ColorDefinition col, Runnable exec)
21 executeWithDifferentColor(col, gc::getBackground, gc::setBackground, exec);
24 private static void executeWithDifferentColor(ColorDefinition col, Supplier<Color> getColor, Consumer<Color> setColor, Runnable exec)
26 ColorManager cm = ColorManager.current();
27 Color oldColor = getColor.get();
28 Color newColor = cm.toColor(col);
29 setColor.accept(newColor);
31 setColor.accept(oldColor);
36 throw new UnsupportedOperationException("No instances of ColorHelper");