コード例 #1
0
ファイル: DialogTab.java プロジェクト: andreyvit/yoursway-swt
  /** Creates the "Control" group. */
  void createControlGroup() {
    /*
     * Create the "Control" group.  This is the group on the
     * right half of each example tab.  It consists of the
     * style group, the display group and the size group.
     */
    controlGroup = new Group(tabFolderPage, SWT.NONE);
    GridLayout gridLayout = new GridLayout();
    controlGroup.setLayout(gridLayout);
    gridLayout.numColumns = 2;
    gridLayout.makeColumnsEqualWidth = true;
    controlGroup.setLayoutData(
        new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
    controlGroup.setText(ControlExample.getResourceString("Parameters"));

    /*
     * Create a group to hold the dialog style combo box and
     * create dialog button.
     */
    dialogStyleGroup = new Group(controlGroup, SWT.NONE);
    dialogStyleGroup.setLayout(new GridLayout());
    GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
    gridData.horizontalSpan = 2;
    dialogStyleGroup.setLayoutData(gridData);
    dialogStyleGroup.setText(ControlExample.getResourceString("Dialog_Type"));
  }
コード例 #2
0
ファイル: AlignableTab.java プロジェクト: abego/java2script
  /** Creates the "Control" group. */
  void createControlGroup() {
    super.createControlGroup();

    /* Create the group */
    alignmentGroup = new Group(controlGroup, SWT.NONE);
    alignmentGroup.setLayout(new GridLayout());
    alignmentGroup.setLayoutData(
        new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
    alignmentGroup.setText(ControlExample.getResourceString("Alignment"));

    /* Create the controls */
    leftButton = new Button(alignmentGroup, SWT.RADIO);
    leftButton.setText(ControlExample.getResourceString("Left"));
    centerButton = new Button(alignmentGroup, SWT.RADIO);
    centerButton.setText(ControlExample.getResourceString("Center"));
    rightButton = new Button(alignmentGroup, SWT.RADIO);
    rightButton.setText(ControlExample.getResourceString("Right"));

    /* Add the listeners */
    SelectionListener selectionListener =
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent event) {
            if (!((Button) event.widget).getSelection()) return;
            setExampleWidgetAlignment();
          }
        };
    leftButton.addSelectionListener(selectionListener);
    centerButton.addSelectionListener(selectionListener);
    rightButton.addSelectionListener(selectionListener);
  }
コード例 #3
0
ファイル: DialogTab.java プロジェクト: andreyvit/yoursway-swt
  /**
   * Handle a dialog type combo selection event.
   *
   * @param event the selection event
   */
  void dialogSelected(SelectionEvent event) {

    /* Enable/Disable the buttons */
    String name = dialogCombo.getText();
    boolean isMessageBox = name.equals(ControlExample.getResourceString("MessageBox"));
    boolean isFileDialog = name.equals(ControlExample.getResourceString("FileDialog"));
    okButton.setEnabled(isMessageBox);
    cancelButton.setEnabled(isMessageBox);
    yesButton.setEnabled(isMessageBox);
    noButton.setEnabled(isMessageBox);
    retryButton.setEnabled(isMessageBox);
    abortButton.setEnabled(isMessageBox);
    ignoreButton.setEnabled(isMessageBox);
    iconErrorButton.setEnabled(isMessageBox);
    iconInformationButton.setEnabled(isMessageBox);
    iconQuestionButton.setEnabled(isMessageBox);
    iconWarningButton.setEnabled(isMessageBox);
    iconWorkingButton.setEnabled(isMessageBox);
    noIconButton.setEnabled(isMessageBox);
    saveButton.setEnabled(isFileDialog);
    openButton.setEnabled(isFileDialog);
    multiButton.setEnabled(isFileDialog);

    /* Unselect the buttons */
    if (!isMessageBox) {
      okButton.setSelection(false);
      cancelButton.setSelection(false);
      yesButton.setSelection(false);
      noButton.setSelection(false);
      retryButton.setSelection(false);
      abortButton.setSelection(false);
      ignoreButton.setSelection(false);
    }
  }
