Ejemplo n.º 1
0
  /**
   * Core stuff for GWindows ctor
   *
   * @param x
   * @param y
   * @param w
   * @param h
   * @param noFrame
   * @param mode
   */
  private void windowCtorCore(
      PApplet theApplet,
      int x,
      int y,
      int w,
      int h,
      PImage image,
      boolean noFrame,
      String mode,
      String name) {
    // If this is the first control to be created then theAapplet must be the sketchApplet
    if (G4P.sketchApplet == null) G4P.sketchApplet = theApplet;
    app = theApplet;
    winName = name;

    if (mode == null || mode.equals("")) mode = PApplet.JAVA2D;

    papplet = new GWinApplet(mode);
    papplet.owner = this;
    papplet.frame = this;
    // So we can resize the frame to get the sketch canvas size reqd.
    papplet.frame.setResizable(true);
    // Now set the window width and height
    if (image == null) {
      papplet.appWidth = w;
      papplet.appHeight = h;
    } else {
      papplet.bkImage = image;
      papplet.appWidth = image.width;
      papplet.appHeight = image.height;
    }
    papplet.bkColor = papplet.color(180);

    // Set the papplet size preferences
    papplet.resize(papplet.appWidth, papplet.appHeight);
    papplet.setPreferredSize(new Dimension(papplet.appWidth, papplet.appHeight));
    papplet.setMinimumSize(new Dimension(papplet.appWidth, papplet.appHeight));

    // add the PApplet to the Frame
    setLayout(new BorderLayout());
    add(papplet, BorderLayout.CENTER);

    // ensures that the animation thread is started and
    // that other internal variables are properly set.
    papplet.init();

    // Set the sketch path to the same as the main PApplet object
    papplet.sketchPath = theApplet.sketchPath;

    // Pack the window, position it and make visible
    setUndecorated(noFrame);
    pack();
    setLocation(x, y);
    setVisible(true);

    // Make the window always on top
    setOnTop(true);

    // Make sure we have some data even if not used
    data = new GWinData();
    data.owner = this;

    // Not resizeable if we are using a back image
    super.setResizable(image == null);

    // Make sure G4P knows about this window
    G4P.addWindow(this);
  }