com.intellij.openapi.ui.popup.JBPopupListener Java Examples

The following examples show how to use com.intellij.openapi.ui.popup.JBPopupListener. 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
Source File: ShowFilterAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void showPopup(@Nonnull Project project, @Nonnull Component anchor) {
  if (myFilterPopup != null || !anchor.isValid()) {
    return;
  }
  JBPopupListener popupCloseListener = new JBPopupListener() {
    @Override
    public void onClosed(@Nonnull LightweightWindowEvent event) {
      myFilterPopup = null;
    }
  };
  myFilterPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(createFilterPanel(), null).setModalContext(false).setFocusable(false).setResizable(true).setCancelOnClickOutside(false)
          .setMinSize(new Dimension(200, 200)).setDimensionServiceKey(project, getDimensionServiceKey(), false).addListener(popupCloseListener).createPopup();
  anchor.addHierarchyListener(new HierarchyListener() {
    @Override
    public void hierarchyChanged(HierarchyEvent e) {
      if (e.getID() == HierarchyEvent.HIERARCHY_CHANGED && !anchor.isValid()) {
        anchor.removeHierarchyListener(this);
        if (myFilterPopup != null) {
          myFilterPopup.cancel();
        }
      }
    }
  });
  myFilterPopup.showUnderneathOf(anchor);
}
 
Example #2
Source File: ChooseByNameFilter.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Create and show popup
 */
private void createPopup() {
  if (myPopup != null) {
    return;
  }
  myPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(myChooserPanel, myChooser).setModalContext(false).setFocusable(false)
          .setResizable(true).setCancelOnClickOutside(false).setMinSize(new Dimension(200, 200))
          .setDimensionServiceKey(myProject, "GotoFile_FileTypePopup", false).createPopup();
  myPopup.addListener(new JBPopupListener.Adapter() {
    @Override
    public void onClosed(LightweightWindowEvent event) {
      myPopup = null;
    }
  });
  myPopup.showUnderneathOf(myToolbar.getComponent());
}
 
Example #3
Source File: TimeTrackerWidget.java    From DarkyenusTimeTracker with The Unlicense 5 votes vote down vote up
private void popupSettings() {
    final TimeTrackerPopupContent content = new TimeTrackerPopupContent(service, (patternFieldType) -> {
        if (patternFieldType == null) {
            setPopupState(PopupState.VISIBLE_LOST_FOCUS);
        } else if (patternFieldType == TimeTrackerPopupContent.PatternField.WIDGET) {
            setPopupState(PopupState.VISIBLE_WIDGET_PATTERN_FOCUS);
        } else if (patternFieldType == TimeTrackerPopupContent.PatternField.GIT) {
            setPopupState(PopupState.VISIBLE_GIT_PATTERN_FOCUS);
        }
    });

    final ComponentPopupBuilder popupBuilder = JBPopupFactory.getInstance().createComponentPopupBuilder(content, null);
    popupBuilder.setCancelOnClickOutside(true);
    popupBuilder.setFocusable(true);
    popupBuilder.setRequestFocus(true);
    popupBuilder.setShowBorder(true);
    popupBuilder.setShowShadow(true);
    final JBPopup popup = popupBuilder.createPopup();
    content.popup = popup;

    final Rectangle visibleRect = TimeTrackerWidget.this.getVisibleRect();
    final Dimension preferredSize = content.getPreferredSize();
    final RelativePoint point = new RelativePoint(TimeTrackerWidget.this, new Point(visibleRect.x+visibleRect.width - preferredSize.width, visibleRect.y - (preferredSize.height + 15)));
    popup.show(point);

    popup.addListener(new JBPopupListener() {
        @Override
        public void onClosed(@NotNull LightweightWindowEvent event) {
            setPopupState(PopupState.HIDDEN);
        }
    });

    // Not sure if needed, but sometimes the popup is not clickable for some mysterious reason
    // and it stopped happening when this was added
    content.requestFocus();
    setPopupState(PopupState.VISIBLE);
}
 
Example #4
Source File: AddCommentAction.java    From Crucible4IDEA with MIT License 5 votes vote down vote up
private void addGeneralComment(@NotNull final Project project, DataContext dataContext) {
  final CommentForm commentForm = new CommentForm(project, true, myIsReply, null);
  commentForm.setReview(myReview);

  if (myIsReply) {
    final JBTable contextComponent = (JBTable)getContextComponent();
    final int selectedRow = contextComponent.getSelectedRow();
    if (selectedRow >= 0) {
      final Object parentComment = contextComponent.getValueAt(selectedRow, 0);
      if (parentComment instanceof Comment) {
        commentForm.setParentComment(((Comment)parentComment));
      }
    }
    else return;
  }

  final JBPopup balloon = CommentBalloonBuilder.getNewCommentBalloon(commentForm, myIsReply ? CrucibleBundle
    .message("crucible.new.reply.$0", commentForm.getParentComment().getPermId()) :
                                                                                  CrucibleBundle
                                                                                    .message("crucible.new.comment.$0",
                                                                                             myReview.getPermaId()));
  balloon.addListener(new JBPopupListener() {
    @Override
    public void onClosed(LightweightWindowEvent event) {
      if(!commentForm.getText().isEmpty()) { // do not try to save draft if text is empty
        commentForm.postComment();
      }
      final JComponent component = getContextComponent();
      if (component instanceof GeneralCommentsTree) {
        ((GeneralCommentsTree)component).refresh();
      }
    }
  });

  commentForm.setBalloon(balloon);
  balloon.showInBestPositionFor(dataContext);
  commentForm.requestFocus();
}
 