コード例 #4
0
 /** 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
ファイル: CanvasTab.java プロジェクト: abego/java2script
  /** Creates the "Other" group. */
  void createOtherGroup() {
    super.createOtherGroup();

    /* Create display controls specific to this example */
    caretButton = new Button(otherGroup, SWT.CHECK);
    caretButton.setText(ControlExample.getResourceString("Caret"));
    fillDamageButton = new Button(otherGroup, SWT.CHECK);
    fillDamageButton.setText(ControlExample.getResourceString("FillDamage"));

    /* Add the listeners */
    caretButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent event) {
            setCaret();
          }
        });
  }
コード例 #6
0
  /** Creates the "Example" widgets. */
  void createExampleWidgets() {

    /* Compute the widget style */
    int style = getDefaultStyle();
    if (topButton.getSelection()) style |= SWT.TOP;
    if (bottomButton.getSelection()) style |= SWT.BOTTOM;
    if (borderButton.getSelection()) style |= SWT.BORDER;

    /* Create the example widgets */
    tabFolder1 = new TabFolder(tabFolderGroup, style);
    for (int i = 0; i < TabItems1.length; i++) {
      TabItem item = new TabItem(tabFolder1, SWT.NONE);
      item.setText(TabItems1[i]);
      item.setToolTipText(ControlExample.getResourceString("Tooltip", new String[] {TabItems1[i]}));
      Text content = new Text(tabFolder1, SWT.WRAP | SWT.MULTI);
      content.setText(ControlExample.getResourceString("TabItem_content") + ": " + i);
      item.setControl(content);
    }
  }
コード例 #7
0
ファイル: DialogTab.java プロジェクト: andreyvit/yoursway-swt
  /** Creates the "Example" group. */
  void createExampleGroup() {
    super.createExampleGroup();
    exampleGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    /*
     * Create a group for the text widget to display
     * the results returned by the example dialogs.
     */
    resultGroup = new Group(exampleGroup, SWT.NONE);
    resultGroup.setLayout(new GridLayout());
    resultGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    resultGroup.setText(ControlExample.getResourceString("Dialog_Result"));
  }
