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 786K of libraries. Click here for Pure Java version (6833L/36K).

!7

cmodule ProcessCPUTrayIcon > DynBigNumber {
  transient BufferedImage trayImage;
  transient TrayIcon trayIcon; 
  
  switchable S color = "ADFF2F"; // green yellow
  switchable S backgroundColor = "228B22"; // forest green
  switchable int size = goodSystemTrayIconSize().x;
  switchable double interval = 1;
  
  transient double loadRelativeToAllCores, recentLoad;
  transient RollingAverage avg = new(5); // =10 seconds
  
  start {
    setDescription("STEFAN'S OS CPU %");
    setToolTip("Percentage is per core (total: " + numberOfCores()*100 + "%)");
    doEvery(interval, r actualUpdate);
    ownResource(tempTrayIcon(trayIcon = installTrayIcon(
      trayImage = newBufferedImage(size, size, colorFromHex(backgroundColor)), "Stefan's OS CPU", rThread dm_activateOSAndModule)));
  }
  
  void actualUpdate {
    recentLoad = processCPULoad();
    avg.add(recentLoad);
    loadRelativeToAllCores = avg!;
    setValue(toIntPercent_ceil(loadRelativeToAllCores*numberOfCores()) + " %");
    int w = trayImage.getWidth(), h = trayImage.getHeight();
    copyImagePart(trayImage, 1, 0, trayImage, 0, 0, w-1, h);
    int y = iround((h-1)*(1 - loadRelativeToAllCores));
    fillRect(trayImage, w-1, 0, 1, y, colorFromHex(backgroundColor));
    fillRect(trayImage, w-1, y, 1, h-y, colorFromHex(color));
    trayIcon.setImage(trayImage);
  }
}

Author comment

Began life as a copy of #1020927

download  show line numbers  debug dex   

Travelled to 2 computer(s): mqqgnosmbjvj, tvejysmllsmz

No comments. add comment

Snippet ID: #1025144
Snippet name: Process CPU % + (Host) Tray Icon
Eternal ID of this version: #1025144/8
Text MD5: ebdb1403b292102d6d12d627bea868dd
Transpilation MD5: 513c04ea2ad7525490a7ac1bdccbd90c
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-09-10 12:55:30
Source code size: 1378 bytes / 35 lines
Pitched / IR pitched: No / No
Views / Downloads: 18 / 450
Version history: 7 change(s)
Referenced in: [show references]