org.eclipse.swt.graphics.TextStyle Java Examples
The following examples show how to use
org.eclipse.swt.graphics.TextStyle.
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: XbaseInformationControl.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
/** * Creates and initializes the text layout used to compute the size hint. * * @since 3.2 */ private void createTextLayout() { fTextLayout = new TextLayout(fSashForm.getDisplay()); // Initialize fonts String symbolicFontName = fSymbolicFontName == null ? JFaceResources.DIALOG_FONT : fSymbolicFontName; Font font = JFaceResources.getFont(symbolicFontName); fTextLayout.setFont(font); fTextLayout.setWidth(-1); font = JFaceResources.getFontRegistry().getBold(symbolicFontName); fBoldStyle = new TextStyle(font, null, null); // Compute and set tab width fTextLayout.setText(" "); //$NON-NLS-1$ int tabWidth = fTextLayout.getBounds().width; fTextLayout.setTabs(new int[] { tabWidth }); fTextLayout.setText(""); //$NON-NLS-1$ }
Example #2
Source File: TagStyleConfigurator.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
public static void configure(TextLayout textLayout) { String text = textLayout.getText(); Document doc = new Document(text); ITokenScanner scanner = getRecipeScanner(doc); scanner.setRange(doc, 0, doc.getLength()); IToken token; while ((token = scanner.nextToken()) != Token.EOF) { int offset = scanner.getTokenOffset(); int length = scanner.getTokenLength(); Object data = token.getData(); if (data != null && data instanceof TextStyle) { TextStyle textStyle = (TextStyle) data; textLayout.setStyle(textStyle, offset, offset + length - 1); } } scanner = null; doc = null; }
Example #3
Source File: CustomBrowserInformationControl.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
/** * Creates and initializes the text layout used to compute the size hint. * * @since 3.2 */ private void createTextLayout() { fTextLayout = new TextLayout(fBrowser.getDisplay()); // Initialize fonts String symbolicFontName = fSymbolicFontName == null ? JFaceResources.DIALOG_FONT : fSymbolicFontName; Font font = JFaceResources.getFont(symbolicFontName); fTextLayout.setFont(font); fTextLayout.setWidth(-1); font = JFaceResources.getFontRegistry().getBold(symbolicFontName); fBoldStyle = new TextStyle(font, null, null); // Compute and set tab width fTextLayout.setText(" "); //$NON-NLS-1$ int tabWidth = fTextLayout.getBounds().width; fTextLayout.setTabs(new int[] { tabWidth }); fTextLayout.setText(""); //$NON-NLS-1$ }
Example #4
Source File: ConcordanceSearchDialog.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
/** * 构造方法 * @param parentShell * @param file * 当前文件 * @param strSrcLang * 当前文件的源语言 * @param strTgtLang * 当前文件的目标语言 * @param strSearchText * 搜索文本 */ public ConcordanceSearchDialog(Shell parentShell, IFile file, String strSrcLang, String strTgtLang, String strSearchText) { super(parentShell); FontData fontData = JFaceResources.getDefaultFont().getFontData()[0]; fontData.setStyle(fontData.getStyle() | SWT.BOLD); font = new Font(Display.getDefault(), fontData); style = new TextStyle(font, null, null); this.strSrcLang = strSrcLang; this.strTgtLang = strTgtLang; this.strSearchText = strSearchText; ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(file.getProject()); lstDatabase = projectConfig.getAllTmDbs(); filterUnAvaliableDatabase(); setHelpAvailable(true); setBlockOnOpen(false); lstSearchHistory = new ArrayList<String>(HISTORY_SIZE - 1); lstFilterHistory = new ArrayList<String>(HISTORY_SIZE - 1); if (!Util.isLinux()) { totalWidth = 910; } }
Example #5
Source File: HsMultiCellEditor.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
public void highlightedTerms(List<String> terms) { if (!isValid()) { return; } StyledText styledText = cellEditor.viewer.getTextWidget(); String text = styledText.getText(); char[] source = text.toCharArray(); List<StyleRange> ranges = new ArrayList<StyleRange>(); TextStyle style = new TextStyle(cellEditor.getSegmentViewer().getTextWidget().getFont(), null, ColorConfigBean.getInstance().getHighlightedTermColor()); for (String term : terms) { if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) { term = term.replaceAll("\\n", Constants.LINE_SEPARATOR_CHARACTER + "\n"); term = term.replaceAll("\\t", Constants.TAB_CHARACTER + "\u200B"); term = term.replaceAll(" ", Constants.SPACE_CHARACTER + "\u200B"); } ranges.addAll(calculateTermsStyleRange(source, term.toCharArray(), style)); } for (StyleRange range : ranges) { styledText.setStyleRange(range); } }
Example #6
Source File: TagStyleConfigurator.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
public static void configure(TextLayout textLayout) { String text = textLayout.getText(); Document doc = new Document(text); ITokenScanner scanner = getRecipeScanner(doc); scanner.setRange(doc, 0, doc.getLength()); IToken token; while ((token = scanner.nextToken()) != Token.EOF) { int offset = scanner.getTokenOffset(); int length = scanner.getTokenLength(); Object data = token.getData(); if (data != null && data instanceof TextStyle) { TextStyle textStyle = (TextStyle) data; textLayout.setStyle(textStyle, offset, offset + length - 1); } } }
Example #7
Source File: TagStyleConfigurator.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
public static void configure(TextLayout textLayout) { String text = textLayout.getText(); Document doc = new Document(text); ITokenScanner scanner = getRecipeScanner(doc); scanner.setRange(doc, 0, doc.getLength()); IToken token; while ((token = scanner.nextToken()) != Token.EOF) { int offset = scanner.getTokenOffset(); int length = scanner.getTokenLength(); Object data = token.getData(); if (data != null && data instanceof TextStyle) { TextStyle textStyle = (TextStyle) data; textLayout.setStyle(textStyle, offset, offset + length - 1); } } }
Example #8
Source File: TagStyleConfigurator.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
public static void configure(TextLayout textLayout) { String text = textLayout.getText(); Document doc = new Document(text); ITokenScanner scanner = getRecipeScanner(doc); scanner.setRange(doc, 0, doc.getLength()); IToken token; while ((token = scanner.nextToken()) != Token.EOF) { int offset = scanner.getTokenOffset(); int length = scanner.getTokenLength(); Object data = token.getData(); if (data != null && data instanceof TextStyle) { TextStyle textStyle = (TextStyle) data; textLayout.setStyle(textStyle, offset, offset + length - 1); } } }
Example #9
Source File: TagStyleConfigurator.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
public static void configure(TextLayout textLayout) { String text = textLayout.getText(); Document doc = new Document(text); ITokenScanner scanner = getRecipeScanner(doc); scanner.setRange(doc, 0, doc.getLength()); IToken token; while ((token = scanner.nextToken()) != Token.EOF) { int offset = scanner.getTokenOffset(); int length = scanner.getTokenLength(); Object data = token.getData(); if (data != null && data instanceof TextStyle) { TextStyle textStyle = (TextStyle) data; textLayout.setStyle(textStyle, offset, offset + length - 1); } } scanner = null; doc = null; }
Example #10
Source File: ConcordanceSearchDialog.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
/** * 构造方法 * @param parentShell * @param file * 当前文件 * @param strSrcLang * 当前文件的源语言 * @param strTgtLang * 当前文件的目标语言 * @param strSearchText * 搜索文本 */ public ConcordanceSearchDialog(Shell parentShell, IFile file, String strSrcLang, String strTgtLang, String strSearchText) { super(parentShell); FontData fontData = JFaceResources.getDefaultFont().getFontData()[0]; fontData.setStyle(fontData.getStyle() | SWT.BOLD); font = new Font(Display.getDefault(), fontData); style = new TextStyle(font, null, null); this.strSrcLang = strSrcLang; this.strTgtLang = strTgtLang; this.strSearchText = strSearchText; ProjectConfiger projectConfig = ProjectConfigerFactory.getProjectConfiger(file.getProject()); lstDatabase = projectConfig.getAllTmDbs(); filterUnAvaliableDatabase(); setHelpAvailable(true); setBlockOnOpen(false); lstSearchHistory = new ArrayList<String>(HISTORY_SIZE - 1); lstFilterHistory = new ArrayList<String>(HISTORY_SIZE - 1); if (!Util.isLinux()) { totalWidth = 910; } }
Example #11
Source File: StyledConnectorLabelProvider.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override public void update(ViewerCell cell) { if (cell.getElement() instanceof Connector) { Connector connector = (Connector) cell.getElement(); ConnectorDefinition def = connectorDefStore.getDefinition(connector.getDefinitionId(),connector.getDefinitionVersion()) ; if(def == null){ def = connectorDefStore.getDefinition(connector.getDefinitionId(),connector.getDefinitionVersion()) ; } StyledString styledString = new StyledString(); styledString.append(getText(connector), null); styledString.append(" -- ",StyledString.QUALIFIER_STYLER) ; String connectorType = connector.getDefinitionId() +" ("+connector.getDefinitionVersion()+")"; styledString.append(connectorType, StyledString.DECORATIONS_STYLER); EObject parent = connector.eContainer(); if (!(parent instanceof Expression)) { if(connector.getEvent() != null && !connector.getEvent().isEmpty()){ styledString.append(" -- ",StyledString.QUALIFIER_STYLER) ; styledString.append(connector.getEvent(), StyledString.COUNTER_STYLER); } } if(def == null){ styledString.setStyle(0, styledString.length(), new org.eclipse.jface.viewers.StyledString.Styler() { @Override public void applyStyles(TextStyle textStyle) { textStyle.strikeout = true ; } }) ; styledString.append(" "); styledString.append(Messages.bind(Messages.connectorDefinitionNotFound,connector.getDefinitionId() + " ("+connector.getDefinitionVersion()+")")) ; } cell.setText(styledString.getString()); cell.setImage(getImage(connector)) ; cell.setStyleRanges(styledString.getStyleRanges()); } }
Example #12
Source File: StylerFactory.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override public void applyStyles(TextStyle textStyle) { textStyle.strikeout = (xtextTextStyle.getStyle() & TextAttribute.STRIKETHROUGH) != 0; textStyle.underline = (xtextTextStyle.getStyle() & TextAttribute.UNDERLINE) != 0; if (xtextTextStyle.getFontData() == null && xtextTextStyle.getStyle() != org.eclipse.xtext.ui.editor.utils.TextStyle.DEFAULT_FONT_STYLE) { FontData fontData = new FontData(); fontData.setStyle(xtextTextStyle.getStyle()); xtextTextStyle.setFontData(fontData); } textStyle.font = fontFromFontData(xtextTextStyle.getFontData()); if (xtextTextStyle.getBackgroundColor() != null) textStyle.background = colorFromRGB(xtextTextStyle.getBackgroundColor()); textStyle.foreground = colorFromRGB(xtextTextStyle.getColor()); }
Example #13
Source File: ConcordanceSearchDialog.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
private TextStyle createResultsStyle() { background = new Color(Display.getCurrent(), 0x19, 0x19, 0x70); foreground = new Color(Display.getCurrent(), 0xff, 0xff, 0xff); FontData fontData = JFaceResources.getDefaultFont().getFontData()[0]; fontData.setStyle(fontData.getStyle()); rsFont = new Font(Display.getDefault(), fontData); TextStyle style = new TextStyle(rsFont, foreground, background); return style; }
Example #14
Source File: StyleTextCellRenderer.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * 构造方法 * @param strStyleText * 要加样式的文本 * @param blnIsCaseSensitive * 是否区分大小写 */ public StyleTextCellRenderer(String strStyleText, boolean blnIsCaseSensitive, boolean blnIsApplyRegular,TextStyle style) { super(); this.strStyleText = strStyleText; this.blnIsCaseSensitive = blnIsCaseSensitive; this.blnIsApplyRegular = blnIsApplyRegular; this.style = style; }
Example #15
Source File: StylerBuilder.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
public Styler create() { return new Styler() { @Override public void applyStyles(TextStyle textStyle) { color.ifPresent(c -> textStyle.foreground = c); font.ifPresent(f -> textStyle.font = f); } }; }
Example #16
Source File: PresentationRepairer.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
public PresentationRepairer(ITokenScanner scanner, ISegmentViewer viewer) { Assert.isNotNull(scanner); fViewer = viewer; fScanner = scanner; fDefaultTextStyle = new TextStyle(); }
Example #17
Source File: PresentationRepairer.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
public void createPresentation(TextPresentation presentation, ITypedRegion region) { if (fScanner == null) { // will be removed if deprecated constructor will be removed addRange(presentation, region.getOffset(), region.getLength(), fDefaultTextStyle); return; } int lastStart = region.getOffset(); int length = 0; boolean firstToken = true; IToken lastToken = Token.UNDEFINED; TextStyle lastTextStyle = getTokenTextStyle(lastToken); fScanner.setRange(fDocument, lastStart, region.getLength()); while (true) { IToken token = fScanner.nextToken(); if (token.isEOF()) break; TextStyle textStyle = getTokenTextStyle(token); if (lastTextStyle != null && lastTextStyle.equals(textStyle)) { length += fScanner.getTokenLength(); firstToken = false; } else { if (!firstToken) addRange(presentation, lastStart, length, lastTextStyle); firstToken = false; lastToken = token; lastTextStyle = textStyle; lastStart = fScanner.getTokenOffset(); length = fScanner.getTokenLength(); } } addRange(presentation, lastStart, length, lastTextStyle); }
Example #18
Source File: ColorStyler.java From olca-app with Mozilla Public License 2.0 | 5 votes |
@Override public void applyStyles(TextStyle textStyle) { if (background != null) { textStyle.background = background; } if (foreground != null) { textStyle.foreground = foreground; } textStyle.strikeout = strikeout; if (italic) { textStyle.font = getFont(); } }
Example #19
Source File: StyledFilterLabelProvider.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
@Override public void update(ViewerCell cell) { if (cell.getElement() instanceof ActorFilter) { ActorFilter filter = (ActorFilter) cell.getElement(); ConnectorDefinition def = defStore.getDefinition(filter.getDefinitionId(),filter.getDefinitionVersion()) ; StyledString styledString = new StyledString(); styledString.append(getText(filter), null); styledString.append(" -- ",StyledString.QUALIFIER_STYLER) ; String connectorType = filter.getDefinitionId() +" ("+filter.getDefinitionVersion()+")"; styledString.append(connectorType, StyledString.DECORATIONS_STYLER); if(filter.getEvent() != null && !filter.getEvent().isEmpty()){ styledString.append(" -- ",StyledString.QUALIFIER_STYLER) ; styledString.append(filter.getEvent(), StyledString.COUNTER_STYLER); } if(def == null){ styledString.setStyle(0, styledString.length(), new org.eclipse.jface.viewers.StyledString.Styler() { @Override public void applyStyles(TextStyle textStyle) { textStyle.strikeout = true ; } }) ; styledString.append(" "); styledString.append(Messages.bind(Messages.filterDefinitionNotFound,filter.getDefinitionId() + " ("+filter.getDefinitionVersion()+")")) ; } cell.setText(styledString.getString()); cell.setImage(getImage(filter)) ; cell.setStyleRanges(styledString.getStyleRanges()); } }
Example #20
Source File: PresentationRepairer.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * Adds style information to the given text presentation. * @param presentation * the text presentation to be extended * @param offset * the offset of the range to be styled * @param length * the length of the range to be styled * @param textStyle * the style of the range to be styled */ protected void addRange(TextPresentation presentation, int offset, int length, TextStyle textStyle) { if (textStyle != null) { if (textStyle.metrics != null && length >= 1) { for (int i = offset; i < offset + length; i++) { try { StyleRange styleRange = new StyleRange(textStyle); String placeHolder = fDocument.get(i, 1); InnerTag innerTag = InnerTagUtil.getInnerTag(fViewer.getInnerTagCacheList(), placeHolder); if (innerTag != null) { Point rect = innerTag.computeSize(SWT.DEFAULT, SWT.DEFAULT); // int ascent = 4 * rect.height / 5 + SEGMENT_LINE_SPACING / 2; // int descent = rect.height - ascent + SEGMENT_LINE_SPACING; styleRange.metrics = new GlyphMetrics(rect.y, 0, rect.x + SEGMENT_LINE_SPACING * 2); } styleRange.start = i; styleRange.length = 1; presentation.addStyleRange(styleRange); } catch (BadLocationException e) { e.printStackTrace(); } } } /* * else { StyleRange styleRange = new StyleRange(textStyle); styleRange.start = offset; styleRange.length = * length; presentation.addStyleRange(styleRange); } */ } }
Example #21
Source File: StylerHelpers.java From goclipse with Eclipse Public License 1.0 | 5 votes |
@Override public void applyStyles(TextStyle textStyle) { if(parentStyler != null) { parentStyler.applyStyles(textStyle); } Font font = textStyle.font; if(font == null) { font = JFaceResources.getDefaultFont(); } FontDescriptor fontDescriptor = FontDescriptor.createFrom(font); fontDescriptor = getModifiedFontDescriptor(fontDescriptor); textStyle.font = fontDescriptor.createFont(Display.getCurrent()); }
Example #22
Source File: StyledStringStyler.java From JDeodorant with MIT License | 5 votes |
public StyledStringStyler(TextStyle textStyle){ textStyleAttributeStyle.font = textStyle.font; textStyleAttributeStyle.background = textStyle.background; textStyleAttributeStyle.borderColor = textStyle.borderColor; textStyleAttributeStyle.borderStyle = textStyle.borderStyle; textStyleAttributeStyle.foreground = textStyle.foreground; textStyleAttributeStyle.metrics = textStyle.metrics; textStyleAttributeStyle.rise = textStyle.rise; textStyleAttributeStyle.strikeout = textStyle.strikeout; textStyleAttributeStyle.strikeoutColor = textStyle.strikeoutColor; textStyleAttributeStyle.underline = textStyle.underline; textStyleAttributeStyle.underlineColor = textStyle.underlineColor; textStyleAttributeStyle.underlineStyle = textStyle.underlineStyle; }
Example #23
Source File: DataStyledTreeLabelProvider.java From bonita-studio with GNU General Public License v2.0 | 5 votes |
private void initStyle() { imageProvider = new AdapterFactoryLabelProvider(new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE)) ; italicGrey = new StyledString.Styler() { @Override public void applyStyles(TextStyle textStyle) { textStyle.font = BonitaStudioFontRegistry.getTransientDataFont(); textStyle.foreground = JFaceResources.getColorRegistry().get(JFacePreferences.QUALIFIER_COLOR); } }; }
Example #24
Source File: PresentationRepairer.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
public PresentationRepairer(ITokenScanner scanner, CellEditorTextViewer viewer) { Assert.isNotNull(scanner); this.viewer = viewer; fScanner = scanner; fDefaultTextStyle = new TextStyle(); }
Example #25
Source File: PresentationRepairer.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
public void createPresentation(TextPresentation presentation, ITypedRegion region) { if (fScanner == null) { // will be removed if deprecated constructor will be removed addRange(presentation, region.getOffset(), region.getLength(), fDefaultTextStyle); return; } int lastStart = region.getOffset(); int length = 0; boolean firstToken = true; IToken lastToken = Token.UNDEFINED; TextStyle lastTextStyle = getTokenTextStyle(lastToken); fScanner.setRange(fDocument, lastStart, region.getLength()); while (true) { IToken token = fScanner.nextToken(); if (token.isEOF()) break; TextStyle textStyle = getTokenTextStyle(token); if (lastTextStyle != null && lastTextStyle.equals(textStyle)) { length += fScanner.getTokenLength(); firstToken = false; } else { if (!firstToken) addRange(presentation, lastStart, length, lastTextStyle); firstToken = false; lastToken = token; lastTextStyle = textStyle; lastStart = fScanner.getTokenOffset(); length = fScanner.getTokenLength(); } } addRange(presentation, lastStart, length, lastTextStyle); }
Example #26
Source File: TextPainterWithPadding.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
private TextLayout getCellTextLayout(LayerCell cell) { int orientation = editor.getTable().getStyle() & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT); TextLayout layout = new TextLayout(editor.getTable().getDisplay()); layout.setOrientation(orientation); layout.setSpacing(Constants.SEGMENT_LINE_SPACING); layout.setFont(font); layout.setAscent(ascent); layout.setDescent(descent); // 和 StyledTextEditor 同步 layout.setTabs(new int[] { tabWidth }); Rectangle rectangle = cell.getBounds(); int width = rectangle.width - leftPadding - rightPadding; width -= 1; if (wrapText && width > 0) { layout.setWidth(width); } String displayText = InnerTagUtil.resolveTag(innerTagFactory.parseInnerTag((String) cell.getDataValue())); if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) { displayText = displayText.replaceAll("\\n", Constants.LINE_SEPARATOR_CHARACTER + "\n"); displayText = displayText.replaceAll("\\t", Constants.TAB_CHARACTER + ""); displayText = displayText.replaceAll(" ", Constants.SPACE_CHARACTER + ""); } layout.setText(displayText); List<InnerTagBean> innerTagBeans = innerTagFactory.getInnerTagBeans(); for (InnerTagBean innerTagBean : innerTagBeans) { String placeHolder = placeHolderBuilder.getPlaceHolder(innerTagBeans, innerTagBeans.indexOf(innerTagBean)); int start = displayText.indexOf(placeHolder); if (start == -1) { continue; } TextStyle style = new TextStyle(); Point rect = tagRender.calculateTagSize(innerTagBean); style.metrics = new GlyphMetrics(rect.y, 0, rect.x + SEGMENT_LINE_SPACING * 2); layout.setStyle(style, start, start + placeHolder.length() - 1); } return layout; }
Example #27
Source File: StyleTextCellRenderer.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
/** * 构造方法 * @param strStyleText * 要加样式的文本 * @param blnIsCaseSensitive * 是否区分大小写 */ public StyleTextCellRenderer(String strStyleText, boolean blnIsCaseSensitive, boolean blnIsApplyRegular,TextStyle style) { super(); this.strStyleText = strStyleText; this.blnIsCaseSensitive = blnIsCaseSensitive; this.blnIsApplyRegular = blnIsApplyRegular; this.style = style; }
Example #28
Source File: PresentationRepairer.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
public void createPresentation(TextPresentation presentation, ITypedRegion region) { if (fScanner == null) { // will be removed if deprecated constructor will be removed addRange(presentation, region.getOffset(), region.getLength(), fDefaultTextStyle); return; } int lastStart = region.getOffset(); int length = 0; boolean firstToken = true; IToken lastToken = Token.UNDEFINED; TextStyle lastTextStyle = getTokenTextStyle(lastToken); fScanner.setRange(fDocument, lastStart, region.getLength()); while (true) { IToken token = fScanner.nextToken(); if (token.isEOF()) break; TextStyle textStyle = getTokenTextStyle(token); if (lastTextStyle != null && lastTextStyle.equals(textStyle)) { length += fScanner.getTokenLength(); firstToken = false; } else { if (!firstToken) addRange(presentation, lastStart, length, lastTextStyle); firstToken = false; lastToken = token; lastTextStyle = textStyle; lastStart = fScanner.getTokenOffset(); length = fScanner.getTokenLength(); } } addRange(presentation, lastStart, length, lastTextStyle); }
Example #29
Source File: PresentationRepairer.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
public void createPresentation(TextPresentation presentation, ITypedRegion region) { if (fScanner == null) { // will be removed if deprecated constructor will be removed addRange(presentation, region.getOffset(), region.getLength(), fDefaultTextStyle); return; } int lastStart = region.getOffset(); int length = 0; boolean firstToken = true; IToken lastToken = Token.UNDEFINED; TextStyle lastTextStyle = getTokenTextStyle(lastToken); fScanner.setRange(fDocument, lastStart, region.getLength()); while (true) { IToken token = fScanner.nextToken(); if (token.isEOF()) break; TextStyle textStyle = getTokenTextStyle(token); if (lastTextStyle != null && lastTextStyle.equals(textStyle)) { length += fScanner.getTokenLength(); firstToken = false; } else { if (!firstToken) addRange(presentation, lastStart, length, lastTextStyle); firstToken = false; lastToken = token; lastTextStyle = textStyle; lastStart = fScanner.getTokenOffset(); length = fScanner.getTokenLength(); } } addRange(presentation, lastStart, length, lastTextStyle); }
Example #30
Source File: ConcordanceSearchDialog.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
private TextStyle createResultsStyle() { background = new Color(Display.getCurrent(), 0x19, 0x19, 0x70); foreground = new Color(Display.getCurrent(), 0xff, 0xff, 0xff); FontData fontData = JFaceResources.getDefaultFont().getFontData()[0]; fontData.setStyle(fontData.getStyle()); rsFont = new Font(Display.getDefault(), fontData); TextStyle style = new TextStyle(rsFont, foreground, background); return style; }