Java Code Examples for com.intellij.ui.DocumentAdapter

The following examples show how to use com.intellij.ui.DocumentAdapter. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public ExtractWidgetDialog(@NotNull Project project,
                           @Nullable Editor editor,
                           @NotNull ExtractWidgetRefactoring refactoring) {
  super(project, editor, refactoring);
  myRefactoring = refactoring;
  setTitle("Extract Widget");
  init();

  myNameField.setText("NewWidget");
  myNameField.selectAll();
  myNameField.getDocument().addDocumentListener(new DocumentAdapter() {
    @Override
    protected void textChanged(DocumentEvent e) {
      updateRefactoringOptions();
    }
  });

  updateRefactoringOptions();
}
 
Example 2
public ExtractWidgetDialog(@NotNull Project project,
                           @Nullable Editor editor,
                           @NotNull ExtractWidgetRefactoring refactoring) {
  super(project, editor, refactoring);
  myRefactoring = refactoring;
  setTitle("Extract Widget");
  init();

  myNameField.setText("NewWidget");
  myNameField.selectAll();
  myNameField.getDocument().addDocumentListener(new DocumentAdapter() {
    @Override
    protected void textChanged(DocumentEvent e) {
      updateRefactoringOptions();
    }
  });

  updateRefactoringOptions();
}
 
Example 3
Source Project: react-templates-plugin   Source File: CreateRTAction.java    License: MIT License 6 votes vote down vote up
public MyDialog(final Project project, final MyInputValidator validator) {
            super(project, true);
            myProject = project;
            myValidator = validator;
            myBaseLayoutManagerCombo.registerUpDownHint(myFormNameTextField);
            myUpDownHintForm.setIcon(PlatformIcons.UP_DOWN_ARROWS);
            myBaseLayoutManagerCombo.addItem("None", RTIcons.RT, "none");
            myBaseLayoutManagerCombo.addItem("AMD", RTIcons.RT, "amd");
            myBaseLayoutManagerCombo.addItem("CommonJS", RTIcons.RT, "commonjs");
            myBaseLayoutManagerCombo.addItem("ES6", RTIcons.RT, "es6");
            myBaseLayoutManagerCombo.addItem("Typescript", RTIcons.RT, "typescript");
            init();
            setTitle(RTBundle.message("title.new.gui.form"));
            setOKActionEnabled(false);

            myFormNameTextField.getDocument().addDocumentListener(new DocumentAdapter() {
                protected void textChanged(DocumentEvent e) {
                    setOKActionEnabled(!myFormNameTextField.getText().isEmpty());
                }
            });

            myBaseLayoutManagerCombo.setSelectedName(Settings.getInstance(project).modules);
            myBaseLayoutManagerCombo.setEnabled(false);
//            myBaseLayoutManagerCombo.setSelectedName(GuiDesignerConfiguration.getInstance(project).DEFAULT_LAYOUT_MANAGER);
        }
 
Example 4
public VueSettingsPage(@NotNull final Project project) {
    this.project = project;
    configRTBinField();
    configNodeField();


    this.packagesNotificationPanel = new PackagesNotificationPanel(project);
    errorPanel.add(this.packagesNotificationPanel.getComponent(), BorderLayout.CENTER);

    DocumentAdapter docAdp = new DocumentAdapter() {
        protected void textChanged(DocumentEvent e) {
            updateLaterInEDT();
        }
    };
    rtBinField.getChildComponent().getTextEditor().getDocument().addDocumentListener(docAdp);
    nodeInterpreterField.getChildComponent().getTextEditor().getDocument().addDocumentListener(docAdp);
}
 
