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).

!7
  
cmodule NestedDesktopPane {
  transient JDesktopPane desktopPane;
  L<Win> windows = syncL();

  sclass Win {
    Rect rect;
    S title;
    transient JInternalFrame frame;
  }

  visualize {
    ret withCenteredButtons(desktopPane = jDesktopPane(),
      "Add frame", rThreadEnter { addAFrame(mL_randomEnglishWord()) });
  }

  // Restoring frames in visualize() leads to the module menu not accessible after
  // reload when there is at least one subwindow. So we do it here instead.
  void enhanceFrame(JInternalFrame f) {
    restoreFrames();
  }
 
  void unvisualize {
    super.unvisualize();
    for (Win win : windows) win.frame = null;
  }
  
  JInternalFrame addAFrame(S title) {
    JInternalFrame f = showInternalFrame(desktopPane, title);
    new Win win;
    win.rect = boundsAsRect(f);
    win.title = title;
    setWinFrame(win, f);
    windows.add(win);
    change();
    ret f;
  }

  void setWinFrame(Win win, JInternalFrame f) {
    setIconifiable(f, false);
    win.frame = f;
    onBoundsChange(f, r { grabRect(win) });
    onInternalFrameClosing(f, r { win.frame = null; removeWin(win) });
    onTitleChanged(f, r {
      if (set_trueIfChanged(win, title := internalFrameTitle(f))) change()
    });
  }

  void restoreFrames {
    if (desktopPane == null) ret;
    for (Win win : windows)
      setWinFrame(win, setBounds(win.rect, showInternalFrame(desktopPane, win.title)));
  }
  
  void grabRect(Win win) {
    if (win != null && win.frame != null && set_trueIfChanged(win, rect := boundsAsRect(win.frame)))
      change();
  }

  void removeWin(Win win) {
    if (windows.remove(win)) {
      disposeInternalFrame(win.frame);
      change();
    }
  }
}

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: 125 / 545
Version history: 23 change(s)
Referenced in: [show references]