/** Paints selection for the specified <code>component</code>. */
  public static void paintSelectionDecoration(
      @NotNull RadComponent component, Graphics g, boolean focused) {
    if (component.isSelected()) {
      if (focused) {
        g.setColor(PlatformColors.BLUE);
      } else {
        g.setColor(Color.GRAY);
      }
      final Point[] points = getPoints(component.getWidth(), component.getHeight());
      for (final Point point : points) {
        g.fillRect(point.x - R, point.y - R, 2 * R + 1, 2 * R + 1);
      }
    } else if (component.getWidth() < FormEditingUtil.EMPTY_COMPONENT_SIZE
        || component.getHeight() < FormEditingUtil.EMPTY_COMPONENT_SIZE) {
      Graphics2D g2d = (Graphics2D) g;
      Composite oldComposite = g2d.getComposite();
      Stroke oldStroke = g2d.getStroke();
      Color oldColor = g2d.getColor();

      g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f));
      g2d.setStroke(new BasicStroke(0.7f));
      g2d.setColor(Color.black);
      g2d.drawRect(
          0,
          0,
          Math.max(component.getWidth(), FormEditingUtil.EMPTY_COMPONENT_SIZE),
          Math.max(component.getHeight(), FormEditingUtil.EMPTY_COMPONENT_SIZE));

      g2d.setComposite(oldComposite);
      g2d.setStroke(oldStroke);
      g2d.setColor(oldColor);
    }
  }
  /**
   * Paints container border. For grids the method also paints vertical and horizontal lines that
   * indicate bounds of the rows and columns. Method does nothing if the <code>component</code> is
   * not an instance of <code>RadContainer</code>.
   */
  private static void paintComponentBoundsImpl(
      final GuiEditor editor, @NotNull final RadComponent component, final Graphics g) {
    if (!(component instanceof RadContainer)
        && !(component instanceof RadNestedForm)
        && !component.isDragBorder()) {
      return;
    }

    boolean highlightBoundaries = (getDesignTimeInsets(component) > 2);

    if (component instanceof RadContainer && !component.isDragBorder()) {
      RadContainer container = (RadContainer) component;
      if (!highlightBoundaries
          && (container.getBorderTitle() != null || container.getBorderType() != BorderType.NONE)) {
        return;
      }
    }
    final Point point =
        SwingUtilities.convertPoint(
            component.getDelegee(), 0, 0, editor.getRootContainer().getDelegee());
    g.translate(point.x, point.y);
    try {
      if (component.isDragBorder()) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.setColor(LightColors.YELLOW);
        g2d.setStroke(new BasicStroke(2.0f));
        g2d.translate(1, 1);
      } else if (highlightBoundaries) {
        g.setColor(HIGHLIGHTED_BOUNDARY_COLOR);
      } else if (component.isSelected()) {
        g.setColor(SELECTED_BOUNDARY_COLOR);
      } else {
        g.setColor(NON_SELECTED_BOUNDARY_COLOR);
      }
      g.drawRect(0, 0, component.getWidth() - 1, component.getHeight() - 1);
      if (component.isDragBorder()) {
        g.translate(-1, -1);
      }
    } finally {
      g.translate(-point.x, -point.y);
    }
  }
  /**
   * @param x in component's coord system
   * @param y in component's coord system
   */
  public static int getResizeMask(@NotNull final RadComponent component, final int x, final int y) {
    if (component.getParent() == null || !component.isSelected()) {
      return 0;
    }

    // only components in XY can be resized...
    /*
    if (!component.getParent().isXY()) {
      return 0;
    }
    */

    final int width = component.getWidth();
    final int height = component.getHeight();

    final Point[] points = getPoints(width, height);

    if (isInside(x, y, points[SE])) {
      return EAST_MASK | SOUTH_MASK;
    } else if (isInside(x, y, points[NW])) {
      return WEST_MASK | NORTH_MASK;
    } else if (isInside(x, y, points[N])) {
      return NORTH_MASK;
    } else if (isInside(x, y, points[NE])) {
      return EAST_MASK | NORTH_MASK;
    } else if (isInside(x, y, points[W])) {
      return WEST_MASK;
    } else if (isInside(x, y, points[E])) {
      return EAST_MASK;
    } else if (isInside(x, y, points[SW])) {
      return WEST_MASK | SOUTH_MASK;
    } else if (isInside(x, y, points[S])) {
      return SOUTH_MASK;
    } else {
      return 0;
    }
  }