Compare commits

...

1 Commits

Author SHA1 Message Date
Chao MENG
04e60a7dae chore: support dark theme 2022-09-15 16:32:33 +08:00

View File

@@ -12,6 +12,7 @@
// ============================================================================
package org.talend.designer.core.ui.editor;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.draw2d.ColorConstants;
import org.eclipse.draw2d.FreeformFigure;
import org.eclipse.draw2d.Graphics;
@@ -19,9 +20,9 @@ import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.editparts.GridLayer;
import org.eclipse.swt.graphics.Color;
import org.talend.commons.exception.ExceptionHandler;
import org.talend.commons.runtime.service.ITalendThemeService;
import org.talend.commons.ui.gmf.draw2d.AnimatableZoomManager;
import org.talend.commons.ui.runtime.image.EImage;
import org.talend.commons.ui.runtime.image.ImageProvider;
/**
* Grid that will be used for the designer. (modification of the default grid to have black points)
@@ -33,9 +34,64 @@ public class TalendGridLayer extends GridLayer {
public static final Color GRID_COLOR = ColorConstants.black;
private static final Color GRID_COLOR_1 = new Color(131, 131, 131);
private static final Color GRID_COLOR_2 = new Color(255, 255, 255);
private static ITalendThemeService themeServ;
public TalendGridLayer() {
super();
setForegroundColor(GRID_COLOR);
setForegroundColor(ColorConstants.red);
}
private static ITalendThemeService getTheme() {
if (themeServ == null) {
themeServ = ITalendThemeService.get();
}
return themeServ;
}
private Color getThemeColor(String prop) {
ITalendThemeService theme = getTheme();
if (theme == null) {
return null;
}
return (Color) theme.getGlobalThemeColor(prop);
}
private Color getColor1() {
Color themeColor = getThemeColor("DESIGNER_COLOR_A");
if (themeColor == null) {
themeColor = GRID_COLOR_1;
}
return themeColor;
}
private Color getColor2() {
Color themeColor = getThemeColor("DESIGNER_COLOR_B");
if (themeColor == null) {
themeColor = GRID_COLOR_2;
}
return themeColor;
}
private int getColorAlpha() {
final int defaultAlpha = 30;
ITalendThemeService theme = getTheme();
if (theme == null) {
return defaultAlpha;
}
String alpha = theme.getGlobalThemeProp("DESIGNER_COLOR_ALPHA");
if (StringUtils.isBlank(alpha)) {
return defaultAlpha;
}
try {
return Integer.valueOf(alpha);
} catch (Exception e) {
ExceptionHandler.process(e);
}
return defaultAlpha;
}
@Override
@@ -71,13 +127,18 @@ public class TalendGridLayer extends GridLayer {
origin.y += distanceY;
}
}
g.setAlpha(getColorAlpha());
for (int i = origin.x - distanceX; i < clip.x + clip.width; i += distanceX) {
for (int j = origin.y - distanceY; j < clip.y + clip.height; j += distanceY) {
// g.drawPoint(i, j);
// g.drawPoint(i, j);
int re = Math.abs(i - j);
if (re / distanceY % 2 == 0) {
g.drawImage(ImageProvider.getImage(EImage.CHESS_GRAY), i, j);
g.setBackgroundColor(getColor1());
// g.drawImage(ImageProvider.getImage(EImage.CHESS_GRAY), i, j);
} else {
g.setBackgroundColor(getColor2());
}
g.fillRectangle(i, j, 32, 32);
}
}
}