Java Code Examples for org.netbeans.editor.BaseDocument#render()
The following examples show how to use
org.netbeans.editor.BaseDocument#render() .
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: AttributeValueFinderTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testFind() throws Exception { final String contents = TestUtils.createXMLConfigText("<bean id='foo' class='org.example.Foo'><ref></ref></bean>"); BaseDocument doc = TestUtils.createSpringXMLConfigDocument(contents); final XMLSyntaxSupport syntaxSupport = XMLSyntaxSupport.getSyntaxSupport(doc); doc.render(new Runnable() { public void run() { int beanOffset = contents.indexOf("<bean "); int classOffset = contents.indexOf("'org.example.Foo'"); AttributeValueFinder finder = new AttributeValueFinder(syntaxSupport, beanOffset); try { assertTrue(finder.find("class")); assertEquals(classOffset, finder.getFoundOffset()); assertEquals("'org.example.Foo'", finder.getValue()); } catch (BadLocationException e) { fail(e.toString()); } } }); }
Example 2
Source File: AttributeFinderTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testFind() throws Exception { final String contents = TestUtils.createXMLConfigText("<bean id='foo' class='org.example.Foo'><ref></ref></bean>"); BaseDocument doc = TestUtils.createSpringXMLConfigDocument(contents); final XMLSyntaxSupport syntaxSupport = XMLSyntaxSupport.getSyntaxSupport(doc); doc.render(new Runnable() { public void run() { int beanOffset = contents.indexOf("<bean "); int classOffset = contents.indexOf("class"); AttributeFinder finder = new AttributeFinder(syntaxSupport, beanOffset); try { assertTrue(finder.find("class")); assertEquals(classOffset, finder.getFoundOffset()); } catch (BadLocationException e) { fail(e.toString()); } } }); }
Example 3
Source File: PropertyChildFinderTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testFind() throws Exception { final String contents = TestUtils.createXMLConfigText("<bean id='foo' class='org.example.Foo'><property name='foobar' value='sample'/></bean>"); BaseDocument doc = TestUtils.createSpringXMLConfigDocument(contents); final XMLSyntaxSupport syntaxSupport = XMLSyntaxSupport.getSyntaxSupport(doc); doc.render(new Runnable() { public void run() { int beanOffset = contents.indexOf("<bean "); int propOffset = contents.indexOf("'foobar'"); PropertyChildFinder finder = new PropertyChildFinder(syntaxSupport, beanOffset); try { assertTrue(finder.find("foobar")); assertEquals(propOffset, finder.getFoundOffset()); assertEquals("'foobar'", finder.getValue()); } catch (BadLocationException e) { fail(e.toString()); } } }); }
Example 4
Source File: TplCompletionProvider.java From netbeans with Apache License 2.0 | 6 votes |
private static void checkHideCompletion(final BaseDocument doc, final int caretOffset) { //test whether we are just in text and eventually close the opened completion //this is handy after end tag autocompletion when user doesn't complete the //end tag and just types a text //test whether the user typed an ending quotation in the attribute value doc.render(new Runnable() { @Override public void run() { TokenHierarchy tokenHierarchy = TokenHierarchy.get(doc); TokenSequence tokenSequence = tokenHierarchy.tokenSequence(); tokenSequence.move(caretOffset == 0 ? 0 : caretOffset - 1); if (!tokenSequence.moveNext()) { return; } } }); }
Example 5
Source File: LessLexerTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testLexing() { FileObject testFile = getTestFile("testFiles/test.less"); BaseDocument document = getDocument(testFile); final TokenHierarchy th = TokenHierarchy.get(document); document.render(new Runnable() { @Override public void run() { TokenSequence tokenSequence = th.tokenSequence(); assertTrue(tokenSequence.moveNext()); //just one big fat token Token token = tokenSequence.token(); assertEquals(CPTokenId.CSS, token.id()); //with embedded plain css tokens TokenSequence<CssTokenId> embedded = tokenSequence.embedded(CssTokenId.language()); assertNotNull(embedded); assertFalse(tokenSequence.moveNext()); //no more tokens } }); }
Example 6
Source File: HtmlCompletionProvider.java From netbeans with Apache License 2.0 | 6 votes |
private static void checkHideCompletion(final BaseDocument doc, final int caretOffset) { //test whether we are just in text and eventually close the opened completion //this is handy after end tag autocompletion when user doesn't complete the //end tag and just types a text //test whether the user typed an ending quotation in the attribute value doc.render(new Runnable() { @Override public void run() { TokenHierarchy tokenHierarchy = TokenHierarchy.get(doc); TokenSequence tokenSequence = tokenHierarchy.tokenSequence(); tokenSequence.move(caretOffset == 0 ? 0 : caretOffset - 1); if (!tokenSequence.moveNext()) { return; } Token tokenItem = tokenSequence.token(); if (tokenItem.id() == HTMLTokenId.TEXT && !tokenItem.text().toString().startsWith("<") && !tokenItem.text().toString().startsWith("&")) { hideCompletion(); } } }); }
Example 7
Source File: HighlightURLs.java From netbeans with Apache License 2.0 | 5 votes |
static void ensureAttached(final BaseDocument doc) { if (doc.getProperty(REGISTERED_KEY) != null) { return; } final HighlightURLs h = new HighlightURLs(doc); doc.putProperty(REGISTERED_KEY, true); if (h.coloring == null) { LOG.log(Level.WARNING, "'url' coloring cannot be found"); return; } doc.addDocumentListener(h); doc.render(new Runnable() { @Override public void run() { try { h.modifiedSpans.add(new Position[] { doc.createPosition(0, Bias.Backward), doc.createPosition(doc.getLength(), Bias.Forward) }); } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } } }); h.schedule(); }
Example 8
Source File: RADIO.java From netbeans with Apache License 2.0 | 5 votes |
private String[] findGroups(final BaseDocument doc) { final CharSequence[] content = new CharSequence[1]; doc.render(new Runnable() { public void run() { try { content[0] = doc.getText(0, doc.getLength()); } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } } }); CharSequence code = content[0]; if (code == null) { return new String[]{}; } List<String> names = new ArrayList<String>(); //search for the input tags HtmlSource source = new HtmlSource(code); Iterator<Element> elements = new ElementsIterator(source); while(elements.hasNext()) { Element e = elements.next(); if (e.type() == ElementType.OPEN_TAG) { OpenTag tag = (OpenTag) e; if (LexerUtils.equals("input", tag.name(), true, true)) { //NOI18N Attribute typeAttr = tag.getAttribute("type"); //NOI18N Attribute nameAttr = tag.getAttribute("name"); //NOI18N if (typeAttr != null && nameAttr != null) { if (LexerUtils.equals("radio", typeAttr.unquotedValue(), true, true)) { //NOI18N CharSequence value = nameAttr.unquotedValue(); if(value != null) { names.add(value.toString()); } } } } } } return names.toArray(new String[]{}); }
Example 9
Source File: HtmlTypedTextInterceptor.java From netbeans with Apache License 2.0 | 4 votes |
private static boolean skipExistingQuote(final Context context) throws BadLocationException { if (!HtmlPreferences.autocompleteQuotes()) { return false; } final BaseDocument doc = (BaseDocument) context.getDocument(); final AtomicBoolean result = new AtomicBoolean(); doc.render(new Runnable() { @Override public void run() { int dotPos = context.getOffset(); int qchar = context.getText().charAt(0); //test whether the user typed an ending quotation in the attribute value TokenSequence<HTMLTokenId> ts = LexUtilities.getTokenSequence(doc, dotPos, HTMLTokenId.language()); if (ts == null) { return; } int diff = ts.move(dotPos); if (diff == 0) { if (!ts.movePrevious()) { return; } } else { if (!ts.moveNext()) { return; } } Token<HTMLTokenId> token = ts.token(); if (isHtmlValueToken(token)) { //test if the user inserted the quotation in an attribute value and before //an already existing end quotation //the text looks following in such a situation: // // atrname="abcd|"", where offset of the | == dotPos if (diff > 0 && token.text().charAt(diff) == qchar) { // NOI18N context.getComponent().setCaretPosition(dotPos + 1); result.set(true); } } } }); return result.get(); }
Example 10
Source File: NavigationHistoryBackAction.java From netbeans with Apache License 2.0 | 4 votes |
static void show(NavigationHistory.Waypoint wpt) { final int offset = wpt.getOffset(); if (offset < 0) { return; } Lookup lookup = findLookupFor(wpt); if (lookup != null) { final EditorCookie editorCookie = lookup.lookup(EditorCookie.class); final LineCookie lineCookie = lookup.lookup(LineCookie.class); Document doc = null; if (editorCookie != null && lineCookie != null) { try { doc = editorCookie.openDocument(); } catch (IOException ioe) { LOG.log(Level.WARNING, "Can't open document", ioe); //NOI18N } } if (doc instanceof BaseDocument) { final BaseDocument baseDoc = (BaseDocument) doc; final Line[] line = new Line[1]; final int column[] = new int[1]; baseDoc.render(new Runnable() { @Override public void run() { Element lineRoot = baseDoc.getParagraphElement(0).getParentElement(); int lineIndex = lineRoot.getElementIndex(offset); if (lineIndex != -1) { Element lineElement = lineRoot.getElement(lineIndex); column[0] = offset - lineElement.getStartOffset(); line[0] = lineCookie.getLineSet().getCurrent(lineIndex); } } }); // Line.show() must NOT be called under doc.writeLock(). // By possible thread's waiting in CloneableEditor.getEditorPane() // an asynchronous editor pane opening would be blocked // by the write-lock. // In case the current unlocked Line.show() solution would be found // unsatisfactory then issue #232175 should be reopened. if (line[0] != null) { line[0].show(ShowOpenType.REUSE, ShowVisibilityType.FOCUS, column[0]); return; } } } // lookup didn't work try simple navigation in the text component JTextComponent component = wpt.getComponent(); if (component != null && component.getCaret() != null) { component.setCaretPosition(offset); component.requestFocusInWindow(); } }