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

59
LINES

< > BotCompany Repo | #1000539 // FrameWithImages

JavaX fragment (include)

class FrameWithImages {
  JFrame frame;
  ImageSurface[] surfaces;
  int n;

  *(int numImages) {
    this(numImages, false);
  }
  
  *(int numImages, boolean scroll) {
    frame = new JFrame("A JavaX Frame");
    
    n = numImages;
    JPanel grid = new JPanel(new GridLayout(n, 1));
    surfaces = new ImageSurface[n];
    for (int i = 0; i < n; i++) {
      surfaces[i] = new ImageSurface();
      grid.add(scroll ? new JScrollPane(surfaces[i]) : surfaces[i]);
    }
    
    frame.add(grid);
    frame.setBounds(100, 100, 100+400+20, 100+600);
  }
  
  void hop() {
    frame.setVisible(true);
    exitOnFrameClose(frame);
  }
  
  void setImage(int i, RGBImage img) {
    if (i >= 0 && i < n)
      surfaces[i].setImage(img);
  }
  
  void setImage(int i, BufferedImage img) {
    if (i >= 0 && i < n)
      surfaces[i].setImage(img);
  }
  
  void setInnerSize(RGBImage img) {
    setInnerSize(img.getWidth(), img.getHeight());
  }
  
  void setInnerSize(int w, int h) {
    double zoom = surfaces[0].getZoomX();
    frame.setSize((int) (w*zoom)+20, (int) (h*zoom*n)+40); // todo...
  }
  
  void setZoom(double zoom) {
    for (ImageSurface s : surfaces) s.setZoom(zoom);
  }
  
  static void exitOnFrameClose(JFrame frame) {
    if (!Boolean.TRUE.equals(getOpt(main.class, "_noExit")))
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  }
  
  !include #1001101 // getOpt for exitOnFrameClose
}

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: 663 / 1214
Referenced in: [show references]