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

40
LINES

< > BotCompany Repo | #1020927 // System 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 (7127L/38K).

!7

cmodule SystemCPUTrayIcon > DynBigNumber {
  transient BufferedImage trayImage;
  transient TrayIcon trayIcon; 
  
  switchable S color = "FD6A02";
  switchable int size = goodSystemTrayIconSize().x;
  switchable double interval = 1;
  switchable bool postToServer;
  
  start {
    setDescription("SYSTEM CPU %");
    setToolTip("Percentage is per core (max=" + numberOfCores()*100 + "%)");
    doEvery(interval, r actualUpdate);
    dm_hostTrayIcon(trayIcon = installTrayIcon(trayImage = whiteImage(size, size), "System CPU", rThread dm_activateOSAndModule));
  }
  
  void actualUpdate {
    double load = systemCPULoad();
    int percent = toIntPercent_ceil(load*numberOfCores());
    
    if (postToServer)
      dm_machineGroupChat_postSigned("System CPU: " + percent + "% (" + nCores(numberOfCores()) + ")");
      
    setValue(percent + " %");
    int w = trayImage.getWidth(), h = trayImage.getHeight();
    copyImagePart(trayImage, 1, 0, trayImage, 0, 0, w-1, h);
    double fullY = (h-1)*(1-load);
    int y = iceil(fullY);
    Color fg = colorFromHex(color), bg = Color.white;
    fillRect(trayImage, w-1, 0, 1, y, bg);
    fillRect(trayImage, w-1, y, 1, h-y, fg);
    if (y > 0) {
      int rgb = colorToIntOpaque(blendColor(fg, bg, y-fullY));
      trayImage.setRGB(w-1, y-1, rgb);
    }
    setTrayIconImage(trayIcon, trayImage);
  }
}

Author comment

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: 511 / 136483
Version history: 28 change(s)
Referenced in: [show references]