コード例 #8
0
ファイル: DialogTab.java プロジェクト: andreyvit/yoursway-swt
  /**
   * 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);
    }
  }
コード例 #9
0
ファイル: DialogTab.java プロジェクト: andreyvit/yoursway-swt
  /** Creates the "Control" widget children. */
  void createControlWidgets() {

    /* Create the combo */
    String[] strings = {
      ControlExample.getResourceString("ColorDialog"),
      ControlExample.getResourceString("DirectoryDialog"),
      ControlExample.getResourceString("FileDialog"),
      ControlExample.getResourceString("FontDialog"),
      ControlExample.getResourceString("PrintDialog"),
      ControlExample.getResourceString("MessageBox"),
    };
    dialogCombo = new Combo(dialogStyleGroup, SWT.READ_ONLY);
    dialogCombo.setItems(strings);
    dialogCombo.setText(strings[0]);
    dialogCombo.setVisibleItemCount(strings.length);

    /* Create the create dialog button */
    createButton = new Button(dialogStyleGroup, SWT.NONE);
    createButton.setText(ControlExample.getResourceString("Create_Dialog"));
    createButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));

    /* Create a group for the various dialog button style controls */
    Group buttonStyleGroup = new Group(controlGroup, SWT.NONE);
    buttonStyleGroup.setLayout(new GridLayout());
    buttonStyleGroup.setLayoutData(
        new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
    buttonStyleGroup.setText(ControlExample.getResourceString("Button_Styles"));

    /* Create the button style buttons */
    okButton = new Button(buttonStyleGroup, SWT.CHECK);
    okButton.setText("SWT.OK");
    cancelButton = new Button(buttonStyleGroup, SWT.CHECK);
    cancelButton.setText("SWT.CANCEL");
    yesButton = new Button(buttonStyleGroup, SWT.CHECK);
    yesButton.setText("SWT.YES");
    noButton = new Button(buttonStyleGroup, SWT.CHECK);
    noButton.setText("SWT.NO");
    retryButton = new Button(buttonStyleGroup, SWT.CHECK);
    retryButton.setText("SWT.RETRY");
    abortButton = new Button(buttonStyleGroup, SWT.CHECK);
    abortButton.setText("SWT.ABORT");
    ignoreButton = new Button(buttonStyleGroup, SWT.CHECK);
    ignoreButton.setText("SWT.IGNORE");

    /* Create a group for the icon style controls */
    Group iconStyleGroup = new Group(controlGroup, SWT.NONE);
    iconStyleGroup.setLayout(new GridLayout());
    iconStyleGroup.setLayoutData(
        new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
    iconStyleGroup.setText(ControlExample.getResourceString("Icon_Styles"));

    /* Create the icon style buttons */
    iconErrorButton = new Button(iconStyleGroup, SWT.RADIO);
    iconErrorButton.setText("SWT.ICON_ERROR");
    iconInformationButton = new Button(iconStyleGroup, SWT.RADIO);
    iconInformationButton.setText("SWT.ICON_INFORMATION");
    iconQuestionButton = new Button(iconStyleGroup, SWT.RADIO);
    iconQuestionButton.setText("SWT.ICON_QUESTION");
    iconWarningButton = new Button(iconStyleGroup, SWT.RADIO);
    iconWarningButton.setText("SWT.ICON_WARNING");
    iconWorkingButton = new Button(iconStyleGroup, SWT.RADIO);
    iconWorkingButton.setText("SWT.ICON_WORKING");
    noIconButton = new Button(iconStyleGroup, SWT.RADIO);
    noIconButton.setText(ControlExample.getResourceString("No_Icon"));

    /* Create a group for the modal style controls */
    Group modalStyleGroup = new Group(controlGroup, SWT.NONE);
    modalStyleGroup.setLayout(new GridLayout());
    modalStyleGroup.setLayoutData(
        new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
    modalStyleGroup.setText(ControlExample.getResourceString("Modal_Styles"));

    /* Create the modal style buttons */
    primaryModalButton = new Button(modalStyleGroup, SWT.RADIO);
    primaryModalButton.setText("SWT.PRIMARY_MODAL");
    applicationModalButton = new Button(modalStyleGroup, SWT.RADIO);
    applicationModalButton.setText("SWT.APPLICATION_MODAL");
    systemModalButton = new Button(modalStyleGroup, SWT.RADIO);
    systemModalButton.setText("SWT.SYSTEM_MODAL");

    /* Create a group for the file dialog style controls */
    Group fileDialogStyleGroup = new Group(controlGroup, SWT.NONE);
    fileDialogStyleGroup.setLayout(new GridLayout());
    fileDialogStyleGroup.setLayoutData(
        new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
    fileDialogStyleGroup.setText(ControlExample.getResourceString("File_Dialog_Styles"));

    /* Create the file dialog style buttons */
    openButton = new Button(fileDialogStyleGroup, SWT.RADIO);
    openButton.setText("SWT.OPEN");
    saveButton = new Button(fileDialogStyleGroup, SWT.RADIO);
    saveButton.setText("SWT.SAVE");
    multiButton = new Button(fileDialogStyleGroup, SWT.CHECK);
    multiButton.setText("SWT.MULTI");

    /* Create the orientation group */
    if (RTL_SUPPORT_ENABLE) {
      createOrientationGroup();
    }

    /* Add the listeners */
    dialogCombo.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent event) {
            dialogSelected(event);
          }
        });
    createButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent event) {
            createButtonSelected(event);
          }
        });
    SelectionListener buttonStyleListener =
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent event) {
            buttonStyleSelected(event);
          }
        };
    okButton.addSelectionListener(buttonStyleListener);
    cancelButton.addSelectionListener(buttonStyleListener);
    yesButton.addSelectionListener(buttonStyleListener);
    noButton.addSelectionListener(buttonStyleListener);
    retryButton.addSelectionListener(buttonStyleListener);
    abortButton.addSelectionListener(buttonStyleListener);
    ignoreButton.addSelectionListener(buttonStyleListener);

    /* Set default values for style buttons */
    okButton.setEnabled(false);
    cancelButton.setEnabled(false);
    yesButton.setEnabled(false);
    noButton.setEnabled(false);
    retryButton.setEnabled(false);
    abortButton.setEnabled(false);
    ignoreButton.setEnabled(false);
    iconErrorButton.setEnabled(false);
    iconInformationButton.setEnabled(false);
    iconQuestionButton.setEnabled(false);
    iconWarningButton.setEnabled(false);
    iconWorkingButton.setEnabled(false);
    noIconButton.setEnabled(false);
    saveButton.setEnabled(false);
    openButton.setEnabled(false);
    openButton.setSelection(true);
    multiButton.setEnabled(false);
    noIconButton.setSelection(true);
  }