Example 5
Source Project: react-templates-plugin   Source File: CreateRTAction.java    License: MIT License 6 votes vote down vote up
public MyDialog(final Project project, final MyInputValidator validator) {
            super(project, true);
            myProject = project;
            myValidator = validator;
            myBaseLayoutManagerCombo.registerUpDownHint(myFormNameTextField);
            myUpDownHintForm.setIcon(PlatformIcons.UP_DOWN_ARROWS);
            myBaseLayoutManagerCombo.addItem("None", RTIcons.RT, "none");
            myBaseLayoutManagerCombo.addItem("AMD", RTIcons.RT, "amd");
            myBaseLayoutManagerCombo.addItem("CommonJS", RTIcons.RT, "commonjs");
            myBaseLayoutManagerCombo.addItem("ES6", RTIcons.RT, "es6");
            myBaseLayoutManagerCombo.addItem("Typescript", RTIcons.RT, "typescript");
            init();
            setTitle(RTBundle.message("title.new.gui.form"));
            setOKActionEnabled(false);

            myFormNameTextField.getDocument().addDocumentListener(new DocumentAdapter() {
                protected void textChanged(DocumentEvent e) {
                    setOKActionEnabled(!myFormNameTextField.getText().isEmpty());
                }
            });

            myBaseLayoutManagerCombo.setSelectedName(Settings.getInstance(project).modules);
            myBaseLayoutManagerCombo.setEnabled(false);
//            myBaseLayoutManagerCombo.setSelectedName(GuiDesignerConfiguration.getInstance(project).DEFAULT_LAYOUT_MANAGER);
        }
 
Example 6
Source Project: intellij-xquery   Source File: ConnectionParametersPanel.java    License: Apache License 2.0 6 votes vote down vote up
private void setUpChangeListeners(final DataSourceConfigurationAggregatingPanel
                                          aggregatingPanel,
                                  final ConfigurationChangeListener listener) {
    DocumentListener textFieldListener = new DocumentAdapter() {
        @Override
        protected void textChanged(DocumentEvent e) {
            listener.changeApplied(aggregatingPanel
                    .getCurrentConfigurationState());
        }
    };
    host.getComponent().getDocument().addDocumentListener(textFieldListener);
    port.getComponent().getDocument().addDocumentListener(textFieldListener);
    username.getComponent().getDocument().addDocumentListener(textFieldListener);
    password.getComponent().getDocument().addDocumentListener(textFieldListener);
    databaseName.getComponent().getDocument().addDocumentListener(textFieldListener);
}
 
Example 7
Source Project: consulo   Source File: SingleIntegerFieldOptionsPanel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Sets integer number format to JFormattedTextField instance,
 * sets value of JFormattedTextField instance to object's field value,
 * synchronizes object's field value with the value of JFormattedTextField instance.
 *
 * @param textField  JFormattedTextField instance
 * @param owner      an object whose field is synchronized with {@code textField}
 * @param property   object's field name for synchronization
 */
public static void setupIntegerFieldTrackingValue(final JFormattedTextField textField,
                                                  final InspectionProfileEntry owner,
                                                  final String property) {
    NumberFormat formatter = NumberFormat.getIntegerInstance();
    formatter.setParseIntegerOnly(true);
    textField.setFormatterFactory(new DefaultFormatterFactory(new NumberFormatter(formatter)));
    textField.setValue(getPropertyValue(owner, property));
    final Document document = textField.getDocument();
    document.addDocumentListener(new DocumentAdapter() {
        @Override
        public void textChanged(DocumentEvent e) {
            try {
                textField.commitEdit();
                setPropertyValue(owner, property,
                        ((Number) textField.getValue()).intValue());
            } catch (ParseException e1) {
                // No luck this time
            }
        }
    });
}
 
Example 8
Source Project: consulo   Source File: NamedConfigurable.java    License: Apache License 2.0 6 votes vote down vote up
protected NamedConfigurable(boolean isNameEditable, @Nullable final Runnable updateTree) {
  myNameEditable = isNameEditable;
  myNamePanel.setVisible(myNameEditable);
  if (myNameEditable) {
    myNameField.getDocument().addDocumentListener(new DocumentAdapter() {
      @Override
      protected void textChanged(DocumentEvent e) {
        setDisplayName(myNameField.getText());
        if (updateTree != null){
          updateTree.run();
        }
      }
    });
  }
  myNamePanel.setBorder(JBUI.Borders.empty(10, 10, 6, 10));
}
 
Example 9
Source Project: consulo   Source File: MasterKeyUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Match passwords
 *
 * @param passwordField1 the first password field
 * @param passwordField2 the second password field
 * @param setError       the callback used to set or to clear an error
 */
