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

36
LINES

< > TinyBrain | #1007341 - coActivateFrames - make multiple frames always go to foreground simultaneously

JavaX fragment (include)

// TODO: sometimes they can't be closed anymore? (see #1014939)
sclass FrameCoActivator {
  long lastTime;
  int timeout = 100; // prohibit endless loop
  
  *(final Frame... frames) {
    for (final Frame f1 : frames) {
      f1.addWindowListener(new WindowAdapter {
        public void windowIconified(WindowEvent e) {
          lastTime = sysNow();
        }
        
        public void windowActivated(WindowEvent e) {
          if (sysNow() >= lastTime+timeout) {
            lastTime = sysNow();
            //print(text);
            for (Frame f2 : frames)
              if (f2 != f1)
                activateFrame(f2);
            activateFrame(f1);
          }
        }
      });
    }
  }
}

static Frame[] coActivateFrames(Frame... frames) {
  new FrameCoActivator(frames);
  ret frames;
}

static <A extends Frame> L<A> coActivateFrames(L<A> frames) {
  coActivateFrames(toArray(frames, Frame.class));
  ret frames;
}

download  show line numbers  debug dex   

Travelled to 4 computer(s): cfunsshuasjs, gwrvuhgaqvyk, mqqgnosmbjvj, tvejysmllsmz

No comments. add comment

Snippet ID: #1007341
Snippet name: coActivateFrames - make multiple frames always go to foreground simultaneously
Eternal ID of this version: #1007341/13
Text MD5: 71f6067923d2a14ff3f6582df689e7a4
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-05-06 19:28:52
Source code size: 967 bytes / 36 lines
Pitched / IR pitched: No / No
Views / Downloads: 140 / 128
Version history: 12 change(s)
Referenced in: [show]