コード例 #10
0
ファイル: DialogTab.java プロジェクト: andreyvit/yoursway-swt
class DialogTab extends Tab {
  /* Example widgets and groups that contain them */
  Group dialogStyleGroup, resultGroup;
  Text textWidget;

  /* Style widgets added to the "Style" group */
  Combo dialogCombo;
  Button createButton;
  Button okButton, cancelButton;
  Button yesButton, noButton;
  Button retryButton;
  Button abortButton, ignoreButton;
  Button iconErrorButton, iconInformationButton, iconQuestionButton;
  Button iconWarningButton, iconWorkingButton, noIconButton;
  Button primaryModalButton, applicationModalButton, systemModalButton;
  Button saveButton, openButton, multiButton;

  static String[] FilterExtensions = {"*.txt", "*.bat", "*.doc", "*"};
  static String[] FilterNames = {
    ControlExample.getResourceString("FilterName_0"),
    ControlExample.getResourceString("FilterName_1"),
    ControlExample.getResourceString("FilterName_2"),
    ControlExample.getResourceString("FilterName_3")
  };

  /** Creates the Tab within a given instance of ControlExample. */
  DialogTab(ControlExample instance) {
    super(instance);
  }

  /**
   * 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));
  }

  /**
   * 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);
    }
  }

  /** Creates the "Control" group. */
  void createControlGroup() {
    /*
     * Create the "Control" group.  This is the group on the
     * right half of each example tab.  It consists of the
     * style group, the display group and the size group.
     */
    controlGroup = new Group(tabFolderPage, SWT.NONE);
    GridLayout gridLayout = new GridLayout();
    controlGroup.setLayout(gridLayout);
    gridLayout.numColumns = 2;
    gridLayout.makeColumnsEqualWidth = true;
    controlGroup.setLayoutData(
        new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
    controlGroup.setText(ControlExample.getResourceString("Parameters"));

    /*
     * Create a group to hold the dialog style combo box and
     * create dialog button.
     */
    dialogStyleGroup = new Group(controlGroup, SWT.NONE);
    dialogStyleGroup.setLayout(new GridLayout());
    GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_CENTER);
    gridData.horizontalSpan = 2;
    dialogStyleGroup.setLayoutData(gridData);
    dialogStyleGroup.setText(ControlExample.getResourceString("Dialog_Type"));
  }

