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;
}
}
});
}
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;
}
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);
}
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);
}
Aggregations