Esempio n. 1
0
  /**
   * Handle a button style selection event.
   *
   * @param event the selection event
   */
  void buttonStyleSelected(SelectionEvent event) {
    /*
     * Only certain combinations of button styles are
     * supported for various dialogs.  Make sure the
     * control widget reflects only valid combinations.
     */
    boolean ok = okButton.getSelection();
    boolean cancel = cancelButton.getSelection();
    boolean yes = yesButton.getSelection();
    boolean no = noButton.getSelection();
    boolean abort = abortButton.getSelection();
    boolean retry = retryButton.getSelection();
    boolean ignore = ignoreButton.getSelection();

    okButton.setEnabled(!(yes || no || retry || abort || ignore));
    cancelButton.setEnabled(!(abort || ignore || (yes != no)));
    yesButton.setEnabled(!(ok || retry || abort || ignore || (cancel && !yes && !no)));
    noButton.setEnabled(!(ok || retry || abort || ignore || (cancel && !yes && !no)));
    retryButton.setEnabled(!(ok || yes || no));
    abortButton.setEnabled(!(ok || cancel || yes || no));
    ignoreButton.setEnabled(!(ok || cancel || yes || no));

    createButton.setEnabled(
        !(ok || cancel || yes || no || retry || abort || ignore)
            || ok
            || (ok && cancel)
            || (yes && no)
            || (yes && no && cancel)
            || (retry && cancel)
            || (abort && retry && ignore));
  }
Esempio n. 2
0
  /** Creates the "Example" widgets. */
  void createExampleWidgets() {

    /* Compute the widget style */
    int style = getDefaultStyle();
    if (horizontalButton.getSelection()) style |= SWT.H_SCROLL;
    if (verticalButton.getSelection()) style |= SWT.V_SCROLL;
    if (borderButton.getSelection()) style |= SWT.BORDER;
    if (noBackgroundButton.getSelection()) style |= SWT.NO_BACKGROUND;
    if (noFocusButton.getSelection()) style |= SWT.NO_FOCUS;
    if (noMergePaintsButton.getSelection()) style |= SWT.NO_MERGE_PAINTS;
    if (noRedrawResizeButton.getSelection()) style |= SWT.NO_REDRAW_RESIZE;

    /* Create the example widgets */
    paintCount = 0;
    cx = 0;
    cy = 0;
    canvas = new Canvas(canvasGroup, style);
    canvas.addPaintListener(
        new PaintListener() {
          public void paintControl(PaintEvent e) {
            paintCount++;
            GC gc = e.gc;
            if (fillDamageButton.getSelection()) {
              Color color = e.display.getSystemColor(colors[paintCount % colors.length]);
              gc.setBackground(color);
              gc.fillRectangle(e.x, e.y, e.width, e.height);
            }
            Point size = canvas.getSize();
            gc.drawArc(cx + 1, cy + 1, size.x - 2, size.y - 2, 0, 360);
            gc.drawRectangle(cx + (size.x - 10) / 2, cy + (size.y - 10) / 2, 10, 10);
          }
        });
    canvas.addControlListener(
        new ControlAdapter() {
          public void controlResized(ControlEvent event) {
            Point size = canvas.getSize();
            maxX = size.x * 3 / 2;
            maxY = size.y * 3 / 2;
            resizeScrollBars();
          }
        });
    ScrollBar bar = canvas.getHorizontalBar();
    if (bar != null) {
      bar.addSelectionListener(
          new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
              scrollHorizontal((ScrollBar) event.widget);
            }
          });
    }
    bar = canvas.getVerticalBar();
    if (bar != null) {
      bar.addSelectionListener(
          new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
              scrollVertical((ScrollBar) event.widget);
            }
          });
    }
  }
Esempio n. 3
0
 /** Sets or clears the caret in the "Example" widget. */
 void setCaret() {
   Caret oldCaret = canvas.getCaret();
   if (caretButton.getSelection()) {
     Caret newCaret = new Caret(canvas, SWT.NONE);
     Font font = canvas.getFont();
     newCaret.setFont(font);
     GC gc = new GC(canvas);
     gc.setFont(font);
     newCaret.setBounds(1, 1, 1, gc.getFontMetrics().getHeight());
     gc.dispose();
     canvas.setCaret(newCaret);
     canvas.setFocus();
   } else {
     canvas.setCaret(null);
   }
   if (oldCaret != null) oldCaret.dispose();
 }
