本文整理了Java中org.netbeans.editor.Utilities.getDocument()
方法的一些代码示例,展示了Utilities.getDocument()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utilities.getDocument()
方法的具体详情如下:
包路径:org.netbeans.editor.Utilities
类名称:Utilities
方法名:getDocument
[英]Helper method to obtain instance of BaseDocument from JTextComponent. If the document of the component is not an instance of the org.netbeans.editor.BaseDocument the method returns null. The method doesn't require any document locking.
[中]帮助器方法从JTextComponent获取BaseDocument实例。如果组件的文档不是组织的实例。上网本。编辑BaseDocument方法返回null。该方法不需要任何文档锁定。
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
/** Get the document to work on. Either component's document or printed document
* is returned. It can return null in case the component's document is not instance
* of BaseDocument.
*/
public final BaseDocument getDocument() {
return (component != null) ? Utilities.getDocument(component) : printDoc;
}
代码示例来源:origin: net.java.abeille/abeille
/**
* Get the document to work on. Either component's document or printed
* document is returned. It can return null in case the component's document
* is not instance of BaseDocument.
*/
public final BaseDocument getDocument() {
return (component != null) ? Utilities.getDocument(component) : printDoc;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-editor
@Override
public void actionPerformed(ActionEvent evt, JTextComponent target) {
if (target == null) {
return;
}
Document doc = Utilities.getDocument(target);
DatabaseConnectionSupport.selectDatabaseConnection(doc);
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mobility-editor
public static String getLine(final JTextComponent component, final int offset) {
final BaseDocument workingDocument = org.netbeans.editor.Utilities.getDocument(component);
try {
final int lineStartOffset = org.netbeans.editor.Utilities.getRowStart(workingDocument, offset);
final int lineEndOffset = org.netbeans.editor.Utilities.getRowEnd(workingDocument, offset);
return String.valueOf(workingDocument.getChars(lineStartOffset, lineEndOffset - lineStartOffset));
} catch (BadLocationException ble) {
return "";
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-mobility-editor
public static String getLine(final JTextComponent component, final int offset) {
final BaseDocument workingDocument=org.netbeans.editor.Utilities.getDocument(component);
try {
final int lineStartOffset = org.netbeans.editor.Utilities.getRowStart(workingDocument, offset);
final int lineEndOffset = org.netbeans.editor.Utilities.getRowEnd(workingDocument, offset);
return String.valueOf(workingDocument.getChars(lineStartOffset, lineEndOffset - lineStartOffset));
} catch (BadLocationException ble) {
return "";
}
}
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
protected boolean hasTextBefore(JTextComponent target, String typedText) {
BaseDocument doc = Utilities.getDocument(target);
int dotPos = target.getCaret().getDot();
try {
int fnw = Utilities.getRowFirstNonWhite(doc, dotPos);
return dotPos != fnw+typedText.length();
} catch (BadLocationException e) {
return false;
}
}
代码示例来源:origin: net.java.abeille/abeille
protected boolean hasTextBefore(JTextComponent target, String typedText) {
BaseDocument doc = Utilities.getDocument(target);
int dotPos = target.getCaret().getDot();
try {
int fnw = Utilities.getRowFirstNonWhite(doc, dotPos);
return dotPos != fnw + typedText.length();
} catch (BadLocationException e) {
return false;
}
}
代码示例来源:origin: org.netbeans.api/org-netbeans-modules-editor-deprecated-pre61completion
/**
* Execute complegtion query subtask
*/
private void performQuery(final JTextComponent target) {
BaseDocument doc = Utilities.getDocument(target);
long start = System.currentTimeMillis();
try {
lastResult = getQuery().query( target, caretPos, doc.getSyntaxSupport());
} finally {
trace("performQuery took " + (System.currentTimeMillis() - start) + "ms"); // NOI18N
setKeyPressed(false);
}
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
/**
* Execute complegtion query subtask
*/
private void performQuery(final JTextComponent target) {
BaseDocument doc = Utilities.getDocument(target);
long start = System.currentTimeMillis();
try {
lastResult = getQuery().query( target, caretPos, doc.getSyntaxSupport());
} finally {
trace("performQuery took " + (System.currentTimeMillis() - start) + "ms"); // NOI18N
setKeyPressed(false);
}
}
代码示例来源:origin: net.java.abeille/abeille
public void run() {
JTextComponent c2 = component;
if (c2 != null) {
BaseDocument doc = Utilities.getDocument(c2);
if (doc != null) {
doc.readLock();
try {
update(scrollRect, scrollPolicy);
} finally {
doc.readUnlock();
}
}
}
}
});
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
public void run() {
JTextComponent c2 = component;
if (c2 != null) {
BaseDocument doc = Utilities.getDocument(c2);
if (doc != null) {
doc.readLock();
try {
update(scrollRect, scrollPolicy);
} finally {
doc.readUnlock();
}
}
}
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-php-editor
@Override
public void defaultAction(JTextComponent component) {
DatabaseConnection newDBConn = DatabaseConnectionSupport.selectDatabaseConnection(Utilities.getDocument(component));
if (newDBConn != null && newDBConn.getJDBCConnection() != null) {
Completion.get().showCompletion();
}
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
/**
* Checks whether class is already imported
* @param cls JCClass
**/
protected boolean isAlreadyImported(JCClass cls){
BaseDocument doc = Utilities.getDocument(target);
if (doc == null) return false;
JavaSyntaxSupport sup = (JavaSyntaxSupport)doc.getSyntaxSupport().get(JavaSyntaxSupport.class);
if (sup == null) return false;
sup.refreshJavaImport();
return sup.isImported(cls);
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
public void actionPerformed(ActionEvent evt, JTextComponent target) {
if (target != null) {
try {
Caret caret = target.getCaret();
BaseDocument doc = Utilities.getDocument(target);
int caretLine = Utilities.getLineOffset(doc, caret.getDot());
AnnotationDesc aDesc = doc.getAnnotations().activateNextAnnotation(caretLine);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
}
代码示例来源:origin: net.java.abeille/abeille
public void actionPerformed(ActionEvent evt, JTextComponent target) {
if (target != null) {
try {
Caret caret = target.getCaret();
BaseDocument doc = Utilities.getDocument(target);
int caretLine = Utilities.getLineOffset(doc, caret.getDot());
AnnotationDesc aDesc = doc.getAnnotations().activateNextAnnotation(caretLine);
} catch (BadLocationException e) {
e.printStackTrace();
}
}
}
}
代码示例来源:origin: net.java.abeille/abeille
public void actionPerformed(ActionEvent evt) {
Caret c = caret;
JTextComponent component = editorUI.getComponent();
if (component != null) {
if (c != null) {
BaseDocument doc = Utilities.getDocument(editorUI.getComponent());
if (doc != null) {
int pos = c.getDot();
String s = Utilities.debugPosition(doc, pos);
setText(CELL_POSITION, s);
}
}
Boolean b = (Boolean) editorUI.getProperty(EditorUI.OVERWRITE_MODE_PROPERTY);
boolean om = (b != null && b.booleanValue());
if (om != overwriteModeDisplayed) {
overwriteModeDisplayed = om;
setText(CELL_TYPING_MODE, overwriteModeDisplayed ? ovrText : insText);
}
}
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
public void actionPerformed(ActionEvent evt) {
Caret c = caret;
JTextComponent component = editorUI.getComponent();
if (component != null) {
if (c != null) {
BaseDocument doc = Utilities.getDocument(editorUI.getComponent());
if (doc != null) {
int pos = c.getDot();
String s = Utilities.debugPosition(doc, pos);
setText(CELL_POSITION, s);
}
}
Boolean b = (Boolean)editorUI.getProperty(EditorUI.OVERWRITE_MODE_PROPERTY);
boolean om = (b != null && b.booleanValue());
if (om != overwriteModeDisplayed) {
overwriteModeDisplayed = om;
setText(CELL_TYPING_MODE, overwriteModeDisplayed ? ovrText : insText);
}
}
}
代码示例来源:origin: net.java.abeille/abeille
public void actionPerformed(ActionEvent evt, JTextComponent target) {
if (target != null) {
try {
Caret caret = target.getCaret();
BaseDocument doc = Utilities.getDocument(target);
int dotPos = caret.getDot();
ExtSyntaxSupport sup = (ExtSyntaxSupport) doc.getSyntaxSupport();
if (dotPos > 0) {
int[] matchBlk = sup.findMatchingBlock(dotPos - 1, false);
if (matchBlk != null) {
if (select) {
caret.moveDot(matchBlk[1]);
}
else {
caret.setDot(matchBlk[1]);
}
}
}
} catch (BadLocationException e) {
target.getToolkit().beep();
}
}
}
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
/** Check the characters that should cause reindenting the line. */
protected void checkIndentHotChars(JTextComponent target, String typedText) {
BaseDocument doc = Utilities.getDocument(target);
if (doc != null) {
Caret caret = target.getCaret();
Formatter f = doc.getFormatter();
if (f instanceof ExtFormatter) {
ExtFormatter ef = (ExtFormatter)f;
int[] fmtBlk = ef.getReformatBlock(target, typedText);
if (fmtBlk != null) {
try {
fmtBlk[0] = Utilities.getRowStart(doc, fmtBlk[0]);
fmtBlk[1] = Utilities.getRowEnd(doc, fmtBlk[1]);
//this was the of #18922, that causes the bug #20198
//ef.reformat(doc, fmtBlk[0], fmtBlk[1]);
//bugfix of the bug #20198. Bug #18922 is fixed too as well as #6968
ef.reformat(doc, fmtBlk[0], fmtBlk[1], true);
} catch (BadLocationException e) {
} catch (IOException e) {
}
}
}
}
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/org-netbeans-modules-editor-lib
/** Deinstalls the UI for a component */
public void uninstallUI(JComponent c) {
super.uninstallUI(c);
Settings.removeSettingsChangeListener(this);
//c.removePropertyChangeListener(this);
if (c instanceof JTextComponent){
JTextComponent comp = (JTextComponent)c;
BaseDocument doc = Utilities.getDocument(comp);
if (doc != null) {
doc.removeDocumentListener(this);
}
comp.setKeymap(null);
comp.setCaret(null);
getEditorUI().uninstallUI(comp);
Registry.removeComponent(comp);
}
// Clear the editorUI so it will be recreated according to the kit
// of the component for which the installUI() is called
editorUI = null;
}
内容来源于网络,如有侵权,请联系作者删除!