Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

35
LINES

< > BotCompany Repo | #1025144 // Process CPU % + (Host) Tray Icon

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (7097L/38K).

1  
!7
2  
3  
cmodule ProcessCPUTrayIcon > DynBigNumber {
4  
  transient BufferedImage trayImage;
5  
  transient TrayIcon trayIcon; 
6  
  
7  
  switchable S color = "ADFF2F"; // green yellow
8  
  switchable S backgroundColor = "228B22"; // forest green
9  
  switchable int size = goodSystemTrayIconSize().x;
10  
  switchable double interval = 1;
11  
  
12  
  transient double loadRelativeToAllCores, recentLoad;
13  
  transient RollingAverage avg = new(5); // =10 seconds
14  
  
15  
  start {
16  
    setDescription("STEFAN'S OS CPU %");
17  
    setToolTip("Percentage is per core (total: " + numberOfCores()*100 + "%)");
18  
    doEvery(interval, r actualUpdate);
19  
    ownResource(tempTrayIcon(trayIcon = installTrayIcon(
20  
      trayImage = newBufferedImage(size, size, colorFromHex(backgroundColor)), "Stefan's OS CPU", rThread dm_activateOSAndModule)));
21  
  }
22  
  
23  
  void actualUpdate {
24  
    recentLoad = processCPULoad();
25  
    avg.add(recentLoad);
26  
    loadRelativeToAllCores = avg!;
27  
    setValue(toIntPercent_ceil(loadRelativeToAllCores*numberOfCores()) + " %");
28  
    int w = trayImage.getWidth(), h = trayImage.getHeight();
29  
    copyImagePart(trayImage, 1, 0, trayImage, 0, 0, w-1, h);
30  
    int y = iround((h-1)*(1 - loadRelativeToAllCores));
31  
    fillRect(trayImage, w-1, 0, 1, y, colorFromHex(backgroundColor));
32  
    fillRect(trayImage, w-1, y, 1, h-y, colorFromHex(color));
33  
    setTrayIconImage(trayIcon, trayImage);
34  
  }
35  
}

Author comment

Began life as a copy of #1020927

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1025144
Snippet name: Process CPU % + (Host) Tray Icon
Eternal ID of this version: #1025144/9
Text MD5: 48a9aa4f5a450dfe2541efae684171f0
Transpilation MD5: 260480cf7fb7d1ec004b428cc4679921
Author: stefan
Category: javax / modules
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-11-04 12:19:46
Source code size: 1387 bytes / 35 lines
Pitched / IR pitched: No / No
Views / Downloads: 290 / 45740
Version history: 8 change(s)
Referenced in: [show references]