Detect dark mode in SWT or Eclipse RCP application? - java

How can I determine from code whether the SWT/RCP application it's running is being presented in a dark theme?
What I've tried so far:
The method org.eclipse.swt.widgets.Display.isSystemDarkTheme() reports whether the operating system prefers dark mode. However, I've observed an application running in light mode even when that method returns true.
Get the Color for something like SWT.COLOR_LIST_BACKGROUND, convert it to HSB, and check its brightness. Works, but seems roundabout.

Display.isSystemDarkTheme() returns only a hint, whether a dark or a light theme is set in the operating system which might be differ from the theme set in Eclipse. See Javadoc:
Note: This operation is a hint and is not supported on platforms that
do not have this concept.
Be aware that there can also be a mixed dark and light theme and that colors can be changed by the user, so in your case it would probably be better to use the background color (or even more precise, comparing the lightness of the foreground/text color vs. the lightness of the background color) of the specific element instead of relying on a hint or on a theme ID (as Eclipse itself does here, for example).

Related

How to make shown colors independent of phone's android dark/light theme?

I need an app that shows exact colors on each device disregarding what Android theme (dark / white) is on that device set.
So I put constraint layouts (same goes in fact for image view and probably other components as well) and make it programmatically set to a particular color, set by a hexa number (tried both 8-digit numbers and 6-digit numbers - dropping the FFs).
I expected that since the color was exactly defind by hexa, the app would show the exact color I needed.
Instead, the app is showing colors similar to what I wanted, but changed. For example - same code with color set on white (#FFFFFFFF or #FFFFFF) is shown as white when I run app on light Android theme, but as grey when I run on a phone set in dark theme mode. The same goes for all the colors - they are all slightly modified by the Android theme.
I set my colors, as follows (app is in Java):
layoutEmptyColor.setBackgroundColor(Color.parseColor(strDesc4)); //i.e. strDesc4 = "#7FFFD4"
Could somebody please let me know, how and where to set my app so that colors shown in it would be independent on Android theme set on the particular phone?
I'm not sure what other code snippets I should put here since I don't have a clue where I should look to solve this problem.

SWT system color displays RGB incorrectly

I am running RAP(RemoteApplicationPlatform) on a Windows machine.
There is a default theme applied to most RAP widgets.
TableItem.setForeground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_MAGENTA))
This code results in lime green font color when applied to a TableItem. For every system-based color code the expected output color is incorrect. I noticed that when applying the same code to a different widget (eg: Button) I get a different color that the TableItem.
Anyone know what is happening here? I have not modified my system color theme in any manner, and the change in colors across different widgets leads me to believe that the GC used in painting is having some problems replicating these colors - as if there were an overlay?
I have a general fear of having to manage resources since I have so many, and need to color match across OS, even if in the SWTResourceManager class and would very much prefer to stick to OS dependent colors.
I will try to find the generated html code for the tableitems. Unfortunately RAP, being generated html/js does not make this easy.

JavaFX: Entirely turn off scene anti-aliasing (inclusive of control text anti-aliasing)

Since both System.setProperty("prism.lcdtext", "false") and System.setProperty("prism.lcdtext", "true") are unsatisfactory (the former appears downy whereas the latter appears colorful at the letter edges even though the text color is black; on my LCD it looks even uglier than reported here: https://bugs.openjdk.java.net/browse/JDK-8131923),
I prefer to turn off anti-aliasing entirely.
The setting SceneAntialiasing.DISABLED seems not to affect my buttons/lists/dropdowns/... (I guess it is meant for drawing only).
How can I turn off anti-aliasing completely? I would like to use a font similar to those of Windows 2000 and the first version of Win XP, which work without anti-aliasing (and besides save space because they can be scaled down more than have-to-be-smoothed fonts).
[UPDATE] Screenshot added (as requested)
The right window is generated by my ScalaFX app. Pure plain standard code, no setting applied.
(Playing with System.setProperty("prism.lcdtext", "false") and System.setProperty("prism.text", "t2k") gives me slightly better, but still unsatisfactory results.)
See the enlarged 'W' and its many colors, which stems from the first button in the right window (JavaFX): for demanding users, this is intolerable. And please compare the smoothness of the monospace texts (left: Ubuntu, right: JavaFX).

Android vs iPhone color rendering

I have used the same color code (#FF0000), but it seems, when compared side by side, Android is showing a slight variance to the red color used.
Is this because of the difference is hardware ?
How can I achieve the same colour standard on both of the devices ?
You will never be able to display the exact same colour on all devices.
The screen might display colours in a different way (oled, TFT, IPS).
The Colourprofile may differ per devices and thus affect the way the colour is shown.
Especially with Android device the colour will look different from device to device. On iOS it might look a bit different between retina and non-retina.

Fonts and their sizes on different machines

I am writing a gui PC program with java and I am using Java Swing, the question is, for a given Font, with a given size and style, on a given String, i compute the bounding box (in pixels) on some machine, is there a possibility that on some other machine, for the exact same Font and exact same String, the computed bounding box will turn out different?
if it is possible( which seems to be the case according to the results I get on my program ), then how can i define a font where for a given string, in every possible machine, it will return the exact same bounding box?
You can't, because the rendering depends on several factors:
The font itself: some computers may not have the font you requested, or the font may have the same name, but be different in its substance. You can avoid this by embedding custom fonts in your deployable package.
The screen resolution: fonts are rendered accordingly to the screen resolution in DPI. On screens with higher density, fonts will be bigger (in pixel size), because they'd otherwise be unreadable. Think, for example, of Apple's retina displays, whose resolution is close to 400dpi, compared to a normal screen, with a 72dpi resolution. A string which is 72px high will take 1 inch on the normal screen, being perfectly readable, while will only occupy 0.18 in, being hardly readable.
The user has the right to customize the size of his fonts. If I'm presbyopic I'll want a bigger font size.
EDIT Or, you can fool the system by using pre-rendered strings (saved as raster graphics or even as SVG paths), but beware of the issues I presented you.
this is the intersection, setting :
Native OS,
accesible, instaled Font (Native OS uses different Fonts, size, bold ....)
theme in Native OS
Font (its properties) used for theme
various users setting, customs themes
idiotics custom application that can change global properties in Native OS, not applications setting
LookAndFeel
L&F uses own Font, are different
by default the same options as for Native OS
i**** custom application that can change global properties in Native OS.....
very different and too hard job is to change Font based on screen ration (in pixels),
any changes are about to iterating in UIManager and to change every key for FontUIResources

Categories