GridLayout

This commit is contained in:
Alexander Lobas
2012-04-25 15:10:37 +04:00
parent 9d222aaca8
commit fbfde3a4f6
7 changed files with 93 additions and 7 deletions
@@ -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
@@ -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;
@@ -21,7 +21,7 @@ import com.intellij.android.designer.model.grid.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);
public RadCaptionGridColumn(RadGridLayoutComponent container, int index, int offset, int width, boolean empty) {
super(container, index, offset, width, empty);
}
}
@@ -21,7 +21,7 @@ import com.intellij.android.designer.model.grid.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);
public RadCaptionGridRow(RadGridLayoutComponent container, int index, int offset, int width, boolean empty) {
super(container, index, offset, width, empty);
}
}
@@ -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]));
}
}
@@ -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) {
@@ -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);
}