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