GridLayout
authorAlexander Lobas <Alexander.Lobas@jetbrains.com>
Mon, 23 Apr 2012 17:48:04 +0000 (21:48 +0400)
committerAlexander Lobas <Alexander.Lobas@jetbrains.com>
Mon, 23 Apr 2012 17:48:04 +0000 (21:48 +0400)
23 files changed:
plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/GridDecorator.java [moved from plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/TableLayoutDecorator.java with 83% similarity]
plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/GridLayoutOperation.java [new file with mode: 0644]
plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/HorizontalCaptionFlowBaseOperation.java
plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/LayoutMarginOperation.java
plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/LayoutSpanOperation.java
plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/TableLayoutOperation.java
plugins/android-designer/src/com/intellij/android/designer/model/RadViewComponent.java
plugins/android-designer/src/com/intellij/android/designer/model/agrid/GridInfo.java [moved from plugins/android-designer/src/com/intellij/android/designer/model/table/GridInfo.java with 95% similarity]
plugins/android-designer/src/com/intellij/android/designer/model/agrid/GridInsertType.java [moved from plugins/android-designer/src/com/intellij/android/designer/model/table/GridInsertType.java with 94% similarity]
plugins/android-designer/src/com/intellij/android/designer/model/agrid/IGridProvider.java [new file with mode: 0644]
plugins/android-designer/src/com/intellij/android/designer/model/agrid/RadCaptionColumn.java [new file with mode: 0644]
plugins/android-designer/src/com/intellij/android/designer/model/agrid/RadCaptionComponent.java [new file with mode: 0644]
plugins/android-designer/src/com/intellij/android/designer/model/agrid/RadCaptionRow.java [new file with mode: 0644]
plugins/android-designer/src/com/intellij/android/designer/model/grid/RadCaptionGridColumn.java [new file with mode: 0644]
plugins/android-designer/src/com/intellij/android/designer/model/grid/RadCaptionGridRow.java [new file with mode: 0644]
plugins/android-designer/src/com/intellij/android/designer/model/grid/RadGridLayout.java
plugins/android-designer/src/com/intellij/android/designer/model/grid/RadGridLayoutComponent.java
plugins/android-designer/src/com/intellij/android/designer/model/table/RadCaptionTableColumn.java
plugins/android-designer/src/com/intellij/android/designer/model/table/RadTableLayout.java
plugins/android-designer/src/com/intellij/android/designer/model/table/RadTableLayoutComponent.java
plugins/android-designer/src/com/intellij/android/designer/model/table/RadTableRowLayout.java
plugins/android-designer/src/com/intellij/android/designer/model/views-meta-model.xml
plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/selection/EmptyPoint.java [new file with mode: 0644]

similarity index 83%
rename from plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/TableLayoutDecorator.java
rename to plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/GridDecorator.java
index 72c5dde6a686e48914822d8b7cfba4a7820a50eb..a98727888bcf72c03d652199d9fed135636cbb04 100644 (file)
@@ -15,8 +15,8 @@
  */
 package com.intellij.android.designer.designSurface.layout;
 
-import com.intellij.android.designer.model.table.GridInfo;
-import com.intellij.android.designer.model.table.RadTableLayoutComponent;
+import com.intellij.android.designer.model.agrid.GridInfo;
+import com.intellij.android.designer.model.agrid.IGridProvider;
 import com.intellij.designer.designSurface.DecorationLayer;
 import com.intellij.designer.designSurface.StaticDecorator;
 import com.intellij.designer.model.RadComponent;
@@ -26,8 +26,8 @@ import java.awt.*;
 /**
  * @author Alexander Lobas
  */
