use of javax.swing.event.DocumentEvent in project intellij-community by JetBrains.
the class ProjectConfigurable method init.
private void init(final ProjectSdksModel model) {
myPanel = new JPanel(new GridBagLayout());
myPanel.setPreferredSize(JBUI.size(700, 500));
if (ProjectKt.isDirectoryBased(myProject)) {
final JPanel namePanel = new JPanel(new BorderLayout());
final JLabel label = new JLabel("<html><body><b>Project name:</b></body></html>", SwingConstants.LEFT);
namePanel.add(label, BorderLayout.NORTH);
myProjectName = new JTextField();
myProjectName.setColumns(40);
final JPanel nameFieldPanel = new JPanel();
nameFieldPanel.setLayout(new BoxLayout(nameFieldPanel, BoxLayout.X_AXIS));
nameFieldPanel.add(Box.createHorizontalStrut(4));
nameFieldPanel.add(myProjectName);
namePanel.add(nameFieldPanel, BorderLayout.CENTER);
final JPanel wrapper = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
wrapper.add(namePanel);
wrapper.setAlignmentX(0);
myPanel.add(wrapper, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, JBUI.insets(4, 0, 10, 0), 0, 0));
}
myProjectJdkConfigurable = new ProjectJdkConfigurable(myProject, model);
myPanel.add(myProjectJdkConfigurable.createComponent(), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, JBUI.insetsTop(4), 0, 0));
myPanel.add(myWholePanel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, JBUI.insetsTop(4), 0, 0));
myPanel.setBorder(new EmptyBorder(0, 10, 0, 10));
myProjectCompilerOutput.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
if (myFreeze)
return;
myModulesConfigurator.processModuleCompilerOutputChanged(getCompilerOutputUrl());
}
});
myProjectJdkConfigurable.addChangeListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
myLanguageLevelCombo.sdkUpdated(myProjectJdkConfigurable.getSelectedProjectJdk(), myProject.isDefault());
LanguageLevelProjectExtensionImpl.getInstanceImpl(myProject).setCurrentLevel(myLanguageLevelCombo.getSelectedLevel());
}
});
myLanguageLevelCombo.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
LanguageLevelProjectExtensionImpl.getInstanceImpl(myProject).setCurrentLevel(myLanguageLevelCombo.getSelectedLevel());
}
});
}
use of javax.swing.event.DocumentEvent in project intellij-community by JetBrains.
the class BuildElementsEditor method createOutputPathPanel.
private CommitableFieldPanel createOutputPathPanel(final String title, final CommitPathRunnable commitPathRunnable) {
final JTextField textField = new JTextField();
final FileChooserDescriptor outputPathsChooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
outputPathsChooserDescriptor.putUserData(LangDataKeys.MODULE_CONTEXT, getModel().getModule());
outputPathsChooserDescriptor.setHideIgnored(false);
InsertPathAction.addTo(textField, outputPathsChooserDescriptor);
FileChooserFactory.getInstance().installFileCompletion(textField, outputPathsChooserDescriptor, true, null);
final Runnable commitRunnable = () -> {
if (!getModel().isWritable()) {
return;
}
final String path = textField.getText().trim();
if (path.length() == 0) {
commitPathRunnable.saveUrl(null);
} else {
// should set only absolute paths
String canonicalPath;
try {
canonicalPath = FileUtil.resolveShortWindowsName(path);
} catch (IOException e) {
canonicalPath = path;
}
commitPathRunnable.saveUrl(VfsUtilCore.pathToUrl(FileUtil.toSystemIndependentName(canonicalPath)));
}
};
final ActionListener listener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
commitRunnable.run();
}
};
myPerModuleCompilerOutput.addActionListener(listener);
textField.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
commitRunnable.run();
}
});
return new CommitableFieldPanel(textField, null, null, new BrowseFilesListener(textField, title, "", outputPathsChooserDescriptor) {
@Override
public void actionPerformed(ActionEvent e) {
super.actionPerformed(e);
commitRunnable.run();
}
}, null, commitRunnable);
}
use of javax.swing.event.DocumentEvent 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 javax.swing.event.DocumentEvent 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 javax.swing.event.DocumentEvent 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