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));
}
use of com.intellij.ui.awt.RelativePoint in project intellij-community by JetBrains.
the class MouseDragHelper method mouseDragged.
@Override
public void mouseDragged(final MouseEvent e) {
if (myPressPointScreen == null || myCancelled)
return;
final boolean deadZone = isWithinDeadZone(e);
if (!myDraggingNow && !deadZone) {
myDraggingNow = true;
myDragJustStarted = true;
} else if (myDraggingNow) {
myDragJustStarted = false;
}
if (myDraggingNow && myPressPointScreen != null) {
final Point draggedTo = new RelativePoint(e).getScreenPoint();
boolean dragOutStarted = false;
if (!myDetachingMode) {
if (isDragOut(e, draggedTo, (Point) myPressPointScreen.clone())) {
myDetachingMode = true;
processDragFinish(e, true);
dragOutStarted = true;
}
}
if (myDetachingMode) {
processDragOut(e, draggedTo, (Point) myPressPointScreen.clone(), dragOutStarted);
} else {
processDrag(e, draggedTo, (Point) myPressPointScreen.clone());
}
}
}
use of com.intellij.ui.awt.RelativePoint in project intellij-community by JetBrains.
the class Callout method showText.
public static void showText(JComponent component, int direction, String text) {
final RelativePoint point = new RelativePoint(component, new Point(component.getWidth() / 2, component.getHeight() / 2));
showText(point, direction, text);
}
Aggregations