-public class TableLayoutDecorator extends StaticDecorator {
-  public TableLayoutDecorator(RadComponent component) {
+public class GridDecorator extends StaticDecorator {
+  public GridDecorator(RadComponent component) {
     super(component);
   }
 
@@ -38,7 +38,7 @@ public class TableLayoutDecorator extends StaticDecorator {
     g.setStroke(FlowStaticDecorator.STROKE);
 
     Rectangle bounds = component.getBounds(layer);
-    GridInfo gridInfo = ((RadTableLayoutComponent)component).getGridInfo();
+    GridInfo gridInfo = ((IGridProvider)component).getGridInfo();
 
     for (int x : gridInfo.vLines) {
       g.drawLine(bounds.x + x, bounds.y, bounds.x + x, bounds.y + gridInfo.height);
diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/GridLayoutOperation.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/GridLayoutOperation.java
new file mode 100644 (file)
index 0000000..baa2bfe
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.android.designer.designSurface.layout;
+
+import com.intellij.android.designer.designSurface.AbstractEditOperation;
+import com.intellij.designer.designSurface.OperationContext;
+import com.intellij.designer.model.RadComponent;
+
+/**
+ * @author Alexander Lobas
+ */
+public class GridLayoutOperation extends AbstractEditOperation {
+  public GridLayoutOperation(RadComponent container, OperationContext context) {
+    super(container, context);
+  }
+
+  @Override
+  public void showFeedback() {
+    // TODO: Auto-generated method stub
+  }
+
+  @Override
+  public void eraseFeedback() {
+    // TODO: Auto-generated method stub
+  }
+}
\ No newline at end of file
index 0994f3c2b5130fc0330fb9d27d1681ff0f4ee85e..b12944f7bf59b5ff338aa8abdc80562da5a1c277 100644 (file)
@@ -105,7 +105,7 @@ public class HorizontalCaptionFlowBaseOperation extends FlowBaseOperation {
 
         List<RadViewComponent> editComponents = new ArrayList<RadViewComponent>();
         for (RadComponent component : myComponents) {
-          int column = ((RadCaptionTableColumn)component).getColumnIndex();
+          int column = ((RadCaptionTableColumn)component).getIndex();
           RadViewComponent editComponent = (RadViewComponent)rowComponents[column];
           if (editComponent != null) {
             editComponents.add(editComponent);
@@ -118,7 +118,7 @@ public class HorizontalCaptionFlowBaseOperation extends FlowBaseOperation {
 
         RadViewComponent insertBeforeColumn = null;
         if (insertBefore != null) {
-          int column = ((RadCaptionTableColumn)insertBefore).getColumnIndex();
+          int column = ((RadCaptionTableColumn)insertBefore).getIndex();
           for (int j = column; j < rowComponents.length; j++) {
             insertBeforeColumn = (RadViewComponent)rowComponents[j];
             if (insertBeforeColumn != null) {
@@ -150,7 +150,7 @@ public class HorizontalCaptionFlowBaseOperation extends FlowBaseOperation {
     List<RadComponent> columns = myContainer.getChildren();
     int size = columns.size();
     for (int i = 0; i < size; i++) {
-      int index = ((RadCaptionTableColumn)columns.get(i)).getColumnIndex();
+      int index = ((RadCaptionTableColumn)columns.get(i)).getIndex();
 
       for (int j = 0; j < components.length; j++) {
         if (RadTableRowLayout.is(rows.get(j))) {
index bfbaa7a8b794b7d27b67fbc345474a4f6169087c..153ed19e140b7097bdeb12fcbd0bb64692106bd0 100644 (file)
@@ -25,9 +25,8 @@ import com.intellij.designer.designSurface.feedbacks.LineMarginBorder;
 import com.intellij.designer.designSurface.feedbacks.RectangleFeedback;
 import com.intellij.designer.designSurface.feedbacks.TextFeedback;
 import com.intellij.designer.designSurface.selection.DirectionResizePoint;
-import com.intellij.designer.designSurface.selection.ResizePoint;
+import com.intellij.designer.designSurface.selection.EmptyPoint;
 import com.intellij.designer.designSurface.selection.ResizeSelectionDecorator;
-import com.intellij.designer.designSurface.tools.InputTool;
 import com.intellij.designer.model.RadComponent;
 import com.intellij.designer.utils.Position;
 import com.intellij.openapi.application.ApplicationManager;
@@ -192,8 +191,6 @@ public class LayoutMarginOperation implements EditOperation {
   //
   //////////////////////////////////////////////////////////////////////////////////////////
 
-  private static final BasicStroke STROKE = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, new float[]{1, 2}, 0);
-
   public static void points(ResizeSelectionDecorator decorator) {
     pointFeedback(decorator);
 
@@ -220,8 +217,10 @@ public class LayoutMarginOperation implements EditOperation {
     pointBottom(decorator, Color.orange, 0.25, TYPE, "Change layout:margin.bottom");
   }
 
+  public static final BasicStroke STROKE = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1, new float[]{1, 2}, 0);
+
   protected static void pointFeedback(ResizeSelectionDecorator decorator) {
-    decorator.addPoint(new ResizePoint() {
+    decorator.addPoint(new EmptyPoint() {
       @Override
       protected void paint(DecorationLayer layer, Graphics2D g, RadComponent component) {
         Rectangle bounds = component.getBounds(layer);
@@ -231,26 +230,6 @@ public class LayoutMarginOperation implements EditOperation {
         g.setColor(Color.red);
         g.drawRect(bounds.x, bounds.y, bounds.width, bounds.height);
       }
-
-      @Override
-      public InputTool findTargetTool(DecorationLayer layer, RadComponent component, int x, int y) {
-        return null;
-      }
-
-      @Override
-      public Object getType() {
-        return null;
-      }
-
-      @Override
-      protected InputTool createTool(RadComponent component) {
-        return null;
-      }
-
-      @Override
-      protected Point getLocation(DecorationLayer layer, RadComponent component) {
-        return null;
-      }
     });
   }
 
index a6d4c6c55a647ec98c51c5631eabd08dd2802bd0..6595a295b5892390fe20e87be2b950262e3f2098 100644 (file)
@@ -17,8 +17,9 @@ package com.intellij.android.designer.designSurface.layout;
 
 import com.intellij.android.designer.model.ModelParser;
 import com.intellij.android.designer.model.RadViewComponent;
-import com.intellij.android.designer.model.table.GridInfo;
+import com.intellij.android.designer.model.agrid.GridInfo;
 import com.intellij.android.designer.model.table.RadTableLayoutComponent;
+import com.intellij.designer.designSurface.DecorationLayer;
 import com.intellij.designer.designSurface.EditOperation;
 import com.intellij.designer.designSurface.FeedbackLayer;
 import com.intellij.designer.designSurface.OperationContext;
@@ -26,6 +27,7 @@ import com.intellij.designer.designSurface.feedbacks.LineMarginBorder;
 import com.intellij.designer.designSurface.feedbacks.RectangleFeedback;
 import com.intellij.designer.designSurface.feedbacks.TextFeedback;
 import com.intellij.designer.designSurface.selection.DirectionResizePoint;
+import com.intellij.designer.designSurface.selection.EmptyPoint;
 import com.intellij.designer.designSurface.selection.ResizeSelectionDecorator;
 import com.intellij.designer.model.RadComponent;
 import com.intellij.designer.utils.Position;
@@ -244,8 +246,60 @@ public class LayoutSpanOperation implements EditOperation {
     });
   }
 
-  public static void points(ResizeSelectionDecorator decorator) {
-    decorator.addPoint(new DirectionResizePoint(COLOR, Color.black, Position.WEST, TYPE, "Change layout:column x layout:span"));
-    decorator.addPoint(new DirectionResizePoint(COLOR, Color.black, Position.EAST, TYPE, "Change layout:span"));
+  //////////////////////////////////////////////////////////////////////////////////////////
+  //
+  // ResizePoint
+  //
+  //////////////////////////////////////////////////////////////////////////////////////////
+
+  public static void tablePoints(ResizeSelectionDecorator decorator) {
+    decorator.addPoint(new DirectionResizePoint(COLOR,
+                                                Color.black,
+                                                Position.WEST,
+                                                TYPE,
+                                                "Change layout:column x layout:span")); // left
+
+    decorator.addPoint(new DirectionResizePoint(COLOR,
+                                                Color.black,
+                                                Position.EAST,
+                                                TYPE,
+                                                "Change layout:span")); // right
+  }
+
+  public static void gridPoints(ResizeSelectionDecorator decorator) {
+    decorator.addPoint(new EmptyPoint() {
+      @Override
+      protected void paint(DecorationLayer layer, Graphics2D g, RadComponent component) {
+        Rectangle bounds = component.getBounds(layer);
+
+        g.setStroke(LayoutMarginOperation.STROKE);
+        g.setColor(COLOR);
+        g.drawRect(bounds.x, bounds.y, bounds.width, bounds.height);
+      }
+    });
+
+    decorator.addPoint(new DirectionResizePoint(COLOR,
+                                                Color.black,
+                                                Position.WEST,
+                                                TYPE,
+                                                "Change layout:column x layout:columnSpan")); // left
+
+    decorator.addPoint(new DirectionResizePoint(COLOR,
+                                                Color.black,
+                                                Position.EAST,
+                                                TYPE,
+                                                "Change layout:columnSpan").move(1, 0.25)); // right
+
+    decorator.addPoint(new DirectionResizePoint(COLOR,
+                                                Color.black,
+                                                Position.NORTH,
+                                                TYPE,
+                                                "Change layout:row x layout:rowSpan")); // top
+
+    decorator.addPoint(new DirectionResizePoint(COLOR,
+                                                Color.black,
+                                                Position.SOUTH,
+                                                TYPE,
+                                                "Change layout:rowSpan").move(0.25, 1)); // bottom
   }
 }
\ No newline at end of file
index a72e24b76d2ad49baa20e35c792f29966f1fad58..da860f0edd0bad5a9a28fa745d05b0efb583db96 100644 (file)
@@ -19,8 +19,8 @@ import com.intellij.android.designer.designSurface.AbstractEditOperation;
 import com.intellij.android.designer.model.ModelParser;
 import com.intellij.android.designer.model.RadViewComponent;
 import com.intellij.android.designer.model.ViewsMetaManager;
-import com.intellij.android.designer.model.table.GridInfo;
-import com.intellij.android.designer.model.table.GridInsertType;
+import com.intellij.android.designer.model.agrid.GridInfo;
+import com.intellij.android.designer.model.agrid.GridInsertType;
 import com.intellij.android.designer.model.table.RadTableLayoutComponent;
 import com.intellij.android.designer.model.table.RadTableRowLayout;
 import com.intellij.designer.designSurface.FeedbackLayer;
index 4335fee51b228a12d97cc33202c187fa4262eec0..1154fd2da3e1025e3a163725a03464a2731a80d0 100644 (file)
@@ -82,10 +82,10 @@ public class RadViewComponent extends RadVisualComponent {
         Object layoutParams = myViewInfo.getLayoutParamsObject();
         Class<?> layoutClass = layoutParams.getClass();
 
-        myMargins.x = layoutClass.getField("leftMargin").getInt(layoutParams);
-        myMargins.y = layoutClass.getField("topMargin").getInt(layoutParams);
-        myMargins.width = layoutClass.getField("rightMargin").getInt(layoutParams);
-        myMargins.height = layoutClass.getField("bottomMargin").getInt(layoutParams);
+        myMargins.x = fixDefault(layoutClass.getField("leftMargin").getInt(layoutParams));
+        myMargins.y = fixDefault(layoutClass.getField("topMargin").getInt(layoutParams));
+        myMargins.width = fixDefault(layoutClass.getField("rightMargin").getInt(layoutParams));
+        myMargins.height = fixDefault(layoutClass.getField("bottomMargin").getInt(layoutParams));
       }
       catch (Throwable e) {
       }
@@ -93,6 +93,10 @@ public class RadViewComponent extends RadVisualComponent {
     return myMargins;
   }
 
+  private static int fixDefault(int value) {
+    return value == Integer.MIN_VALUE ? 0 : value;
+  }
+
   @Override
   public void delete() throws Exception {
     removeFromParent();
similarity index 95%
rename from plugins/android-designer/src/com/intellij/android/designer/model/table/GridInfo.java
rename to plugins/android-designer/src/com/intellij/android/designer/model/agrid/GridInfo.java
index 4ba882ac69c64158b4b02f22b7178b89dd1e3d43..a3e31a5541fea28d25b0439972d24821ffdea343 100644 (file)
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package com.intellij.android.designer.model.table;
+package com.intellij.android.designer.model.agrid;
 
 import com.intellij.designer.model.RadComponent;
 import com.intellij.util.ArrayUtil;
similarity index 94%
rename from plugins/android-designer/src/com/intellij/android/designer/model/table/GridInsertType.java
rename to plugins/android-designer/src/com/intellij/android/designer/model/agrid/GridInsertType.java
index b7ccde6f316e7f4ef7ecafcc61e083a0588e5b1f..85031d642f361b8c4254a2f05654e33961540d75 100644 (file)
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package com.intellij.android.designer.model.table;
+package com.intellij.android.designer.model.agrid;
 
 /**
  * @author Alexander Lobas
diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/agrid/IGridProvider.java b/plugins/android-designer/src/com/intellij/android/designer/model/agrid/IGridProvider.java
new file mode 100644 (file)
index 0000000..c68d67f
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.android.designer.model.agrid;
+
+/**
+ * @author Alexander Lobas
+ */
+public interface IGridProvider {
+  GridInfo getGridInfo();
+}
\ No newline at end of file
diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/agrid/RadCaptionColumn.java b/plugins/android-designer/src/com/intellij/android/designer/model/agrid/RadCaptionColumn.java
new file mode 100644 (file)
index 0000000..254037d
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.android.designer.model.agrid;
+
+import com.intellij.android.designer.model.RadViewComponent;
+
+import java.awt.*;
+
+/**
+ * @author Alexander Lobas
+ */
+public abstract class RadCaptionColumn<T extends RadViewComponent> extends RadCaptionComponent<T> {
+  public RadCaptionColumn(T container, int index, int offset, int width, boolean empty) {
+    super(container, index, offset, width, empty);
+  }
+
+  @Override
+  public Rectangle getBounds() {
+    Rectangle bounds = myContainer.getBounds();
+    return new Rectangle(bounds.x + myOffset, 2, myWidth, 10);
+  }
+
+  @Override
+  public Rectangle getBounds(Component relativeTo) {
+    Rectangle bounds = super.getBounds(relativeTo);
+    bounds.y = 2;
+    bounds.height = 10;
+    return bounds;
+  }
+}
\ No newline at end of file
diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/agrid/RadCaptionComponent.java b/plugins/android-designer/src/com/intellij/android/designer/model/agrid/RadCaptionComponent.java
new file mode 100644 (file)
index 0000000..5c3d87d
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.android.designer.model.agrid;
+
+import com.intellij.android.designer.designSurface.layout.CaptionStaticDecorator;
+import com.intellij.android.designer.model.RadViewComponent;
+import com.intellij.designer.designSurface.StaticDecorator;
+import com.intellij.designer.model.RadComponent;
+import com.intellij.designer.model.RadVisualComponent;
+
+import java.awt.*;
+import java.util.List;
+
+/**
+ * @author Alexander Lobas
+ */
+public abstract class RadCaptionComponent<T extends RadViewComponent> extends RadVisualComponent {
+  private final StaticDecorator myDecorator;
+  protected final T myContainer;
+  protected final int myIndex;
+  protected final int myOffset;
+  protected final int myWidth;
+
+  public RadCaptionComponent(T container, int index, int offset, int width, boolean empty) {
+    myContainer = container;
+    myIndex = index;
+    myOffset = offset;
+    myWidth = width;
+
+    if (empty) {
+      myDecorator = new CaptionStaticDecorator(this, Color.PINK);
+    }
+    else {
+      myDecorator = new CaptionStaticDecorator(this);
+    }
+
+    setNativeComponent(container.getNativeComponent());
+  }
+
+  public int getIndex() {
+    return myIndex;
+  }
+
+  @Override
+  public void addStaticDecorators(List<StaticDecorator> decorators, List<RadComponent> selection) {
+    decorators.add(myDecorator);
+  }
+}
\ No newline at end of file
diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/agrid/RadCaptionRow.java b/plugins/android-designer/src/com/intellij/android/designer/model/agrid/RadCaptionRow.java
new file mode 100644 (file)
index 0000000..04443bf
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.android.designer.model.agrid;
+
+import com.intellij.android.designer.model.RadViewComponent;
+
+import java.awt.*;
+
+/**
+ * @author Alexander Lobas
+ */
+public abstract class RadCaptionRow<T extends RadViewComponent> extends RadCaptionComponent<T> {
+  public RadCaptionRow(T container, int index, int offset, int width, boolean empty) {
+    super(container, index, offset, width, empty);
+  }
+
+  @Override
+  public Rectangle getBounds() {
+    Rectangle bounds = myContainer.getBounds();
+    return new Rectangle(2, bounds.y + myOffset, 10, myWidth);
+  }
+
+  @Override
+  public Rectangle getBounds(Component relativeTo) {
+    Rectangle bounds = super.getBounds(relativeTo);
+    bounds.x = 2;
+    bounds.width = 10;
+    return bounds;
+  }
+}
\ No newline at end of file
diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/grid/RadCaptionGridColumn.java b/plugins/android-designer/src/com/intellij/android/designer/model/grid/RadCaptionGridColumn.java
new file mode 100644 (file)
index 0000000..b250e41
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.android.designer.model.grid;
+
+import com.intellij.android.designer.model.agrid.RadCaptionColumn;
+
+/**
+ * @author Alexander Lobas
+ */
+public class RadCaptionGridColumn extends RadCaptionColumn<RadGridLayoutComponent> {
+  public RadCaptionGridColumn(RadGridLayoutComponent container, int index, int offset, int width) {
+    super(container, index, offset, width, false);
+  }
+}
\ No newline at end of file
diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/grid/RadCaptionGridRow.java b/plugins/android-designer/src/com/intellij/android/designer/model/grid/RadCaptionGridRow.java
new file mode 100644 (file)
index 0000000..0e6b450
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.android.designer.model.grid;
+
+import com.intellij.android.designer.model.agrid.RadCaptionRow;
+
+/**
+ * @author Alexander Lobas
+ */
+public class RadCaptionGridRow extends RadCaptionRow<RadGridLayoutComponent> {
+  public RadCaptionGridRow(RadGridLayoutComponent container, int index, int offset, int width) {
+    super(container, index, offset, width, false);
+  }
+}
\ No newline at end of file
index 9ad9a94c22556e96a00714152b75d8947b0d43e2..8161cbec054635e32728d6c7ef2b57ded84e595c 100644 (file)
 package com.intellij.android.designer.model.grid;
 
 import com.intellij.android.designer.designSurface.TreeDropToOperation;
+import com.intellij.android.designer.designSurface.layout.GridDecorator;
+import com.intellij.android.designer.designSurface.layout.GridLayoutOperation;
+import com.intellij.android.designer.designSurface.layout.LayoutSpanOperation;
+import com.intellij.android.designer.designSurface.layout.ResizeOperation;
+import com.intellij.android.designer.model.RadViewLayout;
 import com.intellij.android.designer.model.RadViewLayoutWithData;
+import com.intellij.android.designer.model.agrid.GridInfo;
 import com.intellij.designer.componentTree.TreeEditOperation;
-import com.intellij.designer.designSurface.EditOperation;
-import com.intellij.designer.designSurface.OperationContext;
+import com.intellij.designer.designSurface.*;
+import com.intellij.designer.designSurface.selection.ResizeSelectionDecorator;
+import com.intellij.designer.model.RadComponent;
+import com.intellij.designer.model.RadLayout;
+import com.intellij.openapi.actionSystem.DefaultActionGroup;
 import org.jetbrains.annotations.NotNull;
 
+import javax.swing.*;
+import java.awt.*;
+import java.util.ArrayList;
+import java.util.List;
+
 /**
  * @author Alexander Lobas
  */
-public class RadGridLayout extends RadViewLayoutWithData {
+public class RadGridLayout extends RadViewLayoutWithData implements ILayoutDecorator, ICaption, ICaptionDecorator {
   private static final String[] LAYOUT_PARAMS = {"GridLayout_Layout", "ViewGroup_MarginLayout"};
 
+  private GridDecorator myGridDecorator;
+  private ResizeSelectionDecorator mySelectionDecorator;
+
   @NotNull
   @Override
   public String[] getLayoutParams() {
@@ -43,9 +60,129 @@ public class RadGridLayout extends RadViewLayoutWithData {
         }
         return null;
       }
-      // XXX
-      return null;
+      return new GridLayoutOperation(myContainer, context);
+    }
+    if (context.is(ResizeOperation.TYPE)) {
+      return new ResizeOperation(context);
+    }
+    if (context.is(LayoutSpanOperation.TYPE)) {
+      return new LayoutSpanOperation(context);
     }
     return null;
   }
+
+  private StaticDecorator getGridDecorator() {
+    if (myGridDecorator == null) {
+      myGridDecorator = new GridDecorator(myContainer);
+    }
+    return myGridDecorator;
+  }
+
+  @Override
+  public void addStaticDecorators(List<StaticDecorator> decorators, List<RadComponent> selection) {
+    if (selection.contains(myContainer)) {
+      if (!(myContainer.getParent().getLayout() instanceof ILayoutDecorator)) {
+        decorators.add(getGridDecorator());
+      }
+    }
+    else {
+      for (RadComponent component : selection) {
+        if (component.getParent() == myContainer) {
+          decorators.add(getGridDecorator());
+          return;
+        }
+      }
+      super.addStaticDecorators(decorators, selection);
+    }
+  }
+
+  @Override
+  public ComponentDecorator getChildSelectionDecorator(RadComponent component, List<RadComponent> selection) {
+    if (mySelectionDecorator == null) {
+      mySelectionDecorator = new ResizeSelectionDecorator(Color.red, 1);
+    }
+
+    mySelectionDecorator.clear();
+    if (selection.size() == 1) {
+      LayoutSpanOperation.gridPoints(mySelectionDecorator);
+    }
+    ResizeOperation.points(mySelectionDecorator);
+
+    return mySelectionDecorator;
+  }
+
+  //////////////////////////////////////////////////////////////////////////////////////////
+  //
+  // Actions
+  //
+  //////////////////////////////////////////////////////////////////////////////////////////
+
+  @Override
+  public void addContainerSelectionActions(DesignerEditorPanel designer,
+                                           DefaultActionGroup actionGroup,
+                                           JComponent shortcuts,
+                                           List<RadComponent> selection) {
+    super.addContainerSelectionActions(designer, actionGroup, shortcuts, selection); // TODO: Auto-generated method stub
+  }
+
+  @Override
+  public void addSelectionActions(DesignerEditorPanel designer,
+                                  DefaultActionGroup actionGroup,
+                                  JComponent shortcuts,
+                                  List<RadComponent> selection) {
+    super.addSelectionActions(designer, actionGroup, shortcuts, selection); // TODO: Auto-generated method stub
+  }
+
+  //////////////////////////////////////////////////////////////////////////////////////////
+  //
+  // Caption
+  //
+  //////////////////////////////////////////////////////////////////////////////////////////
+
+  @Override
+  public ICaption getCaption(RadComponent component) {
+    if (myContainer == component && myContainer.getParent().getLayout() instanceof ICaptionDecorator) {
+      return null;
+    }
+    if (myContainer.getChildren().isEmpty()) {
+      return null;
+    }
+    return this;
+  }
+
+  @NotNull
+  @Override
+  public List<RadComponent> getCaptionChildren(EditableArea mainArea, boolean horizontal) {
+    RadGridLayoutComponent container = (RadGridLayoutComponent)myContainer;
+    GridInfo gridInfo = container.getGridInfo();
+    List<RadComponent> components = new ArrayList<RadComponent>();
+
+    if (horizontal) {
+      int[] lines = gridInfo.vLines;
+      for (int i = 0; i < lines.length - 1; i++) {
+        components.add(new RadCaptionGridColumn(container,
+                                                i,
+                                                lines[i],
+                                                lines[i + 1] - lines[i]));
+      }
+    }
+    else {
+      int[] lines = gridInfo.hLines;
+      for (int i = 0; i < lines.length - 1; i++) {
+        components.add(new RadCaptionGridRow(container,
+                                             i,
+                                             lines[i],
+                                             lines[i + 1] - lines[i]));
+      }
+    }
+
+    return components;
+  }
+
+  @NotNull
+  @Override
+  public RadLayout getCaptionLayout(EditableArea mainArea, boolean horizontal) {
+    // XXX
+    return RadViewLayout.INSTANCE;
+  }
 }
\ No newline at end of file
index 7cd3da281949b806c4ecd83e723c4e5402ba0eaa..d42b79ac0a667dcbff1532918fa81be00fa937a4 100644 (file)
  */
 package com.intellij.android.designer.model.grid;
 
+import com.android.ide.common.rendering.api.ViewInfo;
 import com.intellij.android.designer.model.RadViewContainer;
+import com.intellij.android.designer.model.agrid.GridInfo;
+import com.intellij.android.designer.model.agrid.IGridProvider;
+import com.intellij.designer.model.RadComponent;
+
+import java.awt.*;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
 
 /**
  * @author Alexander Lobas
  */
-public class RadGridLayoutComponent extends RadViewContainer {
+public class RadGridLayoutComponent extends RadViewContainer implements IGridProvider {
+  private GridInfo myGridInfo;
+
+  @Override
+  public void setViewInfo(ViewInfo viewInfo) {
+    super.setViewInfo(viewInfo);
+    myGridInfo = null;
+  }
+
+  @Override
+  public GridInfo getGridInfo() {
+    if (myGridInfo == null) {
+      myGridInfo = new GridInfo();
+
+      try {
+        Object viewObject = myViewInfo.getViewObject();
+        Class<?> viewClass = viewObject.getClass();
+
+        Method getColumnCount = viewClass.getMethod("getColumnCount");
+        myGridInfo.lastColumn = (Integer)getColumnCount.invoke(viewObject) - 1;
+
+        Method getRowCount = viewClass.getMethod("getRowCount");
+        myGridInfo.lastRow = (Integer)getRowCount.invoke(viewObject) - 1;
+
+        Field field_horizontalAxis = viewClass.getDeclaredField("horizontalAxis");
+        field_horizontalAxis.setAccessible(true);
+        Object horizontalAxis = field_horizontalAxis.get(viewObject);
+
+        Class<?> class_Axis = horizontalAxis.getClass();
+
+        Field field_locations = class_Axis.getField("locations");
+        field_locations.setAccessible(true);
+
+        myGridInfo.vLines = (int[])field_locations.get(horizontalAxis);
+
+        Field field_verticalAxis = viewClass.getDeclaredField("verticalAxis");
+        field_verticalAxis.setAccessible(true);
+        Object verticalAxis = field_verticalAxis.get(viewObject);
+
+        myGridInfo.hLines = (int[])field_locations.get(verticalAxis);
+
+        Rectangle bounds = getBounds();
+
+        for (RadComponent child : getChildren()) {
+          Rectangle childBounds = child.getBounds();
+          myGridInfo.width = Math.max(myGridInfo.width, childBounds.x + childBounds.width - bounds.x);
+          myGridInfo.height = Math.max(myGridInfo.height, childBounds.y + childBounds.height - bounds.y);
+        }
+
+        if (myGridInfo.vLines != null && myGridInfo.vLines.length > 0) {
+          myGridInfo.vLines[myGridInfo.vLines.length - 1] = myGridInfo.width;
+        }
+        if (myGridInfo.hLines != null && myGridInfo.hLines.length > 0) {
+          myGridInfo.hLines[myGridInfo.hLines.length - 1] = myGridInfo.height;
+        }
+      }
+      catch (Throwable e) {
+      }
+    }
+    return myGridInfo;
+  }
 }
\ No newline at end of file
index 9590e9d83f2ab38723ba7ccea6645e09f7b92255..88e3bfffd99c5aea2e1a0bc2f6bfa809235a1c63 100644 (file)
  */
 package com.intellij.android.designer.model.table;
 
-import com.intellij.android.designer.designSurface.layout.CaptionStaticDecorator;
-import com.intellij.designer.designSurface.StaticDecorator;
+import com.intellij.android.designer.model.agrid.GridInfo;
+import com.intellij.android.designer.model.agrid.RadCaptionColumn;
 import com.intellij.designer.model.RadComponent;
-import com.intellij.designer.model.RadVisualComponent;
-
-import java.awt.*;
-import java.util.List;
 
 /**
  * @author Alexander Lobas
  */
-public class RadCaptionTableColumn extends RadVisualComponent {
-  private final RadTableLayoutComponent myContainer;
-  private final int myColumnIndex;
-  private final int myColumnOffset;
-  private final int myColumnWidth;
-  private final StaticDecorator myDecorator;
-
-  public RadCaptionTableColumn(RadTableLayoutComponent container, int columnIndex, int columnOffset, int columnWidth, boolean empty) {
-    myContainer = container;
-    myColumnIndex = columnIndex;
-    myColumnOffset = columnOffset;
-    myColumnWidth = columnWidth;
-
-    if (empty) {
-      myDecorator = new CaptionStaticDecorator(this, Color.PINK);
-    }
-    else {
-      myDecorator = new CaptionStaticDecorator(this);
-    }
-
-    setNativeComponent(container.getNativeComponent());
-  }
-
-  public int getColumnIndex() {
-    return myColumnIndex;
-  }
-
-  @Override
-  public Rectangle getBounds() {
-    Rectangle bounds = myContainer.getBounds();
-    return new Rectangle(bounds.x + myColumnOffset, 2, myColumnWidth, 10);
-  }
-
-  @Override
-  public Rectangle getBounds(Component relativeTo) {
-    Rectangle bounds = super.getBounds(relativeTo);
-    bounds.y = 2;
-    bounds.height = 10;
-    return bounds;
-  }
-
-  @Override
-  public void addStaticDecorators(List<StaticDecorator> decorators, List<RadComponent> selection) {
-    decorators.add(myDecorator);
+public class RadCaptionTableColumn extends RadCaptionColumn<RadTableLayoutComponent> {
+  public RadCaptionTableColumn(RadTableLayoutComponent container, int index, int offset, int width, boolean empty) {
+    super(container, index, offset, width, empty);
   }
 
   @Override
@@ -78,13 +33,13 @@ public class RadCaptionTableColumn extends RadVisualComponent {
     RadComponent[][] components = info.components;
 
     for (RadComponent[] rowComponents : components) {
-      RadComponent component = rowComponents[myColumnIndex];
+      RadComponent component = rowComponents[myIndex];
       if (component != null) {
         component.delete();
-        rowComponents[myColumnIndex] = null;
+        rowComponents[myIndex] = null;
       }
 
-      for (int i = myColumnIndex + 1; i < rowComponents.length; i++) {
+      for (int i = myIndex + 1; i < rowComponents.length; i++) {
         RadComponent cellComponent = rowComponents[i];
 
         if (cellComponent != null) {
index e8ba519672efdc0bb20c2fc1fcd3a59fb82c2ee7..99ff2662c5688218188fb27c95d5fd3d57bec6b9 100644 (file)
@@ -20,6 +20,7 @@ import com.intellij.android.designer.designSurface.layout.*;
 import com.intellij.android.designer.model.RadViewComponent;
 import com.intellij.android.designer.model.RadViewLayout;
 import com.intellij.android.designer.model.RadViewLayoutWithData;
+import com.intellij.android.designer.model.agrid.GridInfo;
 import com.intellij.designer.componentTree.TreeEditOperation;
 import com.intellij.designer.designSurface.*;
 import com.intellij.designer.designSurface.selection.ResizeSelectionDecorator;
@@ -37,7 +38,7 @@ import java.util.List;
 public class RadTableLayout extends RadViewLayoutWithData implements ILayoutDecorator, ICaption, ICaptionDecorator {
   private static final String[] LAYOUT_PARAMS = {"", "LinearLayout_Layout", "ViewGroup_MarginLayout"};
 
-  private TableLayoutDecorator myGridDecorator;
+  private GridDecorator myGridDecorator;
   private ResizeSelectionDecorator mySelectionDecorator;
 
   @Override
@@ -65,7 +66,7 @@ public class RadTableLayout extends RadViewLayoutWithData implements ILayoutDeco
 
   private StaticDecorator getGridDecorator() {
     if (myGridDecorator == null) {
-      myGridDecorator = new TableLayoutDecorator(myContainer);
+      myGridDecorator = new GridDecorator(myContainer);
     }
     return myGridDecorator;
   }
index 382c3d75c45dc274a95e55ccf1bde7f8ed0fcc78..d6003b8b022e3e8816dedda16f1b3842a4c8a1d7 100644 (file)
@@ -19,6 +19,8 @@ import com.android.ide.common.rendering.api.ViewInfo;
 import com.intellij.android.designer.model.ModelParser;
 import com.intellij.android.designer.model.RadViewComponent;
 import com.intellij.android.designer.model.RadViewContainer;
+import com.intellij.android.designer.model.agrid.GridInfo;
+import com.intellij.android.designer.model.agrid.IGridProvider;
 import com.intellij.designer.model.RadComponent;
 import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.psi.xml.XmlTag;
@@ -31,7 +33,7 @@ import java.util.List;
 /**
  * @author Alexander Lobas
  */
-public class RadTableLayoutComponent extends RadViewContainer {
+public class RadTableLayoutComponent extends RadViewContainer implements IGridProvider {
   private GridInfo myGridInfo;
   private GridInfo myVirtualGridInfo;
 
index 03830cbf1508f3c7c9af8c7f469a332f0e8f06dd..8e3ebb0b6c4e288ae1bb9cbf7b15f2a1ec9bf872 100644 (file)
@@ -91,7 +91,7 @@ public class RadTableRowLayout extends RadLinearLayout {
 
       mySelectionDecorator.clear();
       if (selection.size() == 1) {
-        LayoutSpanOperation.points(mySelectionDecorator);
+        LayoutSpanOperation.tablePoints(mySelectionDecorator);
       }
       return mySelectionDecorator;
     }
index a94922d56e4197a5e1518cde9906cc4c58963893..cd85637140ed0c352218feb778e6240b19b2fb4d 100644 (file)
              tooltip="A Layout that arranges its children in a single column or a single row."/>
 
     <properties important="orientation gravity baselineAligned measureWithLargestChild showDividers"
-                expert="layout:gravity.fill layout:gravity.clip"
+                expert="layout:gravity.fill layout:gravity.clip layout:gravity.start layout:gravity.end"
                 top="gravity orientation"
         />
 
              tooltip="FrameLayout is designed to block out an area on the screen to display a single item."/>
 
     <properties important="foreground foregroundGravity"
-                expert="layout:gravity.fill layout:gravity.clip"
+                expert="layout:gravity.fill layout:gravity.clip layout:gravity.start layout:gravity.end"
         />
 
     <creation>
         tag="GridLayout">
 
     <properties important="orientation rowCount columnCount"
-                top="rowCount columnCount orientation"
-                expert="layout:gravity.clip"
+                top="rowCount columnCount"
+                expert="layout:gravity.clip layout:gravity.start layout:gravity.end"
         />
 
     <palette title="GridLayout" icon="/com/intellij/android/designer/icons/GridLayout.png"
diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/selection/EmptyPoint.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/selection/EmptyPoint.java
new file mode 100644 (file)
index 0000000..6f4c601
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2000-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.designer.designSurface.selection;
+
+import com.intellij.designer.designSurface.DecorationLayer;
+import com.intellij.designer.designSurface.tools.InputTool;
+import com.intellij.designer.model.RadComponent;
+
+import java.awt.*;
+
+/**
+ * @author Alexander Lobas
+ */
+public abstract class EmptyPoint extends ResizePoint {
+  @Override
+  public InputTool findTargetTool(DecorationLayer layer, RadComponent component, int x, int y) {
+    return null;
+  }
+
+  @Override
+  public Object getType() {
+    return null;
+  }
+
+  @Override
+  protected InputTool createTool(RadComponent component) {
+    return null;
+  }
+
+  @Override
+  protected Point getLocation(DecorationLayer layer, RadComponent component) {
+    return null;
+  }
+}
\ No newline at end of file