0

How can I get a parsed Paint/Color object from a certain css property?

I have a custom terminal-view that has a color scheme. I would really like to read the colors from CSS instead to enable easy and proper theming.

I fiddled around with lookup() and lookupAll() but never quite managed to get PaintConverter.getPaintConverter().convert(...) or PaintConverter.getColorConverter().convert(...) to read the values. It just don't get where I'm supposed to get either the Mutable Map oder ParsedValues for convert.

Could anybody provide an example for that?

LinusCDE
  • 141
  • 3
  • 8
  • 2
    I'm not sure there's a way to do this... even if there is, if you want to programmatically change the theme it's probably better to have a class encapsulating the theme and to ensure the looked-up colors in the CSS are synced to the state of that object, rather than trying to do it the other way around. The CSS is part of the view, and should reflect the data in a model, instead of being a repository for the data. – James_D Apr 25 '20 at 16:42
  • @James_D So I should add multiple themes all in the same css if I understand it correctly. But I would still need to pick out the properties from Java-SourceCode. That is really what I need since I wan't to have all the colors/themes in CSS. – LinusCDE Apr 25 '20 at 20:34
  • No, there’s no need to do that. You can define the theme in terms of a set of “looked-up colors”, and then set those colors programmatically. Just have a Java class representing the theme, and set the looked-up colors to the values in an instance of that class (at start-up, and anytime they change). Unless I completely misunderstand your question (perhaps a simple, complete example would help?) – James_D Apr 25 '20 at 20:38
  • 1
    I agree with @James_D, and would also suggest your custom view be tied to custom css selectors and then just ad that styleClass to the view... if you really want to parse etc, check out this anser to a similar question... https://stackoverflow.com/a/42611487/3625077 – b3tuning Apr 25 '20 at 21:35
  • @b3tuning That sounds promising. I'll look into that. I'm currently porting a 6502-Emulator for educational purposes. https://github.com/LinusCDE/6502-Emulator/ I have added some views, but those are only source classes. I still need to learn a lot regarding this. I'll look more into your suggested answer in a few days. – LinusCDE Apr 28 '20 at 20:49
  • As for a concrete example: I basically wan't to replace the hardcoded enum with a terminal theme with (in the best case swappable) css styles. https://github.com/LinusCDE/6502-Emulator/blob/master/Emulator/src/me/emu6502/emulator/ui/view/BasicVT100View.kt The app currently does support a dark mode, but that can't be turned off (don't know how to unload the css). And the terminal colors (goal of this question) are still hardcoded. – LinusCDE Apr 28 '20 at 20:53

0 Answers0