Esempio n. 4
0
 protected int getStyle() {
   int result = SWT.NONE;
   Control[] ctrls = styleComp.getChildren();
   if (ctrls.length == 0) {
     result = defaultStyle;
   } else {
     for (int i = 0; i < ctrls.length; i++) {
       if (ctrls[i] instanceof Button) {
         Button button = (Button) ctrls[i];
         if (button.getSelection()) {
           Object data = button.getData("style");
           if (data instanceof Integer) {
             int style = ((Integer) data).intValue();
             result |= style;
           }
         }
       }
     }
   }
   return result;
 }
Esempio n. 5
0
  /**
   * Handle the create button selection event.
   *
   * @param event org.eclipse.swt.events.SelectionEvent
   */
  void createButtonSelected(SelectionEvent event) {

    /* Compute the appropriate dialog style */
    int style = getDefaultStyle();
    if (okButton.getEnabled() && okButton.getSelection()) style |= SWT.OK;
    if (cancelButton.getEnabled() && cancelButton.getSelection()) style |= SWT.CANCEL;
    if (yesButton.getEnabled() && yesButton.getSelection()) style |= SWT.YES;
    if (noButton.getEnabled() && noButton.getSelection()) style |= SWT.NO;
    if (retryButton.getEnabled() && retryButton.getSelection()) style |= SWT.RETRY;
    if (abortButton.getEnabled() && abortButton.getSelection()) style |= SWT.ABORT;
    if (ignoreButton.getEnabled() && ignoreButton.getSelection()) style |= SWT.IGNORE;
    if (iconErrorButton.getEnabled() && iconErrorButton.getSelection()) style |= SWT.ICON_ERROR;
    if (iconInformationButton.getEnabled() && iconInformationButton.getSelection())
      style |= SWT.ICON_INFORMATION;
    if (iconQuestionButton.getEnabled() && iconQuestionButton.getSelection())
      style |= SWT.ICON_QUESTION;
    if (iconWarningButton.getEnabled() && iconWarningButton.getSelection())
      style |= SWT.ICON_WARNING;
    if (iconWorkingButton.getEnabled() && iconWorkingButton.getSelection())
      style |= SWT.ICON_WORKING;
    if (primaryModalButton.getEnabled() && primaryModalButton.getSelection())
      style |= SWT.PRIMARY_MODAL;
    if (applicationModalButton.getEnabled() && applicationModalButton.getSelection())
      style |= SWT.APPLICATION_MODAL;
    if (systemModalButton.getEnabled() && systemModalButton.getSelection())
      style |= SWT.SYSTEM_MODAL;
    if (saveButton.getEnabled() && saveButton.getSelection()) style |= SWT.SAVE;
    if (openButton.getEnabled() && openButton.getSelection()) style |= SWT.OPEN;
    if (multiButton.getEnabled() && multiButton.getSelection()) style |= SWT.MULTI;

    /* Open the appropriate dialog type */
    String name = dialogCombo.getText();

    if (name.equals(ControlExample.getResourceString("ColorDialog"))) {
      ColorDialog dialog = new ColorDialog(shell, style);
      dialog.setRGB(new RGB(100, 100, 100));
      dialog.setText(ControlExample.getResourceString("Title"));
      RGB result = dialog.open();
      textWidget.append(ControlExample.getResourceString("ColorDialog") + Text.DELIMITER);
      textWidget.append(
          ControlExample.getResourceString("Result", new String[] {"" + result}) + Text.DELIMITER);
      textWidget.append("getRGB() = " + dialog.getRGB() + Text.DELIMITER + Text.DELIMITER);
      return;
    }

    if (name.equals(ControlExample.getResourceString("DirectoryDialog"))) {
      DirectoryDialog dialog = new DirectoryDialog(shell, style);
      dialog.setMessage(ControlExample.getResourceString("Example_string"));
      dialog.setText(ControlExample.getResourceString("Title"));
      String result = dialog.open();
      textWidget.append(ControlExample.getResourceString("DirectoryDialog") + Text.DELIMITER);
      textWidget.append(
          ControlExample.getResourceString("Result", new String[] {"" + result})
              + Text.DELIMITER
              + Text.DELIMITER);
      return;
    }

    if (name.equals(ControlExample.getResourceString("FileDialog"))) {
      FileDialog dialog = new FileDialog(shell, style);
      dialog.setFileName(ControlExample.getResourceString("readme_txt"));
      dialog.setFilterNames(FilterNames);
      dialog.setFilterExtensions(FilterExtensions);
      dialog.setText(ControlExample.getResourceString("Title"));
      String result = dialog.open();
      textWidget.append(ControlExample.getResourceString("FileDialog") + Text.DELIMITER);
      textWidget.append(
          ControlExample.getResourceString("Result", new String[] {"" + result}) + Text.DELIMITER);
      textWidget.append("getFileNames() =" + Text.DELIMITER);
      if ((dialog.getStyle() & SWT.MULTI) != 0) {
        String[] files = dialog.getFileNames();
        for (int i = 0; i < files.length; i++) {
          textWidget.append("\t" + files[i] + Text.DELIMITER);
        }
      }
      textWidget.append(
          "getFilterIndex() = " + dialog.getFilterIndex() + Text.DELIMITER + Text.DELIMITER);
      return;
    }

    if (name.equals(ControlExample.getResourceString("FontDialog"))) {
      FontDialog dialog = new FontDialog(shell, style);
      dialog.setText(ControlExample.getResourceString("Title"));
      FontData result = dialog.open();
      textWidget.append(ControlExample.getResourceString("FontDialog") + Text.DELIMITER);
      textWidget.append(
          ControlExample.getResourceString("Result", new String[] {"" + result}) + Text.DELIMITER);
      textWidget.append("getFontList() =" + Text.DELIMITER);
      FontData[] fonts = dialog.getFontList();
      if (fonts != null) {
        for (int i = 0; i < fonts.length; i++) {
          textWidget.append("\t" + fonts[i] + Text.DELIMITER);
        }
      }
      textWidget.append("getRGB() = " + dialog.getRGB() + Text.DELIMITER + Text.DELIMITER);
      return;
    }

    if (name.equals(ControlExample.getResourceString("PrintDialog"))) {
      PrintDialog dialog = new PrintDialog(shell, style);
      dialog.setText(ControlExample.getResourceString("Title"));
      PrinterData result = dialog.open();
      textWidget.append(ControlExample.getResourceString("PrintDialog") + Text.DELIMITER);
      textWidget.append(
          ControlExample.getResourceString("Result", new String[] {"" + result}) + Text.DELIMITER);
      textWidget.append("getScope() = " + dialog.getScope() + Text.DELIMITER);
      textWidget.append("getStartPage() = " + dialog.getStartPage() + Text.DELIMITER);
      textWidget.append("getEndPage() = " + dialog.getEndPage() + Text.DELIMITER);
      textWidget.append(
          "getPrintToFile() = " + dialog.getPrintToFile() + Text.DELIMITER + Text.DELIMITER);
      return;
    }

    if (name.equals(ControlExample.getResourceString("MessageBox"))) {
      MessageBox dialog = new MessageBox(shell, style);
      dialog.setMessage(ControlExample.getResourceString("Example_string"));
      dialog.setText(ControlExample.getResourceString("Title"));
      int result = dialog.open();
      textWidget.append(ControlExample.getResourceString("MessageBox") + Text.DELIMITER);
      /*
       * The resulting integer depends on the original
       * dialog style.  Decode the result and display it.
       */
      switch (result) {
        case SWT.OK:
          textWidget.append(ControlExample.getResourceString("Result", new String[] {"SWT.OK"}));
          break;
        case SWT.YES:
          textWidget.append(ControlExample.getResourceString("Result", new String[] {"SWT.YES"}));
          break;
        case SWT.NO:
          textWidget.append(ControlExample.getResourceString("Result", new String[] {"SWT.NO"}));
          break;
        case SWT.CANCEL:
          textWidget.append(
              ControlExample.getResourceString("Result", new String[] {"SWT.CANCEL"}));
          break;
        case SWT.ABORT:
          textWidget.append(ControlExample.getResourceString("Result", new String[] {"SWT.ABORT"}));
          break;
        case SWT.RETRY:
          textWidget.append(ControlExample.getResourceString("Result", new String[] {"SWT.RETRY"}));
          break;
        case SWT.IGNORE:
          textWidget.append(
              ControlExample.getResourceString("Result", new String[] {"SWT.IGNORE"}));
          break;
        default:
          textWidget.append(ControlExample.getResourceString("Result", new String[] {"" + result}));
          break;
      }
      textWidget.append(Text.DELIMITER + Text.DELIMITER);
    }
  }