diff --git a/plugins/android-designer/src/com/intellij/android/designer/componentTree/AndroidTreeDecorator.java b/plugins/android-designer/src/com/intellij/android/designer/componentTree/AndroidTreeDecorator.java index bbbf6f6b5022..5f3542164b00 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/componentTree/AndroidTreeDecorator.java +++ b/plugins/android-designer/src/com/intellij/android/designer/componentTree/AndroidTreeDecorator.java @@ -17,6 +17,7 @@ package com.intellij.android.designer.componentTree; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.designer.componentTree.TreeComponentDecorator; +import com.intellij.designer.model.IComponentDecorator; import com.intellij.designer.model.MetaModel; import com.intellij.designer.model.RadComponent; import com.intellij.designer.palette.Item; @@ -76,6 +77,10 @@ public final class AndroidTreeDecorator extends TreeComponentDecorator { renderer.append(fullTitle.toString()); renderer.setIcon(metaModel.getIcon()); + + if (component instanceof IComponentDecorator) { + ((IComponentDecorator)component).decorateTree(renderer); + } } @Nullable diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/grid/GridInfo.java b/plugins/android-designer/src/com/intellij/android/designer/model/grid/GridInfo.java index 5820c87e3405..1471a955a22a 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/grid/GridInfo.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/grid/GridInfo.java @@ -27,7 +27,9 @@ public class GridInfo { public int[] hLines = ArrayUtil.EMPTY_INT_ARRAY; public int[] vLines = ArrayUtil.EMPTY_INT_ARRAY; + public boolean[] emptyColumns = ArrayUtil.EMPTY_BOOLEAN_ARRAY; + public boolean[] emptyRows = ArrayUtil.EMPTY_BOOLEAN_ARRAY; public RadComponent[][] components; public int lastRow = -1; diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/layout/grid/RadCaptionGridColumn.java b/plugins/android-designer/src/com/intellij/android/designer/model/layout/grid/RadCaptionGridColumn.java index 81a4a767414f..e40dc5bde272 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/layout/grid/RadCaptionGridColumn.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/layout/grid/RadCaptionGridColumn.java @@ -21,7 +21,7 @@ import com.intellij.android.designer.model.grid.RadCaptionColumn; * @author Alexander Lobas */ public class RadCaptionGridColumn extends RadCaptionColumn { - public RadCaptionGridColumn(RadGridLayoutComponent container, int index, int offset, int width) { - super(container, index, offset, width, false); + public RadCaptionGridColumn(RadGridLayoutComponent container, int index, int offset, int width, boolean empty) { + super(container, index, offset, width, empty); } } \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/layout/grid/RadCaptionGridRow.java b/plugins/android-designer/src/com/intellij/android/designer/model/layout/grid/RadCaptionGridRow.java index 9653054a30cd..9d560faf7f6d 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/layout/grid/RadCaptionGridRow.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/layout/grid/RadCaptionGridRow.java @@ -21,7 +21,7 @@ import com.intellij.android.designer.model.grid.RadCaptionRow; * @author Alexander Lobas */ public class RadCaptionGridRow extends RadCaptionRow { - public RadCaptionGridRow(RadGridLayoutComponent container, int index, int offset, int width) { - super(container, index, offset, width, false); + public RadCaptionGridRow(RadGridLayoutComponent container, int index, int offset, int width, boolean empty) { + super(container, index, offset, width, empty); } } \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/layout/grid/RadGridLayout.java b/plugins/android-designer/src/com/intellij/android/designer/model/layout/grid/RadGridLayout.java index ca9e1f8bd6c1..519782557323 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/layout/grid/RadGridLayout.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/layout/grid/RadGridLayout.java @@ -159,20 +159,26 @@ public class RadGridLayout extends RadViewLayoutWithData implements ILayoutDecor if (horizontal) { int[] lines = gridInfo.vLines; + boolean[] emptyColumns = gridInfo.emptyColumns; + for (int i = 0; i < lines.length - 1; i++) { components.add(new RadCaptionGridColumn(container, i, lines[i], - lines[i + 1] - lines[i])); + lines[i + 1] - lines[i], + emptyColumns[i])); } } else { int[] lines = gridInfo.hLines; + boolean[] emptyRows = gridInfo.emptyRows; + for (int i = 0; i < lines.length - 1; i++) { components.add(new RadCaptionGridRow(container, i, lines[i], - lines[i + 1] - lines[i])); + lines[i + 1] - lines[i], + emptyRows[i])); } } diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/layout/grid/RadGridLayoutComponent.java b/plugins/android-designer/src/com/intellij/android/designer/model/layout/grid/RadGridLayoutComponent.java index 4f9e6f1f1ff3..bce306f44222 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/layout/grid/RadGridLayoutComponent.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/layout/grid/RadGridLayoutComponent.java @@ -21,9 +21,12 @@ import com.intellij.android.designer.model.RadViewComponent; import com.intellij.android.designer.model.RadViewContainer; import com.intellij.android.designer.model.grid.GridInfo; import com.intellij.android.designer.model.grid.IGridProvider; +import com.intellij.designer.model.IComponentDecorator; import com.intellij.designer.model.RadComponent; import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.xml.XmlTag; +import com.intellij.ui.ColoredTreeCellRenderer; import java.awt.*; import java.lang.reflect.Field; @@ -32,10 +35,27 @@ import java.lang.reflect.Method; /** * @author Alexander Lobas */ -public class RadGridLayoutComponent extends RadViewContainer implements IGridProvider { +public class RadGridLayoutComponent extends RadViewContainer implements IComponentDecorator, IGridProvider { private GridInfo myGridInfo; private GridInfo myVirtualGridInfo; + @Override + public void decorateTree(ColoredTreeCellRenderer renderer) { + XmlTag tag = getTag(); + StringBuilder value = new StringBuilder(" ("); + + String rowCount = tag.getAttributeValue("android:rowCount"); + value.append(StringUtil.isEmpty(rowCount) ? "?" : rowCount).append(", "); + + String columnCount = tag.getAttributeValue("android:columnCount"); + value.append(StringUtil.isEmpty(columnCount) ? "?" : columnCount).append(", "); + + String orientation = tag.getAttributeValue("android:orientation"); + value.append(StringUtil.isEmpty(orientation) ? "horizontal" : orientation); + + renderer.append(value.append(")").toString()); + } + @Override public void setViewInfo(ViewInfo viewInfo) { super.setViewInfo(viewInfo); @@ -68,12 +88,14 @@ public class RadGridLayoutComponent extends RadViewContainer implements IGridPro field_locations.setAccessible(true); myGridInfo.vLines = (int[])field_locations.get(horizontalAxis); + myGridInfo.emptyColumns = configureEmptyLines(myGridInfo.vLines); Field field_verticalAxis = viewClass.getDeclaredField("verticalAxis"); field_verticalAxis.setAccessible(true); Object verticalAxis = field_verticalAxis.get(viewObject); myGridInfo.hLines = (int[])field_locations.get(verticalAxis); + myGridInfo.emptyRows = configureEmptyLines(myGridInfo.hLines); Rectangle bounds = getBounds(); @@ -96,6 +118,32 @@ public class RadGridLayoutComponent extends RadViewContainer implements IGridPro return myGridInfo; } + private static boolean[] configureEmptyLines(int[] lines) { + boolean[] empty = new boolean[lines.length - 1]; + + for (int i = 0; i < empty.length; i++) { + int line_i = lines[i]; + int length = lines[i + 1] - line_i; + empty[i] = length == 0; + + if (length == 0) { + int startMove = i + 1; + while (startMove < lines.length && line_i == lines[startMove]) { + startMove++; + } + + for (int j = i + 1; j < startMove; j++) { + lines[j] += 3; + } + for (int j = startMove; j < lines.length; j++) { + lines[j] -= 3; + } + } + } + + return empty; + } + @Override public GridInfo getVirtualGridInfo() { if (myVirtualGridInfo == null) { diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/IComponentDecorator.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/IComponentDecorator.java new file mode 100644 index 000000000000..1640515175c2 --- /dev/null +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/IComponentDecorator.java @@ -0,0 +1,25 @@ +/* + * 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.model; + +import com.intellij.ui.ColoredTreeCellRenderer; + +/** + * @author Alexander Lobas + */ +public interface IComponentDecorator { + void decorateTree(ColoredTreeCellRenderer renderer); +} \ No newline at end of file