Uses 911K of libraries. Click here for Pure Java version (7127L/38K).
1 | !7 |
2 | |
3 | cmodule SystemCPUTrayIcon > DynBigNumber { |
4 | transient BufferedImage trayImage; |
5 | transient TrayIcon trayIcon; |
6 | |
7 | switchable S color = "FD6A02"; |
8 | switchable int size = goodSystemTrayIconSize().x; |
9 | switchable double interval = 1; |
10 | switchable bool postToServer; |
11 | |
12 | start { |
13 | setDescription("SYSTEM CPU %"); |
14 | setToolTip("Percentage is per core (max=" + numberOfCores()*100 + "%)"); |
15 | doEvery(interval, r actualUpdate); |
16 | dm_hostTrayIcon(trayIcon = installTrayIcon(trayImage = whiteImage(size, size), "System CPU", rThread dm_activateOSAndModule)); |
17 | } |
18 | |
19 | void actualUpdate { |
20 | double load = systemCPULoad(); |
21 | int percent = toIntPercent_ceil(load*numberOfCores()); |
22 | |
23 | if (postToServer) |
24 | dm_machineGroupChat_postSigned("System CPU: " + percent + "% (" + nCores(numberOfCores()) + ")"); |
25 | |
26 | setValue(percent + " %"); |
27 | int w = trayImage.getWidth(), h = trayImage.getHeight(); |
28 | copyImagePart(trayImage, 1, 0, trayImage, 0, 0, w-1, h); |
29 | double fullY = (h-1)*(1-load); |
30 | int y = iceil(fullY); |
31 | Color fg = colorFromHex(color), bg = Color.white; |
32 | fillRect(trayImage, w-1, 0, 1, y, bg); |
33 | fillRect(trayImage, w-1, y, 1, h-y, fg); |
34 | if (y > 0) { |
35 | int rgb = colorToIntOpaque(blendColor(fg, bg, y-fullY)); |
36 | trayImage.setRGB(w-1, y-1, rgb); |
37 | } |
38 | setTrayIconImage(trayIcon, trayImage); |
39 | } |
40 | } |
Began life as a copy of #1018526
download show line numbers debug dex old transpilations
Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1020927 |
Snippet name: | System CPU % + (Host) Tray Icon |
Eternal ID of this version: | #1020927/29 |
Text MD5: | c527b06ffb7e54d0e9e0abe0d2a7eb27 |
Transpilation MD5: | 470bef8ef8ef05316f116a7dc0ec6b9a |
Author: | stefan |
Category: | javax / modules |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-01-21 13:29:13 |
Source code size: | 1394 bytes / 40 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 513 / 136486 |
Version history: | 28 change(s) |
Referenced in: | [show references] |