Example #5
Source File: EditorMouseHoverPopupManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void performOnCancel(@Nonnull Runnable runnable) {
  performWhenAvailable(popup -> popup.addListener(new JBPopupListener() {
    @Override
    public void onClosed(@Nonnull LightweightWindowEvent event) {
      runnable.run();
    }
  }));
}
 
Example #6
Source File: GoToHashOrRefPopup.java    From consulo with Apache License 2.0 4 votes vote down vote up
public GoToHashOrRefPopup(@Nonnull final Project project,
                          @Nonnull VcsLogRefs variants,
                          Collection<VirtualFile> roots,
                          @Nonnull Function<String, Future> onSelectedHash,
                          @Nonnull Function<VcsRef, Future> onSelectedRef,
                          @Nonnull VcsLogColorManager colorManager,
                          @Nonnull Comparator<VcsRef> comparator) {
  myOnSelectedHash = onSelectedHash;
  myOnSelectedRef = onSelectedRef;
  myTextField =
    new TextFieldWithProgress(project, new VcsRefCompletionProvider(project, variants, roots, colorManager, comparator)) {
      @Override
      public void onOk() {
        if (myFuture == null) {
          final Future future = ((mySelectedRef == null || (!mySelectedRef.getName().equals(getText().trim())))
                                 ? myOnSelectedHash.fun(getText().trim())
                                 : myOnSelectedRef.fun(mySelectedRef));
          myFuture = future;
          showProgress();
          ApplicationManager.getApplication().executeOnPooledThread(() -> {
            try {
              future.get();
              okPopup();
            }
            catch (CancellationException ex) {
              cancelPopup();
            }
            catch (InterruptedException ex) {
              cancelPopup();
            }
            catch (ExecutionException ex) {
              LOG.error(ex);
              cancelPopup();
            }
          });
        }
      }
    };
  myTextField.setAlignmentX(Component.LEFT_ALIGNMENT);

  JBLabel label = new JBLabel("Enter hash or branch/tag name:");
  label.setFont(UIUtil.getLabelFont().deriveFont(Font.BOLD));
  label.setAlignmentX(Component.LEFT_ALIGNMENT);

  JPanel panel = new JPanel();
  BoxLayout layout = new BoxLayout(panel, BoxLayout.PAGE_AXIS);
  panel.setLayout(layout);
  panel.add(label);
  panel.add(myTextField);
  panel.setBorder(new EmptyBorder(2, 2, 2, 2));

  myPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, myTextField.getPreferableFocusComponent())
    .setCancelOnClickOutside(true).setCancelOnWindowDeactivation(true).setCancelKeyEnabled(true).setRequestFocus(true).createPopup();
  myPopup.addListener(new JBPopupListener.Adapter() {
    @Override
    public void onClosed(LightweightWindowEvent event) {
      if (!event.isOk()) {
        if (myFuture != null) {
          myFuture.cancel(true);
        }
      }
      myFuture = null;
      myTextField.hideProgress();
    }
  });
}
 
Example #7
Source File: BalloonImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
private void hideAndDispose(final boolean ok) {
  if (myDisposed) return;

  if (mySmartFadeoutPaused) {
    mySmartFadeoutPaused = false;
    return;
  }

  myDisposed = true;
  hideComboBoxPopups();

  final Runnable disposeRunnable = () -> {
    myFadedOut = true;
    if (myRequestFocus) {
      if (myOriginalFocusOwner != null) {
        myFocusManager.requestFocus(myOriginalFocusOwner, false);
      }
    }

    for (JBPopupListener each : myListeners) {
      each.onClosed(new LightweightWindowEvent(this, ok));
    }

    Disposer.dispose(this);
    onDisposed();
  };

  Toolkit.getDefaultToolkit().removeAWTEventListener(myAwtActivityListener);
  if (myLayeredPane != null) {
    myLayeredPane.removeComponentListener(myComponentListener);

    if (isAnimationEnabled()) {
      runAnimation(false, myLayeredPane, disposeRunnable);
    }
    else {
      if (myAnimator != null) {
        Disposer.dispose(myAnimator);
      }

      myLayeredPane.remove(myComp);
      myLayeredPane.revalidate();
      myLayeredPane.repaint();
      disposeRunnable.run();
    }
  }
  else {
    disposeRunnable.run();
  }

  myVisible = false;
  myTracker = null;
}
 
Example #8
Source File: BalloonImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void addListener(@Nonnull JBPopupListener listener) {
  myListeners.add(listener);
}