下面列出了怎么用javax.swing.event.DocumentListener的API类实例代码及写法,或者点击链接到github查看源代码。
public void addDocumentListener(DocumentListener listener) {
if (listener == null) {
return;
}
if (docListeners == null) {
docListeners = new DocumentListener[1];
docListeners[0] = listener;
} else {
DocumentListener[] oldArr = docListeners;
docListeners = new DocumentListener[oldArr.length + 1];
System.arraycopy(oldArr, 0,
docListeners, 0,
oldArr.length);
docListeners[oldArr.length] = listener;
}
}
private void initProjectNameAndLocation(WizardDescriptor descriptor) {
// default name & location
File projectLocation = ProjectChooser.getProjectsFolder();
projectLocationTextField.setText(projectLocation.getAbsolutePath());
FileObject template = Templates.getTemplate(descriptor);
String projectName = template.getName();
String templateName = projectName;
int index = 0;
while ((new File(projectLocation, projectName)).exists()) {
index++;
projectName = templateName + index;
}
projectNameTextField.setText(projectName);
projectNameTextField.selectAll();
updateProjectFolder();
// listeners
DocumentListener documentListener = new DefaultDocumentListener();
projectNameTextField.getDocument().addDocumentListener(documentListener);
projectLocationTextField.getDocument().addDocumentListener(documentListener);
setName(NbBundle.getMessage(OnlineSampleVisualPanel.class, "LBL_NameAndLocation"));// NOI18N
}
private void initProjectNameAndLocation() {
// default name & location
File projectLocation = ProjectChooser.getProjectsFolder();
projectLocationTextField.setText(projectLocation.getAbsolutePath());
String projectName = projectNameTemplate;
int index = 0;
while ((new File(projectLocation, projectName)).exists()) {
index++;
projectName = projectNameTemplate + index;
}
projectNameTextField.setText(projectName);
projectNameTextField.selectAll();
updateProjectFolder();
// listeners
DocumentListener documentListener = new DefaultDocumentListener();
projectNameTextField.getDocument().addDocumentListener(documentListener);
projectLocationTextField.getDocument().addDocumentListener(documentListener);
}
private void initProjectNameAndLocation(WizardDescriptor descriptor) {
// default name & location
File projectLocation = ProjectChooser.getProjectsFolder();
projectLocationTextField.setText(projectLocation.getAbsolutePath());
FileObject template = Templates.getTemplate(descriptor);
String projectName = template.getName();
String templateName = projectName;
int index = 0;
while ((new File(projectLocation, projectName)).exists()) {
index++;
projectName = templateName + index;
}
projectNameTextField.setText(projectName);
projectNameTextField.selectAll();
updateProjectFolder();
// listeners
DocumentListener documentListener = new DefaultDocumentListener();
projectNameTextField.getDocument().addDocumentListener(documentListener);
projectLocationTextField.getDocument().addDocumentListener(documentListener);
setName(NbBundle.getMessage(SampleVisualPanel.class, "LBL_NameAndLocation"));// NOI18N
}
public BasicBrandingPanel(BrandingModel model) {
super(NbBundle.getMessage(BasicBrandingPanel.class, "LBL_BasicTab"), model); //NOI18N
initComponents();
refresh();
checkValidity();
DocumentListener textFieldChangeListener = new UIUtil.DocumentAdapter() {
@Override
public void insertUpdate(DocumentEvent e) {
checkValidity();
setModified();
titleValueModified = true;
}
};
titleValue.getDocument().addDocumentListener(textFieldChangeListener);
titleValueModified = false;
}
/** Creates new NameAndLocationPanel */
public NameAndLocationPanel(final WizardDescriptor setting, final NewLibraryDescriptor.DataModel data) {
super(setting);
this.data = data;
initComponents();
initAccessibility();
putClientProperty("NewFileWizard_Title",// NOI18N
NbBundle.getMessage(NameAndLocationPanel.class,"LBL_LibraryWizardTitle")); // NOI18N
DocumentListener dListener = new UIUtil.DocumentAdapter() {
public void insertUpdate(DocumentEvent e) {
NewLibraryDescriptor.DataModel _data = getTemporaryDataModel();
setEnabledForFilesInfo(checkValidity(_data));
setFilesInfoIntoTextAreas(_data);
}
};
libraryNameVale.getDocument().addDocumentListener(dListener);
libraryDisplayNameValue.getDocument().addDocumentListener(dListener);
}
/** Creates new NameAndLocationPanel */
public NameAndLocationPanel(final WizardDescriptor setting, final HTMLIterator.DataModel data) {
super(setting);
this.data = data;
initComponents();
initAccessibility();
putClientProperty("NewFileWizard_Title", getMessage("LBL_TCWizardTitle"));
DocumentListener dListener = new UIUtil.DocumentAdapter() {
public void insertUpdate(DocumentEvent e) {
if (checkValidity()) {
updateData();
}
}
};
txtPrefix.getDocument().addDocumentListener(dListener);
txtIcon.getDocument().addDocumentListener(dListener);
if (comPackageName.getEditor().getEditorComponent() instanceof JTextField) {
JTextField txt = (JTextField)comPackageName.getEditor().getEditorComponent();
txt.getDocument().addDocumentListener(dListener);
}
}
/** Creates new NameAndLocationPanel */
public NameAndLocationPanel(final WizardDescriptor setting, final NewTCIterator.DataModel data) {
super(setting);
this.data = data;
initComponents();
initAccessibility();
putClientProperty("NewFileWizard_Title", getMessage("LBL_TCWizardTitle"));
DocumentListener dListener = new UIUtil.DocumentAdapter() {
public void insertUpdate(DocumentEvent e) {
if (checkValidity()) {
updateData();
}
}
};
txtPrefix.getDocument().addDocumentListener(dListener);
txtIcon.getDocument().addDocumentListener(dListener);
if (comPackageName.getEditor().getEditorComponent() instanceof JTextField) {
JTextField txt = (JTextField)comPackageName.getEditor().getEditorComponent();
txt.getDocument().addDocumentListener(dListener);
}
}
private void setUpChangeListeners(final DataSourceConfigurationAggregatingPanel
aggregatingPanel,
final ConfigurationChangeListener listener) {
DocumentListener textFieldListener = new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
listener.changeApplied(aggregatingPanel
.getCurrentConfigurationState());
}
};
host.getComponent().getDocument().addDocumentListener(textFieldListener);
port.getComponent().getDocument().addDocumentListener(textFieldListener);
username.getComponent().getDocument().addDocumentListener(textFieldListener);
password.getComponent().getDocument().addDocumentListener(textFieldListener);
databaseName.getComponent().getDocument().addDocumentListener(textFieldListener);
}
@NbBundle.Messages({
"# {0} - short script name",
"# {1} - long script name",
"# {2} - PHAR script name",
"PhpUnitOptionsPanel.phpUnit.hint=<html>Full path of PHPUnit script (typically {0}, {1} or {2}).",
"# {0} - short script name",
"# {1} - long script name",
"# {2} - PHAR script name",
"PhpUnitOptionsPanel.skelGen.hint=<html>Full path of Skeleton Generator script (typically {0}, {1} or {2})."
})
private void init() {
errorLabel.setText(" "); // NOI18N
phpUnitHintLabel.setText(Bundle.PhpUnitOptionsPanel_phpUnit_hint(
PhpUnit.SCRIPT_NAME, PhpUnit.SCRIPT_NAME_LONG, PhpUnit.SCRIPT_NAME_PHAR));
skelGenHintLabel.setText(Bundle.PhpUnitOptionsPanel_skelGen_hint(
SkeletonGenerator.SCRIPT_NAME, SkeletonGenerator.SCRIPT_NAME_LONG, SkeletonGenerator.SCRIPT_NAME_PHAR));
DocumentListener defaultDocumentListener = new DefaultDocumentListener();
phpUnitTextField.getDocument().addDocumentListener(defaultDocumentListener);
skelGenTextField.getDocument().addDocumentListener(defaultDocumentListener);
}
@NbBundle.Messages({
"# {0} - short script name",
"# {1} - long script name",
"CodeSnifferOptionsPanel.hint=Full path of Code Sniffer script (typically {0} or {1}).",
})
private void initCodeSniffer(DocumentListener defaultDocumentListener) {
codeSnifferHintLabel.setText(Bundle.CodeSnifferOptionsPanel_hint(CodeSniffer.NAME, CodeSniffer.LONG_NAME));
codeSnifferStandardComboBox.setModel(codeSnifferStandardsModel);
// listeners
codeSnifferTextField.getDocument().addDocumentListener(defaultDocumentListener);
codeSnifferTextField.getDocument().addDocumentListener(new CodeSnifferPathDocumentListener());
final ItemListener defaultItemListener = new DefaultItemListener();
codeSnifferStandardsModel.fetchStandards(codeSnifferStandardComboBox, new Runnable() {
@Override
public void run() {
// #232279
codeSnifferStandardComboBox.addItemListener(defaultItemListener);
}
});
}
@NbBundle.Messages({
"# {0} - short script name",
"# {1} - long script name",
"ComposerOptionsPanel.composer.hint=Full path of Composer script (typically {0} or {1}).",
})
private void init() {
hintLabel.setText(Bundle.ComposerOptionsPanel_composer_hint(Composer.COMPOSER_FILENAMES.get(0), Composer.COMPOSER_FILENAMES.get(1)));
errorLabel.setText(" "); // NOI18N
// listeners
DocumentListener documentListener = new DefaultDocumentListener();
composerTextField.getDocument().addDocumentListener(documentListener);
vendorTextField.getDocument().addDocumentListener(documentListener);
authorNameTextField.getDocument().addDocumentListener(documentListener);
authorEmailTextField.getDocument().addDocumentListener(documentListener);
ignoreVendorCheckBox.addItemListener(new DefaultItemListener());
}
@NbBundle.Messages({
"# {0} - nette tester file name",
"TesterOptionsPanel.tester.hint=Full path of Nette Tester file (typically {0}).",
})
private void init() {
for (String binaryExecutable : TesterUtils.BINARY_EXECUTABLES) {
binaryExecutableComboBox.addItem(binaryExecutable);
}
errorLabel.setText(" "); // NOI18N
testerPathHintLabel.setText(Bundle.TesterOptionsPanel_tester_hint(Tester.TESTER_FILE_NAME));
DocumentListener defaultDocumentListener = new DefaultDocumentListener();
ActionListener defaultActionListener = new DefaultActionListener();
testerPathTextField.getDocument().addDocumentListener(defaultDocumentListener);
phpIniTextField.getDocument().addDocumentListener(defaultDocumentListener);
binaryExecutableComboBox.addActionListener(defaultActionListener);
}
@Override
public void setLayout(final LayoutManager mgr) {
if (mgr instanceof DocumentListener) {
Document doc = getDocument();
if (doc != null) doc.removeDocumentListener((DocumentListener) mgr);
}
}
@Override
public void setLayout(final LayoutManager mgr) {
if (mgr instanceof DocumentListener) {
Document doc = getDocument();
if (doc != null) doc.removeDocumentListener((DocumentListener) mgr);
}
}
@Override
public void removeDocumentListener(DocumentListener listener) {
if (LOG_LISTENER.isLoggable(Level.FINE)) {
LOG_LISTENER.fine("REMOVE DocumentListener of class " + listener.getClass() + " from existing " +
org.netbeans.lib.editor.util.swing.DocumentUtilities.getDocumentListenerCount(this) +
" listeners. Listener: " + listener + '\n'
);
if (LOG_LISTENER.isLoggable(Level.FINER)) {
LOG_LISTENER.log(Level.FINER, " StackTrace:\n", new Exception());
}
}
if (!org.netbeans.lib.editor.util.swing.DocumentUtilities.removePriorityDocumentListener(
this, listener, DocumentListenerPriority.DEFAULT))
super.removeDocumentListener(listener);
}
public void addListener(ColorChangedListener ccl, ItemListener il, DocumentListener dl) {
fontBox.addItemListener(il);
styleBox.addItemListener(il);
txtSize.getDocument().addDocumentListener(dl);
color.addColorChangedListener(ccl);
if (dl instanceof DelayedDocumentListener)
this.dl = (DelayedDocumentListener) dl;
}
/** Gives notification that an attribute or set of attributes changed.
* @param ev event describing the action
*/
@Override public void changedUpdate(DocumentEvent ev) {
final DocumentListener l = docGet(ev);
if (l != null) {
l.changedUpdate(ev);
}
}
/** Gives notification that a portion of the document has been removed.
* @param ev event describing the action
*/
@Override public void removeUpdate(DocumentEvent ev) {
final DocumentListener l = docGet(ev);
if (l != null) {
l.removeUpdate(ev);
}
}
/** Getter for the target listener.
* @param event the event the we want to distribute
* @return null if there is no listener because it has been finalized
*/
private DocumentListener docGet(DocumentEvent ev) {
DocumentListener l = (DocumentListener) super.ref.get();
if (l == null) {
super.ref.requestCleanUp(ev.getDocument());
}
return l;
}
private DocumentListener getDelegate() {
DocumentListener l = delegate.get();
if (l == null) {
source.removeDocumentListener(this);
}
return l;
}
private void init() {
setName(Bundle.NewJetModuleWizardPanelUi_name());
DocumentListener defaultDocumentListener = new DefaultDocumentListener();
nameTextField.getDocument().addDocumentListener(defaultDocumentListener);
jsFolderTextField.getDocument().addDocumentListener(defaultDocumentListener);
htmlFolderTextField.getDocument().addDocumentListener(defaultDocumentListener);
}
private void addListeners() {
DocumentListener defaultDocumentListener = new DefaultDocumentListener();
ItemListener defaultItemListener = new DefaultItemListener();
ActionListener defaultActionListener = new DefaultActionListener();
configTextField.getDocument().addDocumentListener(defaultDocumentListener);
autowatchCheckBox.addItemListener(defaultItemListener);
failOnErrorCheckBox.addItemListener(defaultItemListener);
debugCheckBox.addItemListener(new DebugItemListener());
debugBrowserIdComboBox.addActionListener(defaultActionListener);
}
/**
* Initialize text field to size box.
*
* @param tooltipText tooltip text
* @param focusListener
* @param documentListener
* @return
*/
private JTextField createSizeText(String tooltipText, FocusListener focusListener, DocumentListener documentListener) {
JTextField textField = new JTextField("", 5);
Insets insets = new Insets(2, 2, 2, 4);
textField.setToolTipText(tooltipText);
textField.setHorizontalAlignment(JTextField.RIGHT);
textField.setMargin(insets);
textField.addFocusListener(focusListener);
textField.getDocument().addDocumentListener(documentListener);
return textField;
}
QuickSearchPanel(WizardDescriptor settings, DataModel data) {
super(settings);
this.data = data;
initComponents();
putClientProperty("NewFileWizard_Title", getMessage("LBL_QuickSearchPanel_Title"));
DocumentListener dListener = new UIUtil.DocumentAdapter() {
public void insertUpdate(DocumentEvent e) {
checkValidity();
}
};
if (data.getPackageName() != null) {
packageCombo.setSelectedItem(data.getPackageName());
}
classNameTextField.getDocument().addDocumentListener(dListener);
categoryNameTextField.getDocument().addDocumentListener(dListener);
commandPrefixTextField.getDocument().addDocumentListener(dListener);
positionTextField.getDocument().addDocumentListener(dListener);
Component editorComp = packageCombo.getEditor().getEditorComponent();
if (editorComp instanceof JTextComponent) {
((JTextComponent) editorComp).getDocument().addDocumentListener(dListener);
}
}
/** Creates new NameAndLocationPanel */
public NameAndLocationPanel(final WizardDescriptor setting, final NewLoaderIterator.DataModel data) {
super(setting);
this.data = data;
initComponents();
initAccessibility();
putClientProperty("NewFileWizard_Title", getMessage("LBL_LoaderWizardTitle"));
DocumentListener dListener = new UIUtil.DocumentAdapter() {
@Override
public void insertUpdate(DocumentEvent e) {
if (checkValidity()) {
updateData();
}
}
};
txtPrefix.getDocument().addDocumentListener(dListener);
txtIcon.getDocument().addDocumentListener(dListener);
if (comPackageName.getEditor().getEditorComponent() instanceof JTextField) {
JTextField txt = (JTextField)comPackageName.getEditor().getEditorComponent();
txt.getDocument().addDocumentListener(dListener);
}
if (data.canUseMultiview()) {
useMultiView.setEnabled(true);
useMultiView.setSelected(true);
} else {
useMultiView.setEnabled(false);
useMultiView.setSelected(false);
}
}
/** Creates new form CodeGeneratorPanel */
CodeGeneratorPanel(WizardDescriptor settings, NewCodeGeneratorIterator.DataModel data) {
super(settings);
this.data = data;
initComponents();
putClientProperty("NewFileWizard_Title", getMessage("LBL_CodeGeneratorPanel_Title"));
DocumentListener dListener = new UIUtil.DocumentAdapter() {
public void insertUpdate(DocumentEvent e) {
checkValidity();
}
};
if (data.getPackageName() != null) {
packageNameCombo.setSelectedItem(data.getPackageName());
}
fileNametextField.getDocument().addDocumentListener(dListener);
cpFileNameField.getDocument().addDocumentListener(dListener);
mimeTypeTextField.getDocument().addDocumentListener(dListener);
Component editorComp = packageNameCombo.getEditor().getEditorComponent();
if (editorComp instanceof JTextComponent) {
((JTextComponent) editorComp).getDocument().addDocumentListener(dListener);
}
}
public void removeDocumentListener(DocumentListener listener) {
if (this.ipFields != null) {
for (JIPV4Field field : this.ipFields) {
field.getDocument().removeDocumentListener(listener);
}
}
}
/**
* Create event listener to validate account field on the fly.
*/
private DocumentListener initPasswordValidateListener() {
return new ComponentFieldListener() {
@Override
void processEvent() {
valid = passwordValid();
setDescriptorButtons(descriptor, valid);
}
};
}
private void init() {
targetTextField.setText(PhpDocPreferences.getPhpDocTarget(phpModule, false));
titleTextField.setText(PhpDocPreferences.getPhpDocTitle(phpModule));
DocumentListener defaultDocumentListener = new DefaultDocumentListener();
targetTextField.getDocument().addDocumentListener(defaultDocumentListener);
titleTextField.getDocument().addDocumentListener(defaultDocumentListener);
}