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

48
LINES

< > BotCompany Repo | #1004446 // tablePopupMenu - adds to the menu if it already exists

JavaX fragment (include)

1  
sclass tablePopupMenu_Maker {
2  
  new L menuMakers;
3  
}
4  
5  
static Map<JTable, tablePopupMenu_Maker> tablePopupMenu_map = newWeakHashMap();
6  
7  
static new ThreadLocal<MouseEvent> tablePopupMenu_mouseEvent;
8  
static new ThreadLocal<Bool> tablePopupMenu_first;
9  
10  
// menuMaker = voidfunc(JPopupMenu, int row)
11  
static void tablePopupMenu(final JTable table, fO menuMaker) {
12  
  final bool first = isTrue(getAndClearThreadLocal(tablePopupMenu_first));
13  
  swing {
14  
    tablePopupMenu_Maker maker = tablePopupMenu_map.get(table);
15  
    if (maker == null) {
16  
      tablePopupMenu_map.put(table, maker = new tablePopupMenu_Maker);
17  
      final tablePopupMenu_Maker _maker = maker;
18  
      table.addMouseListener(new MouseAdapter {
19  
        public void mousePressed(MouseEvent e) { displayMenu(e); }
20  
        public void mouseReleased(MouseEvent e) { displayMenu(e); }
21  
      
22  
        void displayMenu(MouseEvent e) {
23  
          if (!e.isPopupTrigger()) ret;
24  
          new JPopupMenu menu;
25  
          int row = table.rowAtPoint(e.getPoint());
26  
          if (table.getSelectedRowCount() < 2)
27  
            table.setRowSelectionInterval(row, row);
28  
          int modelRow = convertTableRowToModel(table, row);
29  
          int emptyCount = menu.getComponentCount();
30  
          
31  
          tablePopupMenu_mouseEvent.set(e);
32  
          for (O menuMaker : _maker.menuMakers)
33  
            pcallF(menuMaker, menu, modelRow);
34  
            
35  
          vmBus_send('showingPopupMenu, table, menu);
36  
          
37  
          // show menu if any items in it
38  
          if (menu.getComponentCount() != emptyCount)
39  
            menu.show(e.getComponent(), e.getX(), e.getY());
40  
        }
41  
      });
42  
    }
43  
    if (first)
44  
      maker.menuMakers.add(0, menuMaker);
45  
    else
46  
      maker.menuMakers.add(menuMaker);
47  
  }
48  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1004446
Snippet name: tablePopupMenu - adds to the menu if it already exists
Eternal ID of this version: #1004446/6
Text MD5: 5bbf0eb8153f47ef6151233f24c3da90
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-01-02 16:44:42
Source code size: 1786 bytes / 48 lines
Pitched / IR pitched: No / No
Views / Downloads: 632 / 659
Version history: 5 change(s)
Referenced in: [show references]