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

The following examples show how to use com.intellij.openapi.ui.popup.LightweightWindowEvent. 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: BlamePopup.java    From GitToolBox with Apache License 2.0 6 votes vote down vote up
void showFor(@NotNull JComponent component) {
  balloon = JBPopupFactory.getInstance()
      .createHtmlTextBalloonBuilder(prepareText(), null, BACKGROUND, createLinkListener())
      .setTitle(ResBundle.message("statusBar.blame.popup.title"))
      .setAnimationCycle(200)
      .setShowCallout(false)
      .setCloseButtonEnabled(true)
      .setHideOnCloseClick(true)
      .createBalloon();
  balloon.addListener(new JBPopupAdapter() {
    @Override
    public void onClosed(@NotNull LightweightWindowEvent event) {
      if (!balloon.isDisposed()) {
        Disposer.dispose(balloon);
      }
    }
  });
  balloon.showInCenterOf(component);
}
 
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: 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 #4
Source File: BranchActionGroupPopup.java    From consulo with Apache License 2.0 6 votes vote down vote up
private void trackDimensions(@Nullable String dimensionKey) {
  Window popupWindow = getPopupWindow();
  if (popupWindow == null) return;
  ComponentListener windowListener = new ComponentAdapter() {
    @Override
    public void componentResized(ComponentEvent e) {
      if (myShown) {
        processOnSizeChanged();
      }
    }
  };
  popupWindow.addComponentListener(windowListener);
  addPopupListener(new JBPopupAdapter() {
    @Override
    public void onClosed(@Nonnull LightweightWindowEvent event) {
      popupWindow.removeComponentListener(windowListener);
      if (dimensionKey != null && myUserSizeChanged) {
        WindowStateService.getInstance(myProject).putSizeFor(myProject, dimensionKey, myPrevSize);
      }
    }
  });
}
 
Example #5
Source File: Notification.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void setBalloon(@Nonnull final Balloon balloon) {
  hideBalloon();
  myBalloonRef = new WeakReference<>(balloon);
  balloon.addListener(new JBPopupAdapter() {
    @Override
    public void onClosed(LightweightWindowEvent event) {
      if (SoftReference.dereference(myBalloonRef) == balloon) {
        myBalloonRef = null;
      }
    }
  });
}
 
Example #6
Source File: MultipleValueFilterPopupComponent.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void actionPerformed(@Nonnull AnActionEvent e) {
  Project project = e.getProject();
  if (project == null) {
    return;
  }

  Filter filter = myFilterModel.getFilter();
  List<String> values = filter == null
                        ? Collections.emptyList()
                        : myFilterModel.getFilterValues(filter);
  final MultilinePopupBuilder popupBuilder = new MultilinePopupBuilder(project, myVariants,
                                                                       getPopupText(values),
                                                                       supportsNegativeValues());
  JBPopup popup = popupBuilder.createPopup();
  popup.addListener(new JBPopupAdapter() {
    @Override
    public void onClosed(LightweightWindowEvent event) {
      if (event.isOk()) {
        List<String> selectedValues = popupBuilder.getSelectedValues();
        if (selectedValues.isEmpty()) {
          myFilterModel.setFilter(null);
        }
        else {
          myFilterModel.setFilter(myFilterModel.createFilter(selectedValues));
          rememberValuesInSettings(selectedValues);
        }
      }
    }
  });
  popup.showUnderneathOf(MultipleValueFilterPopupComponent.this);
}
 
Example #7
Source File: FramelessNotificationPopup.java    From consulo with Apache License 2.0 5 votes vote down vote up
public FramelessNotificationPopup(final JComponent owner, final JComponent content, Color backgroud, boolean useDefaultPreferredSize, final ActionListener listener) {
  myBackgroud = backgroud;
  myUseDefaultPreferredSize = useDefaultPreferredSize;
  myContent = new ContentComponent(content);

  myActionListener = listener;

  myFadeInTimer = UIUtil.createNamedTimer("Frameless fade in",10, myFadeTracker);
  myPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(myContent, null)
    .setRequestFocus(false)
    .setResizable(false)
    .setMovable(true)
    .setLocateWithinScreenBounds(false)
    .setAlpha(0.2f).addListener(new JBPopupAdapter() {
    public void onClosed(LightweightWindowEvent event) {
      if (myFadeInTimer.isRunning()) {
        myFadeInTimer.stop();
      }
      myFadeInTimer.removeActionListener(myFadeTracker);
    }
  })
    .createPopup();
  final Point p = RelativePoint.getSouthEastOf(owner).getScreenPoint();
  Rectangle screen = ScreenUtil.getScreenRectangle(p.x, p.y);

  final Point initial = new Point(screen.x + screen.width - myContent.getPreferredSize().width - 50,
                                  screen.y + screen.height - 5);

  myPopup.showInScreenCoordinates(owner, initial);

  myFadeInTimer.setRepeats(true);
  myFadeInTimer.start();
}
 
