Java Code Examples for org.eclipse.swt.custom.StyledText#setForeground()
The following examples show how to use
org.eclipse.swt.custom.StyledText#setForeground() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RenameRefactoringPopup.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
protected void createContent(Composite parent) { Display display = parent.getDisplay(); ColorRegistry registry = JFaceResources.getColorRegistry(); Color foreground= registry.get("org.eclipse.ui.workbench.HOVER_FOREGROUND"); //$NON-NLS-1$ if (foreground == null) { foreground = display.getSystemColor(SWT.COLOR_INFO_FOREGROUND); } Color background= registry.get("org.eclipse.ui.workbench.HOVER_BACKGROUND"); //$NON-NLS-1$ if (background == null) { background = display.getSystemColor(SWT.COLOR_INFO_BACKGROUND); } StyledText hint = new StyledText(popup, SWT.READ_ONLY | SWT.SINGLE); String enterKeyName = getEnterBinding(); String hintTemplate = "Enter new name, press {0} to refactor"; hint.setText(Messages.format(hintTemplate, enterKeyName)); hint.setForeground(foreground); hint.setStyleRange(new StyleRange(hintTemplate.indexOf("{0}"), enterKeyName.length(), null, null, SWT.BOLD)); //$NON-NLS-1$ hint.setEnabled(false); // text must not be selectable addViewMenu(parent); recursiveSetBackgroundColor(parent, background); }
Example 2
Source File: PythonSourceViewer.java From Pydev with Eclipse Public License 1.0 | 6 votes |
/** * Updates the given viewer's colors to match the preferences. */ public void updateViewerColors() { IPreferenceStore store = getPreferenceStore(); if (store != null) { StyledText styledText = getTextWidget(); if (styledText == null || styledText.isDisposed()) { return; } Color color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT) ? null : createColor(store, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, styledText.getDisplay()); styledText.setForeground(color); if (getForegroundColor() != null) { getForegroundColor().dispose(); } setForegroundColor(color); color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT) ? null : createColor(store, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, styledText.getDisplay()); styledText.setBackground(color); if (getBackgroundColor() != null) { getBackgroundColor().dispose(); } setBackgroundColor(color); } }
Example 3
Source File: StyledTextCellEditor.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
/** * 初始化默认颜色、字体等 * @param textControl * ; */ private void initStyle(final StyledText textControl, IStyle cellStyle) { // textControl.setBackground(cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR)); textControl.setBackground(GUIHelper.getColor(210, 210, 240)); textControl.setForeground(cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR)); textControl.setLineSpacing(Constants.SEGMENT_LINE_SPACING); textControl.setLeftMargin(Constants.SEGMENT_LEFT_MARGIN); textControl.setRightMargin(Constants.SEGMENT_RIGHT_MARGIN); textControl.setTopMargin(Constants.SEGMENT_TOP_MARGIN); textControl.setBottomMargin(Constants.SEGMENT_TOP_MARGIN); // textControl.setLeftMargin(0); // textControl.setRightMargin(0); // textControl.setTopMargin(0); // textControl.setBottomMargin(0); textControl.setFont(JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.XLIFF_EDITOR_TEXT_FONT)); textControl.setIME(new IME(textControl, SWT.NONE)); }
Example 4
Source File: RenameInformationPopup.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
private void createContent(Composite parent) { Display display= parent.getDisplay(); Color foreground= display.getSystemColor(SWT.COLOR_INFO_FOREGROUND); Color background= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND); addMoveSupport(fPopup, parent); StyledText hint= new StyledText(fPopup, SWT.READ_ONLY | SWT.SINGLE); String enterKeyName= getEnterBinding(); String hintTemplate= ReorgMessages.RenameInformationPopup_EnterNewName; hint.setText(Messages.format(hintTemplate, enterKeyName)); hint.setForeground(foreground); hint.setStyleRange(new StyleRange(hintTemplate.indexOf("{0}"), enterKeyName.length(), null, null, SWT.BOLD)); //$NON-NLS-1$ hint.setEnabled(false); // text must not be selectable addMoveSupport(fPopup, hint); addViewMenu(parent); recursiveSetBackgroundColor(parent, background); }
Example 5
Source File: RenameInformationPopup.java From typescript.java with MIT License | 6 votes |
private void createContent(Composite parent) { Display display= parent.getDisplay(); Color foreground= display.getSystemColor(SWT.COLOR_INFO_FOREGROUND); Color background= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND); addMoveSupport(fPopup, parent); StyledText hint= new StyledText(fPopup, SWT.READ_ONLY | SWT.SINGLE); hint.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false)); String enterKeyName= getEnterBinding(); String hintTemplate= RefactoringMessages.RenameInformationPopup_EnterNewName; hint.setText(NLS.bind(hintTemplate, enterKeyName)); hint.setForeground(foreground); hint.setStyleRange(new StyleRange(hintTemplate.indexOf("{0}"), enterKeyName.length(), null, null, SWT.BOLD)); //$NON-NLS-1$ hint.setEnabled(false); // text must not be selectable addMoveSupport(fPopup, hint); addLink(parent); addViewMenu(parent); recursiveSetBackgroundColor(parent, background); }
Example 6
Source File: ParamView.java From http4e with Apache License 2.0 | 6 votes |
void setEditable( boolean editable){ StyledText st = (StyledText) textView.getControl(); if (editable) { // bodyText.setFont(ResourceUtils.getFont(Styles.FONT_COURIER)); st.setForeground(ResourceUtils.getColor(Styles.GRAY_RGB_TEXT)); st.setBackground(ResourceUtils.getColor(Styles.BACKGROUND_ENABLED)); st.setEditable(true); attachManager.setEnabled(true); } else { // bodyText.setFont(ResourceUtils.getFont(Styles.FONT_COURIER)); st.setForeground(ResourceUtils.getColor(Styles.LIGHT_RGB_TEXT)); st.setBackground(ResourceUtils.getColor(Styles.PINK_DISABLED)); st.setEditable(false); attachManager.setEnabled(false); } }
Example 7
Source File: StyledTextCellEditor.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
/** * 初始化默认颜色、字体等 * @param textControl * ; */ private void initStyle(final StyledText textControl, IStyle cellStyle) { // textControl.setBackground(cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR)); textControl.setBackground(GUIHelper.getColor(210, 210, 240)); textControl.setForeground(cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR)); textControl.setLineSpacing(Constants.SEGMENT_LINE_SPACING); textControl.setLeftMargin(Constants.SEGMENT_LEFT_MARGIN); textControl.setRightMargin(Constants.SEGMENT_RIGHT_MARGIN); textControl.setTopMargin(Constants.SEGMENT_TOP_MARGIN); textControl.setBottomMargin(Constants.SEGMENT_TOP_MARGIN); // textControl.setLeftMargin(0); // textControl.setRightMargin(0); // textControl.setTopMargin(0); // textControl.setBottomMargin(0); textControl.setFont(JFaceResources.getFont(net.heartsome.cat.ts.ui.Constants.XLIFF_EDITOR_TEXT_FONT)); textControl.setIME(new IME(textControl, SWT.NONE)); }
Example 8
Source File: CellEditor.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
@Override protected Control activateCell(Composite parent, Object originalCanonicalValue, Character initialEditValue) { if (originalCanonicalValue == null || !(originalCanonicalValue instanceof CellEditorCanonicalValue)) { return null; } StyledText textControl = createTextControl(parent); // init style IStyle cellStyle = getCellStyle(); textControl.setBackground(GUIHelper.getColor(210, 210, 240)); textControl.setForeground(cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR)); //textControl.setFont(cellStyle.getAttributeValue(CellStyleAttributes.FONT)); textControl.setLineSpacing(TmxEditorConstanst.SEGMENT_LINE_SPACING); textControl.setLeftMargin(TmxEditorConstanst.SEGMENT_LEFT_MARGIN); textControl.setRightMargin(TmxEditorConstanst.SEGMENT_RIGHT_MARGIN); textControl.setTopMargin(TmxEditorConstanst.SEGMENT_TOP_MARGIN); textControl.setBottomMargin(TmxEditorConstanst.SEGMENT_TOP_MARGIN); textControl.setIME(new IME(textControl, SWT.NONE)); setCanonicalValue(originalCanonicalValue); textControl.forceFocus(); return textControl; }
Example 9
Source File: Notifier.java From nebula with Eclipse Public License 2.0 | 6 votes |
/** * Creates the text part of the window * * @param shell the window * @param text the text * @param colors the color set */ private static void createText(final Shell shell, final String text, final NotifierColors colors) { final StyledText textLabel = new StyledText(shell, SWT.WRAP | SWT.READ_ONLY); final GridData gdText = new GridData(GridData.FILL, GridData.FILL, true, true); gdText.horizontalIndent = 15; textLabel.setLayoutData(gdText); textLabel.setEnabled(false); final Font textFont = SWTGraphicUtil.buildFontFrom(textLabel, SWT.NONE, 10); textLabel.setFont(textFont); final Color textColor = colors.textColor; textLabel.setForeground(textColor); final Color fillColor = colors.rightColor; textLabel.setBackground(fillColor); textLabel.setText(text); SWTGraphicUtil.applyHTMLFormating(textLabel); SWTGraphicUtil.addDisposer(shell, textFont); }
Example 10
Source File: ParamView.java From http4e with Apache License 2.0 | 5 votes |
void setParamText( String txt){ StyledText st = (StyledText) textView.getControl(); if (CoreConstants.EMPTY_TEXT.equals(txt)) { st.setText(CoreMessages.PARAM_DEFAULTS); } else { st.setText(txt); } if (CoreConstants.EMPTY_TEXT.equals(getParamText())) { st.setForeground(ResourceUtils.getColor(Styles.LIGHT_RGB_TEXT)); } else { st.setForeground(ResourceUtils.getColor(Styles.DARK_RGB_TEXT)); } }
Example 11
Source File: ParamView.java From http4e with Apache License 2.0 | 5 votes |
void setFocus( boolean focusGained){ StyledText st = (StyledText) textView.getControl(); if (focusGained) { if (CoreConstants.EMPTY_TEXT.equals(getParamText())) { st.setText(CoreConstants.EMPTY_TEXT); } st.setForeground(ResourceUtils.getColor(Styles.DARK_RGB_TEXT)); } }
Example 12
Source File: EvalExpressionAction.java From Pydev with Eclipse Public License 1.0 | 5 votes |
@Override protected Control createDialogArea(Composite parent) { GridData gd = new GridData(GridData.FILL_BOTH); StyledText text = new StyledText(parent, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP | SWT.H_SCROLL | SWT.V_SCROLL); text.setLayoutData(gd); text.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); text.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); text.setText(this.text); return text; }
Example 13
Source File: HoverInfoWithText.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
@Override public void deferredCreateContent(Composite parent, HoverInformationControl miControl) { this.fParent = parent; this.fMIControl = miControl; fText = new StyledText(parent, SWT.MULTI | SWT.READ_ONLY | fMIControl.getAdditionalTextStyles()); fText.setForeground(parent.getForeground()); fText.setBackground(parent.getBackground()); fText.setFont(JFaceResources.getDialogFont()); fText.addPaintObjectListener(new PaintObjectListener() { public void paintObject(PaintObjectEvent event) { StyleRange style = event.style; Image image = (Image) style.data; if (image != null && !image.isDisposed()) { int x = event.x + 2; int y = event.y + event.ascent / 2 - style.metrics.ascent / 2 + 2; event.gc.drawImage(image, x, y); } } }); FillLayout layout = new FillLayout(); layout.marginHeight = 2; layout.marginWidth = 2; parent.setLayout(layout); if (monospace) { fText.setFont(JFaceResources.getTextFont()); } else { fText.setFont(JFaceResources.getDialogFont()); } fText.setText(xsString.getText()); fText.setStyleRanges(xsString.getStyleRanges().toArray(new StyleRange[0])); parent.layout(true); }
Example 14
Source File: DerivedSourceView.java From xtext-xtend with Eclipse Public License 2.0 | 5 votes |
@Override protected void inititalizeColors() { IPreferenceStore store = preferenceStoreAccess.getPreferenceStore(); getColorRegistry().addListener(this); StyledText textWidget = getSourceViewer().getTextWidget(); textWidget.setForeground( getColorFromStore(store, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT, SWT.COLOR_WIDGET_FOREGROUND, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND)); textWidget.setBackground( getColorFromStore(store, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, SWT.COLOR_INFO_BACKGROUND, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND)); lineNumberRulerColumn.setForeground( getColorFromStore(store, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR, SWT.COLOR_WIDGET_FOREGROUND, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR)); lineNumberRulerColumn.setBackground( getColorFromStore(store, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT, SWT.COLOR_WIDGET_BACKGROUND, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND)); lineNumberRulerColumn.setFont(getFont(getViewerFontName())); }
Example 15
Source File: SuffixText.java From n4js with Eclipse Public License 1.0 | 5 votes |
/** * Creates, configures and returns the suffix text control. */ private StyledText createSuffixText() { StyledText styledText = new StyledText(this, SWT.TRANSPARENT); styledText.setText(""); styledText.setForeground(INACTIVE_COLOR); styledText.setBackground(getDisplay().getSystemColor(SWT.COLOR_TRANSPARENT)); styledText.setEditable(false); styledText.setEnabled(false); styledText.setLeftMargin(0); return styledText; }
Example 16
Source File: ClassFileEditor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
private StyledText createCodeView(Composite parent) { int styles= SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.FULL_SELECTION; StyledText styledText= new StyledText(parent, styles); styledText.setBackground(fBackgroundColor); styledText.setForeground(fForegroundColor); styledText.setEditable(false); return styledText; }
Example 17
Source File: Header.java From nebula with Eclipse Public License 2.0 | 5 votes |
/** * Create the description */ private void createDescription() { final StyledText labelDescription = new StyledText(this, SWT.WRAP | SWT.READ_ONLY); labelDescription.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); labelDescription.setEnabled(false); labelDescription.setFont(getFont()); labelDescription.setForeground(getForeground()); labelDescription.setText(description); SWTGraphicUtil.applyHTMLFormating(labelDescription); }
Example 18
Source File: AbstractSyntaxColoringPage.java From birt with Eclipse Public License 1.0 | 4 votes |
/** * Initializes the colors of the source preview window based on the values in the Editors' UI preference store * * @param viewer the {@link ISourceViewer} used as the source preview */ protected void initializeSourcePreviewColors(ISourceViewer viewer) { final IPreferenceStore store = EditorsUI.getPreferenceStore(); if (store != null && viewer != null) { final StyledText styledText = viewer.getTextWidget(); // ----------- foreground color -------------------- Color color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT) ? null : createColor(store, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, styledText.getDisplay()); styledText.setForeground(color); if (fForegroundColor != null) fForegroundColor.dispose(); fForegroundColor = color; // ---------- background color ---------------------- color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT) ? null : createColor(store, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, styledText.getDisplay()); styledText.setBackground(color); if (fBackgroundColor != null) fBackgroundColor.dispose(); fBackgroundColor = color; // ----------- selection foreground color -------------------- color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND_SYSTEM_DEFAULT) ? null : createColor(store, AbstractTextEditor.PREFERENCE_COLOR_SELECTION_FOREGROUND, styledText.getDisplay()); styledText.setSelectionForeground(color); if (fSelectionForegroundColor != null) fSelectionForegroundColor.dispose(); fSelectionForegroundColor = color; // ---------- selection background color ---------------------- color = store.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND_SYSTEM_DEFAULT) ? null : createColor(store, AbstractTextEditor.PREFERENCE_COLOR_SELECTION_BACKGROUND, styledText.getDisplay()); styledText.setSelectionBackground(color); if (fSelectionBackgroundColor != null) fSelectionBackgroundColor.dispose(); fSelectionBackgroundColor = color; } }
Example 19
Source File: JavaSourceViewer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
@Override public void configure(SourceViewerConfiguration configuration) { /* * Prevent access to colors disposed in unconfigure(), see: * https://bugs.eclipse.org/bugs/show_bug.cgi?id=53641 * https://bugs.eclipse.org/bugs/show_bug.cgi?id=86177 */ StyledText textWidget= getTextWidget(); if (textWidget != null && !textWidget.isDisposed()) { Color foregroundColor= textWidget.getForeground(); if (foregroundColor != null && foregroundColor.isDisposed()) textWidget.setForeground(null); Color backgroundColor= textWidget.getBackground(); if (backgroundColor != null && backgroundColor.isDisposed()) textWidget.setBackground(null); } super.configure(configuration); if (configuration instanceof JavaSourceViewerConfiguration) { JavaSourceViewerConfiguration javaSVCconfiguration= (JavaSourceViewerConfiguration)configuration; fOutlinePresenter= javaSVCconfiguration.getOutlinePresenter(this, false); if (fOutlinePresenter != null) fOutlinePresenter.install(this); fStructurePresenter= javaSVCconfiguration.getOutlinePresenter(this, true); if (fStructurePresenter != null) fStructurePresenter.install(this); fHierarchyPresenter= javaSVCconfiguration.getHierarchyPresenter(this, true); if (fHierarchyPresenter != null) fHierarchyPresenter.install(this); } if (fPreferenceStore != null) { fPreferenceStore.addPropertyChangeListener(this); initializeViewerColors(); } fIsConfigured= true; }
Example 20
Source File: JavaSourceViewer.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 4 votes |
protected void initializeViewerColors() { if (fPreferenceStore != null) { StyledText styledText= getTextWidget(); // ----------- foreground color -------------------- Color color= fPreferenceStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT) ? null : createColor(fPreferenceStore, AbstractTextEditor.PREFERENCE_COLOR_FOREGROUND, styledText.getDisplay()); styledText.setForeground(color); if (fForegroundColor != null) fForegroundColor.dispose(); fForegroundColor= color; // ---------- background color ---------------------- color= fPreferenceStore.getBoolean(AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT) ? null : createColor(fPreferenceStore, AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND, styledText.getDisplay()); styledText.setBackground(color); if (fBackgroundColor != null) fBackgroundColor.dispose(); fBackgroundColor= color; // ----------- selection foreground color -------------------- color= fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR) ? null : createColor(fPreferenceStore, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR, styledText.getDisplay()); styledText.setSelectionForeground(color); if (fSelectionForegroundColor != null) fSelectionForegroundColor.dispose(); fSelectionForegroundColor= color; // ---------- selection background color ---------------------- color= fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR) ? null : createColor(fPreferenceStore, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR, styledText.getDisplay()); styledText.setSelectionBackground(color); if (fSelectionBackgroundColor != null) fSelectionBackgroundColor.dispose(); fSelectionBackgroundColor= color; } }