Java源码示例:org.netbeans.spi.editor.completion.CompletionDocumentation
示例1
protected void show(CompletionDocumentation doc, int anchorOffset) {
JTextComponent editorComponent = getEditorComponent();
if (editorComponent == null) {
return;
}
if (!isVisible()) { // documentation already visible
setContentComponent(new DocumentationScrollPane(editorComponent));
}
getDocumentationScrollPane().setData(doc);
if (!isVisible()) { // do not check for size as it should remain the same
// Set anchoring only if not displayed yet because completion
// may have overriden the anchoring
setAnchorOffset(anchorOffset);
getLayout().updateLayout(this);
} // otherwise leave present doc displayed
}
示例2
private synchronized void setDocumentation(CompletionDocumentation doc) {
currentDocumentation = doc;
if (currentDocumentation != null) {
String text = currentDocumentation.getText();
URL url = currentDocumentation.getURL();
if (text != null){
Document document = view.getDocument();
document.putProperty(Document.StreamDescriptionProperty, null);
if (url!=null){
// fix of issue #58658
if (document instanceof HTMLDocument){
((HTMLDocument)document).setBase(url);
}
}
view.setContent(text, url != null ? url.getRef() : null);
} else if (url != null){
try{
view.setPage(url);
}catch(IOException ioe){
StatusDisplayer.getDefault().setStatusText(ioe.toString());
}
}
bShowWeb.setEnabled(url != null);
bGoToSource.setEnabled(currentDocumentation.getGotoSourceAction() != null);
}
}
示例3
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e != null && HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) {
final String desc = e.getDescription();
if (desc != null) {
RP.post(new Runnable() {
public @Override void run() {
CompletionDocumentation cd = currentDocumentation;
if (cd != null) {
final CompletionDocumentation doc = cd.resolveLink(desc);
if (doc != null) {
EventQueue.invokeLater(new Runnable() {
public @Override void run() {
setData(doc);
}
});
}
}
}
});
}
}
}
示例4
private CompletionDocumentation createDocResourceResultSet(MockUrlGrammarResult r) throws Exception {
if (r == null) {
r = new MockUrlGrammarResult();
r.setContentURL(createResourceName("res/docResource.html"));
r.setExternal(true);
}
ElementResultItem item = new ElementResultItem(0, r);
CompletionTask task = item.doCreateDocumentationTask(r);
CompletionResultSet rs = resultSetFor(task, CompletionProvider.DOCUMENTATION_QUERY_TYPE);
task.query(rs);
assertTrue(rs.isFinished());
return rsImpl.getDocumentation();
}
示例5
/**
* Checks documentation bundled in a JAR - not openable by external browser.
* Need a resource within a JAR
*
* @throws Exception
*/
public void testInternalUrlDocumentation() throws Exception {
URL res = EncodingUtil.class.getResource("/org/netbeans/modules/xml/core/resources/Bundle.properties");
MockUrlGrammarResult test = new MockUrlGrammarResult();
test.setContentURL(res);
test.setExternal(false);
CompletionDocumentation doc = createDocResourceResultSet(test);
assertNull(doc.getURL());
assertTrue(doc.getText().contains("OpenIDE-Module-Name=XML Core"));
// check that relative links still resolve to internal doc
CompletionDocumentation internal = doc.resolveLink("mf-layer.xml");
assertNotNull("Relative links must be resolvable", internal);
assertNull("Relative links cannot be opened in extbrowser", doc.getURL());
assertTrue("Content must be accessible",
internal.getText().contains("org-netbeans-modules-xml-dtd-grammar-DTDGrammarQueryProvider.instance"));
// check that absolute links resolve to external doc
CompletionDocumentation external = doc.resolveLink("http://www.netbeans.org");
assertNotNull("Absolute links must be resolvable", external);
assertEquals("Absolute links must have URL", external.getURL(), new URL("http://www.netbeans.org"));
}
示例6
/**
* Checks that file-based documentation reverts to external as soon as possible
* @throws Exception
*/
public void testFileDocumentation() throws Exception {
URL res = EncodingUtil.class.getResource("/org/netbeans/modules/xml/core/resources/Bundle.properties");
MockUrlGrammarResult test = new MockUrlGrammarResult();
test.setContentURL(res);
test.setExternal(false);
CompletionDocumentation doc = createDocResourceResultSet(test);
assertNull(doc.getURL());
assertTrue("Invalid content", doc.getText().contains("OpenIDE-Module-Name=XML Core"));
// check that resolve of file-based URL turns the doc to external:
URL url = createResourceName("res/docResource.html");
CompletionDocumentation file = doc.resolveLink(url.toString());
assertNotNull(file);
assertEquals("URL must be openable in browser", url, file.getURL());
assertTrue("Invalid content of the linked doc", file.getText().contains("This is an URL resource with <a href="));
}
示例7
@Override
public CompletionDocumentation resolveLink(String link) {
if ("picker".equals(link)) {
Component component = findComponentUnderMouse();
if (component != null) {
Color color = JColorChooser.showDialog(component, "Color Picker", decodeAlfa(value));
if (color != null) {
try {
BaseDocument document = (BaseDocument) this.document;
int startPosition = caretOffset - 1;
while ('\"' != (document.getChars(startPosition, 1)[0])) {
startPosition--;
}
startPosition++;
document.replace(startPosition, caretOffset - startPosition, getHTMLColorString(color), null);
Completion.get().hideAll();
RankingProvider.inserted(completionText.hashCode());
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
}
}
}
}
return null;
}
示例8
@Override
public CompletionTask createDocumentationTask() {
return new AsyncCompletionTask(new AsyncCompletionQuery() {
@Override
protected void query(CompletionResultSet resultSet, Document doc, int caretOffset) {
CompletionDocumentation docItem = SpringXMLConfigCompletionDoc.createBeanRefDoc(beanId,
beanNames, beanClass, beanLocFile, goToBeanAction);
resultSet.setDocumentation(docItem);
resultSet.finish();
}
});
}
示例9
@Override
public CompletionTask createDocumentationTask() {
return new AsyncCompletionTask(new AsyncCompletionQuery() {
@Override
protected void query(CompletionResultSet resultSet, Document doc, int caretOffset) {
if(docText != null) {
CompletionDocumentation documentation = SpringXMLConfigCompletionDoc.getAttribValueDoc(docText);
resultSet.setDocumentation(documentation);
}
resultSet.finish();
}
});
}
示例10
public synchronized void setDocumentation(CompletionDocumentation documentation) {
checkNotFinished();
if (!active || queryType != CompletionProvider.DOCUMENTATION_QUERY_TYPE) {
return;
}
this.documentation = documentation;
}
示例11
private synchronized void addToHistory(CompletionDocumentation doc) {
int histSize = history.size();
for (int i = currentHistoryIndex + 1; i < histSize; i++){
history.remove(history.size() - 1);
}
history.add(doc);
currentHistoryIndex = history.size() - 1;
if (currentHistoryIndex > 0)
bBack.setEnabled(true);
bForward.setEnabled(false);
}
示例12
private void openInExternalBrowser(){
CompletionDocumentation cd = currentDocumentation;
if (cd != null) {
URL url = cd.getURL();
if (url != null)
HtmlBrowser.URLDisplayer.getDefault().showURL(url);
}
}
示例13
private void goToSource() {
CompletionDocumentation cd = currentDocumentation;
if (cd != null) {
Action action = cd.getGotoSourceAction();
if (action != null)
action.actionPerformed(new ActionEvent(cd, 0, null));
}
}
示例14
@Override
public CompletionDocumentation resolveLink(String link) {
try {
DescriptionSource target = src.resolveLink(link);
if (target != null) {
return new ExtDocum(target, null);
}
URL base = src.getContentURL();
if (base == null) {
// sorry, cannot resolve.
return null;
}
URL targetURL = new URL(base, link);
// leave the VM as soon as possible. This hack uses URLMappers
// to find out whether URL (converted to FO and back) can be
// represented outside the VM
boolean external = true;
FileObject f = URLMapper.findFileObject(targetURL);
if (f != null) {
external = URLMapper.findURL(f, URLMapper.EXTERNAL) != null;
}
return new URLDocum(targetURL, external);
} catch (MalformedURLException ex) {
Exceptions.printStackTrace(ex);
return null;
}
}
示例15
@Override
public CompletionDocumentation resolveLink(String link) {
if (content == null) {
return null;
}
try {
return new URLDocum(new URL(content, link), external);
} catch (MalformedURLException ex) {
Exceptions.printStackTrace(ex);
return null;
}
}
示例16
/**
* Checks that custom contents overrides the one supplied by XMLResultItem
*
* @throws Exception
*/
public void testCustomContent() throws Exception {
URL res = EncodingUtil.class.getResource("/org/netbeans/modules/xml/core/resources/Bundle.properties");
MockUrlGrammarResult test = new MockUrlGrammarResult();
test.setContentURL(res);
test.setExternal(false);
test.setDescription(PLAIN_DESCRIPTION_TEXT);
CompletionDocumentation doc = createDocResourceResultSet(test);
assertNull(doc.getURL());
assertEquals("Invalid content", PLAIN_DESCRIPTION_TEXT, doc.getText());
}
示例17
/**
* Checks that relative and .. link resolution works OK.
*
* @throws Exception
*/
public void testResolveRelativeLinks() throws Exception {
CompletionDocumentation doc = createDocResourceResultSet(null);
assertEquals(createResourceName("res/docResource.html"), doc.getURL());
CompletionDocumentation linked = doc.resolveLink("relativeLink1.html");
assertNotNull(linked);
assertEquals("Relative link must be resolved", createResourceName("res/relativeLink1.html"), linked.getURL());
linked = doc.resolveLink("../parentDoc.html");
assertNotNull(linked);
assertEquals("Link to resource in parent folder must be resolved", createResourceName("parentDoc.html"), linked.getURL());
}
示例18
/**
* Checks that DS returning 'external' provides URL and resolves links, although
* no custom resolver is given
*
* @throws Exception
*/
public void testNetworkUrlDocumentation() throws Exception {
MockUrlGrammarResult test = new MockUrlGrammarResult();
test.setExternal(true);
test.setContentURL(new URL("http://www.netbeans.org"));
CompletionDocumentation doc = createDocResourceResultSet(test);
assertEquals("External documentation must have URL", new URL("http://www.netbeans.org"), doc.getURL());
CompletionDocumentation resolved = doc.resolveLink("index.html");
assertEquals("Resolved external link must have URL", new URL("http://www.netbeans.org/index.html"), resolved.getURL());
}
示例19
/**
* Checks that without content URL, no item is produced
* @throws Exception
*/
public void testNoContentUrl() throws Exception {
MockUrlGrammarResult res = new MockUrlGrammarResult();
CompletionDocumentation doc = createDocResourceResultSet(res);
assertNull(doc);
}
示例20
@Override
public CompletionDocumentation resolveLink(String link) {
if (linkResolver != null) {
return linkResolver.resolveLink(link);
}
return null;
}
示例21
@Override
public CompletionDocumentation resolveLink(String link) {
return null;
}
示例22
public CompletionDocumentation resolveLink(String link) {
return null;
}
示例23
@Override
public CompletionDocumentation resolveLink(String link) {
return null;
}
示例24
@Override
public CompletionDocumentation resolveLink(String link) {
return null;
}
示例25
@Override
public CompletionDocumentation resolveLink(String link) {
return null;
}
示例26
@Override
public CompletionDocumentation resolveLink(String link) {
return null;
}
示例27
@Override
public CompletionDocumentation resolveLink(String link) {
return null;
}
示例28
public CompletionDocumentation resolveLink(String link) {
return null;
}
示例29
@Override
public CompletionDocumentation resolveLink(String link) {
return null;
}
示例30
public CompletionDocumentation resolveLink(String link) {
return null;
}