/** 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);
    }
  }
  public static void paintComponentTag(final RadComponent component, final Graphics g) {
    if (component instanceof RadContainer) return;
    for (IProperty prop : component.getModifiedProperties()) {
      if (prop.getName().equals(SwingProperties.TEXT)) {
        final Object desc = prop.getPropertyValue(component);
        if (!(desc instanceof StringDescriptor)
            || ((StringDescriptor) desc).getValue() == null
            || ((StringDescriptor) desc).getValue().length() > 0) {
          return;
        }
      } else if (prop.getName().equals(SwingProperties.MODEL)) {
        // don't paint tags on non-empty lists
        final Object value = prop.getPropertyValue(component);
        if (value instanceof String[] && ((String[]) value).length > 0) {
          return;
        }
      }
    }

    Rectangle bounds = component.getDelegee().getBounds();
    if (bounds.width > 100 && bounds.height > 40) {
      StringBuilder tagBuilder = new StringBuilder();
      if (component.getBinding() != null) {
        tagBuilder.append(component.getBinding()).append(':');
      }
      String className = component.getComponentClassName();
      int pos = className.lastIndexOf('.');
      if (pos >= 0) {
        tagBuilder.append(className.substring(pos + 1));
      } else {
        tagBuilder.append(className);
      }
      final Rectangle2D stringBounds = g.getFontMetrics().getStringBounds(tagBuilder.toString(), g);
      Graphics2D g2d = (Graphics2D) g;
      g2d.setColor(PlatformColors.BLUE);
      g2d.fillRect(0, 0, (int) stringBounds.getWidth(), (int) stringBounds.getHeight());
      g2d.setColor(Color.WHITE);
      g.drawString(tagBuilder.toString(), 0, g.getFontMetrics().getAscent());
    }
  }
  public static void paintButtonGroupLines(
      RadRootContainer rootContainer, RadButtonGroup group, Graphics g) {
    List<RadComponent> components = rootContainer.getGroupContents(group);
    if (components.size() < 2) return;
    Rectangle[] allBounds = new Rectangle[components.size()];
    int lastTop = -1;
    int minLeft = Integer.MAX_VALUE;
    for (int i = 0; i < components.size(); i++) {
      final Rectangle rc =
          SwingUtilities.convertRectangle(
              components.get(i).getParent().getDelegee(),
              components.get(i).getBounds(),
              rootContainer.getDelegee());
      allBounds[i] = rc;

      minLeft = Math.min(minLeft, rc.x);
      if (i == 0) {
        lastTop = rc.y;
      } else if (lastTop != rc.y) {
        lastTop = Integer.MIN_VALUE;
      }
    }

    Graphics2D g2d = (Graphics2D) g;
    Stroke oldStroke = g2d.getStroke();
    g2d.setStroke(new BasicStroke(2.0f));
    g2d.setColor(new Color(104, 107, 130));
    if (lastTop != Integer.MIN_VALUE) {
      // all items in group have same Y
      int left = Integer.MAX_VALUE;
      int right = Integer.MIN_VALUE;
      for (Rectangle rc : allBounds) {
        final int midX = (int) rc.getCenterX();
        left = Math.min(left, midX);
        right = Math.max(right, midX);
        g2d.drawLine(midX, lastTop - 8, midX, lastTop);
      }
      g2d.drawLine(left, lastTop - 8, right, lastTop - 8);
    } else {
      int top = Integer.MAX_VALUE;
      int bottom = Integer.MIN_VALUE;
      for (Rectangle rc : allBounds) {
        final int midY = (int) rc.getCenterY();
        top = Math.min(top, midY);
        bottom = Math.max(bottom, midY);
        g2d.drawLine(minLeft - 8, midY, rc.x, midY);
      }
      g2d.drawLine(minLeft - 8, top, minLeft - 8, bottom);
    }
    g2d.setStroke(oldStroke);
  }
  /**
   * 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);
    }
  }