Esempio n. 1
0
  /**
   * Get an Image of the page. The Image is build from the Control.
   *
   * @param The IPage for which an Image is requested.
   * @return The Image of the page, or null if no Image can be built.
   */
  public static Image getPageImage(IPage page) {
    Rectangle size;
    Control control = page.getControl();

    size = control.getBounds();
    if (size.width == 0 && size.height == 0) {
      Point pt = control.computeSize(SWT.DEFAULT, SWT.DEFAULT);
      size = new Rectangle(0, 0, pt.x, pt.y);
    }

    Image image = new Image(control.getDisplay(), size);
    GC gc = new GC(image);

    boolean success = control.print(gc);
    gc.dispose();
    if (!success) {
      image.dispose();
      return null;
    }

    return image;
  }