Skip to content

Commit

Permalink
scg.klighd: Added SCG dark theme
Browse files Browse the repository at this point in the history
  • Loading branch information
a-sr committed Oct 25, 2023
1 parent 5a0d196 commit 71063b4
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 184 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,31 @@
*/
package de.cau.cs.kieler.scg.klighd;

import java.util.HashMap;

import org.eclipse.emf.ecore.util.EcoreUtil;

import de.cau.cs.kieler.kicool.ui.synthesis.colors.AbstractColorStore;
import de.cau.cs.kieler.klighd.krendering.Colors;
import de.cau.cs.kieler.klighd.krendering.KColor;
import de.cau.cs.kieler.klighd.krendering.KRenderingFactory;
import de.cau.cs.kieler.klighd.krendering.ViewSynthesisShared;
import de.cau.cs.kieler.klighd.util.ColorPreferences;

/**
* The SCCharts colors.
* The SCG colors.
*
* @author als
* @kieler.design 2015-10-27 proposed
* @kieler.rating 2015-10-27 proposed yellow
*/
public class ColorStore {
@ViewSynthesisShared
public class ColorStore extends AbstractColorStore {

public enum Color {
SCCHARTSBLUE(205, 220, 243),
public enum Color implements IColor {
NODE_FOREGROUND(Colors.BLACK),
NODE_BACKGROUND(Colors.WHITE),
NODE_TEXT(Colors.BLACK),
NODE_SHADOW(Colors.BLACK),
NODE_REFERENCED_BACKGROUND_GRADIENT_1(0xfc, 0xf7, 0xfc),
NODE_REFERENCED_BACKGROUND_GRADIENT_2(0xe6, 0xcb, 0xf2),

THREAD_LABEL(Colors.BLACK),
THREAD_BACKGROUND(205, 220, 243),

COMMENT_FOREGROND(0xf0, 0xf0, 0x24),
COMMENT_FOREGROND_TRANSITION(0x00, 0x00, 0x00),
Expand All @@ -41,6 +47,7 @@ public enum Color {

USER_SCHEDULE_COLOR(0x28, 0x99, 0x7E),

CONTROLFLOW_EDGE(0, 0, 0),
DEPENDENCY_ABSWRITEREAD(0, 192, 0),
DEPENDENCY_RELWRITEREAD(0, 192, 192),
DEPENDENCY_ABSWRITERELWRITE(0, 0, 255),
Expand All @@ -55,15 +62,12 @@ public enum Color {
NODE_PRIORITY_COLOR(255, 30, 30),
OPT_PRIORITY_COLOR(30, 30, 255),
PASSIVE_REGION_COLOR(255, 101, 127),
STANDARD_CONTROLFLOWEDGE(0, 0, 0),
BASICBLOCKBORDER(248, 0, 253),
SCHEDULINGBLOCKBORDER(128, 0, 243),
SCHEDULEBORDER(0, 0, 128),
BASICBLOCK_BORDER(248, 0, 253),
SCHEDULINGBLOCK_BORDER(128, 0, 243),
SCHEDULE_BORDER(0, 0, 128),
SCHEDULING_DEADCODE(128, 128, 128),
SCHEDULING_SCHEDULINGEDGE(128, 0, 253),
PROBLEM_COLOR(255, 0, 0),

KEYWORD(115, 0, 65);
SCHEDULING_SCHEDULING_EDGE(128, 0, 253),
PROBLEM_COLOR(255, 0, 0);

/** the default color */
private final KColor defaultColor = KRenderingFactory.eINSTANCE.createKColor();
Expand Down Expand Up @@ -97,64 +101,38 @@ private Color(final Colors color) {
/**
* @return the default color
*/
private KColor getDefaultColor() {
public KColor getDefaultColor() {
return defaultColor;
}
};

private final static KRenderingFactory FACTORY = KRenderingFactory.eINSTANCE;
/** the configuration */
private HashMap<Color, KColor> configuration = new HashMap<ColorStore.Color, KColor>();
@Override
public void configureOwnColors(final ColorPreferences preferences) {
var fg = preferences.getForeground();
var bg = preferences.getBackground();

// check if it can be considered dark mode
var bgHSB = java.awt.Color.RGBtoHSB(bg.getRed(), bg.getGreen(), bg.getBlue(), null);
boolean dark = bgHSB[2] < 0.6f;

/**
* Configures the given color with RGB values.
*
* @param color
* the color to configure
* @param red
* the red component of the desired color in range of 0 to 255
* @param green
* the green component of the desired color in range of 0 to 255
* @param blue
* the blue component of the desired color in range of 0 to 255
*/
public void configureColor(final Color color, final int red, final int green, final int blue) {
KColor kColor = FACTORY.createKColor();
kColor.setRed(red);
kColor.setGreen(green);
kColor.setBlue(blue);
configuration.put(color, kColor);
}
configureColor(Color.NODE_FOREGROUND, fg);
configureColor(Color.NODE_BACKGROUND, bg);
configureColor(Color.NODE_TEXT, fg);
configureColor(Color.CONTROLFLOW_EDGE, fg);
if (dark) {
configureColor(Color.NODE_SHADOW, Colors.LIGHT_GRAY);
configureColor(Color.NODE_REFERENCED_BACKGROUND_GRADIENT_1, 103, 74, 115);
configureColor(Color.NODE_REFERENCED_BACKGROUND_GRADIENT_2, 125, 98, 125);

/**
* Configures the given color with a {@link Colors} color.
*
* @param color
* the color to configure
* @param color
* the {@link Colors} color
*/
public void configureColor(final Color color, final Colors cColor) {
KColor kColor = FACTORY.createKColor();
kColor.setColor(cColor);
configuration.put(color, kColor);
}
configureColor(Color.THREAD_LABEL, fg);
configureColor(Color.THREAD_BACKGROUND, 98, 103, 125);

/**
* @param color
* the color
* @return a new {@link KColor} for the given color respecting all configurations.
*/
public KColor getColor(Color color) {
if (configuration.containsKey(color)) {
return EcoreUtil.copy(configuration.get(color));
} else if (color != null) {
return EcoreUtil.copy(color.getDefaultColor());
configureColor(Color.COMMENT_FOREGROND, Colors.ANTIQUE_WHITE_3);
configureColor(Color.COMMENT_FOREGROND_TRANSITION, Colors.ANTIQUE_WHITE_3);
configureColor(Color.COMMENT_BACKGROUND_GRADIENT_1, Colors.ANTIQUE_WHITE_4);
configureColor(Color.COMMENT_BACKGROUND_GRADIENT_2, Colors.ANTIQUE_WHITE_4);
configureColor(Color.COMMENT_TEXT, fg);
configureColor(Color.COMMENT_EDGE, Colors.ANTIQUE_WHITE_3);
}
return null;
}

public KColor getColor2(Color color) {
return this.getColor(color);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ class SCGraphComponentSynthesis {
// Straightforward rectangle drawing
val figure = node.addRoundedRectangle(SCGraphSynthesisHelper.CORNERRADIUS, SCGraphSynthesisHelper.CORNERRADIUS,
SCGraphSynthesisHelper.LINEWIDTH)
figure.addText("").setSurroundingSpace(6, 0, 2, 0)
figure.addText("") => [
it.setSurroundingSpace(6, 0, 2, 0)
it.foreground = NODE_TEXT.color
]
var isSCGRef = false
if (assignment.expression instanceof ReferenceCall) {
val call = assignment.expression as ReferenceCall
Expand All @@ -97,12 +100,11 @@ class SCGraphComponentSynthesis {
isSCGRef = decl.reference instanceof SCGraph
}
}

node.initialiseFigure(assignment)
if (isSCGRef) {
figure.setBackgroundGradient("#fcf7fc".color, "#e6cbf2".color, 90.0f)
} else {
figure.background = "white".color;
figure.setBackgroundGradient(NODE_REFERENCED_BACKGROUND_GRADIENT_1.color, NODE_REFERENCED_BACKGROUND_GRADIENT_2.color, 90.0f)
}
node.initialiseFigure(assignment)

// Add ports for control-flow and dependency routing.
if (isGuardSCG) {
Expand Down Expand Up @@ -148,10 +150,12 @@ class SCGraphComponentSynthesis {
}
} else {
if (assignment.hasAnnotation(SCGAnnotations.ANNOTATION_HEADNODE)) {
var sbHeadNodeName = assignment.getStringAnnotationValue(SCGAnnotations.ANNOTATION_HEADNODE)
sbHeadNodeName.createLabel(node).associateWith(assignment).
configureOutsideTopLeftNodeLabel(sbHeadNodeName, 9, KlighdConstants::DEFAULT_FONT_NAME).
KRendering.foreground = "black".color
val sbHeadNodeName = assignment.getStringAnnotationValue(SCGAnnotations.ANNOTATION_HEADNODE)
sbHeadNodeName.createLabel(node) => [
it.associateWith(assignment)
it.configureOutsideTopLeftNodeLabel(sbHeadNodeName, 9, KlighdConstants::DEFAULT_FONT_NAME)
it.KRendering.foreground = NODE_TEXT.color
]
}
}

Expand Down Expand Up @@ -343,8 +347,11 @@ class SCGraphComponentSynthesis {
if (ALIGN_ENTRYEXIT_NODES.booleanValue)
node.addLayoutParam(LayeredOptions::LAYERING_LAYER_CONSTRAINT, LayerConstraint::FIRST)
// Draw an ellipse figure for exit nodes...
val figure = node.addEllipse().background = "white".color;
figure.addText("").setAreaPlacementData.from(LEFT, 0, 0, TOP, 0, 0).to(RIGHT, 0, 0, BOTTOM, 1, 0)
val figure = node.addEllipse()
figure.addText("") => [
it.setAreaPlacementData.from(LEFT, 0, 0, TOP, 0, 0).to(RIGHT, 0, 0, BOTTOM, 1, 0)
it.foreground = NODE_TEXT.color
]
val text = if(entry.hasAnnotation("label")) entry.getStringAnnotationValue("label") else "entry"
node.initialiseFigure(SHOW_CAPTION.booleanValue ? text : "")
if (scg.method) {
Expand Down Expand Up @@ -414,8 +421,11 @@ class SCGraphComponentSynthesis {
if (ALIGN_ENTRYEXIT_NODES.booleanValue)
node.addLayoutParam(LayeredOptions::LAYERING_LAYER_CONSTRAINT, LayerConstraint::LAST)
// Draw an ellipse for an exit node...
val figure = node.addEllipse().background = "white".color;
figure.addText("").setAreaPlacementData.from(LEFT, 0, 0, TOP, 0, 0).to(RIGHT, 0, 0, BOTTOM, 1, 0)
val figure = node.addEllipse()
figure.addText("") => [
it.setAreaPlacementData.from(LEFT, 0, 0, TOP, 0, 0).to(RIGHT, 0, 0, BOTTOM, 1, 0)
it.foreground = NODE_TEXT.color
]
node.initialiseFigure(SHOW_CAPTION.booleanValue ? "exit" : "")

if (exit.final) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ class SCGraphDiagramSynthesis extends AbstractDiagramSynthesis<SCGraph> {
@Inject extension KPortExtensions
@Inject extension KContainerRenderingExtensions
@Inject extension KPolylineExtensions
@Inject extension KColorExtensions
@Inject extension AnnotationsExtensions
@Inject extension SCGCoreExtensions
@Inject extension SCGControlFlowExtensions
Expand Down Expand Up @@ -250,6 +249,9 @@ class SCGraphDiagramSynthesis extends AbstractDiagramSynthesis<SCGraph> {
scc = prioAuxData.stronglyConnectedComponents
}
}

// Apply color theme
configureAllColors(usedContext)

// Invoke the synthesis.
SCGraph = model
Expand Down Expand Up @@ -498,12 +500,13 @@ class SCGraphDiagramSynthesis extends AbstractDiagramSynthesis<SCGraph> {

aNode.setMinimalNodeSize(16, 16)
aNode.addRoundedRectangle(1, 1, 1) => [
setBackgroundGradient(COMMENT_BACKGROUND_GRADIENT_1.color2, COMMENT_BACKGROUND_GRADIENT_2.color2, 90);
foreground = COMMENT_FOREGROND.color2;
setBackgroundGradient(COMMENT_BACKGROUND_GRADIENT_1.color, COMMENT_BACKGROUND_GRADIENT_2.color, 90);
foreground = COMMENT_FOREGROND.color;
]
aNode.getKContainerRendering.addText(commentText) => [
fontSize = 8;
setGridPlacementData().from(LEFT, 4, 0, TOP, 4, 0).to(RIGHT, 4, 0, BOTTOM, 4, 0);
foreground = COMMENT_TEXT.color;
]

val edge = createEdge()
Expand Down Expand Up @@ -599,12 +602,14 @@ class SCGraphDiagramSynthesis extends AbstractDiagramSynthesis<SCGraph> {
edge.addRoundedBendsPolyline(8, CONTROLFLOW_THICKNESS.floatValue) => [
it.lineStyle = LineStyle::SOLID
it.addHeadArrowDecorator
it.foreground = STANDARD_CONTROLFLOWEDGE.color
it.foreground = CONTROLFLOW_EDGE.color
it.foreground.propagateToChildren = true
]
// If the outgoing identifier indicates a 'then branch', add a 'then label'.
if (outgoingPortId == SCGraphSynthesisHelper.SCGPORTID_OUTGOING_THEN) {
edge.createLabel.configureTailEdgeLabel('true', 9, KlighdConstants::DEFAULT_FONT_NAME)
edge.createLabel.configureTailEdgeLabel('true', 9, KlighdConstants::DEFAULT_FONT_NAME) => [
it.KRendering.foreground = NODE_TEXT.color
]
}

if (controlFlow.targetNode.schizophrenic) {
Expand All @@ -626,12 +631,14 @@ class SCGraphDiagramSynthesis extends AbstractDiagramSynthesis<SCGraph> {
it.setPortSize(50, 20)
it.KContainerRendering.setProperty(PRIO_STATEMENTS_PROPERTY, true)
var rec = it.KContainerRendering.addRoundedRectangle(SCGraphSynthesisHelper.CORNERRADIUS,
SCGraphSynthesisHelper.CORNERRADIUS, SCGraphSynthesisHelper.LINEWIDTH)
rec.background = "white".color
var txt = rec.addText("prio(" + tgtPrio.value + ")")
txt.fontSize = 7
var x = txt.setAreaPlacementData
x.from(LEFT, 0, 0, TOP, 0, 0).to(RIGHT, 1, 0, BOTTOM, 1, 0)
SCGraphSynthesisHelper.CORNERRADIUS, SCGraphSynthesisHelper.LINEWIDTH) => [
background = NODE_BACKGROUND.color
]
rec.addText("prio(" + tgtPrio.value + ")") => [
fontSize = 7
foreground = NODE_TEXT.color
setAreaPlacementData.from(LEFT, 0, 0, TOP, 0, 0).to(RIGHT, 1, 0, BOTTOM, 1, 0)
]
]
}
}
Expand Down Expand Up @@ -791,7 +798,7 @@ class SCGraphDiagramSynthesis extends AbstractDiagramSynthesis<SCGraph> {

if (!nonScheduleDependencies.empty) {
nonScheduleDependencies.forEach [
colorDependency(SCHEDULING_SCHEDULINGEDGE.color)
colorDependency(SCHEDULING_SCHEDULING_EDGE.color)
thickenDependency(CONTROLFLOW_SCHEDULINGEDGE_WIDTH)
dependencyAlpha(SCHEDULING_SCHEDULINGEDGE_ALPHA)
]
Expand All @@ -800,7 +807,7 @@ class SCGraphDiagramSynthesis extends AbstractDiagramSynthesis<SCGraph> {
it.source = sourceKNode
it.target = targetKNode
it.addRoundedBendsPolyline(8, CONTROLFLOW_SCHEDULINGEDGE_WIDTH) => [
it.foreground = SCHEDULING_SCHEDULINGEDGE.color
it.foreground = SCHEDULING_SCHEDULING_EDGE.color
it.foreground.alpha = SCHEDULING_SCHEDULINGEDGE_ALPHA
it.addHeadArrowDecorator
]
Expand Down
Loading

0 comments on commit 71063b4

Please sign in to comment.