diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/RelativeLayoutOperation.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/RelativeLayoutOperation.java index 1cfeabdc38ca..9f9b05c257f5 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/RelativeLayoutOperation.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/RelativeLayoutOperation.java @@ -71,6 +71,7 @@ public class RelativeLayoutOperation extends AbstractEditOperation { } } + // XXX myBoundsFeedback = new AlphaFeedback(myComponents.size() == 1 ? Color.green : Color.orange); myBoundsFeedback.setSize(myBounds.width, myBounds.height); diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/ContainerSnapPoint.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/ContainerSnapPoint.java index c32691db3bb3..b293cead78eb 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/ContainerSnapPoint.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/ContainerSnapPoint.java @@ -46,7 +46,7 @@ public class ContainerSnapPoint extends SnapPoint { int targetX = targetBounds.x; if (startX <= targetX && targetX <= endX) { targetBounds.x = myBounds.x; - feedback.addVerticalLine(myBounds.x + 2, myBounds.y, myBounds.height); + feedback.addVerticalLine(myBounds.x, myBounds.y, myBounds.height); return true; } @@ -60,7 +60,7 @@ public class ContainerSnapPoint extends SnapPoint { int targetX = targetBounds.x + targetBounds.width; if (startX <= targetX && targetX <= endX) { targetBounds.x = myBounds.x + myBounds.width - targetBounds.width; - feedback.addVerticalLine(myBounds.x + myBounds.width - 2, myBounds.y, myBounds.height); + feedback.addVerticalLine(myBounds.x + myBounds.width, myBounds.y, myBounds.height); return true; } @@ -74,7 +74,7 @@ public class ContainerSnapPoint extends SnapPoint { int targetY = targetBounds.y; if (startY <= targetY && targetY <= endY) { targetBounds.y = myBounds.y; - feedback.addHorizontalLine(myBounds.x, myBounds.y + 2, myBounds.width); + feedback.addHorizontalLine(myBounds.x, myBounds.y, myBounds.width); return true; } @@ -88,7 +88,7 @@ public class ContainerSnapPoint extends SnapPoint { int targetY = targetBounds.y + targetBounds.height; if (startY <= targetY && targetY <= endY) { targetBounds.y = myBounds.y + myBounds.height - targetBounds.height; - feedback.addHorizontalLine(myBounds.x, myBounds.y + myBounds.height - 2, myBounds.width); + feedback.addHorizontalLine(myBounds.x, myBounds.y + myBounds.height, myBounds.width); return true; } diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/RelativeDecorator.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/RelativeDecorator.java new file mode 100644 index 000000000000..431eb49b05e3 --- /dev/null +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/RelativeDecorator.java @@ -0,0 +1,36 @@ +/* + * 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.relative; + +import com.intellij.designer.designSurface.DecorationLayer; +import com.intellij.designer.designSurface.StaticDecorator; +import com.intellij.designer.model.RadComponent; + +import java.awt.*; + +/** + * @author Alexander Lobas + */ +public class RelativeDecorator extends StaticDecorator { + public RelativeDecorator(RadComponent container) { + super(container); + } + + @Override + protected void paint(DecorationLayer layer, Graphics2D g, RadComponent container) { + // TODO: Auto-generated method stub + } +} \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/SnapPointFeedbackHost.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/SnapPointFeedbackHost.java index 6c2ec4cdac61..e204883a5659 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/SnapPointFeedbackHost.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/relative/SnapPointFeedbackHost.java @@ -41,6 +41,13 @@ public class SnapPointFeedbackHost extends JComponent { myLines.clear(); } + private static final int EXPAND_SIZE = 10; + + @Override + public void setBounds(int x, int y, int width, int height) { + super.setBounds(x - EXPAND_SIZE, y - EXPAND_SIZE, width + 2 * EXPAND_SIZE, height + 2 * EXPAND_SIZE); + } + @Override protected void paintComponent(Graphics g) { super.paintComponent(g); diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/PropertyParser.java b/plugins/android-designer/src/com/intellij/android/designer/model/PropertyParser.java index 5de42aa55a77..579ae1514494 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/PropertyParser.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/PropertyParser.java @@ -131,10 +131,6 @@ public class PropertyParser { List properties = loadLayoutProperties(layoutParams, 0, models); if (!properties.isEmpty()) { - if (layout != null) { - layout.configureProperties(properties); - } - properties = new ArrayList(properties); properties.addAll(component.getProperties()); component.setProperties(properties); @@ -336,6 +332,13 @@ public class PropertyParser { PropertyTable.moveProperty(properties, "layout:height", properties, 0); PropertyTable.moveProperty(properties, "layout:width", properties, 0); } + + if (model != null) { + Class layout = model.getLayout(); + if (layout != null) { + layout.newInstance().configureProperties(properties); + } + } } return properties; diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/layout/relative/CenterProperty.java b/plugins/android-designer/src/com/intellij/android/designer/model/layout/relative/CenterProperty.java index ceb93657c325..cacfdc647f7f 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/layout/relative/CenterProperty.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/layout/relative/CenterProperty.java @@ -15,10 +15,16 @@ */ package com.intellij.android.designer.model.layout.relative; +import com.intellij.android.designer.model.ModelParser; import com.intellij.android.designer.model.RadViewComponent; +import com.intellij.android.designer.propertyTable.editors.StringsComboEditor; import com.intellij.designer.propertyTable.Property; import com.intellij.designer.propertyTable.PropertyEditor; import com.intellij.designer.propertyTable.PropertyRenderer; +import com.intellij.designer.propertyTable.renderers.LabelPropertyRenderer; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.psi.xml.XmlTag; +import com.intellij.util.ArrayUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -26,23 +32,78 @@ import org.jetbrains.annotations.Nullable; * @author Alexander Lobas */ public class CenterProperty extends Property { + private static final String[] COMBO_ITEMS = {"horizontal", "vertical", "both"}; + private static final String[] ATTR_ITEMS = + {"android:layout_centerHorizontal", "android:layout_centerVertical", "android:layout_centerInParent"}; + + private final PropertyRenderer myRenderer = new LabelPropertyRenderer(null); + private final PropertyEditor myEditor = new StringsComboEditor(COMBO_ITEMS); + public CenterProperty() { - super(null, "layout:center"); + super(null, "layout:centerInParent"); + setImportant(true); + } + + @Override + public Object getValue(RadViewComponent component) throws Exception { + XmlTag tag = component.getTag(); + for (int i = ATTR_ITEMS.length - 1; i >= 0; i--) { + String value = tag.getAttributeValue(ATTR_ITEMS[i]); + if ("true".equals(value)) { + return COMBO_ITEMS[i]; + } + } + return null; + } + + @Override + public void setValue(final RadViewComponent component, Object value) throws Exception { + final int index = ArrayUtil.indexOf(COMBO_ITEMS, value); + ApplicationManager.getApplication().runWriteAction(new Runnable() { + @Override + public void run() { + XmlTag tag = component.getTag(); + for (int i = 0; i < ATTR_ITEMS.length; i++) { + if (i == index) { + tag.setAttribute(ATTR_ITEMS[i], "true"); + } + else { + ModelParser.deleteAttribute(tag, ATTR_ITEMS[i]); + } + } + } + }); + } + + @Override + public boolean isDefaultValue(RadViewComponent component) throws Exception { + XmlTag tag = component.getTag(); + for (String attribute : ATTR_ITEMS) { + if (tag.getAttribute(attribute) != null) { + return false; + } + } + return true; + } + + @Override + public void setDefaultValue(RadViewComponent component) throws Exception { + setValue(component, null); } @Override public Property createForNewPresentation(@Nullable Property parent, @NotNull String name) { - return null; // TODO: Auto-generated method stub + return null; } @NotNull @Override public PropertyRenderer getRenderer() { - return null; // TODO: Auto-generated method stub + return myRenderer; } @Override public PropertyEditor getEditor() { - return null; // TODO: Auto-generated method stub + return myEditor; } } \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/layout/relative/CompoundProperty.java b/plugins/android-designer/src/com/intellij/android/designer/model/layout/relative/CompoundProperty.java new file mode 100644 index 000000000000..2b1b4451a848 --- /dev/null +++ b/plugins/android-designer/src/com/intellij/android/designer/model/layout/relative/CompoundProperty.java @@ -0,0 +1,45 @@ +/* + * 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.layout.relative; + +import com.intellij.android.designer.model.RadViewComponent; +import com.intellij.designer.propertyTable.Property; +import org.jetbrains.annotations.NotNull; + +/** + * @author Alexander Lobas + */ +public class CompoundProperty extends com.intellij.android.designer.propertyTable.CompoundProperty { + public CompoundProperty(@NotNull String name) { + super(name); + setImportant(true); + } + + @Override + public Object getValue(RadViewComponent component) throws Exception { + StringBuilder value = new StringBuilder("["); + int index = 0; + for (Property child : getChildren(component)) { + if (!child.isDefaultValue(component)) { + if (index++ > 0) { + value.append(", "); + } + value.append(child.getName()); + } + } + return value.append("]").toString(); + } +} \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/layout/relative/RadRelativeLayout.java b/plugins/android-designer/src/com/intellij/android/designer/model/layout/relative/RadRelativeLayout.java index 589d4a6865b6..326bfcbc14e0 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/layout/relative/RadRelativeLayout.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/layout/relative/RadRelativeLayout.java @@ -17,23 +17,28 @@ package com.intellij.android.designer.model.layout.relative; import com.intellij.android.designer.designSurface.TreeDropToOperation; import com.intellij.android.designer.designSurface.layout.RelativeLayoutOperation; +import com.intellij.android.designer.designSurface.layout.relative.RelativeDecorator; import com.intellij.android.designer.model.PropertyParser; import com.intellij.android.designer.model.RadViewLayoutWithData; -import com.intellij.android.designer.propertyTable.CompoundProperty; 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.model.RadComponent; import com.intellij.designer.propertyTable.Property; +import com.intellij.designer.propertyTable.PropertyTable; +import com.intellij.openapi.actionSystem.DefaultActionGroup; import org.jetbrains.annotations.NotNull; +import javax.swing.*; import java.util.List; /** * @author Alexander Lobas */ -public class RadRelativeLayout extends RadViewLayoutWithData { +public class RadRelativeLayout extends RadViewLayoutWithData implements ILayoutDecorator { private static final String[] LAYOUT_PARAMS = {"RelativeLayout_Layout", "ViewGroup_MarginLayout"}; + private RelativeDecorator myRelativeDecorator; + @NotNull @Override public String[] getLayoutParams() { @@ -42,8 +47,20 @@ public class RadRelativeLayout extends RadViewLayoutWithData { @Override public void configureProperties(List properties) { + CompoundProperty alignComponent = new CompoundProperty("layout:alignComponent"); + PropertyParser.moveProperties(properties, alignComponent, + "layout:alignTop", "top:top", + "layout:below", "top:bottom", + "layout:alignLeft", "left:left", + "layout:toRightOf", "left:right", + "layout:alignBottom", "bottom:bottom", + "layout:above", "bottom:top", + "layout:alignRight", "right:right", + "layout:toLeftOf", "right:left", + "layout:alignBaseline", "baseline:baseline"); + properties.add(alignComponent); + CompoundProperty alignParent = new CompoundProperty("layout:alignParent"); - alignParent.setImportant(true); PropertyParser.moveProperties(properties, alignParent, "layout:alignParentTop", "top", "layout:alignParentLeft", "left", @@ -51,6 +68,11 @@ public class RadRelativeLayout extends RadViewLayoutWithData { "layout:alignParentRight", "right", "layout:alignWithParentIfMissing", "missing"); properties.add(alignParent); + + PropertyTable.extractProperty(properties, "layout:centerInParent"); + PropertyTable.extractProperty(properties, "layout:centerHorizontal"); + PropertyTable.extractProperty(properties, "layout:centerVertical"); + properties.add(new CenterProperty()); } @Override @@ -64,6 +86,48 @@ public class RadRelativeLayout extends RadViewLayoutWithData { } return new RelativeLayoutOperation(myContainer, context); } + // XXX return null; } + + private RelativeDecorator getRelativeDecorator() { + if (myRelativeDecorator == null) { + myRelativeDecorator = new RelativeDecorator(myContainer); + } + return myRelativeDecorator; + } + + @Override + public void addStaticDecorators(List decorators, List selection) { + for (RadComponent component : selection) { + if (component.getParent() == myContainer) { + if (!(myContainer.getParent().getLayout() instanceof ILayoutDecorator)) { + decorators.add(getRelativeDecorator()); + } + return; + } + } + super.addStaticDecorators(decorators, selection); + } + + @Override + public ComponentDecorator getChildSelectionDecorator(RadComponent component, List selection) { + return super.getChildSelectionDecorator(component, selection); // TODO: Auto-generated method stub + } + + @Override + public void addContainerSelectionActions(DesignerEditorPanel designer, + DefaultActionGroup actionGroup, + JComponent shortcuts, + List selection) { + super.addContainerSelectionActions(designer, actionGroup, shortcuts, selection); // TODO: Auto-generated method stub + } + + @Override + public void addSelectionActions(DesignerEditorPanel designer, + DefaultActionGroup actionGroup, + JComponent shortcuts, + List selection) { + super.addSelectionActions(designer, actionGroup, shortcuts, selection); // TODO: Auto-generated method stub + } } \ No newline at end of file