static void matchPasswords(final JPasswordField passwordField1, final JPasswordField passwordField2, final Processor<String> setError) {
  DocumentAdapter l = new DocumentAdapter() {
    @Override
    protected void textChanged(DocumentEvent e) {
      if (Arrays.equals(passwordField1.getPassword(), passwordField2.getPassword())) {
        setError.process(null);
      }
      else {
        setError.process("The new password and confirm passwords do not match.");
      }
    }
  };
  passwordField1.getDocument().addDocumentListener(l);
  passwordField2.getDocument().addDocumentListener(l);
}
 
Example 10
Source Project: consulo   Source File: CloneDvcsDialog.java    License: Apache License 2.0 6 votes vote down vote up
private void createUIComponents() {
  myRepositoryURL = new EditorComboBox("");
  final DvcsRememberedInputs rememberedInputs = getRememberedInputs();
  List<String> urls = new ArrayList<>(rememberedInputs.getVisitedUrls());
  if (myDefaultRepoUrl != null) {
    urls.add(0, myDefaultRepoUrl);
  }
  myRepositoryURL.setHistory(ArrayUtil.toObjectArray(urls, String.class));
  myRepositoryURL.addDocumentListener(new com.intellij.openapi.editor.event.DocumentAdapter() {
    @Override
    public void documentChanged(com.intellij.openapi.editor.event.DocumentEvent e) {
      // enable test button only if something is entered in repository URL
      final String url = getCurrentUrlText();
      myTestButton.setEnabled(url.length() != 0);
      if (myDefaultDirectoryName.equals(myDirectoryName.getText()) || myDirectoryName.getText().length() == 0) {
        // modify field if it was unmodified or blank
        myDefaultDirectoryName = defaultDirectoryName(url, myVcsDirectoryName);
        myDirectoryName.setText(myDefaultDirectoryName);
      }
      updateButtons();
    }
  });
}
 
Example 11
Source Project: consulo   Source File: ExtractArtifactDialog.java    License: Apache License 2.0 6 votes vote down vote up
public ExtractArtifactDialog(ArtifactEditorContext context, LayoutTreeComponent treeComponent, String initialName) {
  super(treeComponent.getLayoutTree(), true);
  myContext = context;
  setTitle(ProjectBundle.message("dialog.title.extract.artifact"));
  for (ArtifactType type : ArtifactType.EP_NAME.getExtensions()) {
    myTypeBox.addItem(type);
  }
  myTypeBox.setSelectedItem(PlainArtifactType.getInstance());
  myTypeBox.setRenderer(new ArtifactTypeCellRenderer());
  myNameField.getDocument().addDocumentListener(new DocumentAdapter() {
    @Override
    protected void textChanged(DocumentEvent e) {
      setOKActionEnabled(!StringUtil.isEmptyOrSpaces(getArtifactName()));
    }
  });
  myNameField.setText(initialName);
  init();
}
 
Example 12
Source Project: consulo   Source File: AbstractExtractMethodDialog.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void init() {
  super.init();
  // Set default name and select it
  myMethodNameTextField.setText(myDefaultName);
  myMethodNameTextField.setSelectionStart(0);
  myMethodNameTextField.setSelectionStart(myDefaultName.length());
  myMethodNameTextField.getDocument().addDocumentListener(new DocumentAdapter() {
    @Override
    protected void textChanged(DocumentEvent e) {
      updateOutputVariables();
      updateSignature();
      updateOkStatus();
    }
  });


  myVariableData = createVariableDataByNames(myArguments);
  myVariablesMap = createVariableMap(myVariableData);
  myParametersPanel.init(myVariableData);

  updateOutputVariables();
  updateSignature();
  updateOkStatus();
}
 
