下面列出了javax.swing.event.DocumentEvent#getDocument() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/** Always call the super implementation when overriding this method. */
@Override
public void changedUpdate(DocumentEvent event) {
Document doc = event.getDocument();
if (doc == mNameField.getDocument()) {
LinkedLabel.setErrorMessage(mNameField, mNameField.getText().trim().isEmpty() ? I18n.Text("The name field may not be empty") : null);
} else if (doc == mClassField.getDocument()) {
LinkedLabel.setErrorMessage(mClassField, mClassField.getText().trim().isEmpty() ? I18n.Text("The class field may not be empty") : null);
} else if (doc == mCastingCostField.getDocument()) {
LinkedLabel.setErrorMessage(mCastingCostField, mCastingCostField.getText().trim().isEmpty() ? I18n.Text("The casting cost field may not be empty") : null);
} else if (doc == mCastingTimeField.getDocument()) {
LinkedLabel.setErrorMessage(mCastingTimeField, mCastingTimeField.getText().trim().isEmpty() ? I18n.Text("The casting time field may not be empty") : null);
} else if (doc == mDurationField.getDocument()) {
LinkedLabel.setErrorMessage(mDurationField, mDurationField.getText().trim().isEmpty() ? I18n.Text("The duration field may not be empty") : null);
}
}
protected void handleChange( final DocumentEvent e ) {
if ( inUpdate ) {
return;
}
final DataSetQuery<T> item = dialogModel.getQueries().getSelectedQuery();
if ( item == null ) {
return;
}
try {
inUpdate = true;
final Document document = e.getDocument();
final String queryName = document.getText( 0, document.getLength() );
item.setQueryName( queryName );
dialogModel.getQueries().fireItemChanged( item );
} catch ( BadLocationException e1 ) {
e1.printStackTrace();
} finally {
inUpdate = false;
}
}
/** Handles changes in the Project name and project directory
*/
private void updateTexts( DocumentEvent e ) {
Document doc = e.getDocument();
if ( doc == projectNameTextField.getDocument() || doc == projectLocationTextField.getDocument() ) {
// Change in the project name
String projectName = projectNameTextField.getText();
String projectFolder = projectLocationTextField.getText();
String projFolderPath = FileUtil.normalizeFile(new File(projectFolder)).getAbsolutePath();
if (projFolderPath.endsWith(File.separator)) {
createdFolderTextField.setText(projFolderPath + projectName);
} else {
createdFolderTextField.setText(projFolderPath + File.separator + projectName);
}
}
panel.fireChangeEvent(); // Notify that the panel changed
}
private void checkLengthyAtomicEdit(DocumentEvent evt) {
if (atomicModCount != -1) {
if (++atomicModCount == LENGTHY_ATOMIC_EDIT_THRESHOLD) {
Document doc = evt.getDocument();
// Deactivate view hierarchy
View rootView = getRootView(getComponent());
View view;
if (rootView != null && rootView.getViewCount() > 0 &&
(view = rootView.getView(0)) instanceof org.netbeans.modules.editor.lib2.view.DocumentView)
{
((org.netbeans.modules.editor.lib2.view.DocumentView)view).updateLengthyAtomicEdit(+1);
}
// Inactivate lexer's token hierarchy
// Commented out due to #200270
// MutableTextInput input = (MutableTextInput) doc.getProperty(MutableTextInput.class);
// if (input != null) {
// input.tokenHierarchyControl().setActive(false);
// }
}
}
}
@Override
public void changedUpdate(DocumentEvent event) {
Preferences prefs = Preferences.getInstance();
Document document = event.getDocument();
if (mBlockLayoutField.getDocument() == document) {
prefs.setBlockLayout(List.of(mBlockLayoutField.getText().split("\n")));
} else if (mToolTipTimeout.getDocument() == document) {
prefs.setToolTipTimeout(Numbers.extractInteger(mToolTipTimeout.getText(), Preferences.DEFAULT_TOOLTIP_TIMEOUT, Preferences.MINIMUM_TOOLTIP_TIMEOUT, Preferences.MAXIMUM_TOOLTIP_TIMEOUT, true));
}
adjustResetButton();
}
public final void insertUpdate(DocumentEvent e) {
//Ensure it is consumed
e.getLength();
documentChanged();
if (e.getOffset() + e.getLength() >= getCaretPos() && (locked || !(e instanceof OutputDocument.DO))) {
//#119985 only move caret when not in editable section
OutputDocument doc = (OutputDocument)e.getDocument();
if (! (e instanceof OutputDocument.DO) && getCaretPos() >= doc.getOutputLength()) {
return ;
}
getCaret().setDot(e.getOffset() + e.getLength());
}
}
/**
* Removes the lines.
*
* @param e the e
*/
private void removeLines(DocumentEvent e) {
Document document = e.getDocument();
Element root = document.getDefaultRootElement();
while (root.getElementCount() > maximumLines) {
Element line = root.getElement(0);
int end = line.getEndOffset();
try {
document.remove(0, end);
} catch(BadLocationException ble) {
//System.out.println(ble);
}
}
}
@Override
public void removeUpdate(DocumentEvent e) {
if (e.getDocument() == logicArea.getDocument())
itemToItemMap.setLogic(logicArea.getText());
else
itemToItemMap.setComment(commentsArea.getText());
}
private void update(DocumentEvent e) {
if (ignoreEvent) {
// side-effect of changes done in this handler
return;
}
// start ignoring events
ignoreEvent = true;
if (projectLocation.getDocument() == e.getDocument()) {
antScriptValidityChecked = false;
updateAntScriptLocation();
updateProjectName();
updateProjectFolder();
}
if (antScript.getDocument() == e.getDocument()) {
antScriptValidityChecked = false;
updateProjectName();
}
// stop ignoring events
ignoreEvent = false;
if (projectFolder.getDocument() == e.getDocument()) {
projectFolderTouched = !"".equals(projectFolder.getText()); //NOI18N
}
if (antScript.getDocument() == e.getDocument()) {
antScriptTouched = !"".equals(antScript.getText()); //NOI18N
}
if (projectName.getDocument() == e.getDocument()) {
projectNameTouched = !"".equals(projectName.getText()); //NOI18N
}
listener.stateChanged(null);
}
private void updateShebangLines(DocumentEvent documentEvent) {
validShebangCommands.clear();
try {
Document doc = documentEvent.getDocument();
for (String item : doc.getText(0, doc.getLength()).split("\n")) {
if (item.trim().length() != 0) {
validShebangCommands.add(item);
}
}
} catch (BadLocationException e) {
throw new RuntimeException("Could not save shebang inspection settings input", e);
}
}
private void markChanged( DocumentEvent evt ) {
Document doc = evt.getDocument();
doc.putProperty( MODIFIED, Boolean.TRUE );
File file = (File)doc.getProperty( FILE );
int index = tabPane.indexOfComponent( comp );
tabPane.setTitleAt( index, file.getName() + '*' );
doc.removeDocumentListener( this );
}
public void removeUpdate(DocumentEvent e) {
updateTexts(e);
if (this.projectNameTextField.getDocument() == e.getDocument()) {
firePropertyChange(PROP_PROJECT_NAME, null, this.projectNameTextField.getText());
}
}
/** Handles changes in the Project name and project directory, */
private void updateTexts(DocumentEvent e) {
Document doc = e.getDocument();
if (doc == projectNameTextField.getDocument() || doc == projectLocationTextField.getDocument()) {
// Change in the project name
String projectName = projectNameTextField.getText();
String projectFolder = projectLocationTextField.getText();
//if (projectFolder.trim().length() == 0 || projectFolder.equals(oldName)) {
createdFolderTextField.setText(projectFolder + File.separatorChar + projectName);
//}
}
panel.fireChangeEvent(); // Notify that the panel changed
}
public void changedUpdate(DocumentEvent e) {
updateTexts(e);
if (this.projectNameTextField.getDocument() == e.getDocument()) {
firePropertyChange(PROP_PROJECT_NAME, null, this.projectNameTextField.getText());
}
}
/** Handles changes in the Project name and project directory, */
private void updateTexts(DocumentEvent e) {
Document doc = e.getDocument();
if (doc == projectNameTextField.getDocument() || doc == projectLocationTextField.getDocument()) {
// Change in the project name
String projectName = projectNameTextField.getText();
String projectFolder = projectLocationTextField.getText();
//if (projectFolder.trim().length() == 0 || projectFolder.equals(oldName)) {
createdFolderTextField.setText(projectFolder + File.separatorChar + projectName);
//}
}
panel.fireChangeEvent(); // Notify that the panel changed
}
private void fieldUpdated(DocumentEvent e) {
if (e.getDocument() == notesField.getDocument()) {
setNotesActive(true);
application.getSessionManager().setSessionNotes(getNotesContent());
}
}
public void removeUpdate(DocumentEvent e) {
updateTexts(e);
if (this.projectNameTextField.getDocument() == e.getDocument()) {
firePropertyChange(PROP_PROJECT_NAME, null, this.projectNameTextField.getText());
}
}
/** Handles changes in the Project name and project directory, */
private void updateTexts(DocumentEvent e) {
Document doc = e.getDocument();
if (doc == projectNameTextField.getDocument() || doc == projectLocationTextField.getDocument()) {
// Change in the project name
String projectName = projectNameTextField.getText();
String projectFolder = projectLocationTextField.getText();
//if (projectFolder.trim().length() == 0 || projectFolder.equals(oldName)) {
createdFolderTextField.setText(projectFolder + File.separatorChar + projectName);
//}
}
panel.fireChangeEvent(); // Notify that the panel changed
}
public void removeUpdate(DocumentEvent e) {
updateTexts(e);
if (this.projectNameTextField.getDocument() == e.getDocument()) {
firePropertyChange(PROP_PROJECT_NAME, null, this.projectNameTextField.getText());
}
}
/** Handles changes in the Project name and project directory, */
private void updateTexts(DocumentEvent e) {
Document doc = e.getDocument();
if (doc == projectNameTextField.getDocument() || doc == projectLocationTextField.getDocument()) {
// Change in the project name
String projectName = projectNameTextField.getText();
String projectFolder = projectLocationTextField.getText();
//if (projectFolder.trim().length() == 0 || projectFolder.equals(oldName)) {
createdFolderTextField.setText(projectFolder + File.separatorChar + projectName);
//}
}
panel.fireChangeEvent(); // Notify that the panel changed
}