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

35
LINES

< > BotCompany Repo | #1022569 - OS Size + Free Memory Tray Icon [Dyn Module]

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

Uses 6192K of libraries. Click here for Pure Java version (7896L/41K).

!7

set flag OshiNotSticky.

cmodule MemoryTrayIcon > DynPrintLog {
  transient S value; // OS size in MB + free memory
  transient JLabel lbl;
  transient bool _startMinimized = true;
  switchable bool countSwap = true;
  switchable double interval = 10.0; // restart to take effect
  transient long processSize;
  
  start {
    dm_addTrayIcon(onLeftClick(rThread dm_verboseGC,
      lbl = dm_fieldLabel_noAutoToolTip('value)));
    componentPopupMenuItems(lbl,
      "Garbage Collect", rThread { dm_gc(); actualUpdate(); },
      "Show Module", rThread dm_showModule,
      "Remove", rThread dm_deleteModule);
    doEveryAndNow(interval, r actualUpdate);
    dm_registerAs_direct processSize();
  }
  
  void actualUpdate {
    processSize = oshi_currentProcessResidentSize();
    long mb = toM(processSize);
    GlobalMemory mem = oshi_systemMemory();
    long mb2 = freeSystemMemory(mem);
    if (countSwap) mb2 -= mem.getSwapUsed();
    mb2 = toM(mb2);
    if (set_trueIfChanged(this, value := mb + " / " + mb2))
      fireChangeWithoutPersisting();
    toolTip(lbl, "OS size in memory: " + mb + " MB, free system memory: " + mb2 + " MB");
  }
}

Author comment

Began life as a copy of #1020802

download  show line numbers  debug dex   

Travelled to 3 computer(s): cfunsshuasjs, mqqgnosmbjvj, tvejysmllsmz

No comments. add comment

Snippet ID: #1022569
Snippet name: OS Size + Free Memory Tray Icon [Dyn Module]
Eternal ID of this version: #1022569/9
Text MD5: b08585f15c8e27c5f40ac417162d310a
Transpilation MD5: 1b3a38c8dd23e1b6649f85e2ef19c978
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-10-03 15:26:36
Source code size: 1185 bytes / 35 lines
Pitched / IR pitched: No / No
Views / Downloads: 118 / 27316
Version history: 8 change(s)
Referenced in: [show references]