X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.ui%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fui%2FColorHelper.java;h=0b65d2bec8ecf83891cd766bfd4cef246f0772d2;hb=574918bb58faa3c617911ed4f629f90066668364;hp=b631507294103cfa5318fce24a870c2629876458;hpb=07faf07e3acb8b2afdc2bf65a46bc868faaed0f8;p=Mograsim.git diff --git a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/ColorHelper.java b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/ColorHelper.java index b6315072..0b65d2be 100644 --- a/net.mograsim.logic.ui/src/net/mograsim/logic/ui/ColorHelper.java +++ b/net.mograsim.logic.ui/src/net/mograsim/logic/ui/ColorHelper.java @@ -3,84 +3,36 @@ package net.mograsim.logic.ui; import java.util.function.Consumer; import java.util.function.Supplier; -import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Device; import net.haspamelodica.swt.helper.gcs.GeneralGC; -import net.mograsim.logic.core.types.ColorDefinition; -import net.mograsim.logic.core.types.ColorDefinition.BuiltInColor; +import net.mograsim.preferences.ColorDefinition; +import net.mograsim.preferences.ColorManager; -//TODO replace with a proper ColorManager public class ColorHelper { public static void executeWithDifferentForeground(GeneralGC gc, ColorDefinition col, Runnable exec) { - executeWithDifferentColor(gc.getDevice(), col, gc::getForeground, gc::setForeground, exec); + executeWithDifferentColor(col, gc::getForeground, gc::setForeground, exec); } public static void executeWithDifferentBackground(GeneralGC gc, ColorDefinition col, Runnable exec) { - executeWithDifferentColor(gc.getDevice(), col, gc::getBackground, gc::setBackground, exec); + executeWithDifferentColor(col, gc::getBackground, gc::setBackground, exec); } - private static void executeWithDifferentColor(Device device, ColorDefinition col, Supplier getColor, Consumer setColor, - Runnable exec) + private static void executeWithDifferentColor(ColorDefinition col, Supplier getColor, Consumer setColor, Runnable exec) { - Color oldColor = getColor.get(); - boolean isNoSystemColor = col.builtInColor == null; - Color newColor; - if (isNoSystemColor) - newColor = new Color(device, col.r, col.g, col.b); + if (col == null) + exec.run(); else - newColor = device.getSystemColor(ColorHelper.toSWTColorConstant(col.builtInColor)); - setColor.accept(newColor); - - exec.run(); - - setColor.accept(oldColor); - if (isNoSystemColor) - newColor.dispose(); - } - - public static int toSWTColorConstant(BuiltInColor col) - { - switch (col) { - case COLOR_BLACK: - return SWT.COLOR_BLACK; - case COLOR_BLUE: - return SWT.COLOR_BLUE; - case COLOR_CYAN: - return SWT.COLOR_CYAN; - case COLOR_DARK_BLUE: - return SWT.COLOR_DARK_BLUE; - case COLOR_DARK_CYAN: - return SWT.COLOR_DARK_CYAN; - case COLOR_DARK_GRAY: - return SWT.COLOR_DARK_GRAY; - case COLOR_DARK_GREEN: - return SWT.COLOR_DARK_GREEN; - case COLOR_DARK_MAGENTA: - return SWT.COLOR_DARK_MAGENTA; - case COLOR_DARK_RED: - return SWT.COLOR_DARK_RED; - case COLOR_DARK_YELLOW: - return SWT.COLOR_DARK_YELLOW; - case COLOR_GRAY: - return SWT.COLOR_GRAY; - case COLOR_GREEN: - return SWT.COLOR_GREEN; - case COLOR_MAGENTA: - return SWT.COLOR_MAGENTA; - case COLOR_RED: - return SWT.COLOR_RED; - case COLOR_WHITE: - return SWT.COLOR_WHITE; - case COLOR_YELLOW: - return SWT.COLOR_YELLOW; - default: - throw new IllegalArgumentException("Unknown enum constant: " + col); + ColorManager cm = ColorManager.current(); + Color oldColor = getColor.get(); + Color newColor = cm.toColor(col); + setColor.accept(newColor); + exec.run(); + setColor.accept(oldColor); } }