Example 13
Source Project: consulo   Source File: FileSaverDialogImpl.java    License: Apache License 2.0 6 votes vote down vote up
protected JComponent createFileNamePanel() {
  final JPanel panel = new JPanel(new BorderLayout());
  panel.add(new JLabel(UIBundle.message("file.chooser.save.dialog.file.name")), BorderLayout.WEST);
  myFileName.setText("");
  myFileName.getDocument().addDocumentListener(new DocumentAdapter() {
    protected void textChanged(DocumentEvent e) {
      updateOkButton();
    }
  });

  panel.add(myFileName, BorderLayout.CENTER);
  if (myExtensions.getModel().getSize() > 0) {
    myExtensions.setSelectedIndex(0);
    panel.add(myExtensions, BorderLayout.EAST);
  }
  return panel;
}
 
Example 14
public LogFilterTextField() {
  super(true);
  addDocumentListener(new DocumentAdapter() {
    @Override
    protected void textChanged(@NotNull DocumentEvent e) {
      doFilterIfNeeded();
    }
  });
}
 
Example 15
@Override
public void addSettingsStateListener(@NotNull WebProjectGenerator.SettingsStateListener stateListener) {
  final JTextComponent editorComponent = (JTextComponent)sdkPathComboWithBrowse.getComboBox().getEditor().getEditorComponent();
  editorComponent.getDocument().addDocumentListener(new DocumentAdapter() {
    protected void textChanged(DocumentEvent e) {
      stateListener.stateChanged(validate() == null);
    }
  });

  if (validate() != null) {
    stateListener.stateChanged(false);
  }
}
 
Example 16
public LogFilterTextField() {
  super(true);
  addDocumentListener(new DocumentAdapter() {
    @Override
    protected void textChanged(@NotNull DocumentEvent e) {
      doFilterIfNeeded();
    }
  });
}
 
Example 17
@Override
public void addSettingsStateListener(@NotNull WebProjectGenerator.SettingsStateListener stateListener) {
  final JTextComponent editorComponent = (JTextComponent)sdkPathComboWithBrowse.getComboBox().getEditor().getEditorComponent();
  editorComponent.getDocument().addDocumentListener(new DocumentAdapter() {
    protected void textChanged(DocumentEvent e) {
      stateListener.stateChanged(validate() == null);
    }
  });

  if (validate() != null) {
    stateListener.stateChanged(false);
  }
}
 
Example 18
Source Project: azure-devops-intellij   Source File: ApplyLabelForm.java    License: MIT License 5 votes vote down vote up
public ApplyLabelForm(final Project project, final List<ItemInfo> itemInfos) {
    this.project = project;
    this.itemInfos = itemInfos;
    //myLabelModel = new LabelModel();

    nameText.getDocument().addDocumentListener(new DocumentAdapter() {
        protected void textChanged(final DocumentEvent e) {
            eventDispatcher.getMulticaster().dataChanged(getLabelName(), itemsTableModel.getRowCount());
        }
    });

    // Hide the buttons for now
    addButton.setVisible(false);
    //addButton.addActionListener(new ActionListener() {
    //  public void actionPerformed(final ActionEvent e) {
    //    addItems();
    //  }
    //});

    removeButton.setVisible(false);
    //removeButton.addActionListener(new ActionListener() {
    //  public void actionPerformed(final ActionEvent e) {
    //    removeItems();
    //  }
    //});

    initTable();
    updateButtons();
}
 
Example 19
private JTextArea generateSavingTextArea() {
	JTextArea result = new JTextArea();
	result.setFont(Font.decode(Font.MONOSPACED));
	result.getDocument().addDocumentListener(
			new DocumentAdapter() {
				@Override
				protected void textChanged(DocumentEvent e) {
					saveCurrentTest();
				}
			}
	);
	return result;
}
 
Example 20
/**
 * This method is called to get the panel describing the inspection.
 * It is called every time the user selects the inspection in preferences.
 * The user has the option to edit the list of CHECKED_CLASSES.
 * Adds a document listener to see if
 *
 * @return panel to display inspection information.
 */
@Override
public JComponent createOptionsPanel() {
  JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
  final JTextField checkedClasses = new JTextField(CHECKED_CLASSES);
  checkedClasses.getDocument().addDocumentListener(new DocumentAdapter() {
    public void textChanged(@NotNull DocumentEvent event) {
      CHECKED_CLASSES = checkedClasses.getText();
    }
  });
  panel.add(checkedClasses);
  return panel;
}
 
