Java Code Examples for javax.swing.event.DocumentEvent

The following are top voted examples for showing how to use javax.swing.event.DocumentEvent. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: incubator-netbeans   File: FoldHierarchyTransactionImpl.java   Source Code and License 6 votes vote down vote up
/**
 * This method implements the <code>DocumentListener</code>.
 * <br>
 * It is not intended to be called by clients.
 */
public void insertUpdate(DocumentEvent evt) {
    // Check whether there was an insert done right
    // at the original ending offset of the fold
    // so the fold end offset should be moved back.
    if (LOG.isLoggable(Level.FINE)) {
        LOG.fine("insertUpdate: offset=" + evt.getOffset() // NOI18N
            + ", length=" + evt.getLength() + '\n'); // NOI18N
    }
    try {
        if (FoldHierarchyExecution.isEventInUndoRedoHack(evt)) {
            validateAffectedFolds(execution.getRootFold(), evt);
        }
        
        insertCheckEndOffset(execution.getRootFold(), evt);

    } catch (BadLocationException e) {
        ErrorManager.getDefault().notify(e);
    }
}
 
Example 2
Project: incubator-netbeans   File: PanelProjectLocationVisual.java   Source Code and License 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.equals(projectNameTextField.getDocument()) || doc.equals(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        
    
    if (this.projectNameTextField.getDocument().equals(e.getDocument())) {
        firePropertyChange(PROP_PROJECT_NAME, null, this.projectNameTextField.getText());
    }
    if (this.projectLocationTextField.getDocument().equals(e.getDocument())) {
        firePropertyChange(PROP_PROJECT_LOCATION, null, this.projectLocationTextField.getText());
    }
}
 
Example 3
Project: incubator-netbeans   File: BasicBrandingPanel.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 4
Project: incubator-netbeans   File: SetUpRemotePlatform.java   Source Code and License 6 votes vote down vote up
private void updateDefaultDirectory(DocumentEvent e) {
    Document doc = e.getDocument();
    if (doc.equals(username.getDocument())) {
        String usernameText = username.getText();
        if (!usernameText.isEmpty()) {
            String workdirText = workingDir.getText();
            if (workdirText.isEmpty() || (currentDefaultWorkDir != null && workdirText.equals(currentDefaultWorkDir))) {
                String updatedDefaultworkDir = "/home/" + usernameText + "/NetBeansProjects/"; //NOI18N
                workingDir.setText(updatedDefaultworkDir);
                currentDefaultWorkDir = updatedDefaultworkDir;
            }
        } else {
            if (currentDefaultWorkDir != null && workingDir.getText().equals(currentDefaultWorkDir)) {
                workingDir.setText(""); //NOI18N
                currentDefaultWorkDir = null;
            }
        }
    }
}
 
Example 5
Project: educational-plugin   File: StudyTwitterUtils.java   Source Code and License 6 votes vote down vote up
/**
 * Listener updates label indicating remaining symbols number like in twitter.
 */
private static DocumentListener createTextFieldLengthDocumentListener(@NotNull TwitterDialogWrapper builder, @NotNull final StudyTwitterUtils.TwitterDialogPanel panel) {
  return new DocumentAdapter() {
    @Override
    protected void textChanged(DocumentEvent e) {
      int length = e.getDocument().getLength();
      if (length > 140 || length == 0) {
        builder.setOKActionEnabled(false);
        panel.getRemainSymbolsLabel().setText("<html><font color='red'>" + String.valueOf(140 - length) + "</font></html>");
      } else {
        builder.setOKActionEnabled(true);
        panel.getRemainSymbolsLabel().setText(String.valueOf(140 - length));
      }

    }
  };
}
 
