下面列出了javax.swing.event.TreeSelectionListener#javax.swing.event.DocumentEvent 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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));
}
}
}
}
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;
}
/**
* 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
}
}
});
}
/**
* 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;
}
}
/**
* 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;
}
}
@Override
public void changedUpdate(DocumentEvent e) {
if (peer != null) {
peer.postEvent(new TextEvent(peer.target,
TextEvent.TEXT_VALUE_CHANGED));
}
}
/**
* 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);
}
}
}
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 );
}
/**
* 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);
}
public void removeUpdate(DocumentEvent e, Shape a, ViewFactory f) {
lock();
try {
if (view != null) {
view.removeUpdate(e, a, f);
}
} finally {
unlock();
}
}
@Override
public void removeUpdate(DocumentEvent e) {
updateTexts(e);
if (this.projectNameTextField.getDocument() == e.getDocument()) {
firePropertyChange(PROP_PROJECT_NAME, null, this.projectNameTextField.getText());
}
}
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 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);
}
/**
* 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;
}
}
@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());
}
/**
* 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;
}
}
@Override
public void insertUpdate(DocumentEvent arg0) {
check();
if(autoCalc.isSelected()){
SwingUtilities.invokeLater(runAutoCalc);
}
}
@Override
public void changedUpdate(DocumentEvent e)
{
textChanged(textField.getText());
}
@Override
public void removeUpdate(DocumentEvent e) {
if (mTextWatcher != null) {
mTextWatcher.onChange(mTextArea.getText());
}
}
@Override
public final void removeUpdate (DocumentEvent e) {
fieldModified();
}
@Override
public void changedUpdate(DocumentEvent e) {
setOkState();
}
@Override
public void insertUpdate(DocumentEvent e) {
updateFieldState();
}
@Override
default void insertUpdate(final DocumentEvent e) {
onInsert();
}
@Override
public void insertUpdate(DocumentEvent e) {
validateUserInput();
}
public void changedUpdate(DocumentEvent e) {
fieldUpdated(e);
}
public void changedUpdate(DocumentEvent e) {
changeSupport.fireChange();
}
default void removeUpdate(final DocumentEvent e) {
update();
}
@Override
public void insertUpdate (DocumentEvent e) {
validateName();
}
@Override
public void removeUpdate(DocumentEvent e) {
changedUpdate(e);
}
@Override
public void removeUpdate(final DocumentEvent e) {
update();
}