未验证 提交 4aa133d2 编写于 作者: S Serge Rider 提交者: GitHub

Merge pull request #10196 from dbeaver/text-color#5534

#5534 make cell foreground color contrasting
...@@ -69,8 +69,7 @@ public class DatabaseTasksTree { ...@@ -69,8 +69,7 @@ public class DatabaseTasksTree {
ColorRegistry colorRegistry = UIUtils.getActiveWorkbenchWindow().getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry(); ColorRegistry colorRegistry = UIUtils.getActiveWorkbenchWindow().getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
colorError = colorRegistry.get("org.jkiss.dbeaver.txn.color.reverted.background"); colorError = colorRegistry.get("org.jkiss.dbeaver.txn.color.reverted.background");
colorErrorForeground = UIUtils.getContrastColor(colorError); colorErrorForeground = UIUtils.getContrastColor(colorError);
composite.addDisposeListener(e -> colorErrorForeground.dispose());
taskViewer = DialogUtils.createFilteredTree(composite, taskViewer = DialogUtils.createFilteredTree(composite,
SWT.MULTI | SWT.FULL_SELECTION | (selector ? SWT.BORDER | SWT.CHECK : SWT.NONE), SWT.MULTI | SWT.FULL_SELECTION | (selector ? SWT.BORDER | SWT.CHECK : SWT.NONE),
new NamedObjectPatternFilter(), TaskUIMessages.db_tasks_tree_text_tasks_type); new NamedObjectPatternFilter(), TaskUIMessages.db_tasks_tree_text_tasks_type);
......
...@@ -1836,15 +1836,11 @@ public class SpreadsheetPresentation extends AbstractPresentation implements IRe ...@@ -1836,15 +1836,11 @@ public class SpreadsheetPresentation extends AbstractPresentation implements IRe
boolean recordMode = controller.isRecordMode(); boolean recordMode = controller.isRecordMode();
ResultSetRow row = (ResultSetRow) (!recordMode ? rowElement : colElement); ResultSetRow row = (ResultSetRow) (!recordMode ? rowElement : colElement);
DBDAttributeBinding attribute = (DBDAttributeBinding)(!recordMode ? colElement : rowElement); DBDAttributeBinding attribute = (DBDAttributeBinding)(!recordMode ? colElement : rowElement);
Color fg = controller.getLabelProvider().getCellForeground(attribute, row); Color fg = controller.getLabelProvider().getCellForeground(attribute, row);
if (fg != null) { if (fg != null) {
return fg; return fg;
} }
if (foregroundDefault == null) { return UIUtils.getContrastColor(getCellBackground(colElement, rowElement, false));
foregroundDefault = controller.getDefaultForeground();
}
return foregroundDefault;
} }
@Nullable @Nullable
......
...@@ -89,6 +89,8 @@ public class UIUtils { ...@@ -89,6 +89,8 @@ public class UIUtils {
private static final Log log = Log.getLog(UIUtils.class); private static final Log log = Log.getLog(UIUtils.class);
public static final String INLINE_WIDGET_EDITOR_ID = "org.jkiss.dbeaver.ui.InlineWidgetEditor"; public static final String INLINE_WIDGET_EDITOR_ID = "org.jkiss.dbeaver.ui.InlineWidgetEditor";
private static final Color COLOR_BLACK = new Color(null, 0, 0, 0);
private static final Color COLOR_WHITE = new Color(null, 255, 255, 255);
private static SharedTextColors sharedTextColors = new SharedTextColors(); private static SharedTextColors sharedTextColors = new SharedTextColors();
private static SharedFonts sharedFonts = new SharedFonts(); private static SharedFonts sharedFonts = new SharedFonts();
...@@ -1928,16 +1930,18 @@ public class UIUtils { ...@@ -1928,16 +1930,18 @@ public class UIUtils {
/** /**
* Calculate the Contrast color based on Luma(brightness) * Calculate the Contrast color based on Luma(brightness)
* https://en.wikipedia.org/wiki/Luma_(video) * https://en.wikipedia.org/wiki/Luma_(video)
*
* Do not dispose returned color.
*/ */
public static Color getContrastColor(Color color) { public static Color getContrastColor(Color color) {
if (color == null) if (color == null) {
return new Color(null, 0, 0, 0); return COLOR_BLACK;
}
double luminance = 1 - (0.299 * color.getRed() + 0.587 * color.getGreen() + 0.114 * color.getBlue()) / 255; double luminance = 1 - (0.299 * color.getRed() + 0.587 * color.getGreen() + 0.114 * color.getBlue()) / 255;
if (luminance > 0.5) {
int c = (luminance > 0.5) ? 255 : 0; return COLOR_WHITE;
}
return new Color(null, c, c, c); return COLOR_BLACK;
} }
public static void openWebBrowser(String url) public static void openWebBrowser(String url)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册