use of com.intellij.ui.DocumentAdapter 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 com.intellij.ui.DocumentAdapter in project intellij-community by JetBrains.
the class IdeaJdkConfigurable method createComponent.
public JComponent createComponent() {
mySandboxHome.setHistorySize(5);
JPanel wholePanel = new JPanel(new GridBagLayout());
wholePanel.add(mySandboxHomeLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.emptyInsets(), 0, 0));
wholePanel.add(GuiUtils.constructFieldWithBrowseButton(mySandboxHome, new ActionListener() {
public void actionPerformed(ActionEvent e) {
FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
descriptor.setTitle(DevKitBundle.message("sandbox.home"));
descriptor.setDescription(DevKitBundle.message("sandbox.purpose"));
VirtualFile file = FileChooser.chooseFile(descriptor, mySandboxHome, null, null);
if (file != null) {
mySandboxHome.setText(FileUtil.toSystemDependentName(file.getPath()));
}
myModified = true;
}
}), new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, JBUI.insets(0, 30, 0, 0), 0, 0));
wholePanel.add(myInternalJreLabel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0, 1, GridBagConstraints.WEST, GridBagConstraints.NONE, JBUI.emptyInsets(), 0, 0));
wholePanel.add(myInternalJres, new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 1, 1, GridBagConstraints.EAST, GridBagConstraints.HORIZONTAL, JBUI.insets(0, 30, 0, 0), 0, 0));
myInternalJres.setRenderer(new ListCellRendererWrapper() {
@Override
public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
if (value instanceof Sdk) {
setText(((Sdk) value).getName());
}
}
});
myInternalJres.addItemListener(new ItemListener() {
public void itemStateChanged(final ItemEvent e) {
if (myFreeze)
return;
final Sdk javaJdk = (Sdk) e.getItem();
for (OrderRootType type : OrderRootType.getAllTypes()) {
if (!((SdkType) javaJdk.getSdkType()).isRootTypeApplicable(type)) {
continue;
}
final VirtualFile[] internalRoots = javaJdk.getSdkModificator().getRoots(type);
final VirtualFile[] configuredRoots = mySdkModificator.getRoots(type);
for (VirtualFile file : internalRoots) {
if (e.getStateChange() == ItemEvent.DESELECTED) {
mySdkModificator.removeRoot(file, type);
} else {
if (ArrayUtil.find(configuredRoots, file) == -1) {
mySdkModificator.addRoot(file, type);
}
}
}
}
}
});
mySandboxHome.addDocumentListener(new DocumentAdapter() {
protected void textChanged(DocumentEvent e) {
myModified = true;
}
});
mySandboxHome.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
myModified = true;
}
});
mySandboxHome.setText("");
myModified = true;
return wholePanel;
}
use of com.intellij.ui.DocumentAdapter in project intellij-community by JetBrains.
the class EditLogPatternDialog method createCenterPanel.
@Override
protected JComponent createCenterPanel() {
myFilePattern.addBrowseFolderListener(UIBundle.message("file.chooser.default.title"), null, null, FileChooserDescriptorFactory.createSingleFileOrFolderDescriptor(), TextComponentAccessor.TEXT_FIELD_WHOLE_TEXT);
myFilePattern.getTextField().getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
setOKActionEnabled(myFilePattern.getText() != null && myFilePattern.getText().length() > 0);
}
});
return myWholePanel;
}
use of com.intellij.ui.DocumentAdapter in project intellij-community by JetBrains.
the class GotoActionBase method showNavigationPopup.
protected <T> void showNavigationPopup(final GotoActionCallback<T> callback, @Nullable final String findUsagesTitle, final ChooseByNamePopup popup, final boolean allowMultipleSelection) {
final Class startedAction = myInAction;
LOG.assertTrue(startedAction != null);
popup.setCheckBoxShortcut(getShortcutSet());
popup.setFindUsagesTitle(findUsagesTitle);
final ChooseByNameFilter<T> filter = callback.createFilter(popup);
if (historyEnabled() && popup.getAdText() == null) {
popup.setAdText("Press " + KeymapUtil.getKeystrokeText(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.CTRL_MASK)) + " or " + KeymapUtil.getKeystrokeText(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.CTRL_MASK)) + " to navigate through the history");
}
popup.invoke(new ChooseByNamePopupComponent.Callback() {
@Override
public void onClose() {
//noinspection ConstantConditions
if (startedAction != null && startedAction.equals(myInAction)) {
String text = popup.getEnteredText();
ourLastStrings.put(myInAction, Pair.create(text, popup.getSelectedIndex()));
updateHistory(text);
myInAction = null;
}
if (filter != null) {
filter.close();
}
}
private void updateHistory(@Nullable String text) {
if (!StringUtil.isEmptyOrSpaces(text)) {
List<String> history = ourHistory.get(myInAction);
if (history == null)
history = ContainerUtil.newArrayList();
if (!text.equals(ContainerUtil.getFirstItem(history))) {
history.add(0, text);
}
ourHistory.put(myInAction, history);
}
}
@Override
public void elementChosen(Object element) {
callback.elementChosen(popup, element);
}
}, ModalityState.current(), allowMultipleSelection);
final JTextField editor = popup.getTextField();
final DocumentAdapter historyResetListener = new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
myHistoryIndex = 0;
}
};
abstract class HistoryAction extends DumbAwareAction {
@Override
public void update(@NotNull AnActionEvent e) {
e.getPresentation().setEnabled(historyEnabled());
}
void setText(@NotNull List<String> strings) {
javax.swing.text.Document document = editor.getDocument();
document.removeDocumentListener(historyResetListener);
editor.setText(strings.get(myHistoryIndex));
document.addDocumentListener(historyResetListener);
editor.selectAll();
}
}
editor.getDocument().addDocumentListener(historyResetListener);
new HistoryAction() {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
List<String> strings = ourHistory.get(myInAction);
setText(strings);
myHistoryIndex = myHistoryIndex >= strings.size() - 1 ? 0 : myHistoryIndex + 1;
}
}.registerCustomShortcutSet(CustomShortcutSet.fromString("ctrl UP"), editor);
new HistoryAction() {
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
List<String> strings = ourHistory.get(myInAction);
setText(strings);
myHistoryIndex = myHistoryIndex <= 0 ? strings.size() - 1 : myHistoryIndex - 1;
}
}.registerCustomShortcutSet(CustomShortcutSet.fromString("ctrl DOWN"), editor);
}
use of com.intellij.ui.DocumentAdapter in project intellij-community by JetBrains.
the class ToolEditorDialog method addListeners.
private void addListeners() {
myOutputFiltersButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
OutputFiltersDialog dialog = new OutputFiltersDialog(myOutputFiltersButton, getData().getOutputFilters());
if (dialog.showAndGet()) {
myOutputFilters = dialog.getData();
}
}
});
myInsertCommandMacroButton.addActionListener(new InsertMacroActionListener(myTfCommand));
myInsertParametersMacroButton.addActionListener(new InsertMacroActionListener(myParametersField));
myInsertWorkingDirectoryMacroButton.addActionListener(new InsertMacroActionListener(myTfCommandWorkingDirectory));
myNameField.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
public void textChanged(DocumentEvent event) {
handleOKButton();
}
});
myUseConsoleCheckbox.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
myShowConsoleOnStdOutCheckbox.setVisible(myUseConsoleCheckbox.isSelected());
myShowConsoleOnStdErrCheckbox.setVisible(myUseConsoleCheckbox.isSelected());
}
});
}
Aggregations