Search in sources :

Example 11 with LightweightWindowEvent

use of com.intellij.openapi.ui.popup.LightweightWindowEvent in project intellij-community by JetBrains.

the class Notification method setBalloon.

public void setBalloon(@NotNull 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;
            }
        }
    });
}
Also used : JBPopupAdapter(com.intellij.openapi.ui.popup.JBPopupAdapter) LightweightWindowEvent(com.intellij.openapi.ui.popup.LightweightWindowEvent)

Example 12 with LightweightWindowEvent

use of com.intellij.openapi.ui.popup.LightweightWindowEvent in project intellij-community by JetBrains.

the class BalloonPopupBuilderImpl method createBalloon.

@NotNull
@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;
}
Also used : Disposable(com.intellij.openapi.Disposable) ArrayList(java.util.ArrayList) BalloonImpl(com.intellij.ui.BalloonImpl) Balloon(com.intellij.openapi.ui.popup.Balloon) JBPopupAdapter(com.intellij.openapi.ui.popup.JBPopupAdapter) ArrayList(java.util.ArrayList) List(java.util.List) LightweightWindowEvent(com.intellij.openapi.ui.popup.LightweightWindowEvent) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with LightweightWindowEvent

use of com.intellij.openapi.ui.popup.LightweightWindowEvent in project intellij-community by JetBrains.

the class OccurrencesChooser method showChooser.

public <C extends BaseReplaceChoice> void showChooser(final Pass<C> callback, final Map<C, List<T>> occurrencesMap, String title) {
    if (occurrencesMap.size() == 1) {
        callback.pass(occurrencesMap.keySet().iterator().next());
        return;
    }
    final DefaultListModel<C> model = new DefaultListModel<>();
    for (C choice : occurrencesMap.keySet()) {
        model.addElement(choice);
    }
    final JList<C> list = new JBList<>(model);
    list.setCellRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) {
            final Component rendererComponent = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            @SuppressWarnings("unchecked") final C choices = (C) value;
            if (choices != null) {
                setText(choices.formatDescription(occurrencesMap.get(choices).size()));
            }
            return rendererComponent;
        }
    });
    list.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(final ListSelectionEvent e) {
            final C value = list.getSelectedValue();
            if (value == null)
                return;
            dropHighlighters();
            final MarkupModel markupModel = myEditor.getMarkupModel();
            final List<T> occurrenceList = occurrencesMap.get(value);
            for (T occurrence : occurrenceList) {
                final TextRange textRange = getOccurrenceRange(occurrence);
                final RangeHighlighter rangeHighlighter = markupModel.addRangeHighlighter(textRange.getStartOffset(), textRange.getEndOffset(), HighlighterLayer.SELECTION - 1, myAttributes, HighlighterTargetArea.EXACT_RANGE);
                myRangeHighlighters.add(rangeHighlighter);
            }
        }
    });
    JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle(title).setMovable(true).setResizable(false).setRequestFocus(true).setItemChoosenCallback(() -> callback.pass(list.getSelectedValue())).addListener(new JBPopupAdapter() {

        @Override
        public void onClosed(LightweightWindowEvent event) {
            dropHighlighters();
        }
    }).createPopup().showInBestPositionFor(myEditor);
}
Also used : ListSelectionEvent(javax.swing.event.ListSelectionEvent) TextRange(com.intellij.openapi.util.TextRange) ListSelectionListener(javax.swing.event.ListSelectionListener) LightweightWindowEvent(com.intellij.openapi.ui.popup.LightweightWindowEvent) JBPopupAdapter(com.intellij.openapi.ui.popup.JBPopupAdapter) JBList(com.intellij.ui.components.JBList) JBList(com.intellij.ui.components.JBList) List(java.util.List)

Example 14 with LightweightWindowEvent

use of com.intellij.openapi.ui.popup.LightweightWindowEvent in project intellij-community by JetBrains.

the class LoadContextAction method actionPerformed.