Example #8
Source File: BalloonPopupBuilderImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public Balloon createBalloon() {
  final BalloonImpl result =
          new BalloonImpl(myContent, myBorder, myBorderInsets, myFill, myHideOnMouseOutside, myHideOnKeyOutside, myHideOnAction, myHideOnCloseClick,
                          myShowCallout, myCloseButtonEnabled, myFadeoutTime, myHideOnFrameResize, myHideOnLinkClick, myClickHandler, myCloseOnClick,
                          myAnimationCycle, myCalloutShift, myPositionChangeXShift, myPositionChangeYShift, myDialogMode, myTitle, myContentInsets, myShadow,
                          mySmallVariant, myBlockClicks, myLayer, myRequestFocus, myPointerSize, myCornerToPointerDistance);

  if (myStorage != null && myAnchor != null) {
    List<Balloon> balloons = myStorage.get(myAnchor);
    if (balloons == null) {
      myStorage.put(myAnchor, balloons = new ArrayList<>());
      Disposer.register(myAnchor, new Disposable() {
        @Override
        public void dispose() {
          List<Balloon> toDispose = myStorage.remove(myAnchor);
          if (toDispose != null) {
            for (Balloon balloon : toDispose) {
              if (!balloon.isDisposed()) {
                Disposer.dispose(balloon);
              }
            }
          }
        }
      });
    }
    balloons.add(result);
    result.addListener(new JBPopupAdapter() {
      @Override
      public void onClosed(LightweightWindowEvent event) {
        if (!result.isDisposed()) {
          Disposer.dispose(result);
        }
      }
    });
  }

  return result;
}
 
Example #9
Source File: ActionMacroManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void showBalloon() {
  if (myBalloon != null) {
    Disposer.dispose(myBalloon);
    return;
  }

  myBalloon = JBPopupFactory.getInstance().createBalloonBuilder(myBalloonComponent).setAnimationCycle(200).setCloseButtonEnabled(true).setHideOnAction(false).setHideOnClickOutside(false)
          .setHideOnFrameResize(false).setHideOnKeyOutside(false).setSmallVariant(true).setShadow(true).createBalloon();

  Disposer.register(myBalloon, new Disposable() {
    @Override
    public void dispose() {
      myBalloon = null;
    }
  });

  myBalloon.addListener(new JBPopupAdapter() {
    @Override
    public void onClosed(LightweightWindowEvent event) {
      if (myBalloon != null) {
        Disposer.dispose(myBalloon);
      }
    }
  });

  myBalloon.show(new PositionTracker<Balloon>(myIcon) {
    @Override
    public RelativePoint recalculateLocation(Balloon object) {
      return new RelativePoint(myIcon, new Point(myIcon.getSize().width / 2, 4));
    }
  }, Balloon.Position.above);
}
 
Example #10
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 #11
Source File: SeverityRenderer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void onClosed(LightweightWindowEvent event) {
  super.onClosed(event);
  if (myOnClose != null) {
    myOnClose.run();
  }
}
 