Example 6
Project: incubator-netbeans   File: BaseTextUI.java   Source Code and License 6 votes vote down vote up
/** Remove from document notification. */
    public void removeUpdate(DocumentEvent evt) {
        checkLengthyAtomicEdit(evt);
        // No longer trigger syntax update related repaint
//        try {
//            BaseDocumentEvent bevt = (BaseDocumentEvent)evt;
//            EditorUI eui = getEditorUI();
//            int y = getYFromPos(evt.getOffset());
//            int lineHeight = eui.getLineHeight();
//            int syntaxY = getYFromPos(bevt.getSyntaxUpdateOffset());
//            // !!! patch for case when DocMarksOp.eolMark is at the end of document
//            if (bevt.getSyntaxUpdateOffset() == evt.getDocument().getLength()) {
//                syntaxY += lineHeight;
//            }
//            if (getComponent().isShowing()) {
//                eui.repaint(y, Math.max(lineHeight, syntaxY - y));
//            }
//
//        } catch (BadLocationException ex) {
//            Utilities.annotateLoggable(ex);
//        }
    }
 
Example 7
Project: AntIDE   File: OutputFrame.java   Source Code and License 5 votes vote down vote up
/**
 *  ȭ���� ������ �ٲ� Ouput�� ���̰� ��ȯ�Ѵ�.
 */
private void changeTab( DocumentEvent e ) {
	if ( e.getDocument() == outputStd.getOutput().getDocument() ) {
		if ( tabPane.getSelectedComponent() != outputStd )
			tabPane.setSelectedComponent(outputStd);
	} else if ( e.getDocument() == outputErr.getOutput().getDocument() ) {
		if ( tabPane.getSelectedComponent() != outputErr )
			tabPane.setSelectedComponent(outputErr);
	}
}
 
Example 8
Project: incubator-netbeans   File: LeafView.java   Source Code and License 5 votes vote down vote up
/** Gives notification from the document that attributes were removed
* in a location that this view is responsible for.
*
* @param e the change information from the associated document
* @param a the current allocation of the view
* @param f the factory to use to rebuild if the view has children
*/
public @Override void removeUpdate(DocumentEvent evt, Shape a, ViewFactory f) {
    try {
        BaseDocumentEvent bevt = (BaseDocumentEvent)evt;
        EditorUI editorUI = getEditorUI();
        int y = getYFromPos(evt.getOffset());
        int lineHeight = editorUI.getLineHeight();
        if (bevt.getLFCount() > 0) { // one or more lines removed
            int removeHeight = bevt.getLFCount() * lineHeight;
            mainHeight -= removeHeight;
            editorUI.repaint(y);

        } else { // removing on one line
            int syntaxY = getYFromPos(bevt.getSyntaxUpdateOffset());
            // !!! patch for case when DocMarksOp.eolMark is at the end of document
            if (bevt.getSyntaxUpdateOffset() == evt.getDocument().getLength()) {
                syntaxY += lineHeight;
            }

            if (getComponent().isShowing()) {
                editorUI.repaint(y, Math.max(lineHeight, syntaxY - y));
            }
        }

    } catch (BadLocationException ex) {
        Utilities.annotateLoggable(ex);
    }
}
 
Example 9
Project: incubator-netbeans   File: PanelProjectLocationVisual.java   Source Code and License 5 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());
    }
    if (this.projectLocationTextField.getDocument() == e.getDocument()) {
        firePropertyChange (PROP_PROJECT_LOCATION,null,this.projectLocationTextField.getText());
    }
}
 
Example 10
Project: rapidminer   File: AutoCompletionComboBox.java   Source Code and License 5 votes vote down vote up
@Override
public void insertUpdate(DocumentEvent e) {
	try {
		Vector<String> vectorOfStrings = new Vector<String>();
		for (int i = 0; i < getModel().getSize(); i++) {
			vectorOfStrings.add(String.valueOf(getModel().getElementAt(i)));
		}
		Document document = e.getDocument();
		String documentText = document.getText(0, document.getLength());
		final String result = checkForMatch(documentText, vectorOfStrings, caseSensitive);
		final String newString = (result == null) ? documentText : result;
		final int startSelect = document.getLength();
		final int endSelect = newString.length();
		final JTextField editorComponent = (JTextField) getEditor().getEditorComponent();

		if (startSelect == e.getOffset() + e.getLength()) {
			SwingUtilities.invokeLater(new Runnable() {

				@Override
				public void run() {
					setSelectedItem(newString);
					editorComponent.getDocument().removeDocumentListener(docListener);
					editorComponent.setText(newString);
					editorComponent.getDocument().addDocumentListener(docListener);
					Caret caret = editorComponent.getCaret();
					caret.setDot(endSelect);
					caret.moveDot(startSelect);
				}
			});
		}
	} catch (BadLocationException e1) {
	}
}
 