@Override
public void actionPerformed(AnActionEvent e) {
    final Project project = getProject(e);
    assert project != null;
    DefaultActionGroup group = new DefaultActionGroup();
    final WorkingContextManager manager = WorkingContextManager.getInstance(project);
    List<ContextInfo> history = manager.getContextHistory();
    List<ContextHolder> infos = new ArrayList<>(ContainerUtil.map2List(history, (Function<ContextInfo, ContextHolder>) info -> new ContextHolder() {

        @Override
        void load(final boolean clear) {
            LoadContextUndoableAction undoableAction = LoadContextUndoableAction.createAction(manager, clear, info.name);
            UndoableCommand.execute(project, undoableAction, "Load context " + info.comment, "Context");
        }

        @Override
        void remove() {
            manager.removeContext(info.name);
        }

        @Override
        Date getDate() {
            return new Date(info.date);
        }

        @Override
        String getComment() {
            return info.comment;
        }

        @Override
        Icon getIcon() {
            return TasksIcons.SavedContext;
        }
    }));
    final TaskManager taskManager = TaskManager.getManager(project);
    List<LocalTask> tasks = taskManager.getLocalTasks();
    infos.addAll(ContainerUtil.mapNotNull(tasks, (NullableFunction<LocalTask, ContextHolder>) task -> {
        if (task.isActive()) {
            return null;
        }
        return new ContextHolder() {

            @Override
            void load(boolean clear) {
                LoadContextUndoableAction undoableAction = LoadContextUndoableAction.createAction(manager, clear, task);
                UndoableCommand.execute(project, undoableAction, "Load context " + TaskUtil.getTrimmedSummary(task), "Context");
            }

            @Override
            void remove() {
                SwitchTaskAction.removeTask(project, task, taskManager);
            }

            @Override
            Date getDate() {
                return task.getUpdated();
            }

            @Override
            String getComment() {
                return TaskUtil.getTrimmedSummary(task);
            }

            @Override
            Icon getIcon() {
                return task.getIcon();
            }
        };
    }));
    Collections.sort(infos, (o1, o2) -> o2.getDate().compareTo(o1.getDate()));
    final Ref<Boolean> shiftPressed = Ref.create(false);
    boolean today = true;
    Calendar now = Calendar.getInstance();
    for (int i = 0, historySize = Math.min(MAX_ROW_COUNT, infos.size()); i < historySize; i++) {
        final ContextHolder info = infos.get(i);
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(info.getDate());
        if (today && (calendar.get(Calendar.YEAR) != now.get(Calendar.YEAR) || calendar.get(Calendar.DAY_OF_YEAR) != now.get(Calendar.DAY_OF_YEAR))) {
            group.addSeparator();
            today = false;
        }
        group.add(createItem(info, shiftPressed));
    }
    final ListPopupImpl popup = (ListPopupImpl) JBPopupFactory.getInstance().createActionGroupPopup("Load Context", group, e.getDataContext(), false, null, MAX_ROW_COUNT);
    popup.setAdText("Press SHIFT to merge with current context");
    popup.registerAction("shiftPressed", KeyStroke.getKeyStroke("shift pressed SHIFT"), new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            shiftPressed.set(true);
            popup.setCaption("Merge with Current Context");
        }
    });
    popup.registerAction("shiftReleased", KeyStroke.getKeyStroke("released SHIFT"), new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            shiftPressed.set(false);
            popup.setCaption("Load Context");
        }
    });
    popup.registerAction("invoke", KeyStroke.getKeyStroke("shift ENTER"), new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            popup.handleSelect(true);
        }
    });
    popup.addPopupListener(new JBPopupAdapter() {

        @Override
        public void onClosed(LightweightWindowEvent event) {
        }
    });
    popup.showCenteredInCurrentWindow(project);
}
Also used : ActionEvent(java.awt.event.ActionEvent) LightweightWindowEvent(com.intellij.openapi.ui.popup.LightweightWindowEvent) NullableFunction(com.intellij.util.NullableFunction) Function(com.intellij.util.Function) ContextInfo(com.intellij.tasks.context.ContextInfo) WorkingContextManager(com.intellij.tasks.context.WorkingContextManager) LocalTask(com.intellij.tasks.LocalTask) NullableFunction(com.intellij.util.NullableFunction) Project(com.intellij.openapi.project.Project) LoadContextUndoableAction(com.intellij.tasks.context.LoadContextUndoableAction) TaskManager(com.intellij.tasks.TaskManager) ListPopupImpl(com.intellij.ui.popup.list.ListPopupImpl) JBPopupAdapter(com.intellij.openapi.ui.popup.JBPopupAdapter)

Aggregations

LightweightWindowEvent (com.intellij.openapi.ui.popup.LightweightWindowEvent)14 JBPopupAdapter (com.intellij.openapi.ui.popup.JBPopupAdapter)12 JBList (com.intellij.ui.components.JBList)5 RelativePoint (com.intellij.ui.awt.RelativePoint)4 ActionEvent (java.awt.event.ActionEvent)4 ListSelectionEvent (javax.swing.event.ListSelectionEvent)4 ListSelectionListener (javax.swing.event.ListSelectionListener)4 Pair (com.intellij.openapi.util.Pair)3 TextRange (com.intellij.openapi.util.TextRange)3 ActionListener (java.awt.event.ActionListener)3 Balloon (com.intellij.openapi.ui.popup.Balloon)2 JBPopup (com.intellij.openapi.ui.popup.JBPopup)2 JBPopupListener (com.intellij.openapi.ui.popup.JBPopupListener)2 PsiElement (com.intellij.psi.PsiElement)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 NotNull (org.jetbrains.annotations.NotNull)2 EverywhereContextType (com.intellij.codeInsight.template.EverywhereContextType)1 TemplateContextType (com.intellij.codeInsight.template.TemplateContextType)1 ScopeHighlighter (com.intellij.codeInsight.unwrap.ScopeHighlighter)1