  /** Creates the "Control" widget children. */
  void createControlWidgets() {

    /* Create the combo */
    String[] strings = {
      ControlExample.getResourceString("ColorDialog"),
      ControlExample.getResourceString("DirectoryDialog"),
      ControlExample.getResourceString("FileDialog"),
      ControlExample.getResourceString("FontDialog"),
      ControlExample.getResourceString("PrintDialog"),
      ControlExample.getResourceString("MessageBox"),
    };
    dialogCombo = new Combo(dialogStyleGroup, SWT.READ_ONLY);
    dialogCombo.setItems(strings);
    dialogCombo.setText(strings[0]);
    dialogCombo.setVisibleItemCount(strings.length);

    /* Create the create dialog button */
    createButton = new Button(dialogStyleGroup, SWT.NONE);
    createButton.setText(ControlExample.getResourceString("Create_Dialog"));
    createButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));

    /* Create a group for the various dialog button style controls */
    Group buttonStyleGroup = new Group(controlGroup, SWT.NONE);
    buttonStyleGroup.setLayout(new GridLayout());
    buttonStyleGroup.setLayoutData(
        new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
    buttonStyleGroup.setText(ControlExample.getResourceString("Button_Styles"));

    /* Create the button style buttons */
    okButton = new Button(buttonStyleGroup, SWT.CHECK);
    okButton.setText("SWT.OK");
    cancelButton = new Button(buttonStyleGroup, SWT.CHECK);
    cancelButton.setText("SWT.CANCEL");
    yesButton = new Button(buttonStyleGroup, SWT.CHECK);
    yesButton.setText("SWT.YES");
    noButton = new Button(buttonStyleGroup, SWT.CHECK);
    noButton.setText("SWT.NO");
    retryButton = new Button(buttonStyleGroup, SWT.CHECK);
    retryButton.setText("SWT.RETRY");
    abortButton = new Button(buttonStyleGroup, SWT.CHECK);
    abortButton.setText("SWT.ABORT");
    ignoreButton = new Button(buttonStyleGroup, SWT.CHECK);
    ignoreButton.setText("SWT.IGNORE");

    /* Create a group for the icon style controls */
    Group iconStyleGroup = new Group(controlGroup, SWT.NONE);
    iconStyleGroup.setLayout(new GridLayout());
    iconStyleGroup.setLayoutData(
        new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
    iconStyleGroup.setText(ControlExample.getResourceString("Icon_Styles"));

    /* Create the icon style buttons */
    iconErrorButton = new Button(iconStyleGroup, SWT.RADIO);
    iconErrorButton.setText("SWT.ICON_ERROR");
    iconInformationButton = new Button(iconStyleGroup, SWT.RADIO);
    iconInformationButton.setText("SWT.ICON_INFORMATION");
    iconQuestionButton = new Button(iconStyleGroup, SWT.RADIO);
    iconQuestionButton.setText("SWT.ICON_QUESTION");
    iconWarningButton = new Button(iconStyleGroup, SWT.RADIO);
    iconWarningButton.setText("SWT.ICON_WARNING");
    iconWorkingButton = new Button(iconStyleGroup, SWT.RADIO);
    iconWorkingButton.setText("SWT.ICON_WORKING");
    noIconButton = new Button(iconStyleGroup, SWT.RADIO);
    noIconButton.setText(ControlExample.getResourceString("No_Icon"));

    /* Create a group for the modal style controls */
    Group modalStyleGroup = new Group(controlGroup, SWT.NONE);
    modalStyleGroup.setLayout(new GridLayout());
    modalStyleGroup.setLayoutData(
        new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
    modalStyleGroup.setText(ControlExample.getResourceString("Modal_Styles"));

    /* Create the modal style buttons */
    primaryModalButton = new Button(modalStyleGroup, SWT.RADIO);
    primaryModalButton.setText("SWT.PRIMARY_MODAL");
    applicationModalButton = new Button(modalStyleGroup, SWT.RADIO);
    applicationModalButton.setText("SWT.APPLICATION_MODAL");
    systemModalButton = new Button(modalStyleGroup, SWT.RADIO);
    systemModalButton.setText("SWT.SYSTEM_MODAL");

    /* Create a group for the file dialog style controls */
    Group fileDialogStyleGroup = new Group(controlGroup, SWT.NONE);
    fileDialogStyleGroup.setLayout(new GridLayout());
    fileDialogStyleGroup.setLayoutData(
        new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));
    fileDialogStyleGroup.setText(ControlExample.getResourceString("File_Dialog_Styles"));

    /* Create the file dialog style buttons */
    openButton = new Button(fileDialogStyleGroup, SWT.RADIO);
    openButton.setText("SWT.OPEN");
    saveButton = new Button(fileDialogStyleGroup, SWT.RADIO);
    saveButton.setText("SWT.SAVE");
    multiButton = new Button(fileDialogStyleGroup, SWT.CHECK);
    multiButton.setText("SWT.MULTI");

    /* Create the orientation group */
    if (RTL_SUPPORT_ENABLE) {
      createOrientationGroup();
    }

    /* Add the listeners */
    dialogCombo.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent event) {
            dialogSelected(event);
          }
        });
    createButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent event) {
            createButtonSelected(event);
          }
        });
    SelectionListener buttonStyleListener =
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent event) {
            buttonStyleSelected(event);
          }
        };
    okButton.addSelectionListener(buttonStyleListener);
    cancelButton.addSelectionListener(buttonStyleListener);
    yesButton.addSelectionListener(buttonStyleListener);
    noButton.addSelectionListener(buttonStyleListener);
    retryButton.addSelectionListener(buttonStyleListener);
    abortButton.addSelectionListener(buttonStyleListener);
    ignoreButton.addSelectionListener(buttonStyleListener);

    /* Set default values for style buttons */
    okButton.setEnabled(false);
    cancelButton.setEnabled(false);
    yesButton.setEnabled(false);
    noButton.setEnabled(false);
    retryButton.setEnabled(false);
    abortButton.setEnabled(false);
    ignoreButton.setEnabled(false);
    iconErrorButton.setEnabled(false);
    iconInformationButton.setEnabled(false);
    iconQuestionButton.setEnabled(false);
    iconWarningButton.setEnabled(false);
    iconWorkingButton.setEnabled(false);
    noIconButton.setEnabled(false);
    saveButton.setEnabled(false);
    openButton.setEnabled(false);
    openButton.setSelection(true);
    multiButton.setEnabled(false);
    noIconButton.setSelection(true);
  }

  /** Creates the "Example" group. */
  void createExampleGroup() {
    super.createExampleGroup();
    exampleGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    /*
     * Create a group for the text widget to display
     * the results returned by the example dialogs.
     */
    resultGroup = new Group(exampleGroup, SWT.NONE);
    resultGroup.setLayout(new GridLayout());
    resultGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    resultGroup.setText(ControlExample.getResourceString("Dialog_Result"));
  }

  /** Creates the "Example" widgets. */
  void createExampleWidgets() {
    /*
     * Create a multi lined, scrolled text widget for output.
     */
    textWidget = new Text(resultGroup, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    GridData gridData = new GridData(GridData.FILL_BOTH);
    textWidget.setLayoutData(gridData);
  }

  /** The platform dialogs do not have SWT listeners. */
  void createListenersGroup() {}

  /**
   * Handle a dialog type combo selection event.
   *
   * @param event the selection event
   */
  void dialogSelected(SelectionEvent event) {

    /* Enable/Disable the buttons */
    String name = dialogCombo.getText();
    boolean isMessageBox = name.equals(ControlExample.getResourceString("MessageBox"));
    boolean isFileDialog = name.equals(ControlExample.getResourceString("FileDialog"));
    okButton.setEnabled(isMessageBox);
    cancelButton.setEnabled(isMessageBox);
    yesButton.setEnabled(isMessageBox);
    noButton.setEnabled(isMessageBox);
    retryButton.setEnabled(isMessageBox);
    abortButton.setEnabled(isMessageBox);
    ignoreButton.setEnabled(isMessageBox);
    iconErrorButton.setEnabled(isMessageBox);
    iconInformationButton.setEnabled(isMessageBox);
    iconQuestionButton.setEnabled(isMessageBox);
    iconWarningButton.setEnabled(isMessageBox);
    iconWorkingButton.setEnabled(isMessageBox);
    noIconButton.setEnabled(isMessageBox);
    saveButton.setEnabled(isFileDialog);
    openButton.setEnabled(isFileDialog);
    multiButton.setEnabled(isFileDialog);

    /* Unselect the buttons */
    if (!isMessageBox) {
      okButton.setSelection(false);
      cancelButton.setSelection(false);
      yesButton.setSelection(false);
      noButton.setSelection(false);
      retryButton.setSelection(false);
      abortButton.setSelection(false);
      ignoreButton.setSelection(false);
    }
  }

  /** Gets the "Example" widget children. */
  Widget[] getExampleWidgets() {
    return new Widget[0];
  }

  /** Gets the text for the tab folder item. */
  String getTabText() {
    return "Dialog";
  }

  /** Recreates the "Example" widgets. */
  void recreateExampleWidgets() {
    if (textWidget == null) {
      super.recreateExampleWidgets();
    }
  }
}
コード例 #11
0
 @Override
 protected final void createUI(Composite parent) {
   shell.setText(ControlExample.getResourceString("custom.window.title"));
   new CustomControlExample(shell);
 }