Example 21
Source Project: GitToolBox   Source File: GtPatternFormatterForm.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void init() {
  commitCompletionPatternField.addTextConsumer((text, error) -> {
    updateCommitCompletionStatus(error);
    updateCommitCompletionOutput();
    patternUpdates.forEach(c -> c.accept(text));
  });
  commitCompletionPatternInput.getDocument().addDocumentListener(new DocumentAdapter() {
    @Override
    protected void textChanged(DocumentEvent e) {
      updateCommitCompletionOutput();
    }
  });
}
 
Example 22
Source Project: GitToolBox   Source File: RegExpTextField.java    License: Apache License 2.0 5 votes vote down vote up
public RegExpTextField() {
  getDocument().addDocumentListener(new DocumentAdapter() {
    @Override
    protected void textChanged(DocumentEvent e) {
      String text = getText();
      Optional<String> error = validateTextOnChange(text);
      textConsumers.forEach(c -> c.accept(text, error));
    }
  });
}
 
Example 23
Source Project: StringManipulation   Source File: Base64EncodingDialog.java    License: Apache License 2.0 5 votes vote down vote up
private void createUIComponents() {
	model = new DefaultComboBoxModel(new String[]{
					"UTF-8",
					"ASCII",
					"CP1256",
					"ISO-8859-1",
					"ISO-8859-2",
					"ISO-8859-6",
					"ISO-8859-15",
					"Windows-1252"});
	myComboBox = new ComboBox(model, 20);
	myComboBox.setEditable(true);
	myComboBox.setOpaque(true);
	defaultColor = myComboBox.getForeground();
	myComboBox.setSelectedItem("UTF-8");
	final JTextComponent tc = (JTextComponent) myComboBox.getEditor().getEditorComponent();

	tc.getDocument().addDocumentListener(new DocumentAdapter() {
		@Override
		protected void textChanged(DocumentEvent documentEvent) {
			JTextField editorJComp = (JTextField) myComboBox.getEditor().getEditorComponent();
			try {
				Charset instance = Charset.forName(getCharset());
				editorJComp.setForeground(defaultColor);
			} catch (Exception ee) {
				editorJComp.setForeground(JBColor.RED);
			}
		}
	});

}
 
Example 24
Source Project: StringManipulation   Source File: DecodeHexAction.java    License: Apache License 2.0 5 votes vote down vote up
public DecodeHexAction() {
    DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>(new String[]{
            "UTF-8",
            "ASCII",
            "CP1256",
            "ISO-8859-1",
            "ISO-8859-2",
            "ISO-8859-6",
            "ISO-8859-15",
            "Windows-1252"});
    charsetComboBox = new ComboBox<>(model, 20);
    charsetComboBox.setEditable(true);
    charsetComboBox.setOpaque(true);
    defaultColor = charsetComboBox.getForeground();
    charsetComboBox.setSelectedItem("UTF-8");
    final JTextComponent tc = (JTextComponent) charsetComboBox.getEditor().getEditorComponent();

    tc.getDocument().addDocumentListener(new DocumentAdapter() {
        @Override
        protected void textChanged(DocumentEvent documentEvent) {
            JTextField editorJComp = (JTextField) charsetComboBox.getEditor().getEditorComponent();
            try {
                Charset.forName(getCharset());
                editorJComp.setForeground(defaultColor);
            } catch (Exception ee) {
                editorJComp.setForeground(JBColor.RED);
            }
        }
    });
}
 
Example 25
Source Project: MavenHelper   Source File: AliasEditor.java    License: Apache License 2.0 5 votes vote down vote up
public AliasEditor(String title, String macroName, String value, Validator validator) {
	super(true);
	setTitle(title);
	myValidator = validator;

	goalEditor = new GoalEditor(null, value, ApplicationSettings.get(), false, null, null) {
		@Override
		protected void updateControls() {
			if (goalEditor != null) {
				AliasEditor.this.updateControls();
			}
		}
	};
	goalEditor.commandLineLabel.setText("To:");
	//noinspection deprecation
	fromField.setNextFocusableComponent(goalEditor.getPreferredFocusedComponent());

	fromField.getDocument().addDocumentListener(new DocumentAdapter() {
		@Override
		public void textChanged(@NotNull DocumentEvent event) {
			updateControls();
		}
	});

	fromField.setText(macroName);
	init();
	updateControls();
}
 
