javax.swing.event.DocumentEvent Java Examples

The following examples show how to use javax.swing.event.DocumentEvent. 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 Project: CQL   Author: CategoricalData   File: JFontChooser.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
private void update(DocumentEvent event) {
	String newValue = "";
	try {
		Document doc = event.getDocument();
		newValue = doc.getText(0, doc.getLength());
	} catch (BadLocationException e) {
		e.printStackTrace();
	}

	if (newValue.length() > 0) {
		int index = targetList.getNextMatch(newValue, 0, Position.Bias.Forward);
		if (index < 0) {
			index = 0;
		}
		targetList.ensureIndexIsVisible(index);

		String matchedName = targetList.getModel().getElementAt(index).toString();
		if (newValue.equalsIgnoreCase(matchedName)) {
			if (index != targetList.getSelectedIndex()) {
				SwingUtilities.invokeLater(new ListSelector(index));
			}
		}
	}
}
 
Example #2
Source Project: netbeans   Author: apache   File: BasicBrandingPanel.java    License: Apache License 2.0 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 #3
Source Project: consulo   Author: consulo   File: SingleIntegerFieldOptionsPanel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Sets integer number format to JFormattedTextField instance,
 * sets value of JFormattedTextField instance to object's field value,
 * synchronizes object's field value with the value of JFormattedTextField instance.
 *
 * @param textField  JFormattedTextField instance
 * @param owner      an object whose field is synchronized with {@code textField}
 * @param property   object's field name for synchronization
 */
public static void setupIntegerFieldTrackingValue(final JFormattedTextField textField,
                                                  final InspectionProfileEntry owner,
                                                  final String property) {
    NumberFormat formatter = NumberFormat.getIntegerInstance();
    formatter.setParseIntegerOnly(true);
    textField.setFormatterFactory(new DefaultFormatterFactory(new NumberFormatter(formatter)));
    textField.setValue(getPropertyValue(owner, property));
    final Document document = textField.getDocument();
    document.addDocumentListener(new DocumentAdapter() {
        @Override
        public void textChanged(DocumentEvent e) {
            try {
                textField.commitEdit();
                setPropertyValue(owner, property,
                        ((Number) textField.getValue()).intValue());
            } catch (ParseException e1) {
                // No luck this time
            }
        }
    });
}
 
Example #4
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: ElementTreePanel.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates the tree based on the event type. This will invoke either
 * updateTree with the root element, or handleChange.
 */
protected void updateTree(DocumentEvent event) {
    updatingSelection = true;
    try {
        TreeModel model = getTreeModel();
        Object root = model.getRoot();

        for (int counter = model.getChildCount(root) - 1; counter >= 0;
                counter--) {
            updateTree(event, (Element) model.getChild(root, counter));
        }
    } finally {
        updatingSelection = false;
    }
}
 
Example #5
Source Project: nextreports-designer   Author: nextreports   File: LineNumberBorder.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Called whenever a character is input (key is typed) in the text
 * document we're line-numbering.
 *
 * @param event The document event.
 */
public void insertUpdate(DocumentEvent event) {
	int newNumLines = editorPane.getDocument().getDefaultRootElement().getElementCount();
	if (newNumLines > currentNumLines) {
		// Adjust the amount of space the line numbers take up,
		// if necessary.
		if (newNumLines/10 > currentNumLines / 10) {
			updateCellWidths();
		}
		currentNumLines = newNumLines;
	}
}
 
Example #6
Source Project: jdk8u60   Author: chenghanpeng   File: XTextAreaPeer.java    License: GNU General Public License v2.0 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 #7
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: BoxView.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Forwards the given <code>DocumentEvent</code> to the child views
 * that need to be notified of the change to the model.
 * If a child changed its requirements and the allocation
 * was valid prior to forwarding the portion of the box
 * from the starting child to the end of the box will
 * be repainted.
 *
 * @param ec changes to the element this view is responsible
 *  for (may be <code>null</code> if there were no changes)
 * @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
 * @see #insertUpdate
 * @see #removeUpdate
 * @see #changedUpdate
 * @since 1.3
 */
