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

67
LINES

< > BotCompany Repo | #1028295 // JDesktopPane in a module with persistent windows [original spike]

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

Uses 911K of libraries. Click here for Pure Java version (6080L/31K).

1  
!7
2  
  
3  
cmodule NestedDesktopPane {
4  
  transient JDesktopPane desktopPane;
5  
  L<Win> windows = syncL();
6  
7  
  sclass Win {
8  
    Rect rect;
9  
    S title;
10  
    transient JInternalFrame frame;
11  
  }
12  
13  
  visualize {
14  
    ret withCenteredButtons(desktopPane = jDesktopPane(),
15  
      "Add frame", rThreadEnter { addAFrame(mL_randomEnglishWord()) });
16  
  }
17  
18  
  // Restoring frames in visualize() leads to the module menu not accessible after
19  
  // reload when there is at least one subwindow. So we do it here instead.
20  
  void enhanceFrame(JInternalFrame f) {
21  
    restoreFrames();
22  
  }
23  
 
24  
  void unvisualize {
25  
    super.unvisualize();
26  
    for (Win win : windows) win.frame = null;
27  
  }
28  
  
29  
  JInternalFrame addAFrame(S title) {
30  
    JInternalFrame f = showInternalFrame(desktopPane, title);
31  
    new Win win;
32  
    win.rect = boundsAsRect(f);
33  
    win.title = title;
34  
    setWinFrame(win, f);
35  
    windows.add(win);
36  
    change();
37  
    ret f;
38  
  }
39  
40  
  void setWinFrame(Win win, JInternalFrame f) {
41  
    setIconifiable(f, false);
42  
    win.frame = f;
43  
    onBoundsChange(f, r { grabRect(win) });
44  
    onInternalFrameClosing(f, r { win.frame = null; removeWin(win) });
45  
    onTitleChanged(f, r {
46  
      if (set_trueIfChanged(win, title := internalFrameTitle(f))) change()
47  
    });
48  
  }
49  
50  
  void restoreFrames {
51  
    if (desktopPane == null) ret;
52  
    for (Win win : windows)
53  
      setWinFrame(win, setBounds(win.rect, showInternalFrame(desktopPane, win.title)));
54  
  }
55  
  
56  
  void grabRect(Win win) {
57  
    if (win != null && win.frame != null && set_trueIfChanged(win, rect := boundsAsRect(win.frame)))
58  
      change();
59  
  }
60  
61  
  void removeWin(Win win) {
62  
    if (windows.remove(win)) {
63  
      disposeInternalFrame(win.frame);
64  
      change();
65  
    }
66  
  }
67  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1028295
Snippet name: JDesktopPane in a module with persistent windows [original spike]
Eternal ID of this version: #1028295/24
Text MD5: b79c6abd6a10c4632990a39de0b6dbd4
Transpilation MD5: 4f88b379c71931642d89dc8e0f0dc0b2
Author: stefan
Category:
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-06-09 12:48:21
Source code size: 1688 bytes / 67 lines
Pitched / IR pitched: No / No
Views / Downloads: 131 / 554
Version history: 23 change(s)
Referenced in: [show references]