Example #1
0
  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setLayout(new RowLayout());

    DateTime calendar = new DateTime(shell, SWT.CALENDAR);
    calendar.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            System.out.println("calendar date changed");
          }
        });

    DateTime time = new DateTime(shell, SWT.TIME);
    time.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            System.out.println("time changed");
          }
        });

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
 public static void main(String[] args) {
   Display display = new Display();
   Shell shell = new Shell(display);
   shell.setLayout(new RowLayout());
   Text text = new Text(shell, SWT.MULTI | SWT.BORDER);
   String modifier = SWT.MOD1 == SWT.CTRL ? "Ctrl" : "Command";
   text.setText("Hit " + modifier + "+Return\nto see\nthe default button\nrun");
   text.addTraverseListener(
       e -> {
         switch (e.detail) {
           case SWT.TRAVERSE_RETURN:
             if ((e.stateMask & SWT.MOD1) != 0) e.doit = true;
         }
       });
   Button button = new Button(shell, SWT.PUSH);
   button.pack();
   button.setText("OK");
   button.addSelectionListener(
       new SelectionAdapter() {
         @Override
         public void widgetSelected(SelectionEvent e) {
           System.out.println("OK selected");
         }
       });
   shell.setDefaultButton(button);
   shell.pack();
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) display.sleep();
   }
   display.dispose();
 }
 /**
  * Opens the dialog and returns the input
  *
  * @return String
  */
 public String open() {
   // Create the dialog window
   Shell shell = new Shell(getParent(), getStyle());
   shell.setText(getText());
   shell.setImage(UIUtils.getImageRegistry().get("sfdc_icon")); // $NON-NLS-1$
   createContents(shell);
   shell.pack();
   shell.open();
   Display display = getParent().getDisplay();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) {
       display.sleep();
     }
   }
   // Return the entered value, or null
   return input;
 }
  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 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();
  }
Example #6
0
  /**
   * Constructor to create an editor to update/create an ontology entry
   *
   * @param display - points back to the display
   * @param oureditOntEntry - the entry being edited
   * @param ontParent - the edited item's parent in the hierarchy
   * @param newItem - true if this is a new item
   */
  public EditOntEntry(
      Display display, OntEntry oureditOntEntry, OntEntry ontParent, boolean newItem) {
    super();
    shell = new Shell(display, SWT.DIALOG_TRIM | SWT.PRIMARY_MODAL);
    shell.setText("OntEntry Information");
    GridLayout gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    gridLayout.marginHeight = 5;
    gridLayout.makeColumnsEqualWidth = true;
    shell.setLayout(gridLayout);

    ourOntEntry = oureditOntEntry;
    ourParent = ontParent;

    if (newItem) {
      ourOntEntry.setName("");
      ourOntEntry.setImportance(Importance.MODERATE);
    }

    new Label(shell, SWT.NONE).setText("Name:");

    nameField = new Text(shell, SWT.SINGLE | SWT.BORDER | SWT.H_SCROLL);
    nameField.setText(ourOntEntry.getName());
    GridData gridData =
        new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    DisplayUtilities.setTextDimensions(nameField, gridData, 75);
    gridData.horizontalSpan = 2;
    nameField.setLayoutData(gridData);

    new Label(shell, SWT.NONE).setText("Description:");

    descArea = new Text(shell, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL);
    descArea.setText(ourOntEntry.getDescription());
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    DisplayUtilities.setTextDimensions(descArea, gridData, 75, 5);
    gridData.horizontalSpan = 2;
    gridData.heightHint = descArea.getLineHeight() * 3;
    descArea.setLayoutData(gridData);

    new Label(shell, SWT.NONE).setText("Importance:");
    importanceBox = new Combo(shell, SWT.DROP_DOWN | SWT.READ_ONLY);
    Enumeration impEnum = Importance.elements();
    int l = 0;
    Importance itype;
    while (impEnum.hasMoreElements()) {
      itype = (Importance) impEnum.nextElement();
      importanceBox.add(itype.toString());
      if (itype.toString().compareTo(ourOntEntry.getImportance().toString()) == 0) {
        importanceBox.select(l);
      }
      l++;
    }
    // Error checking: if no such selection is valid, set it to select index 0
    if (importanceBox.getSelectionIndex() == -1) {
      importanceBox.select(0);
    }
    importanceBox.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    new Label(shell, SWT.NONE).setText(" ");
    new Label(shell, SWT.NONE).setText(" ");

    addButton = new Button(shell, SWT.PUSH);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    addButton.setLayoutData(gridData);
    if (newItem) {
      addButton.setText("Add");
      addButton.addSelectionListener(
          new SelectionAdapter() {

            public void widgetSelected(SelectionEvent event) {
              canceled = false;
              if (!nameField.getText().trim().equals("")) {
                ConsistencyChecker checker =
                    new ConsistencyChecker(ourOntEntry.getID(), nameField.getText(), "OntEntries");

                if (ourOntEntry.getName() == nameField.getText() || checker.check()) {
                  ourParent.addChild(ourOntEntry);
                  ourOntEntry.setLevel(ourParent.getLevel() + 1);
                  ourOntEntry.setName(nameField.getText());
                  ourOntEntry.setDescription(descArea.getText());
                  ourOntEntry.setImportance(
                      Importance.fromString(
                          importanceBox.getItem(importanceBox.getSelectionIndex())));

                  // comment before this made no sense...
                  ourOntEntry.setID(ourOntEntry.toDatabase(ourParent.getID()));
                  System.out.println("Name of added item = " + ourOntEntry.getName());

                  shell.close();
                  shell.dispose();
                }
              } else {
                MessageBox mbox = new MessageBox(shell, SWT.ICON_ERROR);
                mbox.setMessage("Need to provide the OntEntry name");
                mbox.open();
              }
            }
          });

    } else {
      addButton.setText("Save");
      addButton.addSelectionListener(
          new SelectionAdapter() {

            public void widgetSelected(SelectionEvent event) {
              canceled = false;

              ConsistencyChecker checker =
                  new ConsistencyChecker(ourOntEntry.getID(), nameField.getText(), "OntEntries");

              if (ourOntEntry.getName() == nameField.getText() || checker.check()) {
                ourOntEntry.setName(nameField.getText());
                ourOntEntry.setDescription(descArea.getText());
                ourOntEntry.setImportance(
                    Importance.fromString(
                        importanceBox.getItem(importanceBox.getSelectionIndex())));
                // since this is a save, not an add, the type and parent are ignored
                ourOntEntry.setID(ourOntEntry.toDatabase(0));

                //			RationaleDB db = RationaleDB.getHandle();
                //			db.addOntEntry(ourOntEntry);

                shell.close();
                shell.dispose();
              }
            }
          });
    }

    cancelButton = new Button(shell, SWT.PUSH);
    cancelButton.setText("Cancel");
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_BEGINNING);
    cancelButton.setLayoutData(gridData);
    cancelButton.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(SelectionEvent event) {
            canceled = true;
            shell.close();
            shell.dispose();
          }
        });

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