本文整理汇总了Java中org.openide.text.NbDocument类的典型用法代码示例。如果您正苦于以下问题:Java NbDocument类的具体用法?Java NbDocument怎么用?Java NbDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NbDocument类属于org.openide.text包,在下文中一共展示了NbDocument类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: useCurrentlySelectedText
import org.openide.text.NbDocument; //导入依赖的package包/类
/**
* Set currently selected text (in editor) as "Text to find" value.
*/
public void useCurrentlySelectedText() {
Node[] arr = TopComponent.getRegistry().getActivatedNodes();
if (arr.length > 0) {
EditorCookie ec = arr[0].getLookup().lookup(EditorCookie.class);
if (ec != null) {
JEditorPane recentPane = NbDocument.findRecentEditorPane(ec);
if (recentPane != null) {
String initSearchText = recentPane.getSelectedText();
if (initSearchText != null) {
cboxTextToFind.setSearchPattern(SearchPattern.create(
initSearchText, false, false, false));
searchCriteria.setTextPattern(initSearchText);
return;
}
}
}
}
searchCriteria.setTextPattern(
cboxTextToFind.getSearchPattern().getSearchExpression());
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:BasicSearchForm.java
示例2: computeLineSpan
import org.openide.text.NbDocument; //导入依赖的package包/类
static int[] computeLineSpan(Document doc, int lineNumber) throws BadLocationException {
lineNumber = Math.min(lineNumber, NbDocument.findLineRootElement((StyledDocument) doc).getElementCount());
int lineStartOffset = NbDocument.findLineOffset((StyledDocument) doc, Math.max(0, lineNumber - 1));
int lineEndOffset;
if (doc instanceof BaseDocument) {
lineEndOffset = Utilities.getRowEnd((BaseDocument) doc, lineStartOffset);
} else {
//XXX: performance:
String lineText = doc.getText(lineStartOffset, doc.getLength() - lineStartOffset);
lineText = lineText.indexOf('\n') != (-1) ? lineText.substring(0, lineText.indexOf('\n')) : lineText;
lineEndOffset = lineStartOffset + lineText.length();
}
int[] span = new int[] {lineStartOffset, lineEndOffset};
computeLineSpan(doc, span);
return span;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:HintsControllerImpl.java
示例3: openDocument
import org.openide.text.NbDocument; //导入依赖的package包/类
@Override
@NbBundle.Messages({"LBL_OpenDocument=Open Document",
"# {0} - to be opened documents path", "MSG_CannotOpen=Could not open document with path\n {0}",
"# {0} - to be found documents path", "MSG_CannotFind=Could not find document with path\n {0}"})
public void openDocument(final String path, final int offset) {
final FileObject fo = findFile(path);
if ( fo != null ) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
DataObject od = DataObject.find(fo);
boolean ret = NbDocument.openDocument(od, offset, -1, Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS);
if(!ret) {
notifyError(Bundle.LBL_OpenDocument(), Bundle.MSG_CannotOpen(path));
}
} catch (DataObjectNotFoundException e) {
IDEServicesImpl.LOG.log(Level.SEVERE, null, e);
}
}
});
} else {
notifyError(Bundle.LBL_OpenDocument(), Bundle.MSG_CannotFind(path));
}
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:IDEServicesImpl.java
示例4: testWrapping
import org.openide.text.NbDocument; //导入依赖的package包/类
public void testWrapping() throws Exception {
MimePath mimePath = MimePath.EMPTY;
MockMimeLookup.setInstances(mimePath, new TestingUndoableEditWrapper(), new TestingUndoableEditWrapper2());
CESEnv env = new CESEnv();
Document doc = env.support.openDocument();
// doc.addUndoableEditListener(new UndoableEditListener() {
// @Override
// public void undoableEditHappened(UndoableEditEvent e) {
// UndoableEdit edit = e.getEdit();
// }
// });
doc.insertString(0, "Test", null);
Class wrapEditClass = TestingUndoableEditWrapper.WrapCompoundEdit.class;
assertNotNull(NbDocument.getEditToBeUndoneOfType(env.support, wrapEditClass));
Class wrapEditClass2 = TestingUndoableEditWrapper2.WrapCompoundEdit2.class;
assertNotNull(NbDocument.getEditToBeUndoneOfType(env.support, wrapEditClass2));
// A trick to get whole edit
UndoableEdit wholeEdit = NbDocument.getEditToBeUndoneOfType(env.support, UndoableEdit.class);
assertTrue(wholeEdit instanceof List);
@SuppressWarnings("unchecked")
List<? extends UndoableEdit> listEdit = (List<? extends UndoableEdit>) wholeEdit;
assertEquals(3, listEdit.size());
assertEquals(wrapEditClass, listEdit.get(1).getClass());
assertEquals(wrapEditClass2, listEdit.get(2).getClass());
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:UndoableEditWrapperTest.java
示例5: defaultAction
import org.openide.text.NbDocument; //导入依赖的package包/类
public void defaultAction(final JTextComponent component) {
Completion.get().hideCompletion();
Completion.get().hideDocumentation();
NbDocument.runAtomic((StyledDocument) component.getDocument(), new Runnable() {
public void run() {
Document doc = component.getDocument();
try {
doc.remove(substituteOffset, component.getCaretPosition() - substituteOffset);
doc.insertString(substituteOffset, getText(), null);
} catch (BadLocationException e) {
ErrorManager.getDefault().notify(e);
}
}
});
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:WordCompletionItem.java
示例6: openFileAtOffset
import org.openide.text.NbDocument; //导入依赖的package包/类
private static boolean openFileAtOffset(DataObject dataObject, int offset) throws IOException {
EditorCookie ec = dataObject.getCookie(EditorCookie.class);
LineCookie lc = dataObject.getCookie(LineCookie.class);
if (ec != null && lc != null) {
StyledDocument doc = ec.openDocument();
if (doc != null) {
int lineNumber = NbDocument.findLineNumber(doc, offset);
if (lineNumber != -1) {
Line line = lc.getLineSet().getCurrent(lineNumber);
if (line != null) {
int lineOffset = NbDocument.findLineOffset(doc, lineNumber);
int column = offset - lineOffset;
line.show(ShowOpenType.OPEN, ShowVisibilityType.FOCUS, column);
return true;
}
}
}
}
return false;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:SpringXMLConfigEditorUtils.java
示例7: toString
import org.openide.text.NbDocument; //导入依赖的package包/类
public String toString () {
int offset = next (1) == null ?
doc.getLength () : next (1).getOffset ();
int lineNumber = NbDocument.findLineNumber (doc, offset);
return (String) doc.getProperty ("title") + ":" +
(lineNumber + 1) + "," +
(offset - NbDocument.findLineOffset (doc, lineNumber) + 1);
// StringBuffer sb = new StringBuffer ();
// TokenItem t = next;
// int i = 0;
// while (i < 10) {
// if (t == null) break;
// EditorToken et = (EditorToken) t.getTokenID ();
// sb.append (Token.create (
// et.getMimeType (),
// et.getType (),
// t.getImage (),
// null
// ));
// t = t.getNext ();
// i++;
// }
// return sb.toString ();
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:EditorTokenInput.java
示例8: isEmpty
import org.openide.text.NbDocument; //导入依赖的package包/类
private static boolean isEmpty (
int ln,
StyledDocument document,
Set<Integer> whitespaces
) throws BadLocationException {
int start = NbDocument.findLineOffset (document, ln);
int end = document.getLength ();
try {
end = NbDocument.findLineOffset (document, ln + 1) - 1;
} catch (IndexOutOfBoundsException ex) {
}
TokenSequence ts = Utils.getTokenSequence (document, start);
if (ts.token () == null) return true;
while (whitespaces.contains (ts.token ().id ().ordinal ())) {
if (!ts.moveNext ()) return true;
if (ts.offset () > end) return true;
}
return false;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:IndentFactory.java
示例9: defaultAction
import org.openide.text.NbDocument; //导入依赖的package包/类
@Override
public void defaultAction(final JTextComponent component) {
Completion.get().hideCompletion();
Completion.get().hideDocumentation();
NbDocument.runAtomic((StyledDocument) component.getDocument(), new Runnable() {
@Override
public void run() {
Document doc = component.getDocument();
try {
doc.remove(0, doc.getLength());
doc.insertString(0, getText(), null);
} catch (BadLocationException e) {
Logger.getLogger(SearchCompletionItem.class.getName()).log(Level.FINE, null, e);
}
}
});
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:SearchCompletionItem.java
示例10: parse
import org.openide.text.NbDocument; //导入依赖的package包/类
public static HighlightImpl parse(StyledDocument doc, String line) throws ParseException, BadLocationException {
MessageFormat f = new MessageFormat("[{0}], {1,number,integer}:{2,number,integer}-{3,number,integer}:{4,number,integer}");
Object[] args = f.parse(line);
String attributesString = (String) args[0];
int lineStart = ((Long) args[1]).intValue();
int columnStart = ((Long) args[2]).intValue();
int lineEnd = ((Long) args[3]).intValue();
int columnEnd = ((Long) args[4]).intValue();
String[] attrElements = attributesString.split(",");
List<ColoringAttributes> attributes = new ArrayList<ColoringAttributes>();
for (String a : attrElements) {
a = a.trim();
attributes.add(ColoringAttributes.valueOf(a));
}
if (attributes.contains(null))
throw new NullPointerException();
int offsetStart = NbDocument.findLineOffset(doc, lineStart) + columnStart;
int offsetEnd = NbDocument.findLineOffset(doc, lineEnd) + columnEnd;
return new HighlightImpl(doc, offsetStart, offsetEnd, attributes);
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:HighlightImpl.java
示例11: getPosition
import org.openide.text.NbDocument; //导入依赖的package包/类
private static Position getPosition(final StyledDocument doc, final int offset) {
class Impl implements Runnable {
private Position pos;
public void run() {
if (offset < 0 || offset >= doc.getLength())
return ;
try {
pos = doc.createPosition(offset - NbDocument.findLineColumn(doc, offset));
} catch (BadLocationException ex) {
//should not happen?
Logger.getLogger(ComputeAnnotations.class.getName()).log(Level.FINE, null, ex);
}
}
}
Impl i = new Impl();
doc.render(i);
return i.pos;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:ComputeAnnotations.java
示例12: close
import org.openide.text.NbDocument; //导入依赖的package包/类
public synchronized @Override void close() throws IOException {
try {
NbDocument.runAtomic(this.doc,
new Runnable () {
@Override
public void run () {
try {
doc.remove(0,doc.getLength());
doc.insertString(0,new String(
data,
0,
pos,
FileEncodingQuery.getEncoding(getHandle().resolveFileObject(false))),
null);
} catch (BadLocationException e) {
if (LOG.isLoggable(Level.SEVERE))
LOG.log(Level.SEVERE, e.getMessage(), e);
}
}
});
} finally {
resetCaches();
}
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:SourceFileObject.java
示例13: getAnnotateLine
import org.openide.text.NbDocument; //导入依赖的package包/类
/**
* Locates AnnotateLine associated with given line. The
* line is translated to Element that is used as map lookup key.
* The map is initially filled up with Elements sampled on
* annotate() method.
*
* <p>Key trick is that Element's identity is maintained
* until line removal (and is restored on undo).
*
* @param line
* @return found AnnotateLine or <code>null</code>
*/
private VcsAnnotation getAnnotateLine(int line) {
StyledDocument sd = (StyledDocument) doc;
int lineOffset = NbDocument.findLineOffset(sd, line);
Element element = sd.getParagraphElement(lineOffset);
VcsAnnotation al = elementAnnotations.get(element);
if (al != null) {
int startOffset = element.getStartOffset();
int endOffset = element.getEndOffset();
try {
int len = endOffset - startOffset;
String text = doc.getText(startOffset, len -1);
String content = al.getDocumentText();
if (text.equals(content)) {
return al;
}
} catch (BadLocationException e) {
ErrorManager err = ErrorManager.getDefault();
err.annotate(e, "CVS.AB: can not locate line annotation."); // NOI18N
err.notify(ErrorManager.INFORMATIONAL, e);
}
}
return null;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:AnnotationBar.java
示例14: defaultAction
import org.openide.text.NbDocument; //导入依赖的package包/类
@Override
public void defaultAction(final JTextComponent component) {
Completion.get().hideCompletion();
Completion.get().hideDocumentation();
NbDocument.runAtomic((StyledDocument) component.getDocument(), new Runnable() {
@Override
public void run() {
Document doc = component.getDocument();
try {
doc.remove(substituteOffset, component.getCaretPosition() - substituteOffset);
doc.insertString(substituteOffset, getText(), null);
} catch (BadLocationException e) {
Logger.getLogger(FXMLCompletionItem.class.getName()).log(Level.FINE, null, e);
}
}
});
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:FXMLCompletionItem.java
示例15: addPositionToJumpList
import org.openide.text.NbDocument; //导入依赖的package包/类
/** Add the line offset into the jump history */
private void addPositionToJumpList(String url, Line l, int column) {
DataObject dataObject = getDataObject (url);
if (dataObject != null) {
EditorCookie ec = dataObject.getLookup().lookup(EditorCookie.class);
if (ec != null) {
try {
StyledDocument doc = ec.openDocument();
JEditorPane[] eps = ec.getOpenedPanes();
if (eps != null && eps.length > 0) {
JumpList.addEntry(eps[0], NbDocument.findLineOffset(doc, l.getLineNumber()) + column);
}
} catch (java.io.IOException ioex) {
ErrorManager.getDefault().notify(ioex);
}
}
}
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:EditorContextImpl.java
示例16: findLineOffset
import org.openide.text.NbDocument; //导入依赖的package包/类
/** return the offset of the first non-whitespace character on the line,
or -1 when the line does not exist
*/
private static int findLineOffset(StyledDocument doc, int lineNumber) {
int offset;
try {
offset = NbDocument.findLineOffset (doc, lineNumber - 1);
int offset2 = NbDocument.findLineOffset (doc, lineNumber);
try {
String lineStr = doc.getText(offset, offset2 - offset);
for (int i = 0; i < lineStr.length(); i++) {
if (!Character.isWhitespace(lineStr.charAt(i))) {
offset += i;
break;
}
}
} catch (BadLocationException ex) {
// ignore
}
} catch (IndexOutOfBoundsException ioobex) {
return -1;
}
return offset;
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:EditorContextImpl.java
示例17: regenerateSourceImpl
import org.openide.text.NbDocument; //导入依赖的package包/类
void regenerateSourceImpl(StyledDocument doc) {
NbDocument.runAtomic(doc, new Runnable() {
public void run() {
regenerateBeanDescriptor();
regenerateProperties();
regenerateEvents();
if (!olderVersion) {
regenerateMethods();
}
regenerateIcons();
regenerateDefaultIdx();
regenerateSuperclass();
isModified = false;
isIconModified = false;
}
} );
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:BiAnalyser.java
示例18: runInAwt
import org.openide.text.NbDocument; //导入依赖的package包/类
private void runInAwt() {
if (doc instanceof NbDocument.CustomToolbar) {
realToolBar = ((NbDocument.CustomToolbar) doc).createToolbar(editorPane);
}
synchronized (XmlMultiViewElement.this) {
if (realToolBar == null) {
toolbar = new JPanel();
} else {
toolbar = realToolBar;
}
initializer = null;
}
if (realToolBar == null) {
return;
}
// patch existing toolbars
for (JComponent p : toolbarPanels) {
if (p.isValid()) {
p.add(realToolBar, BorderLayout.CENTER);
}
}
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:XmlMultiViewElement.java
示例19: MulticaretHandler
import org.openide.text.NbDocument; //导入依赖的package包/类
private MulticaretHandler(final JTextComponent c) {
this.doc = c.getDocument();
doc.render(() -> {
Caret caret = c.getCaret();
if (caret instanceof EditorCaret) {
List<CaretInfo> carets = ((EditorCaret) caret).getCarets();
if (carets.size() > 1) {
this.regions = new ArrayList<>(carets.size());
carets.forEach((ci) -> {
try {
int[] block = ci.isSelectionShowing() ? null : Utilities.getIdentifierBlock(c, ci.getDot());
Position start = NbDocument.createPosition(doc, block != null ? block[0] : ci.getSelectionStart(), Position.Bias.Backward);
Position end = NbDocument.createPosition(doc, block != null ? block[1] : ci.getSelectionEnd(), Position.Bias.Forward);
regions.add(new MutablePositionRegion(start, end));
} catch (BadLocationException ex) {}
});
Collections.reverse(regions);
}
}
});
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:MulticaretHandler.java
示例20: findResult
import org.openide.text.NbDocument; //导入依赖的package包/类
private void findResult() {
if (isCanceled())
return;
int len = sdoc.getLength();
if (startOffset >= len || endOffset > len) {
if (!isCanceled() && ERR.isLoggable(ErrorManager.WARNING)) {
ERR.log(ErrorManager.WARNING, "document changed, but not canceled?" );
ERR.log(ErrorManager.WARNING, "len = " + len );
ERR.log(ErrorManager.WARNING, "startOffset = " + startOffset );
ERR.log(ErrorManager.WARNING, "endOffset = " + endOffset );
}
cancel();
return;
}
try {
result[0] = NbDocument.createPosition(sdoc, startOffset, Bias.Forward);
result[1] = NbDocument.createPosition(sdoc, endOffset, Bias.Backward);
} catch (BadLocationException e) {
ERR.notify(ErrorManager.ERROR, e);
}
}
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:ErrorHintsProvider.java
注:本文中的org.openide.text.NbDocument类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论