本文整理汇总了Java中javax.swing.text.Document.addDocumentListener方法的典型用法代码示例。如果您正苦于以下问题:Java Document.addDocumentListener方法的具体用法?Java Document.addDocumentListener怎么用?Java Document.addDocumentListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.Document
的用法示例。
在下文中一共展示了Document.addDocumentListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: JpaControllerSetupPanelVisual
import javax.swing.text.Document; //导入方法依赖的package包/类
/** Creates new form CrudSetupPanel */
public JpaControllerSetupPanelVisual(WizardDescriptor wizard) {
this.wizard = wizard;
initComponents();
packageComboBoxEditor = ((JTextComponent)packageComboBox.getEditor().getEditorComponent());
Document packageComboBoxDocument = packageComboBoxEditor.getDocument();
packageComboBoxDocument.addDocumentListener(this);
// jsfFolder.addKeyListener(new KeyListener(){
// public void keyPressed(KeyEvent e) {
// changeSupport.fireChange();
// }
// public void keyReleased(KeyEvent e) {
// changeSupport.fireChange();
// }
// public void keyTyped(KeyEvent e) {
// changeSupport.fireChange();
// }
// });
}
示例2: get
import javax.swing.text.Document; //导入方法依赖的package包/类
/**
* Gets a <code>Position</code> in the document at the given offset. The
* position is automatically updated when the document's contents is modified.
* The <code>Position</code> does not reference the document in anyway that
* would prevent the document from being garbage collected.
*
* @param doc The document to get a position in.
* @param offset The initial offset of the position.
*
* @return A <code>Position</code> inside the document.
* @throws BadLocationException If the offset is not valid for the document.
*/
public static Position get(Document doc, int offset) throws BadLocationException {
// Check that the offset is valid. This should excercise any rule imposed by
// the document on its positions.
doc.createPosition(offset);
synchronized (OGLS) {
OffsetGapList<WeakP> ogl = OGLS.get(doc);
if (ogl == null) {
ogl = new OffsetGapList<WeakPositions.WeakP>();
OGLS.put(doc, ogl);
doc.addDocumentListener(WeakListeners.document(documentsTracker, doc));
}
int index = ogl.findElementIndex(offset);
WeakP pos = index >= 0 ? ogl.get(index) : null;
if (pos == null) {
pos = new WeakP(offset);
ogl.add(pos);
}
return pos;
}
}
示例3: query
import javax.swing.text.Document; //导入方法依赖的package包/类
@Override
protected void query(CompletionResultSet resultSet, Document doc, int caretOffset) {
CompletionContext context = new CompletionContext(doc, caretOffset, queryType);
if (context.getCompletionType() == CompletionType.NONE) {
resultSet.finish();
return;
}
SpringXMLConfigDocumentListener listener = SpringXMLConfigDocumentListener.getListener(context.getDocumentContext());
doc.removeDocumentListener(listener);
doc.addDocumentListener(listener);
completor = CompletorRegistry.getDefault().getCompletor(context);
if(completor != null) {
SpringCompletionResult springCompletionResult = completor.complete(context);
populateResultSet(resultSet, springCompletionResult);
}
resultSet.finish();
}
示例4: addEditorPane
import javax.swing.text.Document; //导入方法依赖的package包/类
private void addEditorPane( JEditorPane pane, Icon icon, File file, boolean created, boolean focus ) {
final JComponent c = (pane.getUI() instanceof BaseTextUI) ?
Utilities.getEditorUI(pane).getExtComponent() : new JScrollPane( pane );
Document doc = pane.getDocument();
doc.addDocumentListener( new MarkingDocumentListener( c ) );
doc.putProperty( FILE, file );
doc.putProperty( CREATED, created ? Boolean.TRUE : Boolean.FALSE );
UndoManager um = new UndoManager();
doc.addUndoableEditListener( um );
doc.putProperty( BaseDocument.UNDO_MANAGER_PROP, um );
com2text.put( c, pane );
tabPane.addTab( file.getName(), icon, c, file.getAbsolutePath() );
if (focus) {
tabPane.setSelectedComponent( c );
pane.requestFocus();
}
}
示例5: propertyChange
import javax.swing.text.Document; //导入方法依赖的package包/类
/**
* Invoked when a property changes. We are only interested in when the
* Document changes to reset the DocumentListener.
*/
public void propertyChange(PropertyChangeEvent e) {
if (e.getSource() == getEditor() && e.getPropertyName().equals(
"document")) {
Document oldDoc = (Document) e.getOldValue();
Document newDoc = (Document) e.getNewValue();
// Reset the DocumentListener
oldDoc.removeDocumentListener(this);
newDoc.addDocumentListener(this);
// Recreate the TreeModel.
treeModel = new ElementTreeModel(newDoc);
tree.setModel(treeModel);
}
}
示例6: setText
import javax.swing.text.Document; //导入方法依赖的package包/类
@Override
public final void setText(final String text) {
synchronized (getDelegateLock()) {
// JTextArea.setText() posts two different events (remove & insert).
// Since we make no differences between text events,
// the document listener has to be disabled while
// JTextArea.setText() is called.
final Document document = getTextComponent().getDocument();
document.removeDocumentListener(this);
getTextComponent().setText(text);
revalidate();
if (firstChangeSkipped) {
postEvent(new TextEvent(getTarget(),
TextEvent.TEXT_VALUE_CHANGED));
}
document.addDocumentListener(this);
}
repaintPeer();
}
示例7: replaceRange
import javax.swing.text.Document; //导入方法依赖的package包/类
@Override
public void replaceRange(final String text, final int start,
final int end) {
synchronized (getDelegateLock()) {
// JTextArea.replaceRange() posts two different events.
// Since we make no differences between text events,
// the document listener has to be disabled while
// JTextArea.replaceRange() is called.
final Document document = getTextComponent().getDocument();
document.removeDocumentListener(this);
getTextComponent().replaceRange(text, start, end);
revalidate();
postEvent(new TextEvent(getTarget(), TextEvent.TEXT_VALUE_CHANGED));
document.addDocumentListener(this);
}
repaintPeer();
}
示例8: attach
import javax.swing.text.Document; //导入方法依赖的package包/类
private void attach() {
if( !SwingUtilities.isEventDispatchThread() ) {
SwingUtilities.invokeLater( new Runnable() {
@Override
public void run() {
attach();
}
});
return;
}
if( null != editorCookie ) {
editorCookie.addPropertyChangeListener( editorListener );
JEditorPane[] panes = editorCookie.getOpenedPanes();
if( null != panes && panes.length > 0 ) {
panes[0].getDocument();
}
Document doc = editorCookie.getDocument();
if( null != doc )
doc.addDocumentListener( documentListener );
}
reloadFromDocument();
}
示例9: replaceRange
import javax.swing.text.Document; //导入方法依赖的package包/类
@Override
public void replaceRange(final String text, final int start,
final int end) {
synchronized (getDelegateLock()) {
// JTextArea.replaceRange() posts two different events.
// Since we make no differences between text events,
// the document listener has to be disabled while
// JTextArea.replaceRange() is called.
final Document document = getTextComponent().getDocument();
document.removeDocumentListener(this);
getDelegate().getView().replaceRange(text, start, end);
revalidate();
postEvent(new TextEvent(getTarget(), TextEvent.TEXT_VALUE_CHANGED));
document.addDocumentListener(this);
}
repaintPeer();
}
示例10: setEditor
import javax.swing.text.Document; //导入方法依赖的package包/类
/**
* Resets the JTextComponent to <code>editor</code>. This will update
* the tree accordingly.
*/
public void setEditor(JTextComponent editor) {
if (this.editor == editor) {
return;
}
if (this.editor != null) {
Document oldDoc = this.editor.getDocument();
oldDoc.removeDocumentListener(this);
this.editor.removePropertyChangeListener(this);
this.editor.removeCaretListener(this);
}
this.editor = editor;
if (editor == null) {
treeModel = null;
tree.setModel(null);
} else {
Document newDoc = editor.getDocument();
newDoc.addDocumentListener(this);
editor.addPropertyChangeListener(this);
editor.addCaretListener(this);
treeModel = new ElementTreeModel(newDoc);
tree.setModel(treeModel);
}
}
示例11: CodeFoldingSideBar
import javax.swing.text.Document; //导入方法依赖的package包/类
public CodeFoldingSideBar(JTextComponent component){
super();
this.component = component;
// The same property tag is used by migrated implementation of the SideBar.
// The new implementation is registered with weight higher than CF used to have, so if a
// legacy client registers subclass of this CFSB, it will register the client property first and win.
if (component.getClientProperty("org.netbeans.editor.CodeFoldingSidebar") == null) { // NOI18N
component.putClientProperty("org.netbeans.editor.CodeFoldingSidebar", Boolean.TRUE); // NOI18N
} else {
alreadyPresent = true;
prefs = null;
return;
}
addMouseListener(listener);
addMouseMotionListener(listener);
FoldHierarchy foldHierarchy = FoldHierarchy.get(component);
foldHierarchy.addFoldHierarchyListener(WeakListeners.create(FoldHierarchyListener.class, listener, foldHierarchy));
Document doc = getDocument();
doc.addDocumentListener(WeakListeners.document(listener, doc));
setOpaque(true);
prefs = MimeLookup.getLookup(org.netbeans.lib.editor.util.swing.DocumentUtilities.getMimeType(component)).lookup(Preferences.class);
prefs.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, prefsListener, prefs));
prefsListener.preferenceChange(null);
ViewHierarchy.get(component).addViewHierarchyListener(new ViewHierarchyListener() {
@Override
public void viewHierarchyChanged(ViewHierarchyEvent evt) {
checkRepaint(evt);
}
});
}
示例12: install
import javax.swing.text.Document; //导入方法依赖的package包/类
public static boolean install( JComboBox combo ) {
boolean res = false;
ComboBoxEditor comboEditor = combo.getEditor();
if( comboEditor.getEditorComponent() instanceof JTextComponent ) {
JTextComponent textEditor = ( JTextComponent ) comboEditor.getEditorComponent();
Document doc = textEditor.getDocument();
doc.addDocumentListener( new AutoCompleteListener( combo ) );
setIgnoreSelectionEvents( combo, false );
combo.setEditable( true );
res = true;
}
combo.putClientProperty( "nb.combo.autocomplete", res ); //NOI18N
return res;
}
示例13: CodeFoldingSideBar
import javax.swing.text.Document; //导入方法依赖的package包/类
public CodeFoldingSideBar(final JTextComponent component){
super();
this.component = component;
// prevent from display CF sidebar twice
if (canDisplay(component)) {
component.putClientProperty(PROP_SIDEBAR_MARK, this);
} else {
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "Folding sidebar already present at {0}", component);
}
alreadyPresent = true;
prefs = null;
return;
}
addMouseListener(listener);
addMouseMotionListener(listener);
final FoldHierarchy foldHierarchy = FoldHierarchy.get(component);
foldHierarchy.addFoldHierarchyListener(WeakListeners.create(FoldHierarchyListener.class, listener, foldHierarchy));
final Document doc = getDocument();
doc.addDocumentListener(WeakListeners.document(listener, doc));
setOpaque(true);
prefs = MimeLookup.getLookup(org.netbeans.lib.editor.util.swing.DocumentUtilities.getMimeType(component)).lookup(Preferences.class);
prefs.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, prefsListener, prefs));
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "Code folding sidebar initialized for: {0}", doc);
}
ViewHierarchy.get(component).addViewHierarchyListener(new ViewHierarchyListener() {
@Override
public void viewHierarchyChanged(ViewHierarchyEvent evt) {
checkRepaint(evt);
}
});
}
示例14: BackwardPosition
import javax.swing.text.Document; //导入方法依赖的package包/类
BackwardPosition(Document doc, int offset) {
this.offset = offset;
doc.addDocumentListener(org.openide.util.WeakListeners.document(this, doc));
}
示例15: addDocument
import javax.swing.text.Document; //导入方法依赖的package包/类
/**
* Aggiunge un Document
* @param doc il Document da aggiungere
*/
public void addDocument(Document doc) {
doc.addDocumentListener(this);
documents.add(doc);
documentChanged();
}