public LineEditor(final SWTCanvas canvas, int style) { super(canvas, style, TrpTextLineType.class); textField = new StyledText(SWTUtil.dummyShell, SWT.SINGLE | SWT.BORDER); textField.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1)); // this one highlights words that are tagged: textField.addLineStyleListener(new LineStyleListener() { @Override public void lineGetStyle(LineStyleEvent event) { if (shape==null) return; // List<StyleRange> styleList = ATranscriptionWidget.getTagStylesForLine(shape, event.lineOffset); // event.styles = (StyleRange[]) ArrayUtils.addAll(event.styles, styleList.toArray(new StyleRange[0])); } }); addWidget(textField); // autocomplete field: autocomplete = new TrpAutoCompleteField(textField, new StyledTextContentAdapter(textField), new String[]{}, KeyStroke.getInstance(SWT.CTRL, SWT.SPACE), null ); autocomplete.getAdapter().setEnabled(false); }
public void show(String title, final String message, LineStyleListener listener) { initLayout(); dialog.setText(title); text.setText(message); if (listener != null) { text.addLineStyleListener(listener); } dialog.pack(); dialog.open(); }
public static void applyStyledFormat(StyledText text, String sql) { if (StringUtil.isEmpty(sql)) return; text.setText(sql); text.addLineStyleListener(new LineStyleListener() { public void lineGetStyle(LineStyleEvent event) { String line = event.lineText; LinkedList<StyleRange> list = new LinkedList<StyleRange>(); line = line.toLowerCase(); String[] tokens = StringUtil.tokenizer(line, " \n\r\f\t()+*/-=<>'`\"[],"); if (tokens == null) return; HashSet<String> set = new HashSet<String>(); for (int i = 0; i < tokens.length; i++) { set.add(tokens[i]); } for (int i = 0; i < key.length; i++) { if (set.contains(key[i])) { int cursor = -1; while ((cursor = line.indexOf(key[i], cursor + 1)) > -1) { StyleRange sr = new StyleRange(); sr.start = event.lineOffset + cursor; sr.length = key[i].length(); sr.foreground = Display.getCurrent().getSystemColor(SWT.COLOR_BLUE); list.add(sr); } } } event.styles = list.toArray(new StyleRange[list.size()]); } }); }
public SearchStyleText() { shell.setLayout(new GridLayout(2, false)); styledText = new StyledText(shell, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL); GridData gridData = new GridData(GridData.FILL_BOTH); gridData.horizontalSpan = 2; styledText.setLayoutData(gridData); keywordText = new Text(shell, SWT.SINGLE | SWT.BORDER); keywordText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Font font = new Font(shell.getDisplay(), "Courier New", 12, SWT.NORMAL); styledText.setFont(font); button = new Button(shell, SWT.PUSH); button.setText("Search"); button.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { keyword = keywordText.getText(); styledText.redraw(); } }); styledText.addLineStyleListener(new LineStyleListener() { public void lineGetStyle(LineStyleEvent event) { if(keyword == null || keyword.length() == 0) { event.styles = new StyleRange[0]; return; } String line = event.lineText; int cursor = -1; LinkedList list = new LinkedList(); while( (cursor = line.indexOf(keyword, cursor+1)) >= 0) { list.add(getHighlightStyle(event.lineOffset+cursor, keyword.length())); } event.styles = (StyleRange[]) list.toArray(new StyleRange[list.size()]); } }); keyword = "SW"; styledText.setText("AWT, SWING \r\nSWT & JFACE"); shell.pack(); shell.open(); //textUser.forceFocus(); // Set up the event loop. while (!shell.isDisposed()) { if (!display.readAndDispatch()) { // If no more entries in event queue display.sleep(); } } display.dispose(); }
public void addUserLineStyleListener(LineStyleListener l) { lineStyleListener.add(l); text.addLineStyleListener(l); }
public void addLineStyleListener(LineStyleListener lineStyler){ styledText.addLineStyleListener(lineStyler); }
public void addLineStyleListener( LineStyleListener lineStyler ) { styledText.addLineStyleListener( lineStyler ); }