static int imageIcon_cacheSize = 10; sbool imageIcon_verbose; static Map<S, ImageIcon> imageIcon_cache; static Lock imageIcon_lock = lock(); static new ThreadLocal<Bool> imageIcon_fixGIF; // not going through BufferedImage preserves animations static ImageIcon imageIcon(S imageID) ctex { if (imageID == null) null; lock imageIcon_lock; if (imageIcon_cache == null) imageIcon_cache = new MRUCache(imageIcon_cacheSize); imageID = fsI(imageID); ImageIcon ii = imageIcon_cache.get(imageID); if (ii == null) { if (imageIcon_verbose) print("Loading image icon: " + imageID); File f = loadBinarySnippet(imageID); ifndef DontFixGIFs Bool b = imageIcon_fixGIF!; if (!isFalse(b)) ii = new ImageIcon(loadBufferedImageFixingGIFs(f)); else endifndef ii = new ImageIcon(f.toURI().toURL()); } else imageIcon_cache.remove(imageID); // move to front of cache on access imageIcon_cache.put(imageID, ii); ret ii; } // doesn't fix GIFs static ImageIcon imageIcon(File f) ctex { ret new ImageIcon(f.toURI().toURL()); } static ImageIcon imageIcon(Image img) { ret img == null ?: new ImageIcon(img); } ifclass RGBImage static ImageIcon imageIcon(RGBImage img) { ret imageIcon(img.getBufferedImage()); } endif
download show line numbers debug dex old transpilations
Travelled to 17 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mowyntqkapby, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1003551 |
Snippet name: | imageIcon - make ImageIcon from image ID or BufferedImage |
Eternal ID of this version: | #1003551/16 |
Text MD5: | a892d616213a47ef53002d4d7e61eda0 |
Author: | stefan |
Category: | javax / gui |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-02-12 21:09:50 |
Source code size: | 1317 bytes / 44 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 774 / 1066 |
Version history: | 15 change(s) |
Referenced in: | [show references] |