use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class TaskDefaultFavoriteListProvider method showNotePopup.
private void showNotePopup(Project project, final DnDAwareTree tree, final Consumer<String> after, final String initText) {
final JTextArea textArea = new JTextArea(3, 50);
textArea.setFont(UIUtil.getTreeFont());
textArea.setText(initText);
final JBScrollPane pane = new JBScrollPane(textArea);
final ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(pane, textArea).setCancelOnClickOutside(true).setAdText(KeymapUtil.getShortcutsText(CommonShortcuts.CTRL_ENTER.getShortcuts()) + " to finish").setTitle("Comment").setMovable(true).setRequestFocus(true).setResizable(true).setMayBeParent(true);
final JBPopup popup = builder.createPopup();
final JComponent content = popup.getContent();
final AnAction action = new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
popup.closeOk(e.getInputEvent());
unregisterCustomShortcutSet(content);
after.consume(textArea.getText());
}
};
action.registerCustomShortcutSet(CommonShortcuts.CTRL_ENTER, content);
ApplicationManager.getApplication().invokeLater(() -> popup.showInCenterOf(tree), ModalityState.NON_MODAL, project.getDisposed());
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class TabbedContentTabLabel method showPopup.
private void showPopup() {
IdeEventQueue.getInstance().getPopupManager().closeAllPopups();
ArrayList<String> names = new ArrayList<String>();
for (Pair<String, JComponent> tab : myContent.getTabs()) {
names.add(tab.first);
}
final JBList list = new JBList(names);
list.installCellRenderer(new NotNullFunction<Object, JComponent>() {
private final JLabel label = new JLabel();
{
label.setBorder(new EmptyBorder(UIUtil.getListCellPadding()));
}
@NotNull
@Override
public JComponent fun(Object dom) {
label.setText(dom.toString());
return label;
}
});
final JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(list).setItemChoosenCallback(() -> {
int index = list.getSelectedIndex();
if (index != -1) {
myContent.selectContent(index);
}
}).createPopup();
myPopupReference = new WeakReference<JBPopup>(popup);
popup.showUnderneathOf(this);
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class TabbedContentTabLabel method removeNotify.
@Override
public void removeNotify() {
super.removeNotify();
JBPopup popup = SoftReference.dereference(myPopupReference);
if (popup != null) {
Disposer.dispose(popup);
myPopupReference = null;
}
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class WindowManagerImpl method adjustContainerWindow.
@Override
public void adjustContainerWindow(Component c, Dimension oldSize, Dimension newSize) {
if (c == null)
return;
Window wnd = SwingUtilities.getWindowAncestor(c);
if (wnd instanceof JWindow) {
JBPopup popup = (JBPopup) ((JWindow) wnd).getRootPane().getClientProperty(JBPopup.KEY);
if (popup != null) {
if (oldSize.height < newSize.height) {
Dimension size = popup.getSize();
size.height += newSize.height - oldSize.height;
popup.setSize(size);
popup.moveToFitScreen();
}
}
}
}
use of com.intellij.openapi.ui.popup.JBPopup in project intellij-community by JetBrains.
the class JBComboBoxTableCellEditorComponent method initAndShowPopup.
private void initAndShowPopup() {
myList.removeAll();
myList.setModel(JBList.createDefaultListModel(myOptions));
if (myRenderer != null) {
myList.setCellRenderer(myRenderer);
}
final Rectangle rect = myTable.getCellRect(myRow, myColumn, true);
Point point = new Point(rect.x, rect.y);
final boolean surrendersFocusOnKeystrokeOldValue = myTable instanceof JBTable ? ((JBTable) myTable).surrendersFocusOnKeyStroke() : myTable.getSurrendersFocusOnKeystroke();
final JBPopup popup = JBPopupFactory.getInstance().createListPopupBuilder(myList).setItemChoosenCallback(() -> {
myValue = myList.getSelectedValue();
final ActionEvent event = new ActionEvent(myList, ActionEvent.ACTION_PERFORMED, "elementChosen");
for (ActionListener listener : myListeners) {
listener.actionPerformed(event);
}
TableUtil.stopEditing(myTable);
// on Mac getCellEditorValue() called before myValue is set.
myTable.setValueAt(myValue, myRow, myColumn);
// force repaint
myTable.tableChanged(new TableModelEvent(myTable.getModel(), myRow));
}).setCancelCallback(() -> {
TableUtil.stopEditing(myTable);
return true;
}).addListener(new JBPopupAdapter() {
@Override
public void beforeShown(LightweightWindowEvent event) {
super.beforeShown(event);
myTable.setSurrendersFocusOnKeystroke(false);
}
@Override
public void onClosed(LightweightWindowEvent event) {
myTable.setSurrendersFocusOnKeystroke(surrendersFocusOnKeystrokeOldValue);
super.onClosed(event);
}
}).setMinSize(myWide ? new Dimension(((int) rect.getSize().getWidth()), -1) : null).createPopup();
popup.show(new RelativePoint(myTable, point));
}
Aggregations