use of com.intellij.ui.DocumentAdapter in project intellij-community by JetBrains.
the class AddNamespaceDialog method addUpdateListener.
private void addUpdateListener(ComboBox comboBox) {
final ComboBoxEditor boxEditor = comboBox.getEditor();
if (boxEditor != null) {
final Component component = boxEditor.getEditorComponent();
if (component instanceof JTextField) {
((JTextField) component).getDocument().addDocumentListener(new DocumentAdapter() {
protected void textChanged(DocumentEvent e) {
updateOkAction();
}
});
}
}
comboBox.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
updateOkAction();
}
});
}
use of com.intellij.ui.DocumentAdapter in project intellij-community by JetBrains.
the class SetBackgroundImageDialog method setupComponents.
private void setupComponents() {
myAdjusting = true;
myPreviewPanel.setLayout(new CardLayout());
myPreviewPanel.add(myEditorPreview.getPanel(), "editor");
myPreviewPanel.add(myIdePreview, "ide");
((CardLayout) myPreviewPanel.getLayout()).show(myPreviewPanel, "editor");
myPathField.getComboBox().setEditable(true);
FileChooserDescriptor descriptor = new FileChooserDescriptor(true, false, false, false, true, false).withFileFilter(file -> ImageFileTypeManager.getInstance().isImage(file));
myPathField.addBrowseFolderListener(null, null, null, descriptor, TextComponentAccessor.STRING_COMBOBOX_WHOLE_TEXT);
JTextComponent textComponent = getComboEditor();
textComponent.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
if (myAdjusting)
return;
imagePathChanged();
}
});
for (Enumeration<AbstractButton> e = getTargetRbGroup().getElements(); e.hasMoreElements(); ) {
AbstractButton button = e.nextElement();
button.setActionCommand(button.getText());
button.addItemListener(this::targetChanged);
}
for (Enumeration<AbstractButton> e = getFillRbGroup().getElements(); e.hasMoreElements(); ) {
AbstractButton button = e.nextElement();
button.setActionCommand(button.getText());
button.addItemListener(this::fillOrPlaceChanged);
}
for (Enumeration<AbstractButton> e = getPlaceRbGroup().getElements(); e.hasMoreElements(); ) {
AbstractButton button = e.nextElement();
button.setActionCommand(button.getText());
button.addItemListener(this::fillOrPlaceChanged);
}
ChangeListener opacitySync = new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (myAdjusting)
return;
myAdjusting = true;
boolean b = e.getSource() == myOpacitySpinner;
if (b) {
int value = (Integer) myOpacitySpinner.getValue();
myOpacitySpinner.setValue(Math.min(Math.max(0, value), 100));
myOpacitySlider.setValue(value);
} else {
myOpacitySpinner.setValue(myOpacitySlider.getValue());
}
myAdjusting = false;
opacityChanged();
}
};
myOpacitySpinner.addChangeListener(opacitySync);
myOpacitySlider.addChangeListener(opacitySync);
myOpacitySlider.setValue(15);
myOpacitySpinner.setValue(15);
myScaleRb.setSelected(true);
myCenterRb.setSelected(true);
myEditorRb.setSelected(true);
boolean perProject = !Comparing.equal(getBackgroundSpec(myProject, getSystemProp(true)), getBackgroundSpec(null, getSystemProp(true)));
myThisProjectOnlyCb.setSelected(perProject);
myAdjusting = false;
}
use of com.intellij.ui.DocumentAdapter in project intellij-community by JetBrains.
the class GenerateVisitorByHierarchyAction method actionPerformed.
public void actionPerformed(AnActionEvent e) {
final Ref<String> visitorNameRef = Ref.create("MyVisitor");
final Ref<PsiClass> parentClassRef = Ref.create(null);
final Project project = e.getData(CommonDataKeys.PROJECT);
assert project != null;
final PsiNameHelper helper = PsiNameHelper.getInstance(project);
final PackageChooserDialog dialog = new PackageChooserDialog("Choose Target Package and Hierarchy Root Class", project) {
@Override
protected ValidationInfo doValidate() {
PsiDocumentManager.getInstance(project).commitAllDocuments();
if (!helper.isQualifiedName(visitorNameRef.get())) {
return new ValidationInfo("Visitor class name is not valid");
} else if (parentClassRef.isNull()) {
return new ValidationInfo("Hierarchy root class should be specified");
} else if (parentClassRef.get().isAnnotationType() || parentClassRef.get().isEnum()) {
return new ValidationInfo("Hierarchy root class should be an interface or a class");
}
return super.doValidate();
}
protected JComponent createCenterPanel() {
final JPanel panel = new JPanel(new BorderLayout());
panel.add(super.createCenterPanel(), BorderLayout.CENTER);
panel.add(createNamePanel(), BorderLayout.NORTH);
panel.add(createBaseClassPanel(), BorderLayout.SOUTH);
return panel;
}
private JComponent createNamePanel() {
LabeledComponent<JTextField> labeledComponent = new LabeledComponent<>();
labeledComponent.setText("Visitor class");
final JTextField nameField = new JTextField(visitorNameRef.get());
labeledComponent.setComponent(nameField);
nameField.getDocument().addDocumentListener(new DocumentAdapter() {
protected void textChanged(final DocumentEvent e) {
visitorNameRef.set(nameField.getText());
}
});
return labeledComponent;
}
private JComponent createBaseClassPanel() {
LabeledComponent<EditorTextField> labeledComponent = new LabeledComponent<>();
labeledComponent.setText("Hierarchy root class");
final JavaCodeFragmentFactory factory = JavaCodeFragmentFactory.getInstance(project);
final PsiTypeCodeFragment codeFragment = factory.createTypeCodeFragment("", null, true, JavaCodeFragmentFactory.ALLOW_VOID);
final Document document = PsiDocumentManager.getInstance(project).getDocument(codeFragment);
final EditorTextField editorTextField = new EditorTextField(document, project, StdFileTypes.JAVA);
labeledComponent.setComponent(editorTextField);
editorTextField.addDocumentListener(new com.intellij.openapi.editor.event.DocumentAdapter() {
public void documentChanged(final com.intellij.openapi.editor.event.DocumentEvent e) {
parentClassRef.set(null);
try {
final PsiType psiType = codeFragment.getType();
final PsiClass psiClass = psiType instanceof PsiClassType ? ((PsiClassType) psiType).resolve() : null;
parentClassRef.set(psiClass);
} catch (PsiTypeCodeFragment.IncorrectTypeException e1) {
// ok
}
}
});
return labeledComponent;
}
};
final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(e.getDataContext());
if (element instanceof PsiPackage) {
dialog.selectPackage(((PsiPackage) element).getQualifiedName());
} else if (element instanceof PsiDirectory) {
final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage((PsiDirectory) element);
if (aPackage != null) {
dialog.selectPackage(aPackage.getQualifiedName());
}
}
dialog.show();
if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE || dialog.getSelectedPackage() == null || dialog.getSelectedPackage().getQualifiedName().length() == 0 || parentClassRef.isNull()) {
return;
}
final String visitorQName = generateEverything(dialog.getSelectedPackage(), parentClassRef.get(), visitorNameRef.get());
final IdeView ideView = LangDataKeys.IDE_VIEW.getData(e.getDataContext());
final PsiClass visitorClass = JavaPsiFacade.getInstance(project).findClass(visitorQName, GlobalSearchScope.projectScope(project));
if (ideView != null && visitorClass != null) {
ideView.selectElement(visitorClass);
}
}
use of com.intellij.ui.DocumentAdapter in project intellij-community by JetBrains.
the class MakeParameterizedStaticDialog method createCenterPanel.
protected JComponent createCenterPanel() {
GridBagConstraints gbConstraints = new GridBagConstraints();
JPanel panel = new JPanel(new GridBagLayout());
gbConstraints.insets = JBUI.insets(4, 8);
gbConstraints.weighty = 0;
gbConstraints.weightx = 0;
gbConstraints.gridx = 0;
gbConstraints.gridy = GridBagConstraints.RELATIVE;
gbConstraints.gridwidth = GridBagConstraints.REMAINDER;
gbConstraints.fill = GridBagConstraints.NONE;
gbConstraints.anchor = GridBagConstraints.WEST;
panel.add(createDescriptionLabel(), gbConstraints);
gbConstraints.weighty = 0;
gbConstraints.weightx = 0;
gbConstraints.gridwidth = GridBagConstraints.REMAINDER;
gbConstraints.fill = GridBagConstraints.NONE;
gbConstraints.anchor = GridBagConstraints.WEST;
String text = myMember instanceof PsiMethod ? RefactoringBundle.message("add.object.as.a.parameter.with.name") : RefactoringBundle.message("add.object.as.a.parameter.to.constructors.with.name");
myMakeClassParameter.setText(text);
panel.add(myMakeClassParameter, gbConstraints);
myMakeClassParameter.setSelected(myAnyNonFieldMembersUsed);
gbConstraints.insets = JBUI.insets(0, 8, 4, 8);
gbConstraints.weighty = 0;
gbConstraints.weightx = 1;
gbConstraints.gridwidth = 2;
gbConstraints.fill = GridBagConstraints.HORIZONTAL;
gbConstraints.anchor = GridBagConstraints.NORTHWEST;
if (myNameSuggestions.length > 1) {
myClassParameterNameInputField = createComboBoxForName();
} else {
JTextField textField = new JTextField();
textField.setText(myNameSuggestions[0]);
textField.getDocument().addDocumentListener(new DocumentAdapter() {
public void textChanged(DocumentEvent event) {
updateControls();
}
});
myClassParameterNameInputField = textField;
}
panel.add(myClassParameterNameInputField, gbConstraints);
gbConstraints.gridwidth = GridBagConstraints.REMAINDER;
if (myVariableData.length > 0) {
gbConstraints.insets = JBUI.insets(4, 8);
gbConstraints.weighty = 0;
gbConstraints.weightx = 0;
gbConstraints.gridheight = 1;
gbConstraints.fill = GridBagConstraints.NONE;
gbConstraints.anchor = GridBagConstraints.WEST;
text = myMember instanceof PsiMethod ? RefactoringBundle.message("add.parameters.for.fields") : RefactoringBundle.message("add.parameters.for.fields.to.constructors");
myMakeFieldParameters.setText(text);
panel.add(myMakeFieldParameters, gbConstraints);
myMakeFieldParameters.setSelected(!myAnyNonFieldMembersUsed);
myParameterPanel = new ParameterTablePanel(myProject, myVariableData, myMember) {
protected void updateSignature() {
}
protected void doEnterAction() {
clickDefaultButton();
}
protected void doCancelAction() {
}
};
gbConstraints.insets = JBUI.insets(0, 8, 4, 8);
gbConstraints.gridwidth = 2;
gbConstraints.fill = GridBagConstraints.BOTH;
gbConstraints.weighty = 1;
panel.add(myParameterPanel, gbConstraints);
}
ActionListener inputFieldValidator = new ActionListener() {
public void actionPerformed(ActionEvent e) {
updateControls();
}
};
myMakeClassParameter.addActionListener(inputFieldValidator);
myMakeFieldParameters.addActionListener(inputFieldValidator);
if (myMember instanceof PsiMethod) {
myGenerateDelegateCb = new JCheckBox(RefactoringBundle.message("delegation.panel.delegate.via.overloading.method"));
panel.add(myGenerateDelegateCb, gbConstraints);
}
updateControls();
return panel;
}
use of com.intellij.ui.DocumentAdapter in project intellij-community by JetBrains.
the class CvsFieldValidator method installOn.
public static void installOn(final TagNameFieldOwner dialog, final JTextField field, final JLabel label) {
installOn(dialog, field, label, new AbstractButton[0]);
field.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
public void textChanged(DocumentEvent event) {
checkTagNameField(dialog, field, label);
}
});
checkTagNameField(dialog, field, label);
}
Aggregations