Skip to content

Commit 8c67664

Browse files
Suchita Chaturvedithegreystone
Suchita Chaturvedi
andcommittedSep 16, 2024
8248: [Accessibility] Low Contrast in High Contrast mode on Stacktrace View
Co-authored-by: Marcus Hirt <hirt@openjdk.org> Reviewed-by: aptmac, bdutheil
1 parent 4aa38c7 commit 8c67664

File tree

3 files changed

+71
-7
lines changed
  • application

3 files changed

+71
-7
lines changed
 

‎application/org.openjdk.jmc.flightrecorder.ui/src/main/java/org/openjdk/jmc/flightrecorder/ui/views/stacktrace/StacktraceView.java

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
33
*
44
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
55
*
@@ -134,6 +134,7 @@
134134
import org.openjdk.jmc.ui.UIPlugin;
135135
import org.openjdk.jmc.ui.accessibility.FocusTracker;
136136
import org.openjdk.jmc.ui.common.util.AdapterUtil;
137+
import org.openjdk.jmc.ui.common.util.ThemeUtils;
137138
import org.openjdk.jmc.ui.handlers.ActionToolkit;
138139
import org.openjdk.jmc.ui.handlers.CopySelectionAction;
139140
import org.openjdk.jmc.ui.handlers.InFocusHandlerActivator;
@@ -212,8 +213,10 @@ public void run() {
212213
private static final Color ALTERNATE_COLOR = SWTColorToolkit.getColor(new RGB(255, 255, 240));
213214
private static final String COUNT_IMG_KEY = "countColor"; //$NON-NLS-1$
214215
private static final Color COUNT_COLOR = SWTColorToolkit.getColor(new RGB(100, 200, 100));
216+
private static final Color COUNT_COLOR_DARK_MODE = SWTColorToolkit.getColor(new RGB(7, 94, 7));
215217
private static final String SIBLINGS_IMG_KEY = "siblingsColor"; //$NON-NLS-1$
216218
private static final Color SIBLINGS_COUNT_COLOR = SWTColorToolkit.getColor(new RGB(170, 250, 170));
219+
private static final Color SIBLINGS_COUNT_COLOR_DARK_MODE = SWTColorToolkit.getColor(new RGB(8, 115, 8));
217220
private static final int[] DEFAULT_COLUMN_WIDTHS = {650, 80, 120};
218221
private static final String THREAD_ROOT_KEY = "threadRootAtTop"; //$NON-NLS-1$
219222
private static final String FRAME_OPTIMIZATION_KEY = "distinguishFramesByOptimization"; //$NON-NLS-1$
@@ -860,12 +863,13 @@ public void handleEvent(Event event) {
860863
long forkOffset = parentFork.getItemOffset();
861864
int siblingsStart = (int) Math.floor(event.width * forkOffset / total);
862865
int siblingsWidth = (int) Math.round(event.width * parentFork.getAggregateItemsInFork() / total);
863-
event.gc.setBackground(SIBLINGS_COUNT_COLOR);
866+
event.gc.setBackground(
867+
ThemeUtils.isDarkTheme() ? SIBLINGS_COUNT_COLOR_DARK_MODE : SIBLINGS_COUNT_COLOR);
864868
event.gc.fillRectangle(event.x + siblingsStart, event.y, siblingsWidth, event.height);
865869
// Draw group
866870
double offset = (forkOffset + frame.getBranch().getItemOffsetInFork()) / total;
867871
double fraction = frame.getAttributeAggregate() / total;
868-
event.gc.setBackground(COUNT_COLOR);
872+
event.gc.setBackground(ThemeUtils.isDarkTheme() ? COUNT_COLOR_DARK_MODE : COUNT_COLOR);
869873
int startPixel = (int) Math.floor(event.width * offset);
870874
int widthPixel = (int) Math.round(event.width * fraction);
871875
event.gc.fillRectangle(event.x + startPixel, event.y, Math.max(widthPixel, 1), event.height);
@@ -886,12 +890,13 @@ public void handleEvent(Event event) {
886890
long forkOffset = parentFork.getItemOffset();
887891
int siblingsStart = (int) Math.floor(event.width * forkOffset / total);
888892
int siblingsWidth = (int) Math.round(event.width * parentFork.getAggregateItemsInFork() / total);
889-
event.gc.setBackground(SIBLINGS_COUNT_COLOR);
893+
event.gc.setBackground(
894+
ThemeUtils.isDarkTheme() ? SIBLINGS_COUNT_COLOR_DARK_MODE : SIBLINGS_COUNT_COLOR);
890895
event.gc.fillRectangle(event.x + siblingsStart, event.y, siblingsWidth, event.height);
891896
// Draw group
892897
double offset = (forkOffset + frame.getBranch().getItemOffsetInFork()) / total;
893898
double fraction = frame.getAttributeAggregate() / total;
894-
event.gc.setBackground(COUNT_COLOR);
899+
event.gc.setBackground(ThemeUtils.isDarkTheme() ? COUNT_COLOR_DARK_MODE : COUNT_COLOR);
895900
int startPixel = (int) Math.floor(event.width * offset);
896901
int widthPixel = (int) Math.round(event.width * fraction);
897902
event.gc.fillRectangle(event.x + startPixel, event.y, Math.max(widthPixel, 1), event.height);
@@ -1057,7 +1062,7 @@ public Image getImage(Object element) {
10571062

10581063
@Override
10591064
public Color getBackground(Object element) {
1060-
if (treeLayout) {
1065+
if (treeLayout || ThemeUtils.isDarkTheme()) {
10611066
return null;
10621067
} else {
10631068
int parentCount = 0;

‎application/org.openjdk.jmc.ui.common/META-INF/MANIFEST.MF

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ Bundle-Version: 9.1.0.qualifier
77
Bundle-Activator: org.openjdk.jmc.ui.common.CorePlugin
88
Bundle-Vendor: Oracle Corporation
99
Require-Bundle: org.eclipse.core.runtime;visibility:=reexport,
10-
org.openjdk.jmc.common;visibility:=reexport
10+
org.openjdk.jmc.common;visibility:=reexport,
11+
org.eclipse.jface,
12+
org.eclipse.ui.workbench
1113
Bundle-ActivationPolicy: lazy
1214
Import-Package: org.eclipse.core.expressions
1315
Export-Package: org.openjdk.jmc.ui.common,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.openjdk.jmc.ui.common.util;
2+
3+
import org.eclipse.jface.util.PropertyChangeEvent;
4+
5+
import org.eclipse.jface.preference.JFacePreferences;
6+
import org.eclipse.jface.resource.ColorRegistry;
7+
import org.eclipse.jface.util.IPropertyChangeListener;
8+
import org.eclipse.swt.graphics.RGB;
9+
import org.eclipse.ui.PlatformUI;
10+
11+
public class ThemeUtils {
12+
13+
private static boolean isCurrentThemeDark;
14+
15+
static {
16+
updateCurrentThemeDarkModeStatus(); // To Initialize the value
17+
IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() {
18+
19+
public void propertyChange(PropertyChangeEvent event) {
20+
if (event.getProperty().equalsIgnoreCase(JFacePreferences.CONTENT_ASSIST_BACKGROUND_COLOR)) {
21+
updateCurrentThemeDarkModeStatus(); // To update the value whenever property changes
22+
}
23+
24+
}
25+
26+
};
27+
PlatformUI.getWorkbench().getThemeManager().addPropertyChangeListener(propertyChangeListener);
28+
29+
}
30+
31+
public static boolean isDarkTheme() {
32+
return isCurrentThemeDark;
33+
}
34+
35+
private static final double BRIGHTNESS_THRESHOLD = 0.5;
36+
37+
private static void updateCurrentThemeDarkModeStatus() {
38+
ColorRegistry colorRegistry = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry();
39+
RGB backgroundColor = colorRegistry.getRGB(JFacePreferences.CONTENT_ASSIST_BACKGROUND_COLOR);
40+
41+
if (backgroundColor == null) {
42+
// Fallback to a default behavior if the color is not available
43+
isCurrentThemeDark = false;
44+
} else {
45+
isCurrentThemeDark = calculateBrightness(backgroundColor) < BRIGHTNESS_THRESHOLD;
46+
}
47+
48+
}
49+
50+
private static double calculateBrightness(RGB color) {
51+
// Using the HSP color model for perceived brightness
52+
// See: http://alienryderflex.com/hsp.html
53+
return Math.sqrt(
54+
0.299 * color.red * color.red + 0.587 * color.green * color.green + 0.114 * color.blue * color.blue)
55+
/ 255.0;
56+
}
57+
}

0 commit comments

Comments
 (0)