List of usage examples for org.eclipse.swt.custom StyledText getText
public String getText()
From source file:TextAroundBox.java
public static void main(String[] args) { final Display display = new Display(); final Color RED = display.getSystemColor(SWT.COLOR_RED); Shell shell = new Shell(display); shell.setBounds(10, 10, 250, 250);//from ww w . j a v a2 s . c o m final StyledText text = new StyledText(shell, SWT.NONE); text.setBounds(10, 10, 200, 200); text.addListener(SWT.Paint, new Listener() { public void handleEvent(Event event) { String contents = text.getText(); int stringWidth = event.gc.stringExtent(SEARCH_STRING).x; int lineHeight = text.getLineHeight(); event.gc.setForeground(RED); int index = contents.indexOf(SEARCH_STRING); while (index != -1) { Point topLeft = text.getLocationAtOffset(index); event.gc.drawRectangle(topLeft.x - 1, topLeft.y, stringWidth + 1, lineHeight - 1); index = contents.indexOf(SEARCH_STRING, index + 1); } } }); text.setText("This demonstrates drawing a box\naround every occurrence of the word\nbox in the StyledText"); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:CrossLineStyleListener.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); final StyledText styledText = new StyledText(shell, SWT.V_SCROLL | SWT.BORDER); final MultiLineCommentListener lineStyleListener = new MultiLineCommentListener(); styledText.addLineStyleListener(lineStyleListener); styledText.addExtendedModifyListener(new ExtendedModifyListener() { public void modifyText(ExtendedModifyEvent event) { // Recalculate the comments lineStyleListener.refreshMultilineComments(styledText.getText()); // Redraw the text styledText.redraw();// w w w .ja v a 2 s .co m } }); styledText.setBounds(10, 10, 500, 100); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); }
From source file:MultiLineComment.java
/** * Creates the main window contents//from www. j a va2 s . c o m * * @param shell the main window */ private void createContents(Shell shell) { shell.setLayout(new FillLayout()); final StyledText styledText = new StyledText(shell, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); // Add the line style listener final MultiLineCommentListener lineStyleListener = new MultiLineCommentListener(); styledText.addLineStyleListener(lineStyleListener); // Add the modification listener styledText.addExtendedModifyListener(new ExtendedModifyListener() { public void modifyText(ExtendedModifyEvent event) { // Recalculate the comments lineStyleListener.refreshMultilineComments(styledText.getText()); // Redraw the text styledText.redraw(); } }); }