Code example for JTextComponent

Methods: removeMouseListenergetClientPropertyputClientProperty

0
  } 
 
  private InsertPathAction(JTextComponent textField, FileChooserDescriptor descriptor) {
    super(UIBundle.message("insert.file.path.to.text.action.name")); 
    myTextField = textField;
    registerCustomShortcutSet(CTRL_F, myTextField);
    myDescriptor = descriptor;
  } 
 
  @Override 
  public void actionPerformed(AnActionEvent e) {
    String selectedText = myTextField.getSelectedText();
    VirtualFile virtualFile;
    if (selectedText != null ) {
      virtualFile = LocalFileSystem.getInstance().findFileByPath(selectedText.replace(File.separatorChar, '/'));
    } 
    else { 
      virtualFile = null;
    } 
    //TODO use from openapi 
    //FeatureUsageTracker.getInstance().triggerFeatureUsed("ui.commandLine.insertPath"); 
    VirtualFile[] files = FileChooser.chooseFiles(myDescriptor, myTextField, getEventProject(e), virtualFile);
    if (files.length != 0) {
      myTextField.replaceSelection(files[0].getPresentableUrl());
    } 
  } 
 
  private void uninstall() { 
    uninstallPopupHandler(); 
    myTextField.putClientProperty(INSERT_PATH_ACTION, null);
  } 
 
  private void savePopupHandler(MouseListener popupHandler) {
    if (myPopupHandler != null) {
      LOG.error("Installed twice"); 
      uninstallPopupHandler(); 
    } 
    myPopupHandler = popupHandler;
  } 
 
  private void uninstallPopupHandler() { 
    if (myPopupHandler == null) return;
    myTextField.removeMouseListener(myPopupHandler);
    myPopupHandler = null;
  } 
 
  public static void addTo(JTextComponent textField) {
    addTo(textField, null);
  } 
 
  public static void addTo(JTextComponent textField, FileChooserDescriptor descriptor) {
    if (ApplicationManager.getApplication() != null) { //NPE fixed when another class loader works 
      removeFrom(textField);
      if (textField.getClientProperty(INSERT_PATH_ACTION) != null) return;
      DefaultActionGroup actionGroup = new DefaultActionGroup();
      InsertPathAction action = descriptor != null? new InsertPathAction(textField, descriptor) : new InsertPathAction(textField);
      actionGroup.add(action);
      MouseListener popupHandler = PopupHandler.installUnknownPopupHandler(textField, actionGroup, ActionManager.getInstance());
      action.savePopupHandler(popupHandler);
      textField.putClientProperty(INSERT_PATH_ACTION, action);
    } 
  } 
 
  public static void removeFrom(JTextComponent textComponent) {
    InsertPathAction action = getFrom(textComponent);