Exemple #1
0
  public static void main(String[] args) {
    LoggerContext loggerContext = new LoggerContext();
    Display display = new Display();
    ResourceUtil.init(display);
    Shell shell = new Shell(display);
    final Tree tree = new Tree(shell, SWT.BORDER);
    Rectangle clientArea = shell.getClientArea();
    tree.setBounds(clientArea.x, clientArea.y, 200, 200);

    LoggerTree loggerTree = new LoggerTree(loggerContext, tree);
    tree.setMenu(TreeMenuBuilder.buildTreeMenu(loggerTree, null));
    loggerTree.update("com.foo.Bar");
    loggerTree.update("com.foo.Bar");

    loggerContext.getLogger("org.apache.struts").setLevel(Level.ERROR);

    loggerTree.update("org.apache.struts.BlahAction");

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
Exemple #2
0
 void layout() {
   Rectangle rect = shell.getClientArea();
   // String[] strings = new String[objects.length];
   int width = 0;
   String[] items = list.getItems();
   GC gc = new GC(list);
   for (int i = 0; i < objects.length; i++) {
     width = Math.max(width, gc.stringExtent(items[i]).x);
   }
   gc.dispose();
   Point size1 = start.computeSize(SWT.DEFAULT, SWT.DEFAULT);
   Point size2 = stop.computeSize(SWT.DEFAULT, SWT.DEFAULT);
   Point size3 = check.computeSize(SWT.DEFAULT, SWT.DEFAULT);
   Point size4 = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
   width = Math.max(size1.x, Math.max(size2.x, Math.max(size3.x, width)));
   width = Math.max(64, Math.max(size4.x, list.computeSize(width, SWT.DEFAULT).x));
   start.setBounds(0, 0, width, size1.y);
   stop.setBounds(0, size1.y, width, size2.y);
   check.setBounds(0, size1.y + size2.y, width, size3.y);
   label.setBounds(0, rect.height - size4.y, width, size4.y);
   int height = size1.y + size2.y + size3.y;
   list.setBounds(0, height, width, rect.height - height - size4.y);
   text.setBounds(width, 0, rect.width - width, rect.height);
   canvas.setBounds(width, 0, rect.width - width, rect.height);
 }
 public static void main(String[] args) {
   Display display = new Display();
   Shell shell = new Shell(display);
   Slider slider = new Slider(shell, SWT.HORIZONTAL);
   Rectangle clientArea = shell.getClientArea();
   slider.setBounds(clientArea.x + 10, clientArea.y + 10, 200, 32);
   slider.addListener(
       SWT.Selection,
       event -> {
         String string = "SWT.NONE";
         switch (event.detail) {
           case SWT.DRAG:
             string = "SWT.DRAG";
             break;
           case SWT.HOME:
             string = "SWT.HOME";
             break;
           case SWT.END:
             string = "SWT.END";
             break;
           case SWT.ARROW_DOWN:
             string = "SWT.ARROW_DOWN";
             break;
           case SWT.ARROW_UP:
             string = "SWT.ARROW_UP";
             break;
           case SWT.PAGE_DOWN:
             string = "SWT.PAGE_DOWN";
             break;
           case SWT.PAGE_UP:
             string = "SWT.PAGE_UP";
             break;
         }
         System.out.println("Scroll detail -> " + string);
       });
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   display.dispose();
 }
  protected PresentationTestbed createPresentation(
      AbstractPresentationFactory factory, int type, int numParts) {
    TestPresentablePart selection = null;
    PresentationTestbed testBed = new PresentationTestbed(theShell, factory, type);
    for (int partCount = 0; partCount < numParts; partCount++) {
      TestPresentablePart part = new TestPresentablePart(theShell, img);
      part.setName("Some part");
      part.setContentDescription("Description");
      part.setTitle("Some title");
      part.setDirty(partCount % 2 == 0);
      part.setTooltip("This is a tooltip");
      testBed.add(part);
      selection = part;
    }

    testBed.setSelection(selection);

    Control ctrl = testBed.getControl();
    ctrl.setBounds(theShell.getClientArea());
    return testBed;
  }
 public static void main(String[] args) {
   Display display = new Display();
   Shell shell = new Shell(display);
   final Table table = new Table(shell, SWT.BORDER | SWT.MULTI);
   Rectangle clientArea = shell.getClientArea();
   table.setBounds(clientArea.x, clientArea.y, 200, 200);
   for (int i = 0; i < 128; i++) {
     TableItem item = new TableItem(table, SWT.NONE);
     item.setText("Item " + i);
   }
   Menu menu = new Menu(shell, SWT.POP_UP);
   table.setMenu(menu);
   MenuItem item = new MenuItem(menu, SWT.PUSH);
   item.setText("Delete Selection");
   item.addListener(SWT.Selection, event -> table.remove(table.getSelectionIndices()));
   shell.pack();
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   display.dispose();
 }
  private static Image takeScreenshot(final Display display, final Shell parent) {
    /* Take the screen shot */
    GC gc = new GC(parent);
    Image image = new Image(display, parent.getClientArea());
    gc.copyArea(image, 0, 0);
    GC gcImage = new GC(image);
    gcImage.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
    gcImage.setAdvanced(true);
    Region region = parent.getRegion();

    data = image.getImageData();
    if (region != null) {
      int height = image.getBounds().height;
      int width = image.getBounds().width;
      byte[] alphaData = new byte[height * width];
      int currentPosition = 0;
      for (int i = 0; i < height; i++) {
        for (int j = 0; j < width; j++) {
          if (!region.contains(j, i)) {
            gcImage.drawPoint(j, i);
            alphaData[currentPosition] = 0;
          } else {
            alphaData[currentPosition] = (byte) 255;
          }
          currentPosition++;
        }
      }
      data.alphaData = alphaData;
    }

    image.dispose();
    gcImage.dispose();
    gc.dispose();

    return new Image(display, data);
  }
Exemple #7
0
 private void resizeToContents() {
   int frameX = shell.getSize().x - shell.getClientArea().width;
   int frameY = shell.getSize().y - shell.getClientArea().height;
   shell.setSize(displayModel.getSize().width + frameX, displayModel.getSize().height + frameY);
 }