expressionEditor.setStyleRanges( styleRanges );
/** * Set the given StyleRanges from the Vector to the StyledText * * @param textField Textfield where the text is in * @param styleRanges Vector containing StyleRanges */ public static void highlightText(StyledText textField, Vector styleRanges) { StyleRange styleRangesArray[] = new StyleRange[styleRanges.size()]; for (int a = 0; a < styleRanges.size(); a++) styleRangesArray[a] = (StyleRange) styleRanges.get(a); textField.setStyleRanges(styleRangesArray); }
/** * Applies the given presentation to the given text widget. Helper method. * * @param presentation the style information * @param text the widget to which to apply the style information * @since 2.0 */ public static void applyTextPresentation(TextPresentation presentation, StyledText text) { StyleRange[] ranges= new StyleRange[presentation.getDenumerableRanges()]; int i= 0; Iterator<StyleRange> e= presentation.getAllStyleRangeIterator(); while (e.hasNext()) ranges[i++]= e.next(); text.setStyleRanges(ranges); }
/** * Applies the given presentation to the given text widget. Helper method. * * @param presentation the style information * @param text the widget to which to apply the style information * @since 2.0 */ public static void applyTextPresentation(TextPresentation presentation, StyledText text) { StyleRange[] ranges= new StyleRange[presentation.getDenumerableRanges()]; int i= 0; Iterator<StyleRange> e= presentation.getAllStyleRangeIterator(); while (e.hasNext()) ranges[i++]= e.next(); text.setStyleRanges(ranges); }
/** * Applies the given presentation to the given text widget. Helper method. * * @param presentation the style information * @since 2.1 */ private void applyTextPresentation(TextPresentation presentation) { List<StyleRange> list= new ArrayList<>(presentation.getDenumerableRanges()); Iterator<StyleRange> e= presentation.getAllStyleRangeIterator(); while (e.hasNext()) { StyleRange range= e.next(); range= modelStyleRange2WidgetStyleRange(range); if (range != null) list.add(range); } if (!list.isEmpty()) { StyleRange[] ranges= new StyleRange[list.size()]; list.toArray(ranges); fTextWidget.setStyleRanges(ranges); } }
/** * Applies the given presentation to the given text widget. Helper method. * * @param presentation the style information * @since 2.1 */ private void applyTextPresentation(TextPresentation presentation) { List<StyleRange> list= new ArrayList<>(presentation.getDenumerableRanges()); Iterator<StyleRange> e= presentation.getAllStyleRangeIterator(); while (e.hasNext()) { StyleRange range= e.next(); range= modelStyleRange2WidgetStyleRange(range); if (range != null) list.add(range); } if (!list.isEmpty()) { StyleRange[] ranges= new StyleRange[list.size()]; list.toArray(ranges); fTextWidget.setStyleRanges(ranges); } }
/** Refresh style ranges */ public void refreshStyleRanges() { DiffStyleRange[] ranges = formatter != null ? formatter.getRanges() : new DiffStyleRange[0]; for (DiffStyleRange range : ranges) switch (range.diffType) { case ADD: range.foreground = addForegroundColor; range.lineBackground = addBackgroundColor; break; case REMOVE: range.foreground = removeForegroundColor; range.lineBackground = removeBackgroundColor; break; case HUNK: range.foreground = hunkForegroundColor; range.lineBackground = hunkBackgroundColor; break; case HEADLINE: range.font = headlineFont; range.foreground = headlineForegroundColor; range.lineBackground = headlineBackgroundColor; break; default: break; } getTextWidget().setStyleRanges(ranges); }
private void synchStyles() { StyledText editorTextWidget = fEditorViewer.getTextWidget(); StyleRange[] ranges = editorTextWidget.getStyleRanges(); if (ranges != null) { for (StyleRange range : ranges) { updateStyle(range); } } fMinimapTextWidget.setStyleRanges(ranges); }
/** * Creates the "Example" widgets. */ @Override void createExampleWidgets () { /* Compute the widget style */ int style = getDefaultStyle(); if (singleButton.getSelection ()) style |= SWT.SINGLE; if (multiButton.getSelection ()) style |= SWT.MULTI; if (horizontalButton.getSelection ()) style |= SWT.H_SCROLL; if (verticalButton.getSelection ()) style |= SWT.V_SCROLL; if (wrapButton.getSelection ()) style |= SWT.WRAP; if (readOnlyButton.getSelection ()) style |= SWT.READ_ONLY; if (borderButton.getSelection ()) style |= SWT.BORDER; if (fullSelectionButton.getSelection ()) style |= SWT.FULL_SELECTION; /* Create the example widgets */ styledText = new StyledText (styledTextGroup, style); styledText.setText (ControlExample.getResourceString("Example_string")); styledText.append ("\n"); styledText.append (ControlExample.getResourceString("One_Two_Three")); if (text != null) { styledText.setText(text); text = null; } if (styleRanges != null) { styledText.setStyleRanges(styleRanges); styleRanges = null; } }
void addImage(Image image) { int offset = styledText.getCaretOffset(); styledText.replaceTextRange(offset, 0, "\uFFFC"); //$NON-NLS-1$ StyleRange style = new StyleRange(); Rectangle rect = image.getBounds(); style.metrics = new GlyphMetrics(rect.height, 0, rect.width); style.data = image; int[] ranges = {offset, 1}; StyleRange[] styles = {style}; styledText.setStyleRanges(0,0, ranges, styles); }
if (isListening(ST.LineGetStyle)) return; if (ranges == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); setStyleRanges(0, 0, null, ranges, true);
void addControl(Control control) { int offset = styledText.getCaretOffset(); styledText.replaceTextRange(offset, 0, "\uFFFC"); //$NON-NLS-1$ StyleRange style = new StyleRange(); Point size = control.computeSize(SWT.DEFAULT, SWT.DEFAULT); int ascent = 2 * size.y / 3; int descent = size.y - ascent; style.metrics = new GlyphMetrics(ascent + MARGIN, descent + MARGIN, size.x + 2 * MARGIN); style.data = control; int[] ranges = {offset, 1}; StyleRange[] styles = {style}; styledText.setStyleRanges(0,0, ranges, styles); control.setSize(size); }
public void modifyText(ModifyEvent e) { searchJob.cancel(); StyleRange[] styleRanges = createStyledSearchString(searchText.getText()); searchText.setStyleRanges(styleRanges); if( searchViewControl.isShowingSearchTip() ) return; // showing search tip searchJob.schedule(getSearchQuery(), false, typingSearchDelay); // start with a delay since user might still be typing if( incrementalSearchEnabled ) doIncrementalSearch(); }
void loadProfile(int profile) { try { switch (profile) { case 1: { String text = openFile(TextEditor.class.getResourceAsStream("text.txt")); //$NON-NLS-1$ StyleRange[] styles = getStyles(TextEditor.class.getResourceAsStream("styles.txt")); //$NON-NLS-1$ styledText.setText(text); if (styles != null) styledText.setStyleRanges(styles); break; } case 2: { styledText.setText(getResourceString("Profile2")); //$NON-NLS-1$ break; } case 3: { String text = openFile(TextEditor.class.getResourceAsStream("text4.txt")); //$NON-NLS-1$ styledText.setText(text); break; } case 4: { styledText.setText(getResourceString("Profile4")); //$NON-NLS-1$ break; } } updateToolBar(); } catch (Exception e) { showError(getResourceString("Error"), e.getMessage()); //$NON-NLS-1$ } }
protected void addIconAndLabel(Composite parent, Image image, StyledString text) { Label imageLabel = new Label(parent, SWT.NONE); imageLabel.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); imageLabel.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); imageLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING)); imageLabel.setImage(image); StyledText textLabel = new StyledText(parent, 0); textLabel.setText(text.getString()); textLabel.setStyleRanges(text.getStyleRanges()); // textLabel.setForeground(getTitleColor()); textLabel.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); textLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER)); //textLabel.setText(""); int width = Math.min(textLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).x, MAX_WIDTH); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.BEGINNING).hint(width, SWT.DEFAULT).applyTo(textLabel); }
/** * Adds a line style listener. A LineGetStyle event is sent by the widget to * determine the styles for a line. * * @param listener the listener * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> */ public void addLineStyleListener(LineStyleListener listener) { checkWidget(); if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (!isListening(ST.LineGetStyle)) { setStyleRanges(0, 0, null, null, true); renderer.clearLineStyle(0, content.getLineCount()); } addListener(ST.LineGetStyle, new StyledTextListener(listener)); setCaretLocation(); } /**
/** * Adds a line style listener. A LineGetStyle event is sent by the widget to * determine the styles for a line. * * @param listener the listener * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> */ public void addLineStyleListener(LineStyleListener listener) { checkWidget(); if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (!isListening(ST.LineGetStyle)) { setStyleRanges(0, 0, null, null, true); renderer.clearLineStyle(0, content.getLineCount()); } addListener(ST.LineGetStyle, new StyledTextListener(listener)); setCaretLocation(); } /**
/** * Adds a line style listener. A LineGetStyle event is sent by the widget to * determine the styles for a line. * * @param listener the listener * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> */ public void addLineStyleListener(LineStyleListener listener) { checkWidget(); if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (!isListening(ST.LineGetStyle)) { setStyleRanges(0, 0, null, null, true); renderer.clearLineStyle(0, content.getLineCount()); } addListener(ST.LineGetStyle, new StyledTextListener(listener)); setCaretLocation(); } /**
/** * Adds a line style listener. A LineGetStyle event is sent by the widget to * determine the styles for a line. * * @param listener the listener * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> */ public void addLineStyleListener(LineStyleListener listener) { checkWidget(); if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (!isListening(ST.LineGetStyle)) { setStyleRanges(0, 0, null, null, true); renderer.clearLineStyle(0, content.getLineCount()); } addListener(ST.LineGetStyle, new StyledTextListener(listener)); setCaretLocation(); } /**
/** * Adds a line style listener. A LineGetStyle event is sent by the widget to * determine the styles for a line. * * @param listener the listener * @exception SWTException <ul> * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> */ public void addLineStyleListener(LineStyleListener listener) { checkWidget(); if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (!isListening(ST.LineGetStyle)) { setStyleRanges(0, 0, null, null, true); renderer.clearLineStyle(0, content.getLineCount()); } addListener(ST.LineGetStyle, new StyledTextListener(listener)); setCaretLocation(); } /**