public void processCellResized(
     RadContainer container, final boolean isRow, final int cell, final int newSize) {
   int cellCount = isRow ? container.getGridRowCount() : container.getGridColumnCount();
   if (container.getParent().isXY() && cell == cellCount - 1) {
     processRootContainerResize(container, isRow, newSize);
   } else {
     for (RadComponent component : container.getComponents()) {
       GridConstraints c = component.getConstraints();
       if (c.getCell(isRow) == cell && c.getSpan(isRow) == 1) {
         Dimension preferredSize = new Dimension(c.myPreferredSize);
         if (isRow) {
           preferredSize.height = newSize;
           if (preferredSize.width == -1) {
             preferredSize.width = component.getDelegee().getPreferredSize().width;
           }
         } else {
           preferredSize.width = newSize;
           if (preferredSize.height == -1) {
             preferredSize.height = component.getDelegee().getPreferredSize().height;
           }
         }
         PreferredSizeProperty.getInstance(container.getProject())
             .setValueEx(component, preferredSize);
       }
     }
   }
 }
  public static void paintComponentDecoration(
      final GuiEditor editor, final RadComponent component, final Graphics g) {
    // Collect selected components and paint decoration for non selected components
    final ArrayList<RadComponent> selection = new ArrayList<RadComponent>();
    final Rectangle layeredPaneRect = editor.getLayeredPane().getVisibleRect();
    FormEditingUtil.iterate(
        component,
        new FormEditingUtil.ComponentVisitor<RadComponent>() {
          public boolean visit(final RadComponent component) {
            if (!component.getDelegee().isShowing()) { // Skip invisible components
              return true;
            }
            final Shape oldClip = g.getClip();
            final RadContainer parent = component.getParent();
            if (parent != null) {
              final Point p =
                  SwingUtilities.convertPoint(
                      component.getDelegee(), 0, 0, editor.getLayeredPane());
              final Rectangle visibleRect =
                  layeredPaneRect.intersection(
                      new Rectangle(p.x, p.y, parent.getWidth(), parent.getHeight()));
              g.setClip(visibleRect);
            }
            if (component.isSelected()) { // we will paint selection later
              selection.add(component);
            } else {
              paintComponentBoundsImpl(editor, component, g);
            }
            paintGridOutline(editor, component, g);
            if (parent != null) {
              g.setClip(oldClip);
            }
            return true;
          }
        });

    // Let's paint decoration for selected components
    for (int i = selection.size() - 1; i >= 0; i--) {
      final Shape oldClip = g.getClip();
      final RadComponent c = selection.get(i);
      final RadContainer parent = c.getParent();
      if (parent != null) {
        final Point p = SwingUtilities.convertPoint(c.getDelegee(), 0, 0, editor.getLayeredPane());
        final Rectangle visibleRect =
            layeredPaneRect.intersection(
                new Rectangle(p.x, p.y, parent.getWidth(), parent.getHeight()));
        g.setClip(visibleRect);
      }
      paintComponentBoundsImpl(editor, c, g);
      if (parent != null) {
        g.setClip(oldClip);
      }
    }
  }
 @Override
 public boolean canCellGrow(RadContainer container, boolean isRow, int cellIndex) {
   final GridLayoutManager gridLayoutManager = ((GridLayoutManager) container.getLayout());
   int maxSizePolicy = 0;
   for (int i = 0; i < gridLayoutManager.getCellCount(isRow); i++) {
     maxSizePolicy = Math.max(maxSizePolicy, gridLayoutManager.getCellSizePolicy(isRow, i));
   }
   return gridLayoutManager.getCellSizePolicy(isRow, cellIndex) == maxSizePolicy;
 }
 @Override
 protected void changeLayoutFromGrid(
     final RadContainer container,
     final List<RadComponent> contents,
     final List<Boolean> canRowsGrow,
     final List<Boolean> canColumnsGrow) {
   int rowCount = Math.max(1, canRowsGrow.size());
   int columnCount = Math.max(1, canColumnsGrow.size());
   container.setLayoutManager(this, new GridLayoutManager(rowCount, columnCount));
 }
  /**
   * 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);
    }
  }
 private static void processRootContainerResize(
     final RadContainer container, final boolean isRow, final int newSize) {
   final JComponent parentDelegee = container.getDelegee();
   Dimension containerSize = parentDelegee.getSize();
   if (isRow) {
     containerSize.height = newSize + parentDelegee.getBounds().y;
   } else {
     containerSize.width = newSize + parentDelegee.getBounds().x;
   }
   parentDelegee.setSize(containerSize);
   parentDelegee.revalidate();
 }
  public void writeLayout(final XmlWriter writer, final RadContainer radContainer) {
    GridLayoutManager layout = (GridLayoutManager) radContainer.getLayout();

    writer.addAttribute("row-count", layout.getRowCount());
    writer.addAttribute("column-count", layout.getColumnCount());

    writer.addAttribute(
        UIFormXmlConstants.ATTRIBUTE_SAME_SIZE_HORIZONTALLY, layout.isSameSizeHorizontally());
    writer.addAttribute(
        UIFormXmlConstants.ATTRIBUTE_SAME_SIZE_VERTICALLY, layout.isSameSizeVertically());

    RadXYLayoutManager.INSTANCE.writeLayout(writer, radContainer);
  }
  /** This method paints grid bounds for "grid" containers */
  public static void paintGridOutline(
      final GuiEditor editor, @NotNull final RadComponent component, final Graphics g) {
    if (!editor.isShowGrid()) {
      return;
    }
    if (!(component instanceof RadContainer)) {
      return;
    }
    final RadContainer container = (RadContainer) component;
    if (!container.getLayoutManager().isGrid()) {
      return;
    }

    // performance: don't paint grid outline in drag layer
    Container parent = component.getDelegee().getParent();
    while (parent != null) {
      if (parent == editor.getDragLayer()) {
        return;
      }
      parent = parent.getParent();
    }

    final Point point =
        SwingUtilities.convertPoint(
            component.getDelegee(), 0, 0, editor.getRootContainer().getDelegee());
    g.translate(point.x, point.y);
    try {
      // Paint grid
      if (container.getWidth() > 0 && container.getHeight() > 0) {
        Image gridImage = CachedGridImage.getGridImage(container);
        g.drawImage(gridImage, 0, 0, null);
      }
    } finally {
      g.translate(-point.x, -point.y);
    }
  }
 public void addComponentToContainer(
     final RadContainer container, final RadComponent component, final int index) {
   super.addComponentToContainer(container, component, index);
   container.getDelegee().add(component.getDelegee(), component.getConstraints());
 }
 @Override
 protected void changeLayoutFromIndexed(
     final RadContainer container, final List<RadComponent> components) {
   container.setLayoutManager(this, new GridLayoutManager(1, Math.max(1, components.size())));
 }
 public void copyGridSection(
     final RadContainer source, final RadContainer destination, final Rectangle rc) {
   destination.setLayout(new GridLayoutManager(rc.height, rc.width));
 }
 public int[] getGridCellSizes(RadContainer container, boolean isRow) {
   GridLayoutManager grid = (GridLayoutManager) container.getLayout();
   return isRow ? grid.getHeights() : grid.getWidths();
 }
 public int[] getGridCellCoords(RadContainer container, boolean isRow) {
   GridLayoutManager grid = (GridLayoutManager) container.getLayout();
   return isRow ? grid.getYs() : grid.getXs();
 }
 @Override
 public int[] getVerticalGridLines(RadContainer container) {
   GridLayoutManager grid = (GridLayoutManager) container.getLayout();
   return grid.getVerticalGridLines();
 }
 @Override
 public int getGridColumnCount(RadContainer container) {
   return ((GridLayoutManager) container.getLayout()).getColumnCount();
 }