public static void main(String[] args) {
   final Display display = new Display();
   final Shell shell = new Shell(display);
   shell.setLayout(new FillLayout());
   final StyledText styledText = new StyledText(shell, SWT.WRAP | SWT.BORDER);
   styledText.setText(text);
   FontData data = display.getSystemFont().getFontData()[0];
   Font font = new Font(display, data.getName(), 16, SWT.BOLD);
   styledText.setFont(font);
   styledText.setForeground(display.getSystemColor(SWT.COLOR_BLUE));
   styledText.addListener(
       SWT.Resize,
       new Listener() {
         public void handleEvent(Event event) {
           Rectangle rect = styledText.getClientArea();
           Image newImage = new Image(display, 1, Math.max(1, rect.height));
           GC gc = new GC(newImage);
           gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
           gc.setBackground(display.getSystemColor(SWT.COLOR_YELLOW));
           gc.fillGradientRectangle(rect.x, rect.y, 1, rect.height, true);
           gc.dispose();
           styledText.setBackgroundImage(newImage);
           if (oldImage != null) oldImage.dispose();
           oldImage = newImage;
         }
       });
   shell.setSize(700, 400);
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   if (oldImage != null) oldImage.dispose();
   font.dispose();
   display.dispose();
 }
示例#2
0
文件: View.java 项目: shader/gdr
  public View(Controller controller) {
    this.controller = controller;
    display = new Display();
    shell = new Shell(display);
    shell.setText("Gallant Animation Viewer");

    shell.setLayout(new GridLayout());
  }
示例#3
0
  public Shell open(Display display) {
    shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.addShellListener(
        new ShellAdapter() {
          @Override
          public void shellClosed(ShellEvent e) {
            e.doit = closeAddressBook();
          }
        });

    createMenuBar();

    searchDialog = new SearchDialog(shell);
    searchDialog.setSearchAreaNames(columnNames);
    searchDialog.setSearchAreaLabel(resAddressBook.getString("Column"));
    searchDialog.addFindListener(
        new FindListener() {
          public boolean find() {
            return findEntry();
          }
        });

    table = new Table(shell, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
    table.setHeaderVisible(true);
    table.setMenu(createPopUpMenu());
    table.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            TableItem[] items = table.getSelection();
            if (items.length > 0) editEntry(items[0]);
          }
        });
    for (int i = 0; i < columnNames.length; i++) {
      TableColumn column = new TableColumn(table, SWT.NONE);
      column.setText(columnNames[i]);
      column.setWidth(150);
      final int columnIndex = i;
      column.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              sort(columnIndex);
            }
          });
    }

    newAddressBook();

    shell.setSize(table.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, 300);
    shell.open();
    return shell;
  }
 /** Invokes as a standalone program. */
 public static void main(String[] args) {
   Display display = new Display();
   Shell shell = new Shell(display, SWT.SHELL_TRIM);
   shell.setLayout(new FillLayout());
   ControlExample instance = new ControlExample(shell);
   shell.setText(getResourceString("window.title"));
   setShellSize(instance, shell);
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   instance.dispose();
   display.dispose();
 }
