use of com.intellij.ui.awt.RelativePoint in project intellij-community by JetBrains.
the class InfoAndProgressPanel method buildInInlineIndicator.
private void buildInInlineIndicator(@NotNull final InlineProgressIndicator inline) {
removeAll();
setLayout(new InlineLayout());
final JRootPane pane = getRootPane();
// e.g. project frame is closed
if (pane == null)
return;
add(myRefreshAndInfoPanel);
final JPanel inlinePanel = new JPanel(new BorderLayout());
inline.getComponent().setBorder(JBUI.Borders.empty(1, 0, 0, 2));
final JComponent inlineComponent = inline.getComponent();
inlineComponent.setOpaque(false);
inlinePanel.add(inlineComponent, BorderLayout.CENTER);
//myProgressIcon.setBorder(new IdeStatusBarImpl.MacStatusBarWidgetBorder());
inlinePanel.add(myProgressIcon, BorderLayout.WEST);
inline.updateProgressNow();
inlinePanel.setOpaque(false);
add(inlinePanel);
myRefreshAndInfoPanel.revalidate();
myRefreshAndInfoPanel.repaint();
final PresentationModeProgressPanel panel = new PresentationModeProgressPanel(inline);
MyInlineProgressIndicator delegate = new MyInlineProgressIndicator(true, inline.getInfo(), inline) {
@Override
protected void updateProgress() {
super.updateProgress();
panel.update();
}
};
Disposer.register(inline, delegate);
Component anchor = getAnchor(pane);
final BalloonLayoutImpl balloonLayout = getBalloonLayout(pane);
final Balloon balloon = JBPopupFactory.getInstance().createBalloonBuilder(panel.getProgressPanel()).setFadeoutTime(0).setFillColor(Gray.TRANSPARENT).setShowCallout(false).setBorderColor(Gray.TRANSPARENT).setBorderInsets(JBUI.emptyInsets()).setAnimationCycle(0).setCloseButtonEnabled(false).setHideOnClickOutside(false).setDisposable(inline).setHideOnFrameResize(false).setHideOnKeyOutside(false).setBlockClicksThroughBalloon(true).setHideOnAction(false).createBalloon();
if (balloonLayout != null) {
class MyListener implements JBPopupListener, Runnable {
@Override
public void beforeShown(LightweightWindowEvent event) {
balloonLayout.addListener(this);
}
@Override
public void onClosed(LightweightWindowEvent event) {
balloonLayout.removeListener(this);
}
@Override
public void run() {
if (!balloon.isDisposed()) {
balloon.revalidate();
}
}
}
balloon.addListener(new MyListener());
}
balloon.show(new PositionTracker<Balloon>(anchor) {
@Override
public RelativePoint recalculateLocation(Balloon object) {
Component c = getAnchor(pane);
int y = c.getHeight() - 45;
if (balloonLayout != null && !isBottomSideToolWindowsVisible(pane)) {
Component component = balloonLayout.getTopBalloonComponent();
if (component != null) {
y = SwingUtilities.convertPoint(component, 0, -45, c).y;
}
}
return new RelativePoint(c, new Point(c.getWidth() - 150, y));
}
}, Balloon.Position.above);
}
use of com.intellij.ui.awt.RelativePoint in project intellij-community by JetBrains.
the class ToolWindowsWidget method mouseEntered.
public void mouseEntered() {
final boolean active = ApplicationManager.getApplication().isActive();
if (!active) {
return;
}
if (myAlarm.getActiveRequestCount() == 0) {
myAlarm.addRequest(() -> {
final IdeFrameImpl frame = UIUtil.getParentOfType(IdeFrameImpl.class, this);
if (frame == null)
return;
List<ToolWindow> toolWindows = new ArrayList<>();
final ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(frame.getProject());
for (String id : toolWindowManager.getToolWindowIds()) {
final ToolWindow tw = toolWindowManager.getToolWindow(id);
if (tw.isAvailable() && tw.isShowStripeButton()) {
toolWindows.add(tw);
}
}
Collections.sort(toolWindows, (o1, o2) -> StringUtil.naturalCompare(o1.getStripeTitle(), o2.getStripeTitle()));
final JBList list = new JBList(toolWindows);
list.setCellRenderer(new ListCellRenderer() {
final JBLabel label = new JBLabel();
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
final ToolWindow toolWindow = (ToolWindow) value;
label.setText(toolWindow.getStripeTitle());
label.setIcon(toolWindow.getIcon());
label.setBorder(JBUI.Borders.empty(4, 10));
label.setForeground(UIUtil.getListForeground(isSelected));
label.setBackground(UIUtil.getListBackground(isSelected));
final JPanel panel = new JPanel(new BorderLayout());
panel.add(label, BorderLayout.CENTER);
panel.setBackground(UIUtil.getListBackground(isSelected));
return panel;
}
});
final Dimension size = list.getPreferredSize();
final JComponent c = this;
final Insets padding = UIUtil.getListViewportPadding();
final RelativePoint point = new RelativePoint(c, new Point(-4, -padding.top - padding.bottom - 4 - size.height + (SystemInfo.isMac ? 2 : 0)));
if (popup != null && popup.isVisible()) {
return;
}
list.setSelectedIndex(list.getItemsCount() - 1);
PopupChooserBuilder builder = JBPopupFactory.getInstance().createListPopupBuilder(list);
popup = builder.setAutoselectOnMouseMove(true).setRequestFocus(false).setItemChoosenCallback(() -> {
if (popup != null)
popup.closeOk(null);
final Object value = list.getSelectedValue();
if (value instanceof ToolWindow) {
((ToolWindow) value).activate(null, true, true);
}
}).createPopup();
// override default of 15 set when createPopup() is called
list.setVisibleRowCount(30);
popup.show(point);
}, 300);
}
}
use of com.intellij.ui.awt.RelativePoint in project intellij-community by JetBrains.
the class InfoAndProgressPanel method notifyByBalloon.
public BalloonHandler notifyByBalloon(MessageType type, String htmlBody, @Nullable Icon icon, @Nullable HyperlinkListener listener) {
final Balloon balloon = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(htmlBody.replace("\n", "<br>"), icon != null ? icon : type.getDefaultIcon(), type.getPopupBackground(), listener).createBalloon();
SwingUtilities.invokeLater(() -> {
Component comp = this;
if (comp.isShowing()) {
int offset = comp.getHeight() / 2;
Point point = new Point(comp.getWidth() - offset, comp.getHeight() - offset);
balloon.show(new RelativePoint(comp, point), Balloon.Position.above);
} else {
final JRootPane rootPane = SwingUtilities.getRootPane(comp);
if (rootPane != null && rootPane.isShowing()) {
final Container contentPane = rootPane.getContentPane();
final Rectangle bounds = contentPane.getBounds();
final Point target = UIUtil.getCenterPoint(bounds, JBUI.size(1, 1));
target.y = bounds.height - 3;
balloon.show(new RelativePoint(contentPane, target), Balloon.Position.above);
}
}
});
return new BalloonHandler() {
@Override
public void hide() {
SwingUtilities.invokeLater(() -> balloon.hide());
}
};
}
use of com.intellij.ui.awt.RelativePoint in project intellij-community by JetBrains.
the class DebuggerTreeWithHistoryPopup method updateContainer.
@Override
protected void updateContainer(final Tree tree, String title) {
if (myPopup != null) {
myPopup.cancel();
}
tree.getModel().addTreeModelListener(createTreeListener(tree));
myPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(createMainPanel(tree), tree).setRequestFocus(true).setTitle(title).setResizable(true).setMovable(true).setDimensionServiceKey(myProject, DIMENSION_SERVICE_KEY, false).setMayBeParent(true).setKeyEventHandler(event -> {
if (AbstractPopup.isCloseRequest(event)) {
SpeedSearchSupply supply = SpeedSearchSupply.getSupply(tree);
return supply != null && StringUtil.isEmpty(supply.getEnteredPrefix());
}
return false;
}).addListener(new JBPopupAdapter() {
@Override
public void onClosed(LightweightWindowEvent event) {
if (myHideRunnable != null) {
myHideRunnable.run();
}
}
}).setCancelCallback(() -> {
Window parent = SwingUtilities.getWindowAncestor(tree);
if (parent != null) {
for (Window child : parent.getOwnedWindows()) {
if (child.isShowing()) {
return false;
}
}
}
return true;
}).createPopup();
registerTreeDisposable(myPopup, tree);
//Editor may be disposed before later invokator process this action
if (myEditor.getComponent().getRootPane() == null) {
myPopup.cancel();
return;
}
myPopup.show(new RelativePoint(myEditor.getContentComponent(), myPoint));
updateInitialBounds(tree);
}
use of com.intellij.ui.awt.RelativePoint 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