use of javax.swing.event.DocumentEvent in project intellij-community by JetBrains.
the class ChangesTrackingTableView method addChangeListener.
private static void addChangeListener(final Component component, final ChangeListener listener, Disposable parentDisposable) {
if (component instanceof CellEditorComponentWithBrowseButton) {
addChangeListener(((CellEditorComponentWithBrowseButton) component).getChildComponent(), listener, parentDisposable);
} else if (component instanceof JTextField) {
final DocumentAdapter documentListener = new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
listener.stateChanged(new ChangeEvent(component));
}
};
final Document document = ((JTextField) component).getDocument();
document.addDocumentListener(documentListener);
Disposer.register(parentDisposable, new Disposable() {
@Override
public void dispose() {
document.removeDocumentListener(documentListener);
}
});
} else if (component instanceof JComboBox) {
final ActionListener comboListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
listener.stateChanged(new ChangeEvent(component));
}
};
((JComboBox) component).addActionListener(comboListener);
Disposer.register(parentDisposable, new Disposable() {
@Override
public void dispose() {
((JComboBox) component).removeActionListener(comboListener);
}
});
} else if (component instanceof JCheckBox) {
final ActionListener checkBoxListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
listener.stateChanged(new ChangeEvent(component));
}
};
((JCheckBox) component).addActionListener(checkBoxListener);
Disposer.register(parentDisposable, new Disposable() {
@Override
public void dispose() {
((JCheckBox) component).removeActionListener(checkBoxListener);
}
});
} else {
throw new UnsupportedOperationException("editor control of type " + component.getClass().getName() + " is not supported");
}
}
use of javax.swing.event.DocumentEvent in project intellij-community by JetBrains.
the class ReplaceConstructorWithBuilderDialog method createCenterPanel.
protected JComponent createCenterPanel() {
final Splitter splitter = new Splitter(true);
splitter.setFirstComponent(createTablePanel());
splitter.setSecondComponent(myWholePanel);
final ActionListener enableDisableListener = new ActionListener() {
public void actionPerformed(final ActionEvent e) {
setEnabled(myCreateBuilderClassRadioButton.isSelected());
IdeFocusManager.getInstance(myProject).requestFocus(myCreateBuilderClassRadioButton.isSelected() ? myNewClassName : myExistentClassTF.getChildComponent(), true);
validateButtons();
}
};
myCreateBuilderClassRadioButton.addActionListener(enableDisableListener);
myExistingBuilderClassRadioButton.addActionListener(enableDisableListener);
myCreateBuilderClassRadioButton.setSelected(true);
setEnabled(true);
final DocumentAdapter validateButtonsListener = new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
validateButtons();
}
};
myNewClassName.getDocument().addDocumentListener(validateButtonsListener);
final PsiClass psiClass = myConstructors[0].getContainingClass();
LOG.assertTrue(psiClass != null);
myNewClassName.setText(psiClass.getName() + "Builder");
return splitter;
}
use of javax.swing.event.DocumentEvent in project intellij-community by JetBrains.
the class SearchReplaceComponent method updateReplaceComponent.
private void updateReplaceComponent(@NotNull String textToSet) {
if (!updateTextComponent(false)) {
String existingText = myReplaceTextComponent.getText();
if (!existingText.equals(textToSet)) {
myReplaceTextComponent.setText(textToSet);
if (existingText.length() == 0)
myReplaceTextComponent.selectAll();
}
return;
}
myReplaceTextComponent.setText(textToSet);
myReplaceTextComponent.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
ApplicationManager.getApplication().invokeLater(() -> replaceFieldDocumentChanged());
}
});
if (!isMultiline()) {
installReplaceOnEnterAction(myReplaceTextComponent);
}
new VariantsCompletionAction(myReplaceTextComponent);
myReplaceFieldWrapper.revalidate();
myReplaceFieldWrapper.repaint();
}
use of javax.swing.event.DocumentEvent in project intellij-community by JetBrains.
the class SearchReplaceComponent method updateSearchComponent.
private void updateSearchComponent(@NotNull String textToSet) {
if (!updateTextComponent(true)) {
String existingText = mySearchTextComponent.getText();
if (!existingText.equals(textToSet)) {
mySearchTextComponent.setText(textToSet);
// textToSet should be selected even if we have no selection before (if we have the selection then setText will remain it)
if (existingText.length() == 0)
mySearchTextComponent.selectAll();
}
return;
}
mySearchTextComponent.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
ApplicationManager.getApplication().invokeLater(() -> searchFieldDocumentChanged());
}
});
mySearchTextComponent.registerKeyboardAction(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
if (StringUtil.isEmpty(mySearchTextComponent.getText())) {
close();
} else {
IdeFocusManager.getInstance(myProject).requestFocus(myTargetComponent, true);
addTextToRecent(mySearchTextComponent);
}
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, SystemInfo.isMac ? META_DOWN_MASK : CTRL_DOWN_MASK), JComponent.WHEN_FOCUSED);
// It registers a shortcut set automatically on construction
new VariantsCompletionAction(mySearchTextComponent);
}
use of javax.swing.event.DocumentEvent in project intellij-community by JetBrains.
the class GenerateJavadocAction method getAdditionalActionSettings.
@Override
protected JComponent getAdditionalActionSettings(Project project, final BaseAnalysisActionDialog dialog) {
myConfigurable = new JavadocConfigurable(JavadocGenerationManager.getInstance(project).getConfiguration(), project);
final JComponent component = myConfigurable.createComponent();
myConfigurable.reset();
myConfigurable.getOutputDirField().getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
updateAvailability(dialog);
}
});
updateAvailability(dialog);
return component;
}
Aggregations