Example 26
Source Project: consulo   Source File: ComponentValidator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Convenient wrapper for mostly used scenario.
 */
public ComponentValidator andRegisterOnDocumentListener(@Nonnull JTextComponent textComponent) {
  textComponent.getDocument().addDocumentListener(new DocumentAdapter() {
    @Override
    protected void textChanged(@Nonnull DocumentEvent e) {
      getInstance(textComponent).ifPresent(ComponentValidator::revalidate); // Don't use 'this' to avoid cyclic references.
    }
  });
  return this;
}
 
Example 27
Source Project: consulo   Source File: ListWithFilter.java    License: Apache License 2.0 5 votes vote down vote up
private MySpeedSearch(boolean highlightAllOccurrences) {
  super(highlightAllOccurrences);
  // native mac "clear button" is not captured by SearchTextField.onFieldCleared
  mySearchField.addDocumentListener(new DocumentAdapter() {
    @Override
    protected void textChanged(@Nonnull DocumentEvent e) {
      if (myInUpdate) return;
      if (mySearchField.getText().isEmpty()) {
        mySpeedSearch.reset();
      }
    }
  });
  installSupplyTo(myList);
}
 
Example 28
Source Project: consulo   Source File: JBTextArea.java    License: Apache License 2.0 5 votes vote down vote up
public JBTextArea(Document doc, String text, int rows, int columns) {
  super(doc, text, rows, columns);

  myEmptyText = new TextComponentEmptyText(this) {
    @Override
    protected boolean isStatusVisible() {
      Object function = getClientProperty("StatusVisibleFunction");
      if (function instanceof BooleanFunction) {
        //noinspection unchecked
        return ((BooleanFunction<JTextComponent>)function).fun(JBTextArea.this);
      }
      return super.isStatusVisible();
    }

    @Override
    protected Rectangle getTextComponentBound() {
      Insets insets = ObjectUtils.notNull(getInsets(), JBUI.emptyInsets());
      Insets margin = ObjectUtils.notNull(getMargin(), JBUI.emptyInsets());
      Insets ipad = getComponent().getIpad();
      Dimension size = getSize();
      int left = insets.left + margin.left - ipad.left;
      int top = insets.top + margin.top - ipad.top;
      int right = size.width - (insets.right + margin.right - ipad.right);
      return new Rectangle(left, top, right - left, getRowHeight());
    }
  };

  getDocument().addDocumentListener(new DocumentAdapter() {
    @Override
    protected void textChanged(@Nonnull DocumentEvent e) {
      invalidate();
      revalidate();
      repaint();
    }
  });
}
 
Example 29
Source Project: consulo   Source File: ValidatingTextField.java    License: Apache License 2.0 5 votes vote down vote up
public ValidatingTextField(final JTextField textField) {
  myTextField = textField;
  myTextField.getDocument().addDocumentListener(new DocumentAdapter() {
    protected void textChanged(DocumentEvent e) {
      String errorText = validateTextOnChange(getMainComponent().getText(), e);
      if (errorText != null) {
        setErrorText(errorText);
      }
    }
  });
  doInitialize();
}
 
Example 30
Source Project: consulo   Source File: TextFieldValueEditor.java    License: Apache License 2.0 5 votes vote down vote up
public TextFieldValueEditor(@Nonnull JTextField field, @Nullable String valueName, @Nonnull T defaultValue) {
  super(valueName, defaultValue);
  myField = field;
  myField.getDocument().addDocumentListener(new DocumentAdapter() {
    @Override
    protected void textChanged(@Nonnull DocumentEvent e) {
      String errorText = validateTextOnChange(myField.getText(), e);
      highlightState(StringUtil.isEmpty(errorText));
      if (StringUtil.isNotEmpty(errorText)) {
        setErrorText(errorText);
      }
    }
  });
}