List of usage examples for org.eclipse.jface.resource JFaceResources getFont
public static Font getFont(String symbolicName)
From source file:org.eclipse.ui.console.TextConsole.java
License:Open Source License
/** * Returns the default text font. * * @return the default text font */ private Font getDefaultFont() { return JFaceResources.getFont(JFaceResources.TEXT_FONT); }
From source file:org.eclipse.ui.internal.texteditor.SourceViewerInformationControl.java
License:Open Source License
/** * Creates a source viewer information control with the given shell as * parent. The given shell styles are applied to the created shell. The * given styles are applied to the created styled text widget. The text * widget will be initialized with the given font. The status field will * contain the given text or be hidden.// w w w . j a v a 2 s .c o m * * @param parent the parent shell * @param isResizable <code>true</code> if resizable * @param symbolicFontName the symbolic font name * @param statusFieldText the text to be used in the optional status field * or <code>null</code> if the status field should be hidden */ public SourceViewerInformationControl(Shell parent, boolean isResizable, String symbolicFontName, String statusFieldText) { GridLayout layout; GridData gd; int shellStyle = SWT.TOOL | SWT.ON_TOP | (isResizable ? SWT.RESIZE : 0); int textStyle = isResizable ? SWT.V_SCROLL | SWT.H_SCROLL : SWT.NONE; fShell = new Shell(parent, shellStyle); Display display = fShell.getDisplay(); Composite composite = fShell; layout = new GridLayout(1, false); layout.marginHeight = 0; layout.marginWidth = 0; composite.setLayout(layout); gd = new GridData(GridData.FILL_HORIZONTAL); composite.setLayoutData(gd); if (statusFieldText != null) { composite = new Composite(composite, SWT.NONE); layout = new GridLayout(1, false); layout.marginHeight = 0; layout.marginWidth = 0; composite.setLayout(layout); gd = new GridData(GridData.FILL_BOTH); composite.setLayoutData(gd); composite.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); composite.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); } // Source viewer fViewer = new SourceViewer(composite, null, textStyle); fViewer.configure(new TextSourceViewerConfiguration(EditorsPlugin.getDefault().getPreferenceStore())); fViewer.setEditable(false); fText = fViewer.getTextWidget(); gd = new GridData(GridData.BEGINNING | GridData.FILL_BOTH); fText.setLayoutData(gd); fText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); fText.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); fSymbolicFontName = symbolicFontName; fTextFont = JFaceResources.getFont(symbolicFontName); fText.setFont(fTextFont); fText.addKeyListener(new KeyListener() { public void keyPressed(KeyEvent e) { if (e.character == 0x1B) // ESC fShell.dispose(); } public void keyReleased(KeyEvent e) { } }); // Status field if (statusFieldText != null) { // Horizontal separator line fSeparator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.LINE_DOT); fSeparator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Status field label fStatusField = new Label(composite, SWT.RIGHT); fStatusField.setText(statusFieldText); Font font = fStatusField.getFont(); FontData[] fontDatas = font.getFontData(); for (int i = 0; i < fontDatas.length; i++) fontDatas[i].setHeight(fontDatas[i].getHeight() * 9 / 10); fStatusTextFont = new Font(fStatusField.getDisplay(), fontDatas); fStatusField.setFont(fStatusTextFont); GridData gd2 = new GridData(GridData.FILL_VERTICAL | GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING); fStatusField.setLayoutData(gd2); fStatusTextForegroundColor = new Color(fStatusField.getDisplay(), blend(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND).getRGB(), display.getSystemColor(SWT.COLOR_INFO_FOREGROUND).getRGB(), 0.56f)); fStatusField.setForeground(fStatusTextForegroundColor); fStatusField.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); } addDisposeListener(this); }
From source file:org.eclipse.ui.internal.views.properties.tabbed.view.TabbedPropertyTitle.java
License:Open Source License
/** * Constructor for TabbedPropertyTitle./* w w w . j av a 2 s . com*/ * * @param parent * the parent composite. * @param factory * the widget factory for the tabbed property sheet */ public TabbedPropertyTitle(Composite parent, TabbedPropertySheetWidgetFactory factory) { super(parent, SWT.NO_FOCUS); this.factory = factory; this.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { if (image == null && (text == null || text.equals(BLANK))) { label.setVisible(false); } else { label.setVisible(true); drawTitleBackground(e); } } }); factory.getColors().initializeSectionToolBarColors(); setBackground(factory.getColors().getBackground()); setForeground(factory.getColors().getForeground()); FormLayout layout = new FormLayout(); layout.marginWidth = 1; layout.marginHeight = 2; setLayout(layout); Font font; if (!JFaceResources.getFontRegistry().hasValueFor(TITLE_FONT)) { FontData[] fontData = JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT) .getFontData(); /* title font is 2pt larger than that used in the tabs. */ fontData[0].setHeight(fontData[0].getHeight() + 2); JFaceResources.getFontRegistry().put(TITLE_FONT, fontData); } font = JFaceResources.getFont(TITLE_FONT); label = factory.createCLabel(this, BLANK); label.setBackground(new Color[] { factory.getColors().getColor(IFormColors.H_GRADIENT_END), factory.getColors().getColor(IFormColors.H_GRADIENT_START) }, new int[] { 100 }, true); label.setFont(font); label.setForeground(factory.getColors().getColor(IFormColors.TITLE)); FormData data = new FormData(); data.left = new FormAttachment(0, 0); data.top = new FormAttachment(0, 0); data.right = new FormAttachment(100, 0); data.bottom = new FormAttachment(100, 0); label.setLayoutData(data); /* * setImage(PlatformUI.getWorkbench().getSharedImages().getImage( * ISharedImages.IMG_OBJ_ELEMENT)); */ }
From source file:org.eclipse.ui.tests.decorators.FontDecorator.java
License:Open Source License
/** * Setup the font used by this decorator. */ public static void setUpFont() { font = JFaceResources.getFont(JFaceResources.HEADER_FONT); }
From source file:org.eclipse.ui.tests.layout.constraints.LayoutConstraintsView.java
License:Open Source License
public void createPartControl(Composite parent) { control = parent;/* www . j ava 2 s .c om*/ Composite buttonBar = new Composite(parent, SWT.NONE); { GridDataFactory buttonData = GridDataFactory.fillDefaults().grab(true, false); Button applyButton = new Button(buttonBar, SWT.PUSH); applyButton.setText("Apply"); applyButton.addSelectionListener(new SelectionAdapter() { /* (non-Javadoc) * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) */ public void widgetSelected(SelectionEvent e) { applyPressed(); } }); buttonData.applyTo(applyButton); Button clearButton = new Button(buttonBar, SWT.PUSH); clearButton.setText("Reset"); clearButton.addSelectionListener(new SelectionAdapter() { /* (non-Javadoc) * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) */ public void widgetSelected(SelectionEvent e) { minWidthText.setText(""); maxWidthText.setText(""); quantizedWidthText.setText(""); minHeightText.setText(""); maxHeightText.setText(""); quantizedHeightText.setText(""); fixedAreaText.setText(""); applyPressed(); } }); buttonData.applyTo(clearButton); Button newViewButton = new Button(buttonBar, SWT.PUSH); newViewButton.setText("New View"); newViewButton.addSelectionListener(new SelectionAdapter() { /* (non-Javadoc) * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent) */ public void widgetSelected(SelectionEvent e) { try { getSite().getPage().showView( "org.eclipse.ui.tests.layout.constraints.LayoutConstraintsView", "" + System.currentTimeMillis(), IWorkbenchPage.VIEW_ACTIVATE); } catch (PartInitException e1) { MessageDialog.openError(getSite().getShell(), "Error opening view", "Unable to open view."); } } }); buttonData.applyTo(newViewButton); GridLayoutFactory.fillDefaults().equalWidth(true).numColumns(3).applyTo(buttonBar); } GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(buttonBar); new Label(parent, SWT.NONE).setText("Min Width"); minWidthText = createText(parent); new Label(parent, SWT.NONE).setText("Max Width (blank = unbounded)"); maxWidthText = createText(parent); new Label(parent, SWT.NONE).setText("Quantized Width (blank = none)"); quantizedWidthText = createText(parent); new Label(parent, SWT.NONE).setText("Min Height"); minHeightText = createText(parent); new Label(parent, SWT.NONE).setText("Max Height (blank = unbounded)"); maxHeightText = createText(parent); new Label(parent, SWT.NONE).setText("Quantized Height (blank = none)"); quantizedHeightText = createText(parent); new Label(parent, SWT.NONE).setText("Fixed Area (blank = none"); fixedAreaText = createText(parent); sampleImplementation = new Text(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); sampleImplementation.setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT)); sampleImplementation.setTabs(4); GridDataFactory.fillDefaults().grab(true, true).span(2, 1).applyTo(sampleImplementation); GridLayoutFactory.fillDefaults().numColumns(2).margins(LayoutConstants.getMargins()).generateLayout(parent); applyPressed(); }
From source file:org.eclipse.ui.texteditor.AbstractTextEditor.java
License:Open Source License
/** * Initializes the given viewer's font./*from www . ja v a2 s . co m*/ * * @param viewer the viewer * @since 2.0 */ private void initializeViewerFont(ISourceViewer viewer) { boolean isSharedFont = true; Font font = null; String symbolicFontName = getSymbolicFontName(); if (symbolicFontName != null) font = JFaceResources.getFont(symbolicFontName); else if (fPreferenceStore != null) { // Backward compatibility if (fPreferenceStore.contains(JFaceResources.TEXT_FONT) && !fPreferenceStore.isDefault(JFaceResources.TEXT_FONT)) { FontData data = PreferenceConverter.getFontData(fPreferenceStore, JFaceResources.TEXT_FONT); if (data != null) { isSharedFont = false; font = new Font(viewer.getTextWidget().getDisplay(), data); } } } if (font == null) font = JFaceResources.getTextFont(); if (!font.equals(fSourceViewer.getTextWidget().getFont())) { setFont(viewer, font); disposeFont(); if (!isSharedFont) fFont = font; } else if (!isSharedFont) { font.dispose(); } }
From source file:org.eclipse.ui.texteditor.AbstractTextEditor.java
License:Open Source License
/** * @see org.eclipse.ui.texteditor.ITextEditorExtension5#setBlockSelectionMode(boolean) * @since 3.5/*from w w w . ja v a 2 s. com*/ */ public void setBlockSelectionMode(boolean enable) { if (!isBlockSelectionModeSupported()) return; ISourceViewer viewer = getSourceViewer(); if (viewer != null) { StyledText styledText = viewer.getTextWidget(); if (styledText != null) { /* * Font switching. block selection mode needs a monospace font. * - set the font _before enabling_ block selection mode in order to maintain the * selection * - revert the font _after disabling_ block selection mode in order to maintain the * selection */ if (enable) { Font blockFont = JFaceResources.getFont(BLOCK_SELECTION_MODE_FONT); Font normalFont = styledText.getFont(); if (!blockFont.equals(normalFont) && !normalFont.getFontData()[0].equals(blockFont.getFontData()[0])) { setFont(viewer, blockFont); disposeFont(); updateCaret(); } } styledText.setBlockSelection(enable); if (!enable) { initializeViewerFont(viewer); updateCaret(); } } } }
From source file:org.eclipse.vjet.eclipse.internal.ui.preferences.formatting.JavaPreview.java
License:Open Source License
/** * Create a new Java preview/* w w w .ja v a 2 s . c o m*/ * @param workingValues * @param parent */ public JavaPreview(Map workingValues, Composite parent) { VjoTextTools tools = VjetUIPlugin.getDefault().getTextTools(); fPreviewDocument = new Document(); fWorkingValues = workingValues; tools.setupDocumentPartitioner(fPreviewDocument, IJavaScriptPartitions.JAVA_PARTITIONING); PreferenceStore prioritizedSettings = new PreferenceStore(); prioritizedSettings.setValue(VjetPlugin.COMPILER_SOURCE, VjetPlugin.VERSION_1_5); prioritizedSettings.setValue(VjetPlugin.COMPILER_COMPLIANCE, VjetPlugin.VERSION_1_5); prioritizedSettings.setValue(VjetPlugin.COMPILER_CODEGEN_TARGET_PLATFORM, VjetPlugin.VERSION_1_5); prioritizedSettings.setValue(VjetPlugin.COMPILER_PB_ASSERT_IDENTIFIER, VjetPlugin.ERROR); IPreferenceStore[] chain = { prioritizedSettings, VjetUIPlugin.getDefault().getPreferenceStore(), EditorsUI.getPreferenceStore() }; fPreferenceStore = new ChainedPreferenceStore(chain); fSourceViewer = new JavaSourceViewer(parent, null, null, false, SWT.READ_ONLY | SWT.V_SCROLL | SWT.H_SCROLL | SWT.BORDER, fPreferenceStore); fViewerConfiguration = new SimpleJavascriptSourceViewerConfiguration(tools.getColorManager(), fPreferenceStore, null, IJavaScriptPartitions.JAVA_PARTITIONING, true); fSourceViewer.configure(fViewerConfiguration); fSourceViewer.getTextWidget().setFont(JFaceResources.getFont(JFaceResources.TEXT_FONT)); fMarginPainter = new MarginPainter(fSourceViewer); final RGB rgb = PreferenceConverter.getColor(fPreferenceStore, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_PRINT_MARGIN_COLOR); fMarginPainter.setMarginRulerColor(tools.getColorManager().getColor(rgb)); fSourceViewer.addPainter(fMarginPainter); new JavaSourcePreviewerUpdater(); fSourceViewer.setDocument(fPreviewDocument); }
From source file:org.eclipse.wst.css.ui.internal.preferences.ui.CSSSyntaxColoringPage.java
License:Open Source License
protected Control createContents(final Composite parent) { initializeDialogUnits(parent);//from w w w .ja va2s .c o m fDefaultForeground = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND); fDefaultBackground = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND); Composite pageComponent = createComposite(parent, 2); PlatformUI.getWorkbench().getHelpSystem().setHelp(pageComponent, IHelpContextIds.CSS_PREFWEBX_STYLES_HELPID); Link link = new Link(pageComponent, SWT.WRAP); link.setText(SSEUIMessages.SyntaxColoring_Link); link.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { PreferencesUtil.createPreferenceDialogOn(parent.getShell(), e.text, null, null); } }); GridData linkData = new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1); linkData.widthHint = 150; // only expand further if anyone else requires it link.setLayoutData(linkData); new Label(pageComponent, SWT.NONE).setLayoutData(new GridData()); new Label(pageComponent, SWT.NONE).setLayoutData(new GridData()); SashForm editor = new SashForm(pageComponent, SWT.VERTICAL); GridData gridData2 = new GridData(SWT.FILL, SWT.FILL, true, true); gridData2.horizontalSpan = 2; editor.setLayoutData(gridData2); SashForm top = new SashForm(editor, SWT.HORIZONTAL); Composite styleEditor = createComposite(top, 1); ((GridLayout) styleEditor.getLayout()).marginRight = 5; ((GridLayout) styleEditor.getLayout()).marginLeft = 0; createLabel(styleEditor, CSSUIMessages.SyntaxColoringPage_0); fStylesViewer = createStylesViewer(styleEditor); GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true); gridData.horizontalIndent = 0; Iterator iterator = fStyleToDescriptionMap.values().iterator(); while (iterator.hasNext()) { gridData.widthHint = Math.max(gridData.widthHint, convertWidthInCharsToPixels(iterator.next().toString().length())); } gridData.heightHint = convertHeightInCharsToPixels(5); fStylesViewer.getControl().setLayoutData(gridData); Composite editingComposite = createComposite(top, 1); ((GridLayout) styleEditor.getLayout()).marginLeft = 5; createLabel(editingComposite, ""); Button enabler = createCheckbox(editingComposite, CSSUIMessages.SyntaxColoringPage_2); enabler.setEnabled(false); enabler.setSelection(true); Composite editControls = createComposite(editingComposite, 2); ((GridLayout) editControls.getLayout()).marginLeft = 20; fForegroundLabel = createLabel(editControls, SSEUIMessages.Foreground_UI_); ((GridData) fForegroundLabel.getLayoutData()).verticalAlignment = SWT.CENTER; fForegroundLabel.setEnabled(false); fForegroundColorEditor = new ColorSelector(editControls); Button fForegroundColor = fForegroundColorEditor.getButton(); GridData gd = new GridData(SWT.BEGINNING, SWT.FILL, false, false); fForegroundColor.setLayoutData(gd); fForegroundColorEditor.setEnabled(false); fForegroundColorEditor.getButton().getAccessible().addAccessibleListener(new AccessibleAdapter() { public void getName(final AccessibleEvent e) { e.result = SSEUIMessages.Foreground_Color_Selector_Button; } }); fBackgroundLabel = createLabel(editControls, SSEUIMessages.Background_UI_); ((GridData) fBackgroundLabel.getLayoutData()).verticalAlignment = SWT.CENTER; fBackgroundLabel.setEnabled(false); fBackgroundColorEditor = new ColorSelector(editControls); Button fBackgroundColor = fBackgroundColorEditor.getButton(); gd = new GridData(SWT.BEGINNING, SWT.FILL, false, false); fBackgroundColor.setLayoutData(gd); fBackgroundColorEditor.setEnabled(false); fBackgroundColorEditor.getButton().getAccessible().addAccessibleListener(new AccessibleAdapter() { public void getName(final AccessibleEvent e) { e.result = SSEUIMessages.Background_Color_Selector_Button; } }); fBold = createCheckbox(editControls, CSSUIMessages.SyntaxColoringPage_3); fBold.setEnabled(false); ((GridData) fBold.getLayoutData()).horizontalSpan = 2; fItalic = createCheckbox(editControls, CSSUIMessages.SyntaxColoringPage_4); fItalic.setEnabled(false); ((GridData) fItalic.getLayoutData()).horizontalSpan = 2; fStrike = createCheckbox(editControls, CSSUIMessages.SyntaxColoringPage_5); fStrike.setEnabled(false); ((GridData) fStrike.getLayoutData()).horizontalSpan = 2; fUnderline = createCheckbox(editControls, CSSUIMessages.SyntaxColoringPage_6); fUnderline.setEnabled(false); ((GridData) fUnderline.getLayoutData()).horizontalSpan = 2; fClearStyle = new Button(editingComposite, SWT.PUSH); fClearStyle.setText(SSEUIMessages.Restore_Default_UI_); //$NON-NLS-1$ = "Restore Default" fClearStyle.setLayoutData(new GridData(SWT.BEGINNING)); ((GridData) fClearStyle.getLayoutData()).horizontalIndent = 20; fClearStyle.setEnabled(false); Composite sampleArea = createComposite(editor, 1); ((GridLayout) sampleArea.getLayout()).marginLeft = 5; ((GridLayout) sampleArea.getLayout()).marginTop = 5; createLabel(sampleArea, SSEUIMessages.Sample_text__UI_); //$NON-NLS-1$ = "&Sample text:" fPreviewViewer = new SourceViewer(sampleArea, null, SWT.BORDER | SWT.LEFT_TO_RIGHT | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.READ_ONLY); fText = fPreviewViewer.getTextWidget(); GridData gridData3 = new GridData(SWT.FILL, SWT.FILL, true, true); gridData3.widthHint = convertWidthInCharsToPixels(20); gridData3.heightHint = convertHeightInCharsToPixels(5); gridData3.horizontalSpan = 2; fText.setLayoutData(gridData3); fText.setEditable(false); fText.setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); fText.addKeyListener(getTextKeyListener()); fText.addSelectionListener(getTextSelectionListener()); fText.addMouseListener(getTextMouseListener()); fText.addTraverseListener(getTraverseListener()); setAccessible(fText, SSEUIMessages.Sample_text__UI_); fDocument = StructuredModelManager.getModelManager() .createStructuredDocumentFor(ContentTypeIdForCSS.ContentTypeID_CSS); fDocument.set(getExampleText()); initializeSourcePreviewColors(fPreviewViewer); fPreviewViewer.setDocument(fDocument); top.setWeights(new int[] { 1, 1 }); editor.setWeights(new int[] { 1, 1 }); PlatformUI.getWorkbench().getHelpSystem().setHelp(pageComponent, IHelpContextIds.CSS_PREFWEBX_STYLES_HELPID); fStylesViewer.setInput(getStylePreferenceKeys()); applyStyles(); fStylesViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { if (!event.getSelection().isEmpty()) { Object o = ((IStructuredSelection) event.getSelection()).getFirstElement(); String namedStyle = o.toString(); activate(namedStyle); if (namedStyle == null) return; } } }); fForegroundColorEditor.addListener(new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (event.getProperty().equals(ColorSelector.PROP_COLORCHANGE)) { Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement(); String namedStyle = o.toString(); String prefString = getOverlayStore().getString(namedStyle); String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); if (stylePrefs != null) { String oldValue = stylePrefs[0]; // open color dialog to get new color String newValue = ColorHelper.toRGBString(fForegroundColorEditor.getColorValue()); if (!newValue.equals(oldValue)) { stylePrefs[0] = newValue; String newPrefString = ColorHelper.packStylePreferences(stylePrefs); getOverlayStore().setValue(namedStyle, newPrefString); applyStyles(); fText.redraw(); } } } } }); fBackgroundColorEditor.addListener(new IPropertyChangeListener() { public void propertyChange(PropertyChangeEvent event) { if (event.getProperty().equals(ColorSelector.PROP_COLORCHANGE)) { Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement(); String namedStyle = o.toString(); String prefString = getOverlayStore().getString(namedStyle); String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); if (stylePrefs != null) { String oldValue = stylePrefs[1]; // open color dialog to get new color String newValue = ColorHelper.toRGBString(fBackgroundColorEditor.getColorValue()); if (!newValue.equals(oldValue)) { stylePrefs[1] = newValue; String newPrefString = ColorHelper.packStylePreferences(stylePrefs); getOverlayStore().setValue(namedStyle, newPrefString); applyStyles(); fText.redraw(); activate(namedStyle); } } } } }); fBold.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { super.widgetSelected(e); // get current (newly old) style Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement(); String namedStyle = o.toString(); String prefString = getOverlayStore().getString(namedStyle); String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); if (stylePrefs != null) { String oldValue = stylePrefs[2]; String newValue = String.valueOf(fBold.getSelection()); if (!newValue.equals(oldValue)) { stylePrefs[2] = newValue; String newPrefString = ColorHelper.packStylePreferences(stylePrefs); getOverlayStore().setValue(namedStyle, newPrefString); applyStyles(); fText.redraw(); } } } }); fItalic.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { super.widgetSelected(e); // get current (newly old) style Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement(); String namedStyle = o.toString(); String prefString = getOverlayStore().getString(namedStyle); String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); if (stylePrefs != null) { String oldValue = stylePrefs[3]; String newValue = String.valueOf(fItalic.getSelection()); if (!newValue.equals(oldValue)) { stylePrefs[3] = newValue; String newPrefString = ColorHelper.packStylePreferences(stylePrefs); getOverlayStore().setValue(namedStyle, newPrefString); applyStyles(); fText.redraw(); } } } }); fStrike.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { super.widgetSelected(e); // get current (newly old) style Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement(); String namedStyle = o.toString(); String prefString = getOverlayStore().getString(namedStyle); String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); if (stylePrefs != null) { String oldValue = stylePrefs[4]; String newValue = String.valueOf(fStrike.getSelection()); if (!newValue.equals(oldValue)) { stylePrefs[4] = newValue; String newPrefString = ColorHelper.packStylePreferences(stylePrefs); getOverlayStore().setValue(namedStyle, newPrefString); applyStyles(); fText.redraw(); } } } }); fUnderline.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { super.widgetSelected(e); // get current (newly old) style Object o = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement(); String namedStyle = o.toString(); String prefString = getOverlayStore().getString(namedStyle); String[] stylePrefs = ColorHelper.unpackStylePreferences(prefString); if (stylePrefs != null) { String oldValue = stylePrefs[5]; String newValue = String.valueOf(fUnderline.getSelection()); if (!newValue.equals(oldValue)) { stylePrefs[5] = newValue; String newPrefString = ColorHelper.packStylePreferences(stylePrefs); getOverlayStore().setValue(namedStyle, newPrefString); applyStyles(); fText.redraw(); } } } }); fClearStyle.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { if (fStylesViewer.getSelection().isEmpty()) return; String namedStyle = ((IStructuredSelection) fStylesViewer.getSelection()).getFirstElement() .toString(); getOverlayStore().setToDefault(namedStyle); applyStyles(); fText.redraw(); activate(namedStyle); } }); return pageComponent; }
From source file:org.eclipse.wst.css.ui.internal.preferences.ui.CSSTemplatePreferencePage.java
License:Open Source License
SourceViewer doCreateViewer(Composite parent, SourceViewerConfiguration viewerConfiguration) { SourceViewer viewer = null;/*from www . jav a 2s .c o m*/ String contentTypeID = ContentTypeIdForCSS.ContentTypeID_CSS; viewer = new StructuredTextViewer(parent, null, null, false, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); viewer.getTextWidget().setFont(JFaceResources.getFont("org.eclipse.wst.sse.ui.textfont")); //$NON-NLS-1$ IStructuredModel scratchModel = StructuredModelManager.getModelManager() .createUnManagedStructuredModelFor(contentTypeID); IDocument document = scratchModel.getStructuredDocument(); viewer.configure(viewerConfiguration); viewer.setDocument(document); return viewer; }