Example #12
Source File: PopupUpdateProcessor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeShown(final LightweightWindowEvent windowEvent) {
  final Lookup activeLookup = LookupManager.getInstance(myProject).getActiveLookup();
  if (activeLookup != null) {
    activeLookup.addLookupListener(new LookupAdapter() {
      @Override
      public void currentItemChanged(LookupEvent event) {
        if (windowEvent.asPopup().isVisible()) { //was not canceled yet
          final LookupElement item = event.getItem();
          if (item != null) {
            PsiElement targetElement = CompletionUtil.getTargetElement(item);
            if (targetElement == null) {
              targetElement = DocumentationManager.getInstance(myProject).getElementFromLookup(activeLookup.getEditor(), activeLookup.getPsiFile());
            }

            updatePopup(targetElement); //open next
          }
        } else {
          activeLookup.removeLookupListener(this);
        }
      }
    });
  }
  else {
    final Component focusedComponent = WindowManagerEx.getInstanceEx().getFocusedComponent(myProject);
    boolean fromQuickSearch = focusedComponent != null && focusedComponent.getParent() instanceof ChooseByNameBase.JPanelProvider;
    if (fromQuickSearch) {
      ChooseByNameBase.JPanelProvider panelProvider = (ChooseByNameBase.JPanelProvider)focusedComponent.getParent();
      panelProvider.registerHint(windowEvent.asPopup());
    }
    else if (focusedComponent instanceof JComponent) {
      HintUpdateSupply supply = HintUpdateSupply.getSupply((JComponent)focusedComponent);
      if (supply != null) supply.registerHint(windowEvent.asPopup());
    }
  }
}
 
Example #13
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 #14
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 #15
Source File: PopupState.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void onClosed(@Nonnull LightweightWindowEvent event) {
  markAsHidden();
}
 
Example #16
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 #17
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 #18
Source File: PopupState.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void beforeShown(@Nonnull LightweightWindowEvent event) {
  markAsShown();
}
 
Example #19
Source File: LiveTemplateSettingsEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
private JPanel createShortContextPanel(final boolean allowNoContexts) {
  JPanel panel = new JPanel(new BorderLayout());

  final JLabel ctxLabel = new JLabel();
  final JLabel change = new JLabel();
  change.setForeground(JBColor.BLUE);
  change.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
  panel.add(ctxLabel, BorderLayout.CENTER);
  panel.add(change, BorderLayout.EAST);

  final Runnable updateLabel = new Runnable() {
    @Override
    public void run() {
      StringBuilder sb = new StringBuilder();
      String oldPrefix = "";
      for (TemplateContextType type : getApplicableContexts()) {
        final TemplateContextType base = type.getBaseContextType();
        String ownName = UIUtil.removeMnemonic(type.getPresentableName());
        String prefix = "";
        if (base != null && !(base instanceof EverywhereContextType)) {
          prefix = UIUtil.removeMnemonic(base.getPresentableName()) + ": ";
          ownName = StringUtil.decapitalize(ownName);
        }
        if (type instanceof EverywhereContextType) {
          ownName = "Other";
        }
        if (sb.length() > 0) {
          sb.append(oldPrefix.equals(prefix) ? ", " : "; ");
        }
        if (!oldPrefix.equals(prefix)) {
          sb.append(prefix);
          oldPrefix = prefix;
        }
        sb.append(ownName);
      }
      final boolean noContexts = sb.length() == 0;
      ctxLabel.setText((noContexts ? "No applicable contexts" + (allowNoContexts ? "" : " yet") : "Applicable in " + sb.toString()) + ".  ");
      ctxLabel.setForeground(noContexts ? allowNoContexts ? JBColor.GRAY : JBColor.RED : UIUtil.getLabelForeground());
      change.setText(noContexts ? "Define" : "Change");
    }
  };

  new ClickListener() {
    @Override
    public boolean onClick(MouseEvent e, int clickCount) {
      if (disposeContextPopup()) return false;

      final JPanel content = createPopupContextPanel(updateLabel);
      Dimension prefSize = content.getPreferredSize();
      if (myLastSize != null && (myLastSize.width > prefSize.width || myLastSize.height > prefSize.height)) {
        content.setPreferredSize(new Dimension(Math.max(prefSize.width, myLastSize.width), Math.max(prefSize.height, myLastSize.height)));
      }
      myContextPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(content, null).setResizable(true).createPopup();
      myContextPopup.show(new RelativePoint(change, new Point(change.getWidth() , -content.getPreferredSize().height - 10)));
      myContextPopup.addListener(new JBPopupAdapter() {
        @Override
        public void onClosed(LightweightWindowEvent event) {
          myLastSize = content.getSize();
        }
      });
      return true;
    }
  }.installOn(change);

  updateLabel.run();

  return panel;
}