Libraryless. Click here for Pure Java version (9923L/55K).
1 | sclass PopupMenuMaker {
|
2 | settable bool allowScrolling = true; // ignored when using existingMenu |
3 | settable MouseEvent event; |
4 | settable PtInComponent ptInComponent; // if different from event |
5 | settable IVF1<JPopupMenu> fillMenu; |
6 | settable JPopupMenu existingMenu; |
7 | settable bool addSeparator = true; // add separator if existing meun |
8 | |
9 | JPopupMenu menu; |
10 | |
11 | *() {}
|
12 | *(MouseEvent *event, IVF1<JPopupMenu> *fillMenu) {}
|
13 | |
14 | public void run() swing {
|
15 | if (existingMenu != null) {
|
16 | fix(); |
17 | var menu = existingMenu; |
18 | int emptyCount = menu.getComponentCount(); |
19 | if (addSeparator) |
20 | menu.addSeparator(); |
21 | int emptyCount2 = menu.getComponentCount(); |
22 | fillMenu?.get(menu); |
23 | if (menu.getComponentCount() == emptyCount2) |
24 | truncateContainer(menu, emptyCount); |
25 | //printVars("Extended popup menu", +emptyCount, +emptyCount2, n := menu.getComponentCount());
|
26 | packWindow(menu); |
27 | //revalidate(menu); |
28 | } else {
|
29 | new JPopupMenu menu; |
30 | |
31 | int emptyCount = menu.getComponentCount(); |
32 | fillMenu?.get(menu); |
33 | if (menu.getComponentCount() == emptyCount) |
34 | ret; |
35 | |
36 | if (allowScrolling) {
|
37 | menu = new JPopupMenu; |
38 | JMenuScroller scroller = JMenuScroller.setScrollerFor(menu); |
39 | scroller.fillMenu = toVF1(fillMenu); |
40 | } |
41 | |
42 | ptInComponent if null = ptInComponentFromEvent(event); |
43 | |
44 | if (hasParentOfType JPopupMenu(ptInComponent.component)) {
|
45 | // component is in a menu itself. TODO: better positioning |
46 | // Also this doesn't actually seem to work... |
47 | menu.setInvoker(ptInComponent.component); |
48 | menu.setVisible(true); |
49 | } else |
50 | menu.show(ptInComponent.component, ptInComponent.p.x, ptInComponent.p.y); |
51 | } |
52 | } |
53 | |
54 | svoid fix {
|
55 | JPopupMenu.setDefaultLightWeightPopupEnabled(false); |
56 | } |
57 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj
No comments. add comment
| Snippet ID: | #1034567 |
| Snippet name: | PopupMenuMaker |
| Eternal ID of this version: | #1034567/16 |
| Text MD5: | a7f8d8f73562ae4ba067ee790510a36c |
| Transpilation MD5: | bc3b310088f273053cf5a9dc2223af3a |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-08-20 23:24:50 |
| Source code size: | 1907 bytes / 57 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 670 / 897 |
| Version history: | 15 change(s) |
| Referenced in: | [show references] |