*/
package com.intellij.ui.awt;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
private Component myOriginalComponent;
private Point myOriginalPoint;
- public RelativePoint(MouseEvent event) {
+ public RelativePoint(@NotNull MouseEvent event) {
init(event.getComponent(), event.getPoint());
myOriginalComponent = event.getComponent();
myOriginalPoint = event.getPoint();
}
- public RelativePoint(Component aComponent, Point aPointOnComponent) {
+ public RelativePoint(@NotNull Component aComponent, Point aPointOnComponent) {
init(aComponent, aPointOnComponent);
}
- public RelativePoint(Point screenPoint) {
+ public RelativePoint(@NotNull Point screenPoint) {
Point p = new Point(screenPoint.x, screenPoint.y);
- Window[] windows = Frame.getWindows();
+ Window[] windows = Window.getWindows();
Window targetWindow = null;
for (Window each : windows) {
if (each.isActive()) {
init(targetWindow, p);
}
- private void init(Component aComponent, Point aPointOnComponent) {
+ private void init(@NotNull Component aComponent, Point aPointOnComponent) {
if (aComponent.isShowing()) {
myComponent = SwingUtilities.getRootPane(aComponent);
myPointOnComponent = SwingUtilities.convertPoint(aComponent, aPointOnComponent, myComponent);
return myPointOnComponent;
}
- public Point getPoint(Component aTargetComponent) {
+ public Point getPoint(@Nullable Component aTargetComponent) {
//todo: remove that after implementation of DND to html design time controls
if (aTargetComponent == null || aTargetComponent.getParent() == null || SwingUtilities.getWindowAncestor(aTargetComponent) == null) return new Point();
return SwingUtilities.convertPoint(getComponent(), getPoint(), aTargetComponent);
}
- public RelativePoint getPointOn(Component aTargetComponent) {
+ @NotNull
+ public RelativePoint getPointOn(@NotNull Component aTargetComponent) {
final Point point = getPoint(aTargetComponent);
return new RelativePoint(aTargetComponent, point);
}
+ @NotNull
public Point getScreenPoint() {
final Point point = (Point) getPoint().clone();
SwingUtilities.convertPointToScreen(point, getComponent());
return point;
}
+ @NotNull
public MouseEvent toMouseEvent() {
return new MouseEvent(myComponent, 0, 0, 0, myPointOnComponent.x, myPointOnComponent.y, 1, false);
}
+ @NotNull
public String toString() {
//noinspection HardCodedStringLiteral
return getPoint() + " on " + getComponent().toString();
}
- public static RelativePoint getCenterOf(JComponent component) {
+ @NotNull
+ public static RelativePoint getCenterOf(@NotNull JComponent component) {
final Rectangle visibleRect = component.getVisibleRect();
final Point point = new Point(visibleRect.x + visibleRect.width/2, visibleRect.y + visibleRect.height/2);
return new RelativePoint(component, point);
}
- public static RelativePoint getSouthEastOf(JComponent component) {
+ @NotNull
+ public static RelativePoint getSouthEastOf(@NotNull JComponent component) {
final Rectangle visibleRect = component.getVisibleRect();
final Point point = new Point(visibleRect.x + visibleRect.width, visibleRect.y + visibleRect.height);
return new RelativePoint(component, point);
}
- public static RelativePoint getSouthWestOf(JComponent component) {
+ @NotNull
+ public static RelativePoint getSouthWestOf(@NotNull JComponent component) {
final Rectangle visibleRect = component.getVisibleRect();
final Point point = new Point(visibleRect.x, visibleRect.y + visibleRect.height);
return new RelativePoint(component, point);
}
- public static RelativePoint getNorthWestOf(JComponent component) {
+ @NotNull
+ public static RelativePoint getNorthWestOf(@NotNull JComponent component) {
final Rectangle visibleRect = component.getVisibleRect();
final Point point = new Point(visibleRect.x, visibleRect.y);
return new RelativePoint(component, point);
}
- public static RelativePoint getNorthEastOf(JComponent component) {
+ @NotNull
+ public static RelativePoint getNorthEastOf(@NotNull JComponent component) {
final Rectangle visibleRect = component.getVisibleRect();
final Point point = new Point(visibleRect.x + visibleRect.width, visibleRect.y);
return new RelativePoint(component, point);
}
+ @NotNull
public static RelativePoint fromScreen(Point screenPoint) {
Frame root = JOptionPane.getRootFrame();
SwingUtilities.convertPointFromScreen(screenPoint, root);