From b71707ef282c265542e2d555ecd82976232108e4 Mon Sep 17 00:00:00 2001 From: Alexander Lobas Date: Mon, 16 Apr 2012 22:00:02 +0400 Subject: [PATCH] TableLayout --- .../layout/TableLayoutOperation.java | 84 ++++++++++++++++++- 1 file changed, 82 insertions(+), 2 deletions(-) diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/TableLayoutOperation.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/TableLayoutOperation.java index a1246195d176..f0d700b7c228 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/TableLayoutOperation.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/TableLayoutOperation.java @@ -16,24 +16,104 @@ package com.intellij.android.designer.designSurface.layout; import com.intellij.android.designer.designSurface.AbstractEditOperation; +import com.intellij.android.designer.model.RadViewComponent; +import com.intellij.android.designer.model.table.RadTableLayoutComponent; +import com.intellij.designer.designSurface.FeedbackLayer; import com.intellij.designer.designSurface.OperationContext; import com.intellij.designer.model.RadComponent; +import javax.swing.*; +import java.awt.*; +import java.util.List; + /** * @author Alexander Lobas */ public class TableLayoutOperation extends AbstractEditOperation { + private GridFeedback myFeedback; + public TableLayoutOperation(RadComponent container, OperationContext context) { super(container, context); } + private void createFeedback() { + if (myFeedback == null) { + FeedbackLayer layer = myContext.getArea().getFeedbackLayer(); + myFeedback = new GridFeedback(); + myFeedback.setBounds(myContainer.getBounds(layer)); + layer.add(myFeedback); + layer.repaint(); + } + } + @Override public void showFeedback() { - // TODO: Auto-generated method stub + createFeedback(); } @Override public void eraseFeedback() { - // TODO: Auto-generated method stub + if (myFeedback != null) { + FeedbackLayer layer = myContext.getArea().getFeedbackLayer(); + layer.remove(myFeedback); + layer.repaint(); + myFeedback = null; + } + } + + ////////////////////////////////////////////////////////////////////////////////////////// + // + // Feedback + // + ////////////////////////////////////////////////////////////////////////////////////////// + + public static final Color COLOR = new Color(80, 110, 160); + + private class GridFeedback extends JComponent { + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + g.setColor(COLOR); + + Rectangle bounds = getBounds(); + bounds.x = bounds.y = 0; + + int[] columnWidths = ((RadTableLayoutComponent)myContainer).getColumnWidths(); + + if (columnWidths != null && columnWidths.length > 0) { + int x = bounds.x; + + for (int i = 0; i < columnWidths.length; i++) { + int width = columnWidths[i]; + + if (width > 0) { + x += width; + + if (i != columnWidths.length - 1 || x < bounds.getMinX()) { + g.drawLine(x, bounds.y, x, bounds.y + bounds.height); + } + } + else { + g.drawLine(x + 2, bounds.y, x + 2, bounds.y + bounds.height); + } + } + + bounds.width = Math.max(bounds.width, x - bounds.x); + } + + List children = myContainer.getChildren(); + RadComponent last = children.isEmpty() ? null : children.get(children.size() - 1); + + for (RadComponent child : children) { + Rectangle childBounds = child.getBounds(this); + int y = childBounds.y + childBounds.height + ((RadViewComponent)child).getMargins().height; + + if (child != last || y < bounds.getMaxY()) { + g.drawLine(bounds.x, y, bounds.x + bounds.width, y); + } + } + + g.drawRect(bounds.x, bounds.y, bounds.width, bounds.height); + } } } \ No newline at end of file