/** 사용자 폰트를 설정합니다. */
 private void setFontData() {
   FontDialog fd = new FontDialog(getShell(), SWT.NONE);
   FontData fdFont = fd.open();
   if (fdFont != null) {
     lblUserFont.setText(fdFont.getName() + "|" + fdFont.getHeight() + "|" + fdFont.getStyle());
   }
 }
Пример #2
0
 /** Sets the font related data to be applied to the text in page 2. */
 void setFont() {
   FontDialog fontDialog = new FontDialog(getSite().getShell());
   fontDialog.setFontList(text.getFont().getFontData());
   FontData fontData = fontDialog.open();
   if (fontData != null) {
     if (font != null) font.dispose();
     font = new Font(text.getDisplay(), fontData);
     text.setFont(font);
   }
 }
 /* (non-Javadoc)
  * @see org.eclipse.jface.viewers.DialogCellEditor#openDialogBox(org.eclipse.swt.widgets.Control)
  */
 protected Object openDialogBox(Control cellEditorWindow) {
   FontDialog dialog = new FontDialog(cellEditorWindow.getShell());
   dialog.setText(MessageUtil.getString("FontDialogTitle"));
   if (getValue() != null) {
     FontData[] oldFont = new FontData[] {new FontData(getValue().toString(), 12, SWT.NORMAL)};
     dialog.setFontList(oldFont);
   }
   FontData fontData = dialog.open();
   if (fontData != null) return fontData.getName();
   return "";
 }
Пример #4
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);
    }
  }
