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

48
LINES

< > BotCompany Repo | #1003656 // installTrayIcon - takes image ID and menu item params

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (5627L) is out of date.

sbool trayIcon_imageAutoSize = true;

static TrayIcon installTrayIcon(S imageID, S tooltip) {
  ret installTrayIcon(imageID, tooltip, null);
}

// menuItems can also just be a PopupMenu
// also, first of menuItems can be a Runnable for left-click on icon
static TrayIcon installTrayIcon(S imageID, S tooltip, O... menuItems) ctex {
  // convenience parameter swap :-)

  if (!isSnippetID(imageID) && isSnippetID(tooltip)) {
    S s = tooltip;
    tooltip = imageID;
    imageID = s;
  }
  
  ifdef installTrayIcon_useImageIcon
  Image image = imageIcon(imageID).getImage();
  endifdef
  ifndef installTrayIcon_useImageIcon
  Image image = loadImage2(imageID);
  endifndef
  ret installTrayIcon(image, tooltip, menuItems);
}

static TrayIcon installTrayIcon(final Image image, fS tooltip, fO... _menuItems) null on exception {
  ret swing(func -> TrayIcon {
    Runnable leftClick = null;
    O[] menuItems = params_unpackList(_menuItems);
    if (l(menuItems) > 0 && menuItems[0] instanceof Runnable) {
      leftClick = (Runnable) menuItems[0];
      menuItems = dropFirst(menuItems);
    }
  
    PopupMenu menu = makePopupMenu(menuItems);
    TrayIcon trayIcon = new TrayIcon(image, tooltip, menu);
    trayIcon.setImageAutoSize(trayIcon_imageAutoSize);
    
    if (leftClick != null) {
      final Runnable _leftClick = leftClick;
      onLeftClick(trayIcon, _leftClick);
    }
    
    SystemTray.getSystemTray().add(trayIcon);
    ret trayIcon;
  });
}

download  show line numbers  debug dex  old transpilations   

Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1003656
Snippet name: installTrayIcon - takes image ID and menu item params
Eternal ID of this version: #1003656/15
Text MD5: 035a541396f051ec7d56eaa9072511cf
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-28 22:07:36
Source code size: 1506 bytes / 48 lines
Pitched / IR pitched: No / No
Views / Downloads: 733 / 883
Version history: 14 change(s)
Referenced in: [show references]