notnull
authorAlexey Kudravtsev <cdr@intellij.com>
Wed, 1 Feb 2012 09:15:58 +0000 (13:15 +0400)
committerAlexey Kudravtsev <cdr@intellij.com>
Wed, 1 Feb 2012 09:20:31 +0000 (13:20 +0400)
platform/util/src/com/intellij/ui/awt/RelativePoint.java

index dcc24baad4b5fb9f843e994f01085beedabe510c..dad11a355004900b9ee965d597e96625d6d4e8e5 100644 (file)
@@ -15,6 +15,9 @@
  */
 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;
@@ -27,20 +30,20 @@ public class RelativePoint {
   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()) {
@@ -57,7 +60,7 @@ public class RelativePoint {
     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);
@@ -79,63 +82,73 @@ public class RelativePoint {
     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);