JavaFX Override Loading images from CSS - css

Is it possible to set how JavaFX loads images from CSS? If I could delegate this to a certain utility class.
In Swing I had an ImageStore utility class which loaded the images needed by all the components. The ImageStore retrieved the image from a given URL and cached it to disk for later retrieval. It also used in memory cache for running application to avoid touching the disk on every retrieval. This way if 100 components wanted the same image, the image was only fetched 1 times, and not 100 times.
I have a dilemma now with using CSS for styling
-fx-background-image:url('/images/single-search.png')
How to delegate this loading to ImageStore?
How does JavaFX handle loading of images defined in CSS?
If JavaFX CSS does some caching on their own, this will only solve one problem. It will not fetch the same image multiple times. However my ImageStore saves all images to file cache where they are also available the next time the application is started a new.

JavaFX uses it's own cache class:
com.sun.javafx.css.StyleManager contains the Image getCachedImage(String url) method that is used by the converter used for the background image css properties. (Note that this class is not part of the public API.) This class does not seem to write the images to files and neither is there a way to replace the way the images are loaded in a clean way (i.e. not using reflection or similar means), but keeps references to the images used in memory...
Of course you could replace the CssMetaData object responsible for the background properties in the List returned by the getCssMetaData() method with a CssMetaData object using your own cache, but this would require extending every subclass of Region you want to use your cache with and using those classes instead of the standard Regions...

Related

Dynamically update css properties in scss file (Angular 2+)

I have a .scss file which is holding all the application css classes. There is an admin portal which user can set the properties like font size, text color e.t.c. When the application loads, client will be receiving these properties in a form of a key value object.
ex:
properties:{
'font-size':26,
'color':'blue'
}
I want to override these properties with defaults holding in my scss file.
I searched a bit and found that css variables is one of the option. But with that we will loose the support for IE11 as it does not work in IE 11.
Is there is any other way where i can look in to. Or is there any way where I can build the css file when i receive this object response from server.
Kindly help and suggest some approaches to deal with this.

Angular Material 2 themes - output single file or lazy load

Disclaimer: There are a few questions on SO regarding CSS and debates over a single or multiple CSS files but I think this is a bit different
I have a pretty big Angular 7 app using Angular Material 2 and I want to introduce themes. Each theme will be retrieved on user login (the theme is saved on the server and cannot be changed by the user).
The question is mainly regarding whether it would be best to export a single CSS file using top-level classes (body or app container) for each theme, replacing only classes that change for each theme or lazy load a new css file on top of the main css file with only the classes that are getting overwritten.
My biggest concern with the first option is getting a huge single CSS file. The current file is already around 300kb (unminified CSS is about 11k lines of code) and with themes ranging from 200-500 lines each and there could be 10+ themes, the file can easily get double or even triple that amount.
On the other hand, lazy loaded CSS might cause the user to download 2 smaller files but the implications might be worse. For example a lazy loaded CSS file needs to be exported with separate configs in Angular CLI and the name needs to be specific so it can be loaded from Angular on login which means caching might be an issue if something changes and also no versioning (eg. theme-blah-2.17.css) is also not possible in the name of the file. Possibly other implications that I cannot think of at the moment too.
Look at how material handles themes.
Also, take a look at how teradata Covalent handles themes.

How to use SVG images for Xamarin.Forms application?

It seems it's possible to some extent to use SVG images in some controls, for instance SVG files can be only added as embedded resources when using some of the available NuGet packages out there. Also, at least for ToolbarItem the images need to be stored somewhere in the file system, so I had to create my own SVG rasterizer that saves those images to bitmaps in the cache directory, so those could be passed in a FileImageSource to the Icon property in the control ToolbarItem. For, the control Button those images need to be stored in the Resources or drawable directory, so it won't work with the rasterized bitmaps, since those are stored in the cache directory. With all those limitations when trying to use SVG files directly at runtime, I was thinking maybe I could convert all those images to the corresponding JPG or PNG images at build time using some task, but I'm not sure whether that conversion could be done with the current available tools. So, my questions is how to use convert directly SVG images for using in common controls in a Xamarin.Forms application (ToolbarItem, Button, etc)?

How to load only used classes of CSS files in ASP.net MVC?

I've got a question about loading CSS files,
Is there any way or method to optimize the loading procedure by cutting back on classes that are not used in the current page and load the ones that are being used currently in ASP.NET MVC?
As an example suppose that the current page has style.css linked to it, style.css has 230 different classes defined, but the current page only uses 5 . Is there any way to make it load only those 5 classes and send a somehow customized version of style.css not the whole file?
I'm new to this, so give me a chance in terms of criticism that I'm sure I will receive for this answer.
This is exactly what minification is used for, having said that I would also incorporate this; if I was trying to achieve this I would be more inclined to make separate style sheets for that many classes (classes that are likely to be used together are on the same sheet).
This means you can load in a style sheet per page that contains the classes you need without loading in the whole sheet.
(essentially split your 230 classes into multiple style sheets according to what classes you need to use together).
EDIT: Just want to point out, a style-sheet's loading times will be negligible unless it's a couple of MB in size at least.

Dynamically loading style in Flex AIR App

So i decided to implement some themes in my AIR app. I have converted my CSS files into SWF files, removed the Style linkage from my main file. Based on the user preferences stored in a file, I decide which theme to use. i.e; load the SWF file using StyleManager class.
I made my application window invisible, added a StyleEvent.COMPLETE event listener for the IEventDispatcher object returned by StyleManager.loadStyleDeclarations method. After the StyleEvent.COMPLETE occurs, I made my main window visible.
The problem i have now is, for a few seconds, i can see white canvases and all my components without any styles before using the style selected. I want to know if my approach is correct or do I need to make any changes to implement this properly?
Alright, so I seem to have figured it out myself. Getting some help from this link albeit.
Previously i read the settings in my applicationComplete and loaded the styles. So i guess all the UI components were created and added to the display list. They were bare naked without any style values.
So i changed the reading of the settings file to preinitialize, so that by the time the applicationComplete is triggered, AIR has already loaded the SWF stylesheet. So it will display the UI as i wanted.

Resources