protected void forwardUpdate(DocumentEvent.ElementChange ec,
                             DocumentEvent e, Shape a, ViewFactory f) {
    boolean wasValid = isLayoutValid(majorAxis);
    super.forwardUpdate(ec, e, a, f);

    // determine if a repaint is needed
    if (wasValid && (! isLayoutValid(majorAxis))) {
        // Repaint is needed because one of the tiled children
        // have changed their span along the major axis.  If there
        // is a hosting component and an allocated shape we repaint.
        Component c = getContainer();
        if ((a != null) && (c != null)) {
            int pos = e.getOffset();
            int index = getViewIndexAtPosition(pos);
            Rectangle alloc = getInsideAllocation(a);
            if (majorAxis == X_AXIS) {
                alloc.x += majorOffsets[index];
                alloc.width -= majorOffsets[index];
            } else {
                alloc.y += minorOffsets[index];
                alloc.height -= minorOffsets[index];
            }
            c.repaint(alloc.x, alloc.y, alloc.width, alloc.height);
        }
    }
}
 
Example #8
Source Project: pentaho-reporting   Author: pentaho   File: ImportBundleFileDialog.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
protected void handleChange( final DocumentEvent e ) {
  final String s = entryNameField.getText();
  if ( StringUtils.isEmpty( s ) ) {
    getConfirmAction().setEnabled( false );
    return;
  }

  if ( StringUtils.isEmpty( (String) mimeTypeBox.getSelectedItem() ) ) {
    getConfirmAction().setEnabled( false );
    return;
  }

  getConfirmAction().setEnabled( bundle.isEntryExists( s ) == false );
}
 
Example #9
Source Project: rapidminer-studio   Author: rapidminer   File: SyntaxDocument.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * We overwrite this method to update the token marker state immediately so that any event
 * listeners get a consistent token marker.
 */
@Override
protected void fireInsertUpdate(DocumentEvent evt) {
	if (tokenMarker != null) {
		DocumentEvent.ElementChange ch = evt.getChange(getDefaultRootElement());
		if (ch != null) {
			tokenMarker.insertLines(ch.getIndex() + 1, ch.getChildrenAdded().length - ch.getChildrenRemoved().length);
		}
	}

	super.fireInsertUpdate(evt);
}
 
Example #10
Source Project: netbeans   Author: apache   File: LockView.java    License: Apache License 2.0 5 votes vote down vote up
public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f) {
    lock();
    try {
        
        if (view != null) {
            view.removeUpdate(e, a, f);
        }

    } finally {
        unlock();
    }
}
 
Example #11
Source Project: nb-springboot   Author: AlexFalappa   File: InitializrProjectPanelVisual3.java    License: Apache License 2.0 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 #12
Source Project: BashSupport   Author: BashSupport   File: FixShebangInspection.java    License: 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 #13
Source Project: netbeans   Author: apache   File: ConnectionType.java    License: Apache License 2.0 5 votes vote down vote up
private void textChanged(final DocumentEvent e) {
    // repost later to AWT otherwise it can deadlock because
    // the document is locked while firing event and we try
    // synchronously access its content from selected repository
    Runnable awt = new Runnable() {
        public void run() {
            textChanged(e.getDocument());
            repository.validateSvnUrl();
        }
    };
    SwingUtilities.invokeLater(awt);
}
 
Example #14
Source Project: dragonwell8_jdk   Author: alibaba   File: ElementTreePanel.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates the tree based on the event type. This will invoke either
 * updateTree with the root element, or handleChange.
 */
protected void updateTree(DocumentEvent event) {
    updatingSelection = true;
    try {
        TreeModel model = getTreeModel();
        Object root = model.getRoot();

        for (int counter = model.getChildCount(root) - 1; counter >= 0;
                counter--) {
            updateTree(event, (Element) model.getChild(root, counter));
        }
    } finally {
        updatingSelection = false;
    }
}
 
