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

51
LINES

< > BotCompany Repo | #1019874 // Current Actions [so they can be cancelled]

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

Uses 1113K of libraries. Click here for Pure Java version (4707L/24K).

!7

cm CurrentAction {
  transient JPanel stack;
  transient new RestartableCountdown deleteIfUnused;
  
  start {
    startCountdown();
    if (dm_getBounds() == null) {
      int w = getWidth(dm_desktopPane()), h = getHeight(dm_desktopPane());
      dm_setBounds(this, w-300, h-200, 300, 200);
    }
  }
  
  visualize {
    ret withRightMargin(stack = dynamicVStack2());
  }
  
  // start countdown to delete module if unused
  void startCountdown {
    deleteIfUnused.start(60.0, rEnter deleteIfUnused);
  }
  
  // API
  
  interface AnAction extends AutoCloseable {
    void setText(S text);
  }
  
  // Note: cancelMe will be called in GUI thread
  AutoCloseable showAction(S action, Runnable cancelMe) {
    deleteIfUnused.stop();
    final JLabel lbl = jlabel(action);
    final JComponent c = centerAndEast(lbl, jbutton("Cancel", cancelMe));
    addAndValidate(stack, c);
    ret new AnAction {
      public void close() enter {
        removeAndValidate(c);
        //print("Remaining components: " + componentCount(stack));
        if (emptyContainer(stack)) dm_hideModule();
        startCountdown();
      }
      public void setText(S text) { main.setText(lbl, text); }
    };
  }
  
  void deleteIfUnused {
    // TODO: minimal race condition
    if (countComponents(stack) == 0) dm_deleteModule();
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 11 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1019874
Snippet name: Current Actions [so they can be cancelled]
Eternal ID of this version: #1019874/27
Text MD5: c271040898628287e5a045bd1f4e8140
Transpilation MD5: 6a6ede54303fa49ae2f5247827bb371a
Author: stefan
Category: javax / stefan's os
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-07-11 16:15:07
Source code size: 1370 bytes / 51 lines
Pitched / IR pitched: No / No
Views / Downloads: 441 / 18618
Version history: 26 change(s)
Referenced in: [show references]