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

59
LINES

< > BotCompany Repo | #1000539 // FrameWithImages

JavaX fragment (include)

1  
class FrameWithImages {
2  
  JFrame frame;
3  
  ImageSurface[] surfaces;
4  
  int n;
5  
6  
  *(int numImages) {
7  
    this(numImages, false);
8  
  }
9  
  
10  
  *(int numImages, boolean scroll) {
11  
    frame = new JFrame("A JavaX Frame");
12  
    
13  
    n = numImages;
14  
    JPanel grid = new JPanel(new GridLayout(n, 1));
15  
    surfaces = new ImageSurface[n];
16  
    for (int i = 0; i < n; i++) {
17  
      surfaces[i] = new ImageSurface();
18  
      grid.add(scroll ? new JScrollPane(surfaces[i]) : surfaces[i]);
19  
    }
20  
    
21  
    frame.add(grid);
22  
    frame.setBounds(100, 100, 100+400+20, 100+600);
23  
  }
24  
  
25  
  void hop() {
26  
    frame.setVisible(true);
27  
    exitOnFrameClose(frame);
28  
  }
29  
  
30  
  void setImage(int i, RGBImage img) {
31  
    if (i >= 0 && i < n)
32  
      surfaces[i].setImage(img);
33  
  }
34  
  
35  
  void setImage(int i, BufferedImage img) {
36  
    if (i >= 0 && i < n)
37  
      surfaces[i].setImage(img);
38  
  }
39  
  
40  
  void setInnerSize(RGBImage img) {
41  
    setInnerSize(img.getWidth(), img.getHeight());
42  
  }
43  
  
44  
  void setInnerSize(int w, int h) {
45  
    double zoom = surfaces[0].getZoomX();
46  
    frame.setSize((int) (w*zoom)+20, (int) (h*zoom*n)+40); // todo...
47  
  }
48  
  
49  
  void setZoom(double zoom) {
50  
    for (ImageSurface s : surfaces) s.setZoom(zoom);
51  
  }
52  
  
53  
  static void exitOnFrameClose(JFrame frame) {
54  
    if (!Boolean.TRUE.equals(getOpt(main.class, "_noExit")))
55  
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
56  
  }
57  
  
58  
  !include #1001101 // getOpt for exitOnFrameClose
59  
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1000539
Snippet name: FrameWithImages
Eternal ID of this version: #1000539/1
Text MD5: 75c2c4db28d22e6853ab4c13dec824ac
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-01-29 18:54:23
Source code size: 1475 bytes / 59 lines
Pitched / IR pitched: No / No
Views / Downloads: 665 / 1216
Referenced in: [show references]