mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
RelativeLayout
This commit is contained in:
+1
@@ -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);
|
||||
|
||||
|
||||
+4
-4
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+36
@@ -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
|
||||
}
|
||||
}
|
||||
+7
@@ -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);
|
||||
|
||||
+7
-4
@@ -131,10 +131,6 @@ public class PropertyParser {
|
||||
|
||||
List<Property> properties = loadLayoutProperties(layoutParams, 0, models);
|
||||
if (!properties.isEmpty()) {
|
||||
if (layout != null) {
|
||||
layout.configureProperties(properties);
|
||||
}
|
||||
|
||||
properties = new ArrayList<Property>(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<RadLayout> layout = model.getLayout();
|
||||
if (layout != null) {
|
||||
layout.newInstance().configureProperties(properties);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return properties;
|
||||
|
||||
+65
-4
@@ -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<RadViewComponent> {
|
||||
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<RadViewComponent> 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;
|
||||
}
|
||||
}
|
||||
+45
@@ -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<RadViewComponent> child : getChildren(component)) {
|
||||
if (!child.isDefaultValue(component)) {
|
||||
if (index++ > 0) {
|
||||
value.append(", ");
|
||||
}
|
||||
value.append(child.getName());
|
||||
}
|
||||
}
|
||||
return value.append("]").toString();
|
||||
}
|
||||
}
|
||||
+69
-5
@@ -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<Property> 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<StaticDecorator> decorators, List<RadComponent> 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<RadComponent> selection) {
|
||||
return super.getChildSelectionDecorator(component, selection); // TODO: Auto-generated method stub
|
||||
}
|
||||
|
||||
@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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user