示例#5
0
 public static void main(String[] args) {
   Display display = Display.getDefault();
   Shell shell = new Shell(display);
   @SuppressWarnings("unused")
   MainWindow inst = new MainWindow(shell, SWT.NULL);
   shell.setLayout(new FillLayout());
   shell.setImage(SWTResourceManager.getImage("images/16x16.png"));
   shell.setText("Change This Title");
   shell.setBackgroundImage(SWTResourceManager.getImage("images/ToolbarBackground.gif"));
   shell.layout();
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
 }
  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout(2, false));

    final Text text = new Text(shell, SWT.SEARCH | SWT.ICON_CANCEL);
    Image image = null;
    if ((text.getStyle() & SWT.ICON_CANCEL) == 0) {
      image = display.getSystemImage(SWT.ICON_ERROR);
      ToolBar toolBar = new ToolBar(shell, SWT.FLAT);
      ToolItem item = new ToolItem(toolBar, SWT.PUSH);
      item.setImage(image);
      item.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              text.setText("");
              System.out.println("Search cancelled");
            }
          });
    }
    text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    text.setText("Search text");
    text.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            if (e.detail == SWT.CANCEL) {
              System.out.println("Search cancelled");
            } else {
              System.out.println("Searching for: " + text.getText() + "...");
            }
          }
        });

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    if (image != null) image.dispose();
    display.dispose();
  }
 public static void main(String[] args) {
   final Display display = new Display();
   final Image image = new Image(display, 16, 16);
   GC gc = new GC(image);
   gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
   gc.fillRectangle(image.getBounds());
   gc.dispose();
   final Shell shell = new Shell(display);
   shell.setText("Lazy Table");
   shell.setLayout(new FillLayout());
   final Table table = new Table(shell, SWT.BORDER | SWT.MULTI);
   table.setSize(200, 200);
   Thread thread =
       new Thread() {
         @Override
         public void run() {
           for (int i = 0; i < 20000; i++) {
             if (table.isDisposed()) return;
             final int[] index = new int[] {i};
             display.syncExec(
                 () -> {
                   if (table.isDisposed()) return;
                   TableItem item = new TableItem(table, SWT.NONE);
                   item.setText("Table Item " + index[0]);
                   item.setImage(image);
                 });
           }
         }
       };
   thread.start();
   shell.setSize(200, 200);
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   image.dispose();
   display.dispose();
 }
  public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    Composite comp = new Composite(shell, SWT.NONE);
    comp.setLayout(new FillLayout());
    GLData data = new GLData();
    data.doubleBuffer = true;
    final GLCanvas canvas = new GLCanvas(comp, SWT.NONE, data);

    canvas.setCurrent();
    try {
      GLContext.useContext(canvas);
    } catch (LWJGLException e) {
      e.printStackTrace();
    }

    canvas.addListener(
        SWT.Resize,
        new Listener() {
          public void handleEvent(Event event) {
            Rectangle bounds = canvas.getBounds();
            float fAspect = (float) bounds.width / (float) bounds.height;
            canvas.setCurrent();
            try {
              GLContext.useContext(canvas);
            } catch (LWJGLException e) {
              e.printStackTrace();
            }
            GL11.glViewport(0, 0, bounds.width, bounds.height);
            GL11.glMatrixMode(GL11.GL_PROJECTION);
            GL11.glLoadIdentity();
            GLU.gluPerspective(45.0f, fAspect, 0.5f, 400.0f);
            GL11.glMatrixMode(GL11.GL_MODELVIEW);
            GL11.glLoadIdentity();
          }
        });

    GL11.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    GL11.glColor3f(1.0f, 0.0f, 0.0f);
    GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
    GL11.glClearDepth(1.0);
    GL11.glLineWidth(2);
    GL11.glEnable(GL11.GL_DEPTH_TEST);

    shell.setText("SWT/LWJGL Example");
    shell.setSize(640, 480);
    shell.open();

    display.asyncExec(
        new Runnable() {
          int rot = 0;

          public void run() {
            if (!canvas.isDisposed()) {
              canvas.setCurrent();
              try {
                GLContext.useContext(canvas);
              } catch (LWJGLException e) {
                e.printStackTrace();
              }
              GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
              GL11.glClearColor(.3f, .5f, .8f, 1.0f);
              GL11.glLoadIdentity();
              GL11.glTranslatef(0.0f, 0.0f, -10.0f);
              float frot = rot;
              GL11.glRotatef(0.15f * rot, 2.0f * frot, 10.0f * frot, 1.0f);
              GL11.glRotatef(0.3f * rot, 3.0f * frot, 1.0f * frot, 1.0f);
              rot++;
              GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
              GL11.glColor3f(0.9f, 0.9f, 0.9f);
              drawTorus(1, 1.9f + ((float) Math.sin((0.004f * frot))), 15, 15);
              canvas.swapBuffers();
              display.asyncExec(this);
            }
          }
        });

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
  public static void main(String[] args) {
    final Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    final Tree tree = new Tree(shell, SWT.FULL_SELECTION | SWT.BORDER);
    tree.setHeaderVisible(true);
    TreeColumn column0 = new TreeColumn(tree, SWT.LEFT);
    column0.setText("Column 0");
    TreeColumn column1 = new TreeColumn(tree, SWT.LEFT);
    column1.setText("Column 1");
    TreeColumn column2 = new TreeColumn(tree, SWT.LEFT);
    column2.setText("Column 2");
    for (int i = 0; i < 9; i++) {
      TreeItem item = new TreeItem(tree, SWT.NONE);
      item.setText("item " + i);
      item.setText(1, "column 1 - " + i);
      item.setText(2, "column 2 - " + i);
      for (int j = 0; j < 9; j++) {
        TreeItem subItem = new TreeItem(item, SWT.NONE);
        subItem.setText("item " + i + " " + j);
        subItem.setText(1, "column 1 - " + i + " " + j);
        subItem.setText(2, "column 2 - " + i + " " + j);
        for (int k = 0; k < 9; k++) {
          TreeItem subsubItem = new TreeItem(subItem, SWT.NONE);
          subsubItem.setText("item " + i + " " + j + " " + k);
          subsubItem.setText(1, "column 1 - " + i + " " + j + " " + k);
          subsubItem.setText(2, "column 2 - " + i + " " + j + " " + k);
        }
      }
    }
    column0.pack();
    column1.pack();
    column2.pack();

    Heartbeat =
        new Runnable() {
          @Override
          public void run() {
            if (!Tracking || tree.isDisposed()) return;
            Point cursor = display.getCursorLocation();
            cursor = display.map(null, tree, cursor);
            Scroll(tree, cursor.x, cursor.y);
            display.timerExec(ScrollSpeed, Heartbeat);
          }
        };
    Listener listener =
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            switch (event.type) {
              case SWT.MouseEnter:
                Tracking = true;
                display.timerExec(0, Heartbeat);
                break;
              case SWT.MouseExit:
                Tracking = false;
                break;
            }
          }
        };
    tree.addListener(SWT.MouseEnter, listener);
    tree.addListener(SWT.MouseExit, listener);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
  public Shell open(Display display) {

    // Window dressing - the icon
    windowIcon =
        new Image(display, getClass().getClassLoader().getResourceAsStream("icons/joanju.gif"));

    shell = new Shell(display);
    shell.setLayout(new FillLayout());
    shell.addShellListener(
        new ShellAdapter() {
          public void shellClosed(ShellEvent e) {
            e.doit = closeAddressBook();
          }
        });

    shell.setImage(windowIcon);

    createMenuBar();

    searchDialog = new SearchDialog(shell);
    searchDialog.setSearchAreaNames(columnNames);
    searchDialog.setSearchAreaLabel(resMessages.getString("Column"));
    searchDialog.addFindListener(
        new FindListener() {
          public boolean find() {
            return findEntry();
          }
        });

    table = new Table(shell, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION);
    table.setHeaderVisible(true);
    table.setMenu(createPopUpMenu());
    table.addSelectionListener(
        new SelectionAdapter() {
          public void widgetDefaultSelected(SelectionEvent e) {
            TableItem[] items = table.getSelection();
            if (items.length > 0) launchEditor(items[0]);
          }
        });
    int[] widths = {150, 50, 200, 200};
    for (int i = 0; i < columnNames.length; i++) {
      TableColumn column = new TableColumn(table, SWT.NONE);
      column.setText(columnNames[i]);
      column.setWidth(widths[i]);
      final int columnIndex = i;
      column.addSelectionListener(
          new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) {
              sort(columnIndex);
            }
          });
    }

    newAddressBook();

    shell.addDisposeListener(
        new DisposeListener() {
          public void widgetDisposed(DisposeEvent e) {
            windowIcon.dispose();
          }
        });

    shell.setSize(table.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, 300);
    shell.open();
    return shell;
  }
  public static void main(String[] args) {
    Shell shell = new Shell();
    Display display = shell.getDisplay();
    shell.setLayout(new FillLayout());
    shell.setText("ExpandBar Example");

    Menu menubar = new Menu(shell, SWT.BAR);
    shell.setMenuBar(menubar);
    MenuItem fileItem = new MenuItem(menubar, SWT.CASCADE);
    fileItem.setText("&File");
    Menu submenu = new Menu(shell, SWT.DROP_DOWN);
    fileItem.setMenu(submenu);
    item = new MenuItem(submenu, SWT.PUSH);
    item.setText("New ExpandItem");

    bar = new ExpandBar(shell, SWT.V_SCROLL);
    image = display.getSystemImage(SWT.ICON_QUESTION);

    // First item
    Composite composite = new Composite(bar, SWT.NONE);
    Menu popupmenu = new Menu(shell, SWT.POP_UP);
    MenuItem popupItem = new MenuItem(popupmenu, SWT.PUSH);
    popupItem.setText("Popup");
    composite.setMenu(popupmenu);

    GridLayout layout = new GridLayout(2, false);
    layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10;
    layout.verticalSpacing = 10;
    composite.setLayout(layout);
    Label label = new Label(composite, SWT.NONE);
    label.setImage(display.getSystemImage(SWT.ICON_ERROR));
    label = new Label(composite, SWT.NONE);
    label.setText("SWT.ICON_ERROR");
    label = new Label(composite, SWT.NONE);
    label.setImage(display.getSystemImage(SWT.ICON_INFORMATION));
    label = new Label(composite, SWT.NONE);
    label.setText("SWT.ICON_INFORMATION");
    label = new Label(composite, SWT.NONE);
    label.setImage(display.getSystemImage(SWT.ICON_WARNING));
    label = new Label(composite, SWT.NONE);
    label.setText("SWT.ICON_WARNING");
    label = new Label(composite, SWT.NONE);
    label.setImage(display.getSystemImage(SWT.ICON_QUESTION));
    label = new Label(composite, SWT.NONE);
    label.setText("SWT.ICON_QUESTION");
    ExpandItem item1 = new ExpandItem(bar, SWT.NONE);
    item1.setText("What is your favorite icon");
    item1.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
    item1.setControl(composite);
    item1.setImage(image);

    // Second item
    composite = new Composite(bar, SWT.NONE);
    layout = new GridLayout(2, true);
    layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 10;
    layout.verticalSpacing = 10;
    composite.setLayout(layout);
    Button button1 = new Button(composite, SWT.PUSH);
    button1.setText("Button 1");
    Button button2 = new Button(composite, SWT.PUSH);
    button2.setText("Button 2");

    ExpandItem item0 = new ExpandItem(bar, SWT.NONE);
    item0.setText("What is your favorite button");
    item0.setHeight(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
    item0.setControl(composite);
    item0.setImage(image);
    item0.setExpanded(false);

    item.addListener(
        SWT.Selection,
        new Listener() {
          @Override
          public void handleEvent(Event e) {
            ExpandItem item2 = new ExpandItem(bar, SWT.NONE);
            Composite composite = new Composite(bar, SWT.NONE);
            GridLayout layout = new GridLayout(2, false);
            composite.setLayout(layout);
            Label label = new Label(composite, SWT.NONE);
            label.setText("What is your name?");
            Composite pcomposite = new Composite(composite, SWT.NONE);
            Text text = new Text(pcomposite, SWT.NONE);
            item2.setText("New Question");
            text.pack();
            composite.pack();
            Point size = composite.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            item2.setHeight(size.y);
            item2.setControl(composite);
            item2.setImage(image);
            item2.setExpanded(true);
          }
        });

    bar.setSpacing(8);
    shell.setSize(400, 550);
    shell.open();
    System.out.println("------------------------------");
    System.out.println("getSize: " + button1.getSize());
    System.out.println("getBounds: " + button1.getBounds());
    System.out.println("computeSize: " + button1.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    System.out.println("getLocation: " + button1.getLocation());

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    image.dispose();
    display.dispose();
  }
示例#12
0
  public Shell open(Display display) {
    clipboard = new Clipboard(display);
    shell = new Shell(display);
    shell.setText("SWT Clipboard");
    shell.setLayout(new FillLayout());

    ScrolledComposite sc = new ScrolledComposite(shell, SWT.H_SCROLL | SWT.V_SCROLL);
    Composite parent = new Composite(sc, SWT.NONE);
    sc.setContent(parent);
    parent.setLayout(new GridLayout(2, true));

    Group copyGroup = new Group(parent, SWT.NONE);
    copyGroup.setText("Copy From:");
    GridData data = new GridData(GridData.FILL_BOTH);
    copyGroup.setLayoutData(data);
    copyGroup.setLayout(new GridLayout(3, false));

    Group pasteGroup = new Group(parent, SWT.NONE);
    pasteGroup.setText("Paste To:");
    data = new GridData(GridData.FILL_BOTH);
    pasteGroup.setLayoutData(data);
    pasteGroup.setLayout(new GridLayout(3, false));

    Group controlGroup = new Group(parent, SWT.NONE);
    controlGroup.setText("Control API:");
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    controlGroup.setLayoutData(data);
    controlGroup.setLayout(new GridLayout(5, false));

    Group typesGroup = new Group(parent, SWT.NONE);
    typesGroup.setText("Available Types");
    data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 2;
    typesGroup.setLayoutData(data);
    typesGroup.setLayout(new GridLayout(2, false));

    status = new Label(parent, SWT.BORDER);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    data.heightHint = 60;
    status.setLayoutData(data);

    createTextTransfer(copyGroup, pasteGroup);
    createRTFTransfer(copyGroup, pasteGroup);
    createHTMLTransfer(copyGroup, pasteGroup);
    createFileTransfer(copyGroup, pasteGroup);
    createMyTransfer(copyGroup, pasteGroup);
    createControlTransfer(controlGroup);
    createAvailableTypes(typesGroup);

    sc.setMinSize(parent.computeSize(SWT.DEFAULT, SWT.DEFAULT));
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);

    Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    Rectangle monitorArea = shell.getMonitor().getClientArea();
    shell.setSize(
        Math.min(size.x, monitorArea.width - 20), Math.min(size.y, monitorArea.height - 20));
    shell.open();
    return shell;
  }
  public static void main(String[] args) {
    final ImageFileNameProvider filenameProvider =
        new ImageFileNameProvider() {
          @Override
          public String getImagePath(int zoom) {
            switch (zoom) {
              case 150:
                return IMAGE_PATH_150;
              case 200:
                return IMAGE_PATH_200;
              default:
                return IMAGE_PATH_100;
            }
          }
        };
    final ImageDataProvider imageDataProvider =
        new ImageDataProvider() {
          @Override
          public ImageData getImageData(int zoom) {
            switch (zoom) {
              case 150:
                return new ImageData(IMAGE_PATH_150);
              case 200:
                return new ImageData(IMAGE_PATH_200);
              default:
                return new ImageData(IMAGE_PATH_100);
            }
          }
        };

    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new GridLayout(2, false));

    new Label(shell, SWT.NONE).setText(IMAGE_200 + ":");
    new Label(shell, SWT.NONE).setImage(new Image(display, IMAGE_PATH_200));

    new Label(shell, SWT.NONE).setText(IMAGE_150 + ":");
    new Label(shell, SWT.NONE).setImage(new Image(display, IMAGE_PATH_150));

    new Label(shell, SWT.NONE).setText(IMAGE_100 + ":");
    new Label(shell, SWT.NONE).setImage(new Image(display, IMAGE_PATH_100));

    new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL)
        .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));

    new Label(shell, SWT.NONE).setText("ImageFileNameProvider:");
    new Label(shell, SWT.NONE).setImage(new Image(display, filenameProvider));

    new Label(shell, SWT.NONE).setText("ImageDataProvider:");
    new Label(shell, SWT.NONE).setImage(new Image(display, imageDataProvider));

    new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL)
        .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));

    new Label(shell, SWT.NONE).setText("Canvas\n(PaintListener)");
    final Point size = new Point(550, 35);
    final Canvas canvas = new Canvas(shell, SWT.NONE);
    canvas.addPaintListener(
        new PaintListener() {
          @Override
          public void paintControl(PaintEvent e) {
            Point size = canvas.getSize();
            paintImage(e.gc, size);
          }
        });
    canvas.setLayoutData(new GridData(size.x, size.y));

    new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL)
        .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));

    new Label(shell, SWT.NONE).setText("Painted image\n (default resolution)");
    Image image = new Image(display, size.x, size.y);
    GC gc = new GC(image);
    try {
      paintImage(gc, size);
    } finally {
      gc.dispose();
    }
    new Label(shell, SWT.NONE).setImage(image);

    new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL)
        .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));

    new Label(shell, SWT.NONE).setText("Painted image\n(multi-res, unzoomed paint)");
    new Label(shell, SWT.NONE)
        .setImage(
            new Image(
                display,
                new ImageDataProvider() {
                  @Override
                  public ImageData getImageData(int zoom) {
                    Image temp = new Image(display, size.x * zoom / 100, size.y * zoom / 100);
                    GC gc = new GC(temp);
                    try {
                      paintImage(gc, size);
                      return temp.getImageData();
                    } finally {
                      gc.dispose();
                      temp.dispose();
                    }
                  }
                }));

    new Label(shell, SWT.SEPARATOR | SWT.HORIZONTAL)
        .setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));

    new Label(shell, SWT.NONE).setText("Painted image\n(multi-res, zoomed paint)");
    new Label(shell, SWT.NONE)
        .setImage(
            new Image(
                display,
                new ImageDataProvider() {
                  @Override
                  public ImageData getImageData(int zoom) {
                    Image temp = new Image(display, size.x * zoom / 100, size.y * zoom / 100);
                    GC gc = new GC(temp);
                    try {
                      paintImage2(
                          gc, new Point(size.x * zoom / 100, size.y * zoom / 100), zoom / 100);
                      return temp.getImageData();
                    } finally {
                      gc.dispose();
                      temp.dispose();
                    }
                  }
                }));

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
  public static boolean test1(String url) {
    if (verbose)
      System.out.println(
          "javascript window.open with location and size parameters - args: "
              + url
              + "\n  Expected Event Sequence: Visibility.show");
    passed = false;

    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());
    final Browser browser = new Browser(shell, SWT.NONE);
    browser.addOpenWindowListener(
        new OpenWindowListener() {
          public void open(WindowEvent event) {
            if (verbose) System.out.println("OpenWindow " + index);
            Shell newShell = new Shell(display);
            newShell.setLayout(new FillLayout());
            Browser browser = new Browser(newShell, SWT.NONE);
            browser.setData("index", new Integer(index));
            browser.addVisibilityWindowListener(
                new VisibilityWindowListener() {
                  public void hide(WindowEvent event) {}

                  public void show(WindowEvent event) {
                    Browser browser = (Browser) event.widget;
                    Shell parent = browser.getShell();
                    Point location = event.location;
                    Point size = event.size;
                    if (location != null) parent.setLocation(location);
                    if (size != null) parent.setSize(size);
                    int index = ((Integer) browser.getData("index")).intValue();
                    parent.setText("SWT Browser shell " + index);
                    parent.open();
                    if (index < 0) {
                      /* Certain browsers fire multiple show events for no good reason. Further show events
                       * are considered 'legal' as long as they don't contain size and location information.
                       */
                      if (location != null || size != null) {
                        if (verbose)
                          System.out.println(
                              "Failure - Browser " + index + " is receiving multiple show events");
                        passed = false;
                        shell.close();
                      } else {
                        if (verbose)
                          System.out.println(
                              "Unnecessary (but harmless) visibility.show event Browser " + index);
                      }
                    } else {
                      if (verbose)
                        System.out.println(
                            "Visibility.show browser "
                                + index
                                + " location "
                                + location
                                + " size "
                                + size);
                      browser.setData("index", new Integer(-100 - index));

                      /* Certain browsers include decorations in addition to the expected size.
                       * Accept sizes that are greater than or equal to the expected size.
                       * Certain browsers invent size or location when some parameters are missing.
                       * If we expect null for one of size or location, also accept non null answers.
                       */
                      Point expectedLocation = regressionBounds[index][0];
                      Point expectedSize = regressionBounds[index][1];
                      if (verbose)
                        System.out.println(
                            "Expected location " + expectedLocation + " size " + expectedSize);
                      boolean checkLocation =
                          (location == null && expectedLocation == null)
                              || (location != null && location.equals(expectedLocation)
                                  || (location != null && expectedLocation == null));
                      boolean checkSize =
                          (size == null && expectedSize == null)
                              || (size != null && size.equals(expectedSize))
                              || (size != null && expectedSize == null)
                              || (size != null
                                  && size.x >= expectedSize.x
                                  && size.y >= expectedSize.y);
                      if (!checkSize || !checkLocation) {
                        if (verbose) System.out.println("	Failure ");
                        passed = false;
                        shell.close();
                        return;
                      } else cntPassed++;
                    }
                  }
                });
            browser.addCloseWindowListener(
                new CloseWindowListener() {
                  public void close(WindowEvent event) {
                    cntClosed++;
                    if (verbose) System.out.println("Close");
                    Browser browser = (Browser) event.widget;
                    browser.getShell().close();
                    if (cntPassed == regressionBounds.length) passed = true;
                    if (cntClosed == regressionBounds.length) {
                      shell.close();
                      return;
                    }
                  }
                });
            event.browser = browser;
            index++;
          }
        });
    shell.open();
    browser.setUrl(url);

    boolean timeout = runLoopTimer(display, shell, 600);
    if (timeout) passed = false;
    display.dispose();
    return passed;
  }
  public static void main(String[] args) {
    final Display display = new Display();
    final Clipboard clipboard = new Clipboard(display);
    final Shell shell = new Shell(display, SWT.SHELL_TRIM);
    shell.setLayout(new GridLayout());
    shell.setText("Clipboard ImageTransfer");

    final Button imageButton = new Button(shell, SWT.NONE);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.minimumHeight = 400;
    gd.minimumWidth = 600;
    imageButton.setLayoutData(gd);

    final Text imageText = new Text(shell, SWT.BORDER);
    imageText.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));

    Composite buttons = new Composite(shell, SWT.NONE);
    buttons.setLayout(new GridLayout(4, true));
    Button button = new Button(buttons, SWT.PUSH);
    button.setText("Open");
    button.addListener(
        SWT.Selection,
        event -> {
          FileDialog dialog = new FileDialog(shell, SWT.OPEN);
          dialog.setText("Open an image file or cancel");
          String string = dialog.open();
          if (string != null) {
            imageButton.setText("");
            Image image = imageButton.getImage();
            if (image != null) image.dispose();
            image = new Image(display, string);
            imageButton.setImage(image);
            imageText.setText(string);
          }
        });

    button = new Button(buttons, SWT.PUSH);
    button.setText("Copy");
    button.addListener(
        SWT.Selection,
        event -> {
          Image image = imageButton.getImage();
          if (image != null) {
            ImageTransfer imageTransfer = ImageTransfer.getInstance();
            TextTransfer textTransfer = TextTransfer.getInstance();
            clipboard.setContents(
                new Object[] {image.getImageData(), imageText.getText()},
                new Transfer[] {imageTransfer, textTransfer});
          }
        });

    button = new Button(buttons, SWT.PUSH);
    button.setText("Paste");
    button.addListener(
        SWT.Selection,
        event -> {
          ImageData imageData = (ImageData) clipboard.getContents(ImageTransfer.getInstance());
          if (imageData != null) {
            imageButton.setText("");
            Image image = imageButton.getImage();
            if (image != null) image.dispose();
            image = new Image(display, imageData);
            imageButton.setImage(image);
          } else {
            imageButton.setText("No image");
            imageButton.setImage(null);
          }
          String text = (String) clipboard.getContents(TextTransfer.getInstance());
          if (text != null) {
            imageText.setText(text);
          } else {
            imageText.setText("");
          }
        });

    button = new Button(buttons, SWT.PUSH);
    button.setText("Clear");
    button.addListener(
        SWT.Selection,
        event -> {
          imageButton.setText("");
          Image image = imageButton.getImage();
          if (image != null) image.dispose();
          imageButton.setImage(null);
          imageText.setText("");
        });

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }