/** * Constructor. Sets properties of the editor window. * * @param parent * @param text * @param editable * @param shortcutHandler */ public Note(Composite parent, String text, boolean editable) { // Enable multiple lines and scroll bars. super(parent, SWT.V_SCROLL | SWT.H_SCROLL); preferences = InstanceScope.INSTANCE.getNode(Notepad4e.PLUGIN_ID); undoRedoManager = new UndoRedoManager(this); bulletStyle = new StyleRange(); bulletStyle.metrics = new GlyphMetrics(0, 0, 0); // Scroll bars only appear when the text extends beyond the note window. setAlwaysShowScrollBars(false); setParametersFromPreferences(); setText(text); initialiseMenu(); if (!editable) { toggleEditable(); } }
private void createUI30Hints(final Composite parent) { final Composite container = new Composite(parent, SWT.NONE); GridDataFactory.fillDefaults().grab(true, false).span(2, 1).applyTo(container); GridLayoutFactory.fillDefaults().numColumns(1).applyTo(container); { // use a bulleted list to display this info final StyleRange style = new StyleRange(); style.metrics = new GlyphMetrics(0, 0, 10); final Bullet bullet = new Bullet(style); final String infoText = Messages.Modify_MapProvider_Label_Hints; final int lineCount = Util.countCharacter(infoText, '\n'); final StyledText styledText = new StyledText(container, SWT.READ_ONLY | SWT.WRAP | SWT.MULTI); GridDataFactory.fillDefaults().grab(true, false).applyTo(styledText); styledText.setText(infoText); styledText.setBackground(container.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); styledText.setLineBullet(1, lineCount, bullet); styledText.setLineWrapIndent(1, lineCount, 10); } }
private void createUI_76_Hints(final Composite parent) { // use a bulleted list to display this info final StyleRange style = new StyleRange(); style.metrics = new GlyphMetrics(0, 0, 10); final Bullet bullet = new Bullet(style); final String infoText = Messages.ColumnModifyDialog_Label_Hints; final int lineCount = Util.countCharacter(infoText, '\n'); final StyledText styledText = new StyledText(parent, SWT.READ_ONLY | SWT.WRAP | SWT.MULTI); styledText.setText(infoText); styledText.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); styledText.setLineBullet(1, lineCount, bullet); styledText.setLineWrapIndent(1, lineCount, 10); GridDataFactory.fillDefaults()// .grab(true, false) .span(2, 1) .applyTo(styledText); }
private void configureStyledText(String text, boolean enabled) { if (fStyledText == null) return; fStyledText.setText(text); int count= fStyledText.getCharCount(); if (count == 0) return; Color foreground= enabled ? null : Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY); fStyledText.setStyleRange(new StyleRange(0, count, foreground, null)); StyleRange styleRange= new StyleRange(0, count, foreground, null); styleRange.metrics= new GlyphMetrics(0, 0, 20); fStyledText.setLineBullet(0, fStyledText.getLineCount(), new Bullet(styleRange)); fStyledText.setEnabled(enabled); }
@Override public void lineGetStyle(LineStyleEvent e) { // Set the line number int line = tc.getLineAtOffset(e.lineOffset); int lastLine = tc.getLineCount() - 1; e.bulletIndex = line; String prompt = "gdb>"; // Set the style, 12 pixles wide for each digit StyleRange style = new StyleRange(); style.metrics = new GlyphMetrics(0, 0, prompt.length() * 12); // Create and set the bullet e.bullet = new Bullet(ST.BULLET_TEXT, style); if (line == lastLine) { e.bullet.text = prompt; } else { e.bullet.text = ""; } }
private Bullet buildMainModelStyle() { StyleRange style = new StyleRange(); style.metrics = new GlyphMetrics(0, 0, 40); style.foreground = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); Bullet bullet = new Bullet(style); return bullet; }
private Bullet buildAdditionalTitleModelStyle() { StyleRange style = new StyleRange(); style.metrics = new GlyphMetrics(0, 0, 40); style.foreground = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); Bullet bullet = new Bullet(style); return bullet; }
private Bullet buildCheckedlStyle() { StyleRange style2 = new StyleRange(); style2.metrics = new GlyphMetrics(0, 0, 80); style2.foreground = Display.getDefault().getSystemColor(SWT.COLOR_BLACK); Bullet bullet = new Bullet(ST.BULLET_TEXT, style2); bullet.text = "\u2713"; return bullet; }
public void lineGetStyle(LineStyleEvent e) { int lineStart = e.lineOffset; int lineEnd = lineStart + e.lineText.length(); // Set the line number e.bulletIndex = text.getLineAtOffset(lineStart); // Set the style, 12 pixels wide for each digit StyleRange style = new StyleRange(); style.foreground = new Color(text.getDisplay(), 120, 120, 120); style.fontStyle = SWT.ITALIC; style.metrics = new GlyphMetrics(0, 0, Integer.toString(text.getLineCount() + 1).length() * 12); // Create and set the bullet e.bullet = new Bullet(ST.BULLET_NUMBER, style); List<StyleRange> ranges = Lists.newArrayList(); for(TermOccurrence occ:FileEditorPart.this.occurrences) { if((occ.getBegin() < lineEnd && occ.getEnd() > lineStart)) { int styleStart = Ints.max(occ.getBegin(), lineStart); int styleEnd = Ints.min(occ.getEnd(), lineEnd); int overlap = styleEnd - styleStart; StyleRange styleRange = new StyleRange(); styleRange.start = styleStart; styleRange.length = overlap; if(occ.equals(activeOccurrence)) { styleRange.fontStyle = SWT.BOLD | SWT.ITALIC; styleRange.background = COLOR_CYAN; } else { styleRange.background = COLOR_GRAY; } ranges.add(styleRange); } } e.styles = ranges.toArray(new StyleRange[ranges.size()]); }
protected void setLineBulletAndStuff() { text.setLineBullet(0, text.getLineCount(), null); // delete line bullet first to guarantee update! (bug in SWT?) if (settings.isShowLineBullets() && currentRegionObject!=null && getNTextLines()>0) { Storage store = Storage.getInstance(); for (int i=0; i<text.getLineCount(); ++i) { final int docId = store.getDoc().getId(); final int pNr = store.getPage().getPageNr(); int bulletFgColor = SWT.COLOR_BLACK; int fontStyle = SWT.NORMAL; if (i>= 0 && i <currentRegionObject.getTextLine().size()) { final String lineId = currentRegionObject.getTextLine().get(i).getId(); boolean hasWg = store.hasWordGraph(docId, pNr, lineId); fontStyle = (i == getCurrentLineIndex()) ? SWT.BOLD : SWT.NORMAL; bulletFgColor = hasWg ? SWT.COLOR_DARK_GREEN : SWT.COLOR_BLACK; } StyleRange style = new StyleRange(0, text.getCharCount(), Colors.getSystemColor(bulletFgColor), Colors.getSystemColor(SWT.COLOR_GRAY), fontStyle); style.metrics = new GlyphMetrics(0, 0, Integer.toString(text.getLineCount() + 1).length() * 12); // style.background = Colors.getSystemColor(SWT.COLOR_GRAY); Bullet bullet = new Bullet(/*ST.BULLET_NUMBER |*/ ST.BULLET_TEXT, style); bullet.text = ""+(i+1); text.setLineBullet(i, 1, bullet); text.setLineIndent(i, 1, 25); text.setLineAlignment(i, 1, settings.getTextAlignment()); text.setLineWrapIndent(i, 1, 25+style.metrics.width); } // text.setLineBullet(0, text.getLineCount(), bullet); // text.setLineIndent(0, text.getLineCount(), 25); // text.setLineAlignment(0, text.getLineCount(), textAlignment); // text.setLineWrapIndent(0, text.getLineCount(), 25+style.metrics.width); } }
private void setLineBullet() { StyleRange style = new StyleRange(); style.metrics = new GlyphMetrics(0, 0, Integer.toString(text.getLineCount() + 1).length() * 12); style.background = Colors.getSystemColor(SWT.COLOR_GRAY); Bullet bullet = new Bullet(ST.BULLET_NUMBER, style); text.setLineBullet(0, text.getLineCount(), bullet); // text.setLineIndent(0, text.getLineCount(), 25); // text.setLineAlignment(0, text.getLineCount(), textAlignment); // text.setLineWrapIndent(0, text.getLineCount(), 25+style.metrics.width); }
private static void addBulletForLine(StyledText styledText, LineStyleEvent event, Map<StyleType, StyleRangeTemplate> theme) { // Using ST.BULLET_NUMBER sometimes results in weird alignment. //event.bulletIndex = styledText.getLineAtOffset(event.lineOffset); StyleRange styleRange = theme.get(StyleType.LINE_NUMBER).create(); int maxLine = styledText.getLineCount(); int bulletLength = Integer.toString(maxLine).length(); // Width of number character is half the height in monospaced font, add 1 character width for right padding. int bulletWidth = (bulletLength + 1) * styledText.getLineHeight() / 2; styleRange.metrics = new GlyphMetrics(0, 0, bulletWidth); event.bullet = new Bullet(ST.BULLET_TEXT, styleRange); // getLineAtOffset() returns a zero-based line index. int bulletLine = styledText.getLineAtOffset(event.lineOffset) + 1; event.bullet.text = String.format("%" + bulletLength + "s", bulletLine); }
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 + "\u200B"); displayText = displayText.replaceAll(" ", Constants.SPACE_CHARACTER + "\u200B"); } 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; }
/** * 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); } */ } }
private void addRange(List<StyleRange> ranges, int start, int length, Color foreground, boolean isCode) { StyleRange range = new StyleRange(start, length, foreground, null); AnsiConsoleAttributes.updateRangeStyle(range, lastAttributes); if (isCode) { range.metrics = new GlyphMetrics(0, 0, 0); } ranges.add(range); lastRangeEnd = lastRangeEnd + range.length; }
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; }
private void createUI_60_PaintingMethod(final Composite parent) { final Display display = parent.getDisplay(); /* * checkbox: paint tour method */ final Group groupMethod = new Group(parent, SWT.NONE); GridDataFactory.fillDefaults().applyTo(groupMethod); groupMethod.setText(Messages.Pref_MapLayout_Label_TourPaintMethod); // groupMethod.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED)); { _editorTourPaintMethod = new RadioGroupFieldEditor( ITourbookPreferences.MAP_LAYOUT_TOUR_PAINT_METHOD, UI.EMPTY_STRING, 2, new String[][] { { Messages.Pref_MapLayout_Label_TourPaintMethod_Simple, TOUR_PAINT_METHOD_SIMPLE }, { Messages.Pref_MapLayout_Label_TourPaintMethod_Complex, TOUR_PAINT_METHOD_COMPLEX } }, groupMethod); addField(_editorTourPaintMethod); _pageBookPaintMethod = new PageBook(groupMethod, SWT.NONE); GridDataFactory.fillDefaults()// .grab(true, false) .span(2, 1) .hint(350, SWT.DEFAULT) .indent(16, 0) .applyTo(_pageBookPaintMethod); // use a bulleted list to display this info final StyleRange style = new StyleRange(); style.metrics = new GlyphMetrics(0, 0, 10); final Bullet bullet = new Bullet(style); /* * simple painting method */ String infoText = Messages.Pref_MapLayout_Label_TourPaintMethod_Simple_Tooltip; int lineCount = Util.countCharacter(infoText, '\n'); _pageSimple = new StyledText(_pageBookPaintMethod, SWT.READ_ONLY | SWT.WRAP | SWT.MULTI); GridDataFactory.fillDefaults().grab(true, false).applyTo(_pageSimple); _pageSimple.setText(infoText); _pageSimple.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); _pageSimple.setLineBullet(0, lineCount + 1, bullet); _pageSimple.setLineWrapIndent(0, lineCount + 1, 10); /* * complex painting method */ infoText = Messages.Pref_MapLayout_Label_TourPaintMethod_Complex_Tooltip; lineCount = Util.countCharacter(infoText, '\n'); _pageComplex = new StyledText(_pageBookPaintMethod, SWT.READ_ONLY | SWT.WRAP | SWT.MULTI); GridDataFactory.fillDefaults().grab(true, false).applyTo(_pageComplex); _pageComplex.setText(infoText); _pageComplex.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND)); _pageComplex.setLineBullet(0, lineCount + 1, bullet); _pageComplex.setLineWrapIndent(0, lineCount + 1, 10); } // set group margin after the fields are created GridLayoutFactory.swtDefaults().margins(0, 5).numColumns(2).applyTo(groupMethod); }
/** * Display text as a bulleted list * * @param parent * @param bulletText * @param startLine * Line where bullets should be started, 0 is the first line * @param spanHorizontal * @param horizontalHint * @param backgroundColor * background color or <code>null</code> when color should not be set * @return Returns the bulleted list as styled text */ public static StyledText createBullets( final Composite parent, final String bulletText, final int startLine, final int spanHorizontal, final int horizontalHint, final Color backgroundColor) { StyledText styledText = null; try { final Composite container = new Composite(parent, SWT.NONE); GridDataFactory.fillDefaults()// .grab(true, false) .span(spanHorizontal, 1) .hint(horizontalHint, SWT.DEFAULT) .applyTo(container); GridLayoutFactory.fillDefaults()// .numColumns(1) .margins(5, 5) .applyTo(container); container.setBackground(backgroundColor == null ? // container.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND) : backgroundColor); { final StyleRange style = new StyleRange(); style.metrics = new GlyphMetrics(0, 0, 10); final Bullet bullet = new Bullet(style); final int lineCount = Util.countCharacter(bulletText, '\n'); styledText = new StyledText(container, SWT.READ_ONLY | SWT.WRAP | SWT.MULTI); GridDataFactory.fillDefaults().grab(true, false).applyTo(styledText); styledText.setText(bulletText); styledText.setLineBullet(startLine, lineCount, bullet); styledText.setLineWrapIndent(startLine, lineCount, 10); styledText.setBackground(backgroundColor == null ? // container.getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND) : backgroundColor); } } catch (final Exception e) { // ignore exception when there are less lines as required StatusUtil.log(e); } return styledText; }
private TextStyle createTextStyle() { TextStyle style = new TextStyle(); style.metrics = new GlyphMetrics(0, 0, 0); return style; }
/** * Convenience method, returns a default <code>StyleRange</code> with the * specified width that can be used to format line bullets. * * @param inWidth * int * @return StyleRange */ public static StyleRange getDefaultRange(final int inWidth) { final StyleRange outRange = new StyleRange(); outRange.start = 0; outRange.length = 0; outRange.metrics = new GlyphMetrics(0, 0, inWidth); return outRange; }