Example #15
Source Project: java-swing-tips   Author: aterai   File: MainPanel.java    License: MIT License 5 votes vote down vote up
@Override public void insertUpdate(DocumentEvent e) {
  Document doc = e.getDocument();
  Element root = doc.getDefaultRootElement();
  if (root.getElementCount() <= MAX_LINES) {
    return;
  }
  EventQueue.invokeLater(() -> removeLines(doc, root));
  textComponent.setCaretPosition(doc.getLength());
}
 
Example #16
Source Project: jdk8u-jdk   Author: frohoff   File: ElementTreePanel.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates the tree based on the event type. This will invoke either
 * updateTree with the root element, or handleChange.
 */
protected void updateTree(DocumentEvent event) {
    updatingSelection = true;
    try {
        TreeModel model = getTreeModel();
        Object root = model.getRoot();

        for (int counter = model.getChildCount(root) - 1; counter >= 0;
                counter--) {
            updateTree(event, (Element) model.getChild(root, counter));
        }
    } finally {
        updatingSelection = false;
    }
}
 
Example #17
Source Project: Hollow-Knight-SaveManager   Author: KayDeeTee   File: Listeners.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void insertUpdate(DocumentEvent arg0) {
	check();
	if(autoCalc.isSelected()){
		SwingUtilities.invokeLater(runAutoCalc);
	}
}
 
Example #18
Source Project: pcgen   Author: PCGen   File: TextFieldListener.java    License: GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void changedUpdate(DocumentEvent e)
{
	textChanged(textField.getText());
}
 
Example #19
Source Project: SVG-Android   Author: MegatronKing   File: VectorContentViewer.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void removeUpdate(DocumentEvent e) {
    if (mTextWatcher != null) {
        mTextWatcher.onChange(mTextArea.getText());
    }
}
 
Example #20
Source Project: netbeans   Author: apache   File: TaskPanel.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public final void removeUpdate (DocumentEvent e) {
    fieldModified();
}
 
Example #21
Source Project: idea-php-symfony2-plugin   Author: Haehnchen   File: TwigNamespaceDialog.java    License: MIT License 4 votes vote down vote up
@Override
public void changedUpdate(DocumentEvent e) {
    setOkState();
}
 
Example #22
Source Project: symja_android_library   Author: axkr   File: IOFunctions.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public void insertUpdate(DocumentEvent e) {
	updateFieldState();
}
 
Example #23
Source Project: darklaf   Author: weisJ   File: InsertDocumentListener.java    License: MIT License 4 votes vote down vote up
@Override
default void insertUpdate(final DocumentEvent e) {
    onInsert();
}
 
Example #24
Source Project: netbeans   Author: apache   File: Export.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void insertUpdate(DocumentEvent e) {
    validateUserInput();
}
 
Example #25
Source Project: chipster   Author: chipster   File: SessionDetails.java    License: MIT License 4 votes vote down vote up
public void changedUpdate(DocumentEvent e) {
	fieldUpdated(e);		
}
 
Example #26
Source Project: netbeans   Author: apache   File: PersistenceClientSetupPanelVisual.java    License: Apache License 2.0 4 votes vote down vote up
public void changedUpdate(DocumentEvent e) {
    changeSupport.fireChange();
}
 
Example #27
Source Project: darklaf   Author: weisJ   File: UpdateDocumentListener.java    License: MIT License 4 votes vote down vote up
default void removeUpdate(final DocumentEvent e) {
    update();
}
 
Example #28
Source Project: netbeans   Author: apache   File: AbstractCheckoutRevision.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void insertUpdate (DocumentEvent e) {
    validateName();
}
 
Example #29
Source Project: netbeans   Author: apache   File: WikiEditPanel.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void removeUpdate(DocumentEvent e) {
    changedUpdate(e);
}
 
Example #30
Source Project: darklaf   Author: weisJ   File: DarkFormattedTextFieldUI.java    License: MIT License 4 votes vote down vote up
@Override
public void removeUpdate(final DocumentEvent e) {
    update();
}