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

41
LINES

< > BotCompany Repo | #1005626 // freeFloatingAnimation

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (8731L/56K).

1  
// Note: Doesn't show anything if are is not completely in allowed bounds
2  
3  
static JWindow freeFloatingAnimation(S imageID, int x, int y, double seconds) {
4  
  ret disposeWindowAfter(iround(seconds*1000),
5  
    freeFloatingAnimation(imageID, x, y));
6  
}
7  
8  
static JWindow freeFloatingAnimation(final S imageID, final int x, final int y) {
9  
  ret (JWindow) swingAndWait(func {
10  
    JLabel label = new JLabel(imageIcon(imageID));
11  
    label.setOpaque(false);
12  
    new JWindow w;
13  
    w.setLocation(x, y);
14  
    w.add(label); // add it to get appropriate size through pack()
15  
    w.pack();
16  
    Rectangle maxBounds = maxWindowBounds();
17  
    Rectangle r = w.getBounds();
18  
    if (!maxBounds.contains(r)) null;
19  
    /*w.setLocation(
20  
      max(0, min(x, maxBounds.x+maxBounds.width-w.getWidth())),
21  
      max(0, min(y, maxBounds.y+maxBounds.height-w.getHeight())));*/
22  
    
23  
    Rectangle r2 = intersectWithScreen(r);
24  
    BufferedImage background = shootScreen2(r2);
25  
    //w.setLayout(null);
26  
    w.remove(label);
27  
    new JLayeredPane layeredPane;
28  
    Rectangle bounds = new Rectangle(0, 0, w.getContentPane().getWidth(), w.getContentPane().getHeight());
29  
    w.add(layeredPane);
30  
    JLabel lBackground = new JLabel(imageIcon(background));
31  
    lBackground.setBounds(0, 0, r2.width, r2.height);
32  
    layeredPane.add(lBackground, boxed(1));
33  
    label.setBounds(bounds);
34  
    layeredPane.add(label, new Int(2));
35  
    revalidate(w);
36  
    
37  
    w.setAlwaysOnTop(true);
38  
    w.setVisible(true);
39  
    ret w;
40  
  });
41  
}

Author comment

Began life as a copy of #1005622

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, ddnzoavkxhuk, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1005626
Snippet name: freeFloatingAnimation
Eternal ID of this version: #1005626/2
Text MD5: 3dcd98997278e9e8e927706779adb758
Transpilation MD5: dcedc26da371a2f18e9b5e533b90235a
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-01 23:25:07
Source code size: 1509 bytes / 41 lines
Pitched / IR pitched: No / No
Views / Downloads: 604 / 635
Version history: 1 change(s)
Referenced in: [show references]