コード例 #12
0
class TabFolderTab extends Tab {
  /* Example widgets and groups that contain them */
  TabFolder tabFolder1;
  Group tabFolderGroup;

  /* Style widgets added to the "Style" group */
  Button topButton, bottomButton;

  static String[] TabItems1 = {
    ControlExample.getResourceString("TabItem1_0"),
    ControlExample.getResourceString("TabItem1_1"),
    ControlExample.getResourceString("TabItem1_2")
  };

  /** Creates the Tab within a given instance of ControlExample. */
  TabFolderTab(ControlExample instance) {
    super(instance);
  }

  /** Creates the "Example" group. */
  void createExampleGroup() {
    super.createExampleGroup();

    /* Create a group for the TabFolder */
    tabFolderGroup = new Group(exampleGroup, SWT.NONE);
    tabFolderGroup.setLayout(new GridLayout());
    tabFolderGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    tabFolderGroup.setText("TabFolder");
  }

  /** Creates the "Example" widgets. */
  void createExampleWidgets() {

    /* Compute the widget style */
    int style = getDefaultStyle();
    if (topButton.getSelection()) style |= SWT.TOP;
    if (bottomButton.getSelection()) style |= SWT.BOTTOM;
    if (borderButton.getSelection()) style |= SWT.BORDER;

    /* Create the example widgets */
    tabFolder1 = new TabFolder(tabFolderGroup, style);
    for (int i = 0; i < TabItems1.length; i++) {
      TabItem item = new TabItem(tabFolder1, SWT.NONE);
      item.setText(TabItems1[i]);
      item.setToolTipText(ControlExample.getResourceString("Tooltip", new String[] {TabItems1[i]}));
      Text content = new Text(tabFolder1, SWT.WRAP | SWT.MULTI);
      content.setText(ControlExample.getResourceString("TabItem_content") + ": " + i);
      item.setControl(content);
    }
  }

