use of javax.swing.event.DocumentEvent in project android by JetBrains.
the class SelectionEditors method createDocumentListener.
/**
* Create a document listener that will update the {@link MockupViewPanel} selection
* when the attached document is updated.
*
* @return the new document listener
*/
private DocumentListener createDocumentListener() {
return new DocumentListener() {
private void processChange(@NotNull DocumentEvent e) {
if (myBoundsUpdating) {
return;
}
try {
Document document = e.getDocument();
int value;
if (document.getLength() <= 0) {
value = 0;
} else {
value = Integer.parseInt(document.getText(0, document.getLength()));
}
SelectionLayer selectionLayer = myMockupViewPanel.getSelectionLayer();
Rectangle selection = selectionLayer.getSelection();
if (document == myBoundsDocuments[W]) {
selectionLayer.setSelection(selection.x, selection.y, value, selection.height);
} else if (document == myBoundsDocuments[H]) {
selectionLayer.setSelection(selection.x, selection.y, selection.width, value);
} else if (document == myBoundsDocuments[X]) {
selectionLayer.setSelection(value, selection.y, selection.width, selection.height);
} else if (document == myBoundsDocuments[Y]) {
selectionLayer.setSelection(selection.x, value, selection.width, selection.height);
}
} catch (BadLocationException | NumberFormatException ex) {
// Do nothing
}
}
@Override
public void insertUpdate(DocumentEvent e) {
processChange(e);
}
@Override
public void removeUpdate(DocumentEvent e) {
processChange(e);
}
@Override
public void changedUpdate(DocumentEvent e) {
}
};
}
use of javax.swing.event.DocumentEvent in project intellij-plugins by JetBrains.
the class DartConfigurable method initDartSdkAndDartiumControls.
private void initDartSdkAndDartiumControls() {
final Computable<ChromeSettings> currentDartiumSettingsRetriever = () -> myDartiumSettingsCurrent;
final Computable<Boolean> isResettingControlsComputable = () -> myInReset;
DartSdkUtil.initDartSdkAndDartiumControls(myProject, mySdkPathComboWithBrowse, myVersionLabel, myDartiumPathComboWithBrowse, currentDartiumSettingsRetriever, myDartiumSettingsButton, isResettingControlsComputable);
final JTextComponent sdkEditor = (JTextComponent) mySdkPathComboWithBrowse.getComboBox().getEditor().getEditorComponent();
sdkEditor.getDocument().addDocumentListener(new DocumentAdapter() {
protected void textChanged(final DocumentEvent e) {
final String sdkHomePath = getTextFromCombo(mySdkPathComboWithBrowse);
if (!sdkHomePath.isEmpty()) {
final String version = DartSdkUtil.getSdkVersion(sdkHomePath);
if (version != null && (version.contains("-dev.") || version.contains("-edge."))) {
mySdkUpdateChannelCombo.setSelectedItem(DartSdkUpdateOption.StableAndDev);
}
}
updateControlsEnabledState();
updateErrorLabel();
}
});
final JTextComponent dartiumEditor = (JTextComponent) myDartiumPathComboWithBrowse.getComboBox().getEditor().getEditorComponent();
dartiumEditor.getDocument().addDocumentListener(new DocumentAdapter() {
protected void textChanged(final DocumentEvent e) {
updateErrorLabel();
}
});
myCheckSdkUpdateCheckBox.addActionListener(e -> {
final boolean enabled = myCheckSdkUpdateCheckBox.isSelected() && myCheckSdkUpdateCheckBox.isEnabled();
mySdkUpdateChannelCombo.setEnabled(enabled);
myCheckSdkUpdateButton.setEnabled(enabled);
if (enabled) {
IdeFocusManager.getInstance(myProject).requestFocus(mySdkUpdateChannelCombo, true);
}
});
mySdkUpdateChannelCombo.setModel(new DefaultComboBoxModel(DartSdkUpdateOption.OPTIONS_TO_SHOW_IN_COMBO));
mySdkUpdateChannelCombo.setRenderer(new ListCellRendererWrapper<DartSdkUpdateOption>() {
@Override
public void customize(JList list, DartSdkUpdateOption value, int index, boolean selected, boolean hasFocus) {
setText(value.getPresentableName());
}
});
myCheckSdkUpdateButton.addActionListener(e -> {
final Runnable runnable = this::checkSdkUpdate;
ApplicationManagerEx.getApplicationEx().runProcessWithProgressSynchronously(runnable, DartBundle.message("checking.dart.sdk.update"), true, myProject, myMainPanel);
});
}
use of javax.swing.event.DocumentEvent in project intellij-plugins by JetBrains.
the class DartSdkUtil method initDartSdkAndDartiumControls.
public static void initDartSdkAndDartiumControls(@Nullable final Project project, @NotNull final ComboboxWithBrowseButton dartSdkPathComponent, @NotNull final JBLabel versionLabel, @NotNull final ComboboxWithBrowseButton dartiumPathComponent, @NotNull final Computable<ChromeSettings> currentDartiumSettingsRetriever, @NotNull final JButton dartiumSettingsButton, @NotNull final Computable<Boolean> isResettingControlsComputable) {
dartSdkPathComponent.getComboBox().setEditable(true);
addKnownPathsToCombo(dartSdkPathComponent.getComboBox(), DART_SDK_KNOWN_PATHS, DartSdkUtil::isDartSdkHome);
if (SystemInfo.isMac && getItemFromCombo(dartSdkPathComponent.getComboBox()).isEmpty()) {
// no need to check folder presence here; even if it doesn't exist - that's the best we can suggest
dartSdkPathComponent.getComboBox().getEditor().setItem("/usr/local/opt/dart/libexec");
}
dartiumPathComponent.getComboBox().setEditable(true);
addKnownPathsToCombo(dartiumPathComponent.getComboBox(), DARTIUM_KNOWN_PATHS, path -> !path.isEmpty() && new File(path).exists());
if (SystemInfo.isMac && getItemFromCombo(dartiumPathComponent.getComboBox()).isEmpty()) {
// Dartium path is optional, so set it only if valid
if (new File("/usr/local/opt/dart/Chromium.app").isDirectory()) {
dartiumPathComponent.getComboBox().getEditor().setItem("/usr/local/opt/dart/Chromium.app");
}
}
final String sdkHomePath = getItemFromCombo(dartSdkPathComponent.getComboBox());
versionLabel.setText(sdkHomePath.isEmpty() ? "" : getSdkVersion(sdkHomePath));
final TextComponentAccessor<JComboBox> textComponentAccessor = new TextComponentAccessor<JComboBox>() {
@Override
public String getText(final JComboBox component) {
return getItemFromCombo(component);
}
@Override
public void setText(@NotNull final JComboBox component, @NotNull final String text) {
if (!text.isEmpty() && !isDartSdkHome(text)) {
final String probablySdkPath = text + "/dart-sdk";
if (isDartSdkHome(probablySdkPath)) {
component.getEditor().setItem(FileUtilRt.toSystemDependentName(probablySdkPath));
return;
}
}
component.getEditor().setItem(FileUtilRt.toSystemDependentName(text));
}
};
final ComponentWithBrowseButton.BrowseFolderActionListener<JComboBox> browseFolderListener = new ComponentWithBrowseButton.BrowseFolderActionListener<>("Select Dart SDK path", null, dartSdkPathComponent, project, FileChooserDescriptorFactory.createSingleFolderDescriptor(), textComponentAccessor);
dartSdkPathComponent.addActionListener(browseFolderListener);
dartiumPathComponent.addBrowseFolderListener("Select Dartium browser path", null, project, FileChooserDescriptorFactory.createSingleFileOrExecutableAppDescriptor(), TextComponentAccessor.STRING_COMBOBOX_WHOLE_TEXT);
final JTextComponent editorComponent = (JTextComponent) dartSdkPathComponent.getComboBox().getEditor().getEditorComponent();
editorComponent.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(final DocumentEvent e) {
final String sdkHomePath = getItemFromCombo(dartSdkPathComponent.getComboBox());
versionLabel.setText(sdkHomePath.isEmpty() ? "" : getSdkVersion(sdkHomePath));
if (!isResettingControlsComputable.compute() && isDartSdkHome(sdkHomePath)) {
final String dartiumPath = DartiumUtil.getDartiumPathForSdk(sdkHomePath);
if (dartiumPath != null) {
dartiumPathComponent.getComboBox().getEditor().setItem(FileUtilRt.toSystemDependentName(dartiumPath));
}
}
}
});
dartiumSettingsButton.addActionListener(e -> ShowSettingsUtil.getInstance().editConfigurable(dartiumSettingsButton, currentDartiumSettingsRetriever.compute().createConfigurable()));
// we decided to save one line in settings and always use Dartium in checked mode
//checkedModeCheckBox.addActionListener(new ActionListener() {
// public void actionPerformed(final ActionEvent e) {
// DartiumUtil.setCheckedMode(currentDartiumSettingsRetriever.compute().getEnvironmentVariables(), checkedModeCheckBox.isSelected());
// }
//});
}
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, AbstractButton[] buttons) {
field.getDocument().addDocumentListener(new DocumentAdapter() {
@Override
public void textChanged(DocumentEvent event) {
checkTagNameField(dialog, field, label);
}
});
for (AbstractButton button : buttons) {
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
checkTagNameField(dialog, field, label);
}
});
}
checkTagNameField(dialog, field, label);
}
use of javax.swing.event.DocumentEvent in project intellij-community by JetBrains.
the class CopyFilesOrDirectoriesDialog method createNorthPanel.
@Override
protected JComponent createNorthPanel() {
myInformationLabel = JBLabelDecorator.createJBLabelDecorator().setBold(true);
final FormBuilder formBuilder = FormBuilder.createFormBuilder().addComponent(myInformationLabel).addVerticalGap(UIUtil.LARGE_VGAP - UIUtil.DEFAULT_VGAP);
DocumentListener documentListener = new DocumentAdapter() {
@Override
public void textChanged(DocumentEvent event) {
validateOKButton();
}
};
if (myShowNewNameField) {
myNewNameField = new JBTextField();
myNewNameField.getDocument().addDocumentListener(documentListener);
formBuilder.addLabeledComponent(RefactoringBundle.message("copy.files.new.name.label"), myNewNameField);
}
if (myShowDirectoryField) {
myTargetDirectoryField = new TextFieldWithHistoryWithBrowseButton();
myTargetDirectoryField.setTextFieldPreferredWidth(MAX_PATH_LENGTH);
final List<String> recentEntries = RecentsManager.getInstance(myProject).getRecentEntries(RECENT_KEYS);
if (recentEntries != null) {
getTargetDirectoryComponent().setHistory(recentEntries);
}
final FileChooserDescriptor descriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor();
myTargetDirectoryField.addBrowseFolderListener(RefactoringBundle.message("select.target.directory"), RefactoringBundle.message("the.file.will.be.copied.to.this.directory"), myProject, descriptor, TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT);
getTargetDirectoryComponent().addDocumentListener(new DocumentAdapter() {
@Override
protected void textChanged(DocumentEvent e) {
validateOKButton();
}
});
formBuilder.addLabeledComponent(RefactoringBundle.message("copy.files.to.directory.label"), myTargetDirectoryField);
String shortcutText = KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_CODE_COMPLETION));
formBuilder.addTooltip(RefactoringBundle.message("path.completion.shortcut", shortcutText));
}
final JPanel wrapper = new JPanel(new BorderLayout());
wrapper.add(myOpenFilesInEditor, BorderLayout.EAST);
formBuilder.addComponent(wrapper);
return formBuilder.getPanel();
}
Aggregations