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