  /** Creates the "Style" group. */
  void createStyleGroup() {
    super.createStyleGroup();

    /* Create the extra widgets */
    topButton = new Button(styleGroup, SWT.RADIO);
    topButton.setText("SWT.TOP");
    topButton.setSelection(true);
    bottomButton = new Button(styleGroup, SWT.RADIO);
    bottomButton.setText("SWT.BOTTOM");
    borderButton = new Button(styleGroup, SWT.CHECK);
    borderButton.setText("SWT.BORDER");
  }

  /**
   * Gets the "Example" widget children's items, if any.
   *
   * @return an array containing the example widget children's items
   */
  Item[] getExampleWidgetItems() {
    return tabFolder1.getItems();
  }

  /** Gets the "Example" widget children. */
  Widget[] getExampleWidgets() {
    return new Widget[] {tabFolder1};
  }

  /**
   * Returns a list of set/get API method names (without the set/get prefix) that can be used to
   * set/get values in the example control(s).
   */
  String[] getMethodNames() {
    return new String[] {"Selection", "SelectionIndex", "ToolTipText"};
  }

  String setMethodName(String methodRoot) {
    /* Override to handle special case of int getSelectionIndex()/setSelection(int) */
    return (methodRoot.equals("SelectionIndex")) ? "setSelection" : "set" + methodRoot;
  }

  Object[] parameterForType(String typeName, String value, Widget widget) {
    if (value.equals("")) return new Object[] {new TabItem[0]};
    if (typeName.equals("org.eclipse.swt.widgets.TabItem")) {
      TabItem item = findItem(value, ((TabFolder) widget).getItems());
      if (item != null) return new Object[] {item};
    }
    if (typeName.equals("[Lorg.eclipse.swt.widgets.TabItem;")) {
      String[] values = split(value, ',');
      TabItem[] items = new TabItem[values.length];
      for (int i = 0; i < values.length; i++) {
        items[i] = findItem(values[i], ((TabFolder) widget).getItems());
      }
      return new Object[] {items};
    }
    return super.parameterForType(typeName, value, widget);
  }

  TabItem findItem(String value, TabItem[] items) {
    for (int i = 0; i < items.length; i++) {
      TabItem item = items[i];
      if (item.getText().equals(value)) return item;
    }
    return null;
  }

  /** Gets the short text for the tab folder item. */
  String getShortTabText() {
    return "TF";
  }

  /** Gets the text for the tab folder item. */
  String getTabText() {
    return "TabFolder";
  }

  /** Sets the state of the "Example" widgets. */
  void setExampleWidgetState() {
    super.setExampleWidgetState();
    topButton.setSelection((tabFolder1.getStyle() & SWT.TOP) != 0);
    bottomButton.setSelection((tabFolder1.getStyle() & SWT.BOTTOM) != 0);
    borderButton.setSelection((tabFolder1.getStyle() & SWT.BORDER) != 0);
  }
}