Пример #5
0
  @Override
  public void widgetSelected(SelectionEvent e) {
    Object source = e.getSource();
    boolean updateQuickly = true;

    // Tabs
    if (source == mImageRadio) {
      chooseForegroundTab((Button) source, mImageForm);
    } else if (source == mClipartRadio) {
      chooseForegroundTab((Button) source, mClipartForm);
    } else if (source == mTextRadio) {
      updateFontLabel(mFontButton.getFont());
      chooseForegroundTab((Button) source, mTextForm);
      mText.setFocus();
    }

    // Choose image file
    if (source == mPickImageButton) {
      FileDialog dialog = new FileDialog(mPickImageButton.getShell(), SWT.OPEN);
      String file = dialog.open();
      if (file != null) {
        mImagePathText.setText(file);
      }
    }

    // Enforce Radio Groups
    if (source == mCropRadio) {
      mCropRadio.setSelection(true); // Ensure that you can't toggle it off
      mCenterRadio.setSelection(false);
    } else if (source == mCenterRadio) {
      mCenterRadio.setSelection(true);
      mCropRadio.setSelection(false);
    }
    if (source == mSquareRadio) {
      mSquareRadio.setSelection(true);
      mCircleButton.setSelection(false);
    } else if (source == mCircleButton) {
      mCircleButton.setSelection(true);
      mSquareRadio.setSelection(false);
    }

    if (SUPPORT_LAUNCHER_ICON_TYPES) {
      if (source == mSimpleRadio) {
        mSimpleRadio.setSelection(true);
        mGlossyRadio.setSelection(false);
        mFancyRadio.setSelection(false);
      } else if (source == mFancyRadio) {
        mFancyRadio.setSelection(true);
        mSimpleRadio.setSelection(false);
        mGlossyRadio.setSelection(false);
      } else if (source == mGlossyRadio) {
        mGlossyRadio.setSelection(true);
        mSimpleRadio.setSelection(false);
        mFancyRadio.setSelection(false);
      }
    }

    if (source == mHoloDarkRadio) {
      mHoloDarkRadio.setSelection(true);
      mHoloLightRadio.setSelection(false);
    } else if (source == mHoloLightRadio) {
      mHoloLightRadio.setSelection(true);
      mHoloDarkRadio.setSelection(false);
    }

    if (source == mChooseClipart) {
      MessageDialog dialog =
          new MessageDialog(
              mChooseClipart.getShell(),
              "Choose Clip Art",
              null,
              "Choose Clip Art Image:",
              MessageDialog.NONE,
              new String[] {"Close"},
              0) {
            @Override
            protected Control createCustomArea(Composite parent) {
              // Outer form which just establishes a width for the inner form which
              // wraps in a RowLayout
              Composite outer = new Composite(parent, SWT.NONE);
              GridLayout gridLayout = new GridLayout();
              outer.setLayout(gridLayout);

              Composite chooserForm = new Composite(outer, SWT.NONE);
              GridData gd = new GridData();
              gd.grabExcessVerticalSpace = true;
              gd.widthHint = 450;
              chooserForm.setLayoutData(gd);
              RowLayout clipartFormLayout = new RowLayout(SWT.HORIZONTAL);
              clipartFormLayout.center = true;
              clipartFormLayout.wrap = true;
              chooserForm.setLayout(clipartFormLayout);

              MouseAdapter clickListener =
                  new MouseAdapter() {
                    @SuppressWarnings("unused")
                    @Override
                    public void mouseDown(MouseEvent event) {
                      // Clicked on some of the sample art
                      if (event.widget instanceof ImageControl) {
                        ImageControl image = (ImageControl) event.widget;
                        mSelectedClipart = (String) image.getData();
                        close();

                        for (Control c : mClipartPreviewPanel.getChildren()) {
                          c.dispose();
                        }
                        if (mClipartPreviewPanel.getChildren().length == 0) {
                          try {
                            BufferedImage icon = GraphicGenerator.getClipartIcon(mSelectedClipart);
                            if (icon != null) {
                              Display display = mClipartForm.getDisplay();
                              Image swtImage = SwtUtils.convertToSwt(display, icon, true, -1);
                              new ImageControl(mClipartPreviewPanel, SWT.NONE, swtImage);
                            }
                          } catch (IOException e1) {
                            AdtPlugin.log(e1, null);
                          }
                          mClipartPreviewPanel.pack();
                          mClipartPreviewPanel.layout();
                        }

                        updatePreview();
                      }
                    }
                  };
              Display display = chooserForm.getDisplay();
              Color hoverColor = display.getSystemColor(SWT.COLOR_RED);
              Iterator<String> clipartImages = GraphicGenerator.getClipartNames();
              while (clipartImages.hasNext()) {
                String name = clipartImages.next();
                try {
                  BufferedImage icon = GraphicGenerator.getClipartIcon(name);
                  if (icon != null) {
                    Image swtImage = SwtUtils.convertToSwt(display, icon, true, -1);
                    ImageControl img = new ImageControl(chooserForm, SWT.NONE, swtImage);
                    img.setData(name);
                    img.setHoverColor(hoverColor);
                    img.addMouseListener(clickListener);
                  }
                } catch (IOException e1) {
                  AdtPlugin.log(e1, null);
                }
              }
              outer.pack();
              outer.layout();
              return outer;
            }
          };
      dialog.open();
    }

    if (source == mBgButton) {
      ColorDialog dlg = new ColorDialog(mBgButton.getShell());
      dlg.setRGB(mBgColor);
      dlg.setText("Choose a new Background Color");
      RGB rgb = dlg.open();
      if (rgb != null) {
        // Dispose the old color, create the
        // new one, and set into the label
        updateColor(mBgButton.getDisplay(), rgb, true /*background*/);
      }
    } else if (source == mFgButton) {
      ColorDialog dlg = new ColorDialog(mFgButton.getShell());
      dlg.setRGB(mFgColor);
      dlg.setText("Choose a new Foreground Color");
      RGB rgb = dlg.open();
      if (rgb != null) {
        // Dispose the old color, create the
        // new one, and set into the label
        updateColor(mFgButton.getDisplay(), rgb, false /*background*/);
      }
    }

    if (source == mFontButton) {
      FontDialog dialog = new FontDialog(mFontButton.getShell());
      FontData[] fontList;
      if (mFontButton.getData() == null) {
        fontList = mFontButton.getDisplay().getFontList("Helvetica", true /*scalable*/);
      } else {
        fontList = mFontButton.getFont().getFontData();
      }
      dialog.setFontList(fontList);
      FontData data = dialog.open();
      if (data != null) {
        Font font = new Font(mFontButton.getDisplay(), dialog.getFontList());
        mFontButton.setFont(font);
        updateFontLabel(font);
        mFontButton.getParent().pack();
        // Mark the font on the button as custom (since the renderer needs to
        // distinguish between this font and the default font it starts out with)
        mFontButton.setData(Boolean.TRUE);
      }
    }

    if (source == mPaddingSlider) {
      mPercentLabel.setText(Integer.toString(getPadding()) + '%');

      // When dragging the slider, only do periodic updates
      updateQuickly = false;
    }

    requestUpdatePreview(updateQuickly);
  }
Пример #6
0
 protected void showFontDialog() {
   FontDialog dialog = new FontDialog(getShell(), SWT.SHELL_TRIM);
   FontData result = dialog.open();
   messageBoxDlgResLabel.setText("Result: " + result + " / " + dialog.getRGB());
   messageBoxDlgResLabel.pack();
 }