Example 11
Project: BEAST   File: TextChangedActionAdder.java   Source Code and License 5 votes vote down vote up
@Override
public void insertUpdate(DocumentEvent de) {       
    if(!listen) return; 
    try {
        String added = pane.getStyledDocument().getText(de.getOffset(), de.getLength());
                  
        TextAddedAction action = new TextAddedAction(
                new TextDelta(de.getOffset(), added),
                pane.getStyledDocument());
        actionList.add(action);
    } catch (BadLocationException ex) {
        Logger.getLogger(TextChangedActionAdder.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example 12
Project: batmapper   File: MapperPanel.java   Source Code and License 5 votes vote down vote up
@Override
public void removeUpdate( DocumentEvent arg0 ) {
    if (this.room != null) {
        this.room.setNotes( this.roomNotes.getText() );
    }

}
 
Example 13
Project: difftool   File: DocumentManager.java   Source Code and License 5 votes vote down vote up
private void processInsert(DocumentEvent e) throws BadLocationException {

            final Document document = e.getDocument();
            Element root = document.getDefaultRootElement();
            int start = root.getElementIndex(e.getOffset());
            int end = root.getElementIndex(e.getOffset() + e.getLength() - 1);
            Element startElement = root.getElement(start);
            Element endElement = root.getElement(end);
            if (start == end) {
                String newValue = getText(document, startElement);
                replaceLine(document, start, newValue);
                if (e.getOffset() + e.getLength() == startElement.getEndOffset()) {
                    Element startNext = root.getElement(start + 1);

                    insertLines(document, start + 1, Collections.singletonList(
                            getText(document, startNext)
                    ));
                }
            } else {
                removeLines(document, start, start);

                List<String> lines = new ArrayList<>();

                for (int line = start; line <= end; ++line) {
                    lines.add(getText(document, root.getElement(line)));
                }

               if (e.getOffset() + e.getLength() == endElement.getEndOffset() && end + 1 < root.getElementCount()) {
                    Element endNext = root.getElement(end + 1);
                    lines.add(getText(document, endNext));
                }

                insertLines(document, start, lines);
            }
        }
 
Example 14
Project: openjdk-jdk10   File: TableView.java   Source Code and License 5 votes vote down vote up
protected void forwardUpdate(DocumentEvent.ElementChange ec,
                                 DocumentEvent e, Shape a, ViewFactory f) {
    super.forwardUpdate(ec, e, a, f);
    // A change in any of the table cells usually effects the whole table,
    // so redraw it all!
    if (a != null) {
        Component c = getContainer();
        if (c != null) {
            Rectangle alloc = (a instanceof Rectangle) ? (Rectangle)a :
                               a.getBounds();
            c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
        }
    }
}
 
Example 15
Project: incubator-netbeans   File: LeafView.java   Source Code and License 5 votes vote down vote up
/** Gives notification that something was inserted into the document
* in a location that this view is responsible for.
*
* @param e the change information from the associated document
* @param a the current allocation of the view
* @param f the factory to use to rebuild if the view has children
*/
public @Override void insertUpdate(DocumentEvent evt, Shape a, ViewFactory f) {
    try {
        BaseDocumentEvent bevt = (BaseDocumentEvent)evt;
        EditorUI editorUI = getEditorUI();
        int y = getYFromPos(evt.getOffset());
        int lineHeight = editorUI.getLineHeight();
        if (bevt.getLFCount() > 0) { // one or more lines inserted
            int addHeight = bevt.getLFCount() * lineHeight;
            mainHeight += addHeight;
            editorUI.repaint(y);

        } else { // inserting on one line

            int syntaxY = getYFromPos(bevt.getSyntaxUpdateOffset());
            // !!! patch for case when DocMarksOp.eolMark is at the end of document
            if (bevt.getSyntaxUpdateOffset() == evt.getDocument().getLength()) {
                syntaxY += lineHeight;
            }

            if (getComponent().isShowing()) {
                editorUI.repaint(y, Math.max(lineHeight, syntaxY - y));
            }
        }

    } catch (BadLocationException ex) {
        Utilities.annotateLoggable(ex);
    }
}
 
Example 16
Project: incubator-netbeans   File: GapDocumentView.java   Source Code and License 5 votes vote down vote up
public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {
    layoutLockDepth++;
    try {
        // Do not check pendingUpdate since changedUpdate() is likely invoked by BaseDocument.repaintBlock()
        super.changedUpdate(e, a, f);
    } finally {
        updateLayout();
        layoutLockDepth--;
    }
}
 
Example 17
Project: jdk8u-jdk   File: XTextAreaPeer.java   Source Code and License 5 votes vote down vote up
@Override
public void removeUpdate(DocumentEvent e) {
    if (peer != null) {
        peer.postEvent(new TextEvent(peer.target,
                                     TextEvent.TEXT_VALUE_CHANGED));
    }
}
 
Example 18
Project: incubator-netbeans   File: QuickSearchPanel.java   Source Code and License 5 votes vote down vote up
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);
    }
}
 
Example 19
Project: incubator-netbeans   File: BasicPanelVisual.java   Source Code and License 5 votes vote down vote up
@Override
public void changedUpdate(DocumentEvent e) {
    updateTexts(e);
    if (this.projectNameTextField.getDocument() == e.getDocument()) {
        firePropertyChange(PROP_PROJECT_NAME,null,this.projectNameTextField.getText());
    }
}
 
Example 20
Project: jdk8u-jdk   File: XTextFieldPeer.java   Source Code and License 5 votes vote down vote up
@Override
public void changedUpdate(DocumentEvent e) {
    if (peer != null) {
        peer.postEvent(new TextEvent(peer.target,
                                     TextEvent.TEXT_VALUE_CHANGED));
    }
}
 
Example 21
Project: OpenJSharp   File: XTextFieldPeer.java   Source Code and License 5 votes vote down vote up
@Override
public void insertUpdate(DocumentEvent e) {
    if (peer != null) {
        peer.postEvent(new TextEvent(peer.target,
                                     TextEvent.TEXT_VALUE_CHANGED));
    }
}
 
Example 22
Project: incubator-netbeans   File: PanelProjectLocationVisual.java   Source Code and License 5 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());
    }
    if (this.projectLocationTextField.getDocument() == e.getDocument()) {
        firePropertyChange (PROP_PROJECT_LOCATION,null,this.projectLocationTextField.getText());
    }
}
 
Example 23
Project: incubator-netbeans   File: WeakPositions.java   Source Code and License 5 votes vote down vote up
@Override
public void removeUpdate(DocumentEvent e) {
    synchronized (OGLS) {
        OffsetGapList<WeakPositions.WeakP> ogl = getOgl(e);
        if (ogl != null) {
            ogl.defaultRemoveUpdate(e.getOffset(), e.getLength());
        }
    }
}
 
Example 24
Project: incubator-netbeans   File: DocumentUtilities.java   Source Code and License 5 votes vote down vote up
/**
 * Set a property of a given document event.
 *
 * @param evt non-null document event to which the property should be stored.
 * @param key non-null key of the property.
 * @param value for the given property.
 */
public static void putEventProperty(DocumentEvent evt, Object key, Object value) {
    EventPropertiesElementChange change = (EventPropertiesElementChange)
            evt.getChange(EventPropertiesElement.INSTANCE);
    if (change == null) {
        throw new IllegalStateException("addEventPropertyStorage() not called for evt=" + evt); // NOI18N
    }
    change.putProperty(key, value);
}
 
Example 25
Project: incubator-netbeans   File: ProjectCopyPanel.java   Source Code and License 5 votes vote down vote up
public void insertUpdate(DocumentEvent e) {
    if (e.getDocument().equals(projectLocation.getDocument())) {
        if (lastComputedName != null && lastComputedName.equals(projectName.getText())) {
            projectName.setText(computeValidProjectName(new File(projectLocation.getText()).getAbsolutePath(), 
                    ProjectUtils.getInformation(project).getName()));
        }            
    }
    updateProjectFolder();
    validateDialog();
}
 
Example 26
Project: incubator-netbeans   File: LockView.java   Source Code and License 5 votes vote down vote up
public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f) {
    lock();
    try {
        
        if (view != null) {
            view.changedUpdate(e, a, f);
        }

    } finally {
        unlock();
    }
}
 
Example 27
Project: incubator-netbeans   File: BasicPanelVisual.java   Source Code and License 5 votes vote down vote up
@Override
public void removeUpdate(DocumentEvent e) {
    updateTexts(e);
    if (this.projectNameTextField.getDocument() == e.getDocument()) {
        firePropertyChange(PROP_PROJECT_NAME,null,this.projectNameTextField.getText());
    }
}
 
Example 28
Project: Lang871   File: CodeListener.java   Source Code and License 4 votes vote down vote up
@Override
public void removeUpdate(DocumentEvent e)
{

}
 
Example 29
Project: incubator-netbeans   File: CoverageHighlightsContainer.java   Source Code and License 4 votes vote down vote up
public void changedUpdate(DocumentEvent ev) {
}
 
Example 30
Project: incubator-netbeans   File: StatusBar.java   Source Code and License 4 votes vote down vote up
public void removeUpdate(DocumentEvent evt) {
    if (evt.getType() == DocumentEvent.EventType.INSERT) { // undo
        documentUndo(evt);
    }
}
 
Example 31
Project: Pogamut3   File: TemplateBotProjectPanelVisual.java   Source Code and License 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 32
Project: incubator-netbeans   File: BaseDocumentTest.java   Source Code and License 4 votes vote down vote up
public void insertUpdate(DocumentEvent e) {
    // less, not less and equal
    if (e.getOffset() < offset) {
        offset += e.getLength();
    }
}
 
Example 33
Project: bitbox   File: BaseConverter.java   Source Code and License 4 votes vote down vote up
@Override
public void insertUpdate(DocumentEvent documentEvent) {
    updateSingleField((EditableBaseLogicGUI) documentEvent.getDocument().getProperty("parentEditable"));
}
 
Example 34
Project: incubator-netbeans   File: DocumentModel.java   Source Code and License 4 votes vote down vote up
public void changedUpdate(javax.swing.event.DocumentEvent documentEvent) {
    //no need to handle document attributes changes
}
 
Example 35
Project: OpenJSharp   File: CAccessible.java   Source Code and License 4 votes vote down vote up
@Override
public void changedUpdate(DocumentEvent e) {
    if (ptr != 0) valueChanged(ptr);
}
 
Example 36
Project: incubator-netbeans   File: AttachmentPanel.java   Source Code and License 4 votes vote down vote up
@Override
public void removeUpdate (DocumentEvent e) {
    fieldUpdated(e.getDocument());
}
 
Example 37
Project: incubator-netbeans   File: ComboBoxAutoCompleteSupport.java   Source Code and License 4 votes vote down vote up
@Override
public void changedUpdate( DocumentEvent e ) {
    matchSelection( e );
}
 
Example 38
Project: incubator-netbeans   File: PanelProjectLocationVisual.java   Source Code and License 4 votes vote down vote up
@Override
public void removeUpdate(DocumentEvent e) {
    updateTexts(e);
}
 
Example 39
Project: incubator-netbeans   File: Merge.java   Source Code and License 4 votes vote down vote up
@Override
public void removeUpdate(DocumentEvent e) {
    setPreviewLabels();
}
 
Example 40
Project: incubator-netbeans   File: GoToPanelImpl.java   Source Code and License 4 votes vote down vote up
public void changedUpdate( DocumentEvent e ) {
    update();
}