/** * 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; }
@Override public void createPartControl(Composite parent) { super.createPartControl(parent); Control adapter = getAdapter(Control.class); if (adapter instanceof StyledText) { StyledText text = (StyledText) adapter; text.addCaretListener(new BatchEditorCaretListener()); } activateBatchEditorContext(); installAdditionalSourceViewerSupport(); StyledText styledText = getSourceViewer().getTextWidget(); styledText.addKeyListener(new BatchBracketInsertionCompleter(this)); /* * register as resource change listener to provide marker change * listening */ ResourcesPlugin.getWorkspace().addResourceChangeListener(this); setTitleImageInitial(); }
@Override public void createPartControl(Composite parent) { super.createPartControl(parent); Control adapter = getAdapter(Control.class); if (adapter instanceof StyledText) { StyledText text = (StyledText) adapter; text.addCaretListener(new BashEditorCaretListener()); } activateBashEditorContext(); installAdditionalSourceViewerSupport(); StyledText styledText = getSourceViewer().getTextWidget(); styledText.addKeyListener(new BashBracketInsertionCompleter(this)); /* * register as resource change listener to provide marker change * listening */ ResourcesPlugin.getWorkspace().addResourceChangeListener(this); setTitleImageInitial(); }
@Override public void paint(int reason) { IDocument document = textViewer.getDocument(); if (document == null) { deactivate(false); return; } if (!fIsActive) { StyledText styledText = textViewer.getTextWidget(); fIsActive = true; styledText.addPaintListener(this); redrawAll(); } else if (reason == CONFIGURATION || reason == INTERNAL) { redrawAll(); } }
@Override public void draw(int paintX, int paintSpaceLeadingX, int paintY, GC gc) { StyledText styledText = getTextViewer().getTextWidget(); Rectangle client = styledText.getClientArea(); gc.setBackground(styledText.getDisplay().getSystemColor(SWT.COLOR_WHITE)); styledText.drawBackground(gc, paintX, paintY, client.width, this.getHeightInPx()); gc.setForeground(styledText.getDisplay().getSystemColor(SWT.COLOR_GRAY)); Font font = new Font(styledText.getDisplay(), "Arial", 9, SWT.ITALIC); gc.setFont(font); String text = getText(gc, paintSpaceLeadingX); if (text != null) { int y = paintY + 4; gc.drawText(text, paintSpaceLeadingX, y); if (hoveredCodeLensEndX != null) { Point extent = gc.textExtent(text); gc.drawLine(hoveredCodeLensStartX, y + extent.y - 1, hoveredCodeLensEndX, y + extent.y - 1); } } }
/** * Recursive function for setting up children controls for a control if it is * a composite and setting up the main control's manager. * @param part * @param control */ private void setupControls(IWorkbenchPart part, Control control) { //If composite, setup children controls. if (control instanceof Composite) { Composite composite = (Composite) control; Control[] children = composite.getChildren(); if (children.length > 0 && children[0] != null) { for (Control curControl : children) setupControls(part, curControl); } } if (control instanceof StyledText) { //set up styled text manager if there is one setupStyledText((IEditorPart) part, (StyledText) control); } else if (control instanceof Browser) { //set up browser manager if there is one setupBrowser((Browser) control); } //TODO: no control set up for a ProjectExplorer, since there isn't an need for //a Manager right now, might be needed in the future }
private static /* org.eclipse.swt.custom.StyledTextRenderer */ Object createStyledTextRenderer( StyledText styledText, ILineSpacingProvider lineSpacingProvider) throws Exception { // get the org.eclipse.swt.custom.StyledTextRenderer instance of // StyledText /* org.eclipse.swt.custom.StyledTextRenderer */ Object originalRenderer = getRendererField(styledText) .get(styledText); // Create a Javassist proxy ProxyFactory factory = new ProxyFactory(); factory.setSuperclass(originalRenderer.getClass()); StyledTextRenderer renderer = new StyledTextRenderer(styledText, originalRenderer.getClass()); renderer.setLineSpacingProvider(lineSpacingProvider); factory.setHandler(renderer); return factory.create(new Class[] { Device.class, StyledText.class }, new Object[] { styledText.getDisplay(), styledText }); }
protected void createTextWidget(String textContents) { StyledText styledText = new StyledText(getComposite(), SWT.NONE); styledText.setText(textContents); styledText.setFont(getCourierFont()); styledText.setEditable(false); //styledText.setWordWrap(true); // seems to throw size out-of-whack Point size = styledText.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); getComposite().setContent(styledText); getComposite().setExpandHorizontal(true); getComposite().setExpandVertical(true); getComposite().setMinWidth(size.x); getComposite().setMinHeight(size.y); getComposite().getContent().addListener(SWT.KeyUp, getToolbarCommandHandler()); getToolItem().setSelection(true); setContentTypeAdapter(new StyledTextAdapter(styledText, getFileEntry().getFilename())); }
private void createContents(String str) { aboutToolsShell = new Shell(getParent(), getStyle()); aboutToolsShell.setImage(SWTResourceManager.getImage(ShortcutKeyExplain.class, Resource.IMAGE_ICON)); aboutToolsShell.setSize(400, 391); aboutToolsShell.setText(getText()); PubUtils.setCenterinParent(getParent(), aboutToolsShell); Link link = new Link(aboutToolsShell, SWT.NONE); link.setBounds(143, 336, 108, 17); link.setText("<a>www.itlaborer.com</a>"); link.addSelectionListener(new LinkSelection()); StyledText readMeTextLabel = new StyledText(aboutToolsShell, SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL); readMeTextLabel.setBounds(3, 33, 389, 297); readMeTextLabel.setText(str); Label label_2 = new Label(aboutToolsShell, SWT.NONE); label_2.setFont(org.eclipse.wb.swt.SWTResourceManager.getFont("微软雅黑", 9, SWT.BOLD)); label_2.setText("快捷键说明:"); label_2.setBounds(3, 12, 136, 17); }
private StyledText createStyledText() { styledText = new StyledText(shell, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); // SWT.WRAP GridData gridData = new GridData(); styledText.setFont( new Font(shell.getDisplay(), "Source Code Pro Light", 10, SWT.NORMAL)); gridData.horizontalAlignment = GridData.FILL; gridData.grabExcessHorizontalSpace = true; gridData.verticalAlignment = GridData.FILL; gridData.grabExcessVerticalSpace = true; styledText.setLayoutData(gridData); styledText.addLineStyleListener(lineStyler); styledText.setEditable(false); styledText .setBackground(Display.getDefault().getSystemColor(SWT.COLOR_GRAY)); return styledText; }
/** * Create the composite. * * @param parent * @param expressionEditorTextBox * @param categoriesComposite * @param style */ public FunctionsComposite(Composite parent, StyledText expressionEditorTextBox, CategoriesComposite categoriesComposite, int style) { super(parent, style); setLayout(new GridLayout(1, false)); this.expressionEditorTextBox=expressionEditorTextBox; functionUppersComposite = new FunctionsUpperComposite(this, SWT.BORDER); GridData gd_composite = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1); gd_composite.heightHint = 35; functionUppersComposite.setLayoutData(gd_composite); methodList = new List(this, SWT.BORDER | SWT.V_SCROLL); methodList.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); addDragSupport(); linkFunctionAndClassComposite(categoriesComposite); functionUppersComposite.setMethodList(methodList); functionUppersComposite.setClassNameList(categoriesComposite.getClassNamelist()); addListnersToMethodList(methodList); addDoubleClickListner(methodList); }
public StyledText newTextArea(Composite composite, boolean editable, int sty) { int style = SWT.MULTI | SWT.V_SCROLL; if (!editable) style |= SWT.READ_ONLY; else style |= SWT.WRAP; StyledText d = new StyledText(composite, style); d.setText("To be entered\ntest\n\test\ntest"); GridData gd = new GridData(GridData.FILL_HORIZONTAL); gd.heightHint = 80; gd.widthHint = 460; gd.verticalAlignment = GridData.VERTICAL_ALIGN_BEGINNING; d.setEditable(editable); d.setLayoutData(gd); d.setFont(FontShop.textFont()); if (keyListener != null) d.addKeyListener(keyListener); d.setWordWrap(editable); WidgetShop.tweakTextWidget(d); return d; }
/** * The function will move cursor in reverse direction. * @param styledText * @param text * @param prevLineIndex * @param nextLineIndex * @return int[] */ public int[] prevButtonListener(StyledText styledText, String text, int prevLineIndex, int nextLineIndex){ logger.debug("StyledText prev button selected"); if(prevLineIndex == 0){ prevLineIndex = styledText.getText().length() - 1; } int lastIndex = StringUtils.lastIndexOf(StringUtils.lowerCase(styledText.getText()), StringUtils.lowerCase(text), prevLineIndex-1); if(lastIndex < 0 ){ prevLineIndex = styledText.getText().length() - 1; prevLineIndex= StringUtils.lastIndexOf(StringUtils.lowerCase(styledText.getText()), StringUtils.lowerCase(text), prevLineIndex-1); styledText.setSelection(prevLineIndex); setStyledRange(styledText, prevLineIndex, text.length(), null, Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY)); nextLineIndex = prevLineIndex + 1; return new int[]{prevLineIndex,nextLineIndex}; }else{ setStyledRange(styledText, lastIndex, text.length(), null, Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY)); styledText.setSelection(lastIndex); prevLineIndex = lastIndex; nextLineIndex = lastIndex + 1; styledText.redraw(); } return new int[]{prevLineIndex,nextLineIndex}; }
/** * The function will move the cursor in forward direction. * @param styledText * @param text * @param prevLineIndex * @param nextLineIndex * @return int[] */ public int[] nextButtonListener(StyledText styledText, String text, int prevLineIndex, int nextLineIndex){ logger.debug("StyledText next button selected"); int txtIndex = StringUtils.indexOf(StringUtils.lowerCase(styledText.getText()), StringUtils.lowerCase(text), nextLineIndex); if(txtIndex < 0){ nextLineIndex = 0; prevLineIndex = StringUtils.indexOf(StringUtils.lowerCase(styledText.getText()), StringUtils.lowerCase(text), nextLineIndex); nextLineIndex = prevLineIndex + 1; styledText.setSelection(prevLineIndex); setStyledRange(styledText, prevLineIndex, text.length(), null, Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY)); return new int[]{prevLineIndex,nextLineIndex}; }else{ setStyledRange(styledText, txtIndex, text.length(), null, Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY)); styledText.setSelection(txtIndex); prevLineIndex = txtIndex; nextLineIndex = txtIndex+1; styledText.redraw(); } return new int[]{prevLineIndex,nextLineIndex}; }
/** * The function will change selected text background color. * @param styledText * @param text * @param foreground * @param background */ public void allButtonListener(StyledText styledText, String text, Color foreground, Color background, Label label){ logger.debug("StyledText All button selected"); int index = 0; int recordCount = 0; if(styledText == null){return;} for(;index < styledText.getText().length();){ int lastIndex = StringUtils.indexOf(StringUtils.lowerCase(styledText.getText()), StringUtils.lowerCase(text), index); if(lastIndex < 0){return;} else{ setStyledRange(styledText, lastIndex, text.length(), null, background); index = lastIndex + 1; recordCount++ ; label.setVisible(true); label.setText("Matching count - " + recordCount); } } }
/** * Create contents of the application window. * * @param parent the parent * @return the control */ @Override protected Control createContents(Composite parent) { getShell().setText("Execution tracking console - " + consoleName); getShell().setBounds(50, 250, 450, 500); Composite container = new Composite(parent, SWT.NONE); container.setLayout(new GridLayout(1, false)); { styledText = new StyledText(container, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); styledText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); styledText.setEditable(false); } statusLineManager.setMessage("Waiting for tracking status from server. Please wait!"); return container; }
/** * Creates and returns a new IGazeHandler object from the specified object * and partRef, or returns null if no handler object is defined for that object. */ public static IGazeHandler createHandler(Object target, IWorkbenchPartReference partRef) { // create gaze handler for a StyledText widget within an EditorPart if (target instanceof StyledText && partRef instanceof IEditorReference) { return new StyledTextGazeHandler(target); //can go back to using partRef } else if (target instanceof Browser) { //create gaze handler for a Browser Stack overflow and Bug Report widget //cannot get associated partRef return new BrowserGazeHandler(target); } else if (target instanceof Tree && partRef instanceof IViewReference && partRef.getTitle().equals("Project Explorer")) { //create gaze handler for a Project Explorer Tree return new ProjectExplorerGazeHandler(target, partRef); } return null; }
/** * Constructor. Loads the AST and sets up the StyledText to automatically * reload after certain events. * @param editor IEditorPart which owns the following StyledText. * @param styledText StyledText to which this AST pertains. */ public AstManager(IEditorPart editor, StyledText styledText) { try { editorPath = ((IFileEditorInput) editor.getEditorInput()).getFile() .getFullPath().toFile().getCanonicalPath(); } catch (IOException e) { // ignore IOErrors while constructing path editorPath = "?"; } this.editor = editor; this.styledText = styledText; //This is the only why I know to get the ProjectionViewer. Perhaps there is better way. ~Ben ITextOperationTarget t = (ITextOperationTarget) editor.getAdapter(ITextOperationTarget.class); if(t instanceof ProjectionViewer) projectionViewer = (ProjectionViewer)t; hookupAutoReload(); reload(); }
@Override protected Composite createToolTipContentArea(final Event event, final Composite parent) { final Object layoutData = parent.getLayoutData(); final StyledText text = lastDescriptor.toStyledText(parent, NONE); if (layoutData instanceof GridData) { ((GridData) layoutData).heightHint = text.getBounds().height; ((GridData) layoutData).widthHint = text.getBounds().width; } return parent; }
private void createErrorGroup(Composite parent) { Composite errorGroup = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.numColumns = 1; errorGroup.setLayout(layout); errorGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); errorGroup.setFont(parent.getFont()); errorText = new StyledText(errorGroup, SWT.READ_ONLY | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); errorText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); }
/** * Copy text into clipboard * * @param text Any control capable of holding text */ void actionCopyText(Control text) { /* Control is a StyledText widget */ if (text instanceof StyledText) { if (((StyledText) text).getText() != null) { /* User has selected text */ if (((StyledText) text).getSelectionCount() > 0) cb.setContents(new Object[]{((StyledText) text).getSelectionText()}, new Transfer[]{TextTransfer.getInstance()}); /* User has not selected text */ else cb.setContents(new Object[]{((StyledText) text).getText()}, new Transfer[]{TextTransfer.getInstance()}); } } }
/** * Unregisters a document manager with an editor. * @param doc the document to be managed * @param st the styled text of the editor * @param dm the document manager */ public static void unregister(IDocument doc, StyledText st, DocumentManager dm) { if (doc != null) { doc.removeDocumentListener(dm); IDocumentUndoManager undoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(doc); DocumentUndoManagerRegistry.disconnect(doc); if (undoManager != null) { undoManager.removeDocumentUndoListener(dm); } } if (st != null) { st.removeListener(SWT.KeyDown, dm); st.removeListener(SWT.MouseDown, dm); st.removeListener(SWT.MouseDoubleClick, dm); } }
private void ensureColorsFetched() { if (bgColor == null || fgColor == null) { ISourceViewer sourceViewer = getSourceViewer(); if (sourceViewer == null) { return; } StyledText textWidget = sourceViewer.getTextWidget(); if (textWidget == null) { return; } /* * TODO ATR, 03.02.2017: there should be an easier approach to get * editors back and foreground, without syncexec */ EclipseUtil.getSafeDisplay().syncExec(new Runnable() { @Override public void run() { bgColor = ColorUtil.convertToHexColor(textWidget.getBackground()); fgColor = ColorUtil.convertToHexColor(textWidget.getForeground()); } }); } }
protected final IRegion getSignedSelection(ISourceViewer sourceViewer) { Point viewerSelection = sourceViewer.getSelectedRange(); StyledText text = sourceViewer.getTextWidget(); Point selection = text.getSelectionRange(); if (text.getCaretOffset() == selection.x) { viewerSelection.x = viewerSelection.x + viewerSelection.y; viewerSelection.y = -viewerSelection.y; } return new Region(viewerSelection.x, viewerSelection.y); }
/** * Set the text of the display from a StyledString object * @param text The StyledText object on the display to set * @param styledString The text with which to set the display to in StyledString format */ private void setThreadSafeText(StyledText text, StyledString styledString) { if (text.isDisposed()) { return; } text.getDisplay().syncExec(() -> { if (text.isDisposed()) { return; } text.setText(styledString.toString()); text.setStyleRanges(styledString.getStyleRanges()); }); }
@SuppressWarnings("squid:S1604") private void setThreadSafeText(StyledText text, StyledString styledString) { if (text.isDisposed()) { return; } text.getDisplay().syncExec(new Runnable() { @Override public void run() { if (text.isDisposed()) { return; } text.setText(styledString.toString()); text.setStyleRanges(styledString.getStyleRanges()); } }); }
@Override public int getAfterLineNumber() { if (offsetAtLine != -1) { try { StyledText styledText = textViewer.getTextWidget(); afterLineNumber = textViewer.getDocument().getLineOfOffset(offsetAtLine); //styledText.getLineAtOffset(offsetAtLine); } catch (Exception e) { // e.printStackTrace(); return -1; } } return afterLineNumber; }
@Override public void layoutZone(IViewZone zone) { StyledText styledText = textViewer.getTextWidget(); int line = zone.getAfterLineNumber(); if (line == 0) { styledText.setTopMargin(zone.isDisposed() ? originalTopMargin : zone.getHeightInPx()); } else { line--; int start = styledText.getOffsetAtLine(line); int length = styledText.getText().length() - start; styledText.redrawRange(start, length, true); } }
@Override public void draw(int paintX, int paintSpaceLeadingX, int paintY, GC gc) { StyledText styledText = super.getTextViewer().getTextWidget(); Rectangle client = styledText.getClientArea(); gc.setBackground(styledText.getDisplay().getSystemColor(SWT.COLOR_WHITE)); styledText.drawBackground(gc, paintX, paintY, client.width, super.getHeightInPx()); gc.setForeground(styledText.getDisplay().getSystemColor(SWT.COLOR_GRAY)); Font font = new Font(styledText.getDisplay(), "Arial", 9, SWT.ITALIC); gc.setFont(font); gc.drawText(this.getText(), paintX, paintY + 4); }
@Override public void mouseHover(MouseEvent event) { hover = event; StyledText styledText = getTextViewer().getTextWidget(); styledText.setCursor(styledText.getDisplay().getSystemCursor(SWT.CURSOR_HAND)); }
@Override public void dispose() { if (!isDisposed()) { StyledText styledText = getTextViewer().getTextWidget(); styledText.getDisplay().syncExec(() -> styledText.setCursor(null)); } super.dispose(); }
public static void setVariableLineHeight(StyledText styledText) { try { Method m1 = styledText.getClass().getDeclaredMethod("setVariableLineHeight"); m1.setAccessible(true); m1.invoke(styledText); } catch (Exception e) { e.printStackTrace(); } }
public static void resetCache(StyledText styledText, int firstLine, int count) { try { Method m1 = styledText.getClass().getDeclaredMethod("resetCache", int.class, int.class); m1.setAccessible(true); m1.invoke(styledText, firstLine, count); } catch (Exception e) { e.printStackTrace(); } }
public static void setCaretLocation(StyledText styledText) { try { Method m1 = styledText.getClass().getDeclaredMethod("setCaretLocation"); m1.setAccessible(true); m1.invoke(styledText); } catch (Exception e) { e.printStackTrace(); } }
private static void initialize(Object styledTextRenderer, StyledText styledText) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException { // renderer.setContent(content); Method m1 = getSetContentMethod(styledTextRenderer); m1.invoke(styledTextRenderer, styledText.getContent()); // renderer.setFont(getFont(), tabLength); Method m2 = getSetFontMethod(styledTextRenderer); m2.invoke(styledTextRenderer, styledText.getFont(), 4); }
public StyledText newTextArea(Composite composite, boolean editable) { int style = SWT.MULTI | SWT.V_SCROLL; if (!editable) style |= SWT.READ_ONLY; else style |= SWT.WRAP; return newTextArea(composite, editable, style); }
public static void main(String[] args) throws Exception { // create the widget's shell Shell shell = new Shell(); shell.setLayout(new FillLayout()); shell.setSize(500, 500); Display display = shell.getDisplay(); Composite parent = new Composite(shell, SWT.NONE); parent.setLayout(new GridLayout()); StyledText styledText = new StyledText(parent, SWT.BORDER | SWT.V_SCROLL); styledText.setLayoutData(new GridData(GridData.FILL_BOTH)); styledText.setText("a\nb\nc\nd"); StyledTextPatcher.setLineSpacingProvider(styledText, new ILineSpacingProvider() { @Override public Integer getLineSpacing(int lineIndex) { if (lineIndex == 0) { return 10; } else if (lineIndex == 1) { return 30; } return null; } }); shell.open(); while (!shell.isDisposed()) if (!display.readAndDispatch()) display.sleep(); }
public static void main(String[] args) throws Exception { // create the widget's shell Shell shell = new Shell(); shell.setLayout(new FillLayout()); shell.setSize(500, 500); Display display = shell.getDisplay(); Composite parent = new Composite(shell, SWT.NONE); parent.setLayout(new GridLayout(2, false)); ITextViewer textViewer = new TextViewer(parent, SWT.V_SCROLL | SWT.BORDER); textViewer.setDocument(new Document("")); StyledText styledText = textViewer.getTextWidget(); styledText.setLayoutData(new GridData(GridData.FILL_BOTH)); ViewZoneChangeAccessor viewZones = new ViewZoneChangeAccessor(textViewer); Button add = new Button(parent, SWT.NONE); add.setLayoutData(new GridData(SWT.RIGHT, SWT.TOP, false, false, 0, 0)); add.setText("Add Zone"); add.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { InputDialog dlg = new InputDialog(Display.getCurrent().getActiveShell(), "", "Enter view zone content", "Zone " + viewZones.getSize(), null); if (dlg.open() == Window.OK) { int line = styledText.getLineAtOffset(styledText.getCaretOffset()); IViewZone zone = new DefaultViewZone(line, 20, dlg.getValue()); viewZones.addZone(zone); viewZones.layoutZone(zone); } } }); shell.open(); while (!shell.isDisposed()) if (!display.readAndDispatch()) display.sleep(); }