Java Code Examples for javax.swing.event.DocumentEvent#getDocument()

The following examples show how to use javax.swing.event.DocumentEvent#getDocument() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QueryNameTextFieldDocumentListener.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
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;
  }

}
 
Example 2
Source File: BaseTextUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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);
//                }
            }
        }
    }
 
Example 3
Source File: PanelProjectLocationVisual.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** 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        
}
 
Example 4
Source File: BaseSpellEditor.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
/** 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);
    }
}
 
Example 5
Source File: AbstractOutputPane.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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());
    }
}
 
Example 6
Source File: MessageConsole.java    From portable-ftp-server with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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);
		}
	}
}
 
Example 7
Source File: DetailsPanel.java    From WhiteRabbit with Apache License 2.0 5 votes vote down vote up
@Override
public void removeUpdate(DocumentEvent e) {
	if (e.getDocument() == logicArea.getDocument())
		itemToItemMap.setLogic(logicArea.getText());
	else
		itemToItemMap.setComment(commentsArea.getText());
}
 
Example 8
Source File: BasicProjectInfoPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 9
Source File: FixShebangInspection.java    From BashSupport with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example 10
Source File: DisplayPreferences.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
@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();
}
 
Example 11
Source File: Editor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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 );
}
 
Example 12
Source File: GroovyJavaDemoPanelVisual.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void changedUpdate(DocumentEvent e) {
    updateTexts(e);
    if (this.projectNameTextField.getDocument() == e.getDocument()) {
        firePropertyChange(PROP_PROJECT_NAME, null, this.projectNameTextField.getText());
    }
}
 
Example 13
Source File: hostviewPanelVisual.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
/** 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

}
 
Example 14
Source File: SessionDetails.java    From chipster with MIT License 4 votes vote down vote up
private void fieldUpdated(DocumentEvent e) {
	if (e.getDocument() == notesField.getDocument()) {
		setNotesActive(true);
		application.getSessionManager().setSessionNotes(getNotesContent());
	}
}
 
Example 15
Source File: PHPSamplesPanelVisual.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void removeUpdate(DocumentEvent e) {
    updateTexts(e);
    if (this.projectNameTextField.getDocument() == e.getDocument()) {
        firePropertyChange(PROP_PROJECT_NAME, null, this.projectNameTextField.getText());
    }
}
 
Example 16
Source File: PHPSamplesPanelVisual.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** 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

}
 
Example 17
Source File: datasourcePanelVisual.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
/** 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

}
 
Example 18
Source File: pluggableViewDemoSuitePanelVisual.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
public void removeUpdate(DocumentEvent e) {
    updateTexts(e);
    if (this.projectNameTextField.getDocument() == e.getDocument()) {
        firePropertyChange(PROP_PROJECT_NAME, null, this.projectNameTextField.getText());
    }
}
 
Example 19
Source File: jvmcapsPanelVisual.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
/** 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

}
 
Example 20
Source File: subnodesPanelVisual.java    From visualvm with GNU General Public License v2.0 4 votes vote down vote up
public void removeUpdate(DocumentEvent e) {
    updateTexts(e);
    if (this.projectNameTextField.getDocument() == e.getDocument()) {
        firePropertyChange(PROP_PROJECT_NAME, null, this.projectNameTextField.getText());
    }
}