This commit is contained in:
Alexander Lobas
2012-03-10 22:43:16 +04:00
parent d1afa62d28
commit 9da59c659b
10 changed files with 370 additions and 283 deletions
@@ -29,14 +29,11 @@ public final class AndroidTreeDecorator extends TreeComponentDecorator {
public void decorate(RadComponent component, ColoredTreeCellRenderer renderer) {
MetaModel metaModel = component.getMetaModel();
// TODO
if (metaModel == null) {
RadViewComponent viewComponent = (RadViewComponent)component;
renderer.append(viewComponent.getTag().getName());
}
else {
renderer.append(metaModel.getPaletteItem().getTitle());
renderer.setIcon(metaModel.getIcon());
}
StringBuffer fullTitle = new StringBuffer();
String title1 = new String(metaModel.getPaletteItem().getTitle());
fullTitle.append(title1.replaceAll("%tag%", ((RadViewComponent)component).getTag().getName()));
renderer.append(fullTitle.toString());
renderer.setIcon(metaModel.getIcon());
}
}
@@ -17,12 +17,13 @@ package com.intellij.android.designer.designSurface;
import com.android.ide.common.rendering.api.RenderSession;
import com.android.ide.common.rendering.api.Result;
import com.android.ide.common.rendering.api.ViewInfo;
import com.android.ide.common.resources.configuration.*;
import com.android.sdklib.IAndroidTarget;
import com.intellij.android.designer.actions.ProfileAction;
import com.intellij.android.designer.componentTree.AndroidTreeDecorator;
import com.intellij.android.designer.model.ModelParser;
import com.intellij.android.designer.model.PropertyParser;
import com.intellij.android.designer.model.RadViewComponent;
import com.intellij.android.designer.model.ViewsMetaManager;
import com.intellij.android.designer.profile.ProfileManager;
import com.intellij.designer.DesignerToolWindowManager;
import com.intellij.designer.componentTree.TreeComponentDecorator;
@@ -30,14 +31,10 @@ import com.intellij.designer.designSurface.ComponentDecorator;
import com.intellij.designer.designSurface.DesignerEditorPanel;
import com.intellij.designer.designSurface.EditOperation;
import com.intellij.designer.designSurface.OperationContext;
import com.intellij.designer.designSurface.selection.DirectionResizePoint;
import com.intellij.designer.designSurface.selection.ResizeSelectionDecorator;
import com.intellij.designer.designSurface.selection.NonResizeSelectionDecorator;
import com.intellij.designer.designSurface.tools.ComponentCreationFactory;
import com.intellij.designer.designSurface.tools.ComponentPasteFactory;
import com.intellij.designer.model.MetaManager;
import com.intellij.designer.model.RadComponent;
import com.intellij.designer.palette.Item;
import com.intellij.designer.utils.Position;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.util.Computable;
@@ -45,16 +42,13 @@ import com.intellij.openapi.util.Condition;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.psi.XmlRecursiveElementVisitor;
import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.ThrowableRunnable;
import org.jetbrains.android.dom.attrs.AttributeDefinitions;
import org.jetbrains.android.facet.AndroidFacet;
import org.jetbrains.android.sdk.AndroidPlatform;
import org.jetbrains.android.uipreview.LayoutDeviceConfiguration;
import org.jetbrains.android.uipreview.LocaleData;
import org.jetbrains.android.uipreview.RenderUtil;
import org.jetbrains.android.uipreview.RenderingException;
import org.jetbrains.android.sdk.AndroidTargetData;
import org.jetbrains.android.uipreview.*;
import org.jetbrains.android.util.AndroidSdkNotConfiguredException;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -62,7 +56,6 @@ import org.jetbrains.annotations.NotNull;
import javax.swing.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.Collections;
import java.util.List;
/**
@@ -132,52 +125,24 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel {
}
}
private void parseFile(final Runnable runnable) {
final RadViewComponent[] rootComponents = new RadViewComponent[1];
final MetaManager metaManager = ViewsMetaManager.getInstance(getProject());
final String layoutXmlText = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
RadViewComponent myComponent;
@Override
public String compute() {
XmlTag root = myXmlFile.getRootTag();
if (root != null) {
root.accept(new XmlRecursiveElementVisitor() {
@Override
public void visitXmlTag(XmlTag tag) {
myComponent = new RadViewComponent(myComponent);
myComponent.setTag(tag);
myComponent.setMetaModel(metaManager.getModelByTag(tag.getName()));
if (rootComponents[0] == null) {
rootComponents[0] = myComponent;
}
super.visitXmlTag(tag);
myComponent = (RadViewComponent)myComponent.getParent();
}
});
}
return myXmlFile.getText();
}
});
createRenderer(layoutXmlText, new ThrowableRunnable<Throwable>() {
private void parseFile(final Runnable runnable) throws Exception {
final ModelParser parser = new ModelParser(getProject(), myXmlFile);
createRenderer(parser.getLayoutXmlText(), new ThrowableRunnable<Throwable>() {
@Override
public void run() throws Throwable {
checkRenderer();
RootView rootView = new RootView(mySession.getImage(), 30, 20);
updateRootComponent(rootComponents, mySession.getRootViews(), rootView);
parser.updateRootComponent(mySession.getRootViews(), rootView);
new PropertyParser(myModule, myProfileAction.getProfileManager().getSelectedTarget()).loadRecursive(parser.getRootComponent());
JPanel rootPanel = new JPanel(null);
rootPanel.setBackground(Color.WHITE);
rootPanel.add(rootView);
removeNativeRoot();
myRootComponent = rootComponents[0];
myRootComponent = parser.getRootComponent();
myLayeredPane.add(rootPanel, LAYER_COMPONENT);
runnable.run();
@@ -200,7 +165,7 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel {
RadViewComponent rootComponent = (RadViewComponent)myRootComponent;
RootView rootView = (RootView)rootComponent.getNativeComponent();
rootView.setImage(mySession.getImage());
updateRootComponent(rootComponent, mySession.getRootViews(), rootView);
ModelParser.updateRootComponent(rootComponent, mySession.getRootViews(), rootView);
myLayeredPane.repaint();
}
@@ -210,6 +175,8 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel {
private void checkRenderer() throws Throwable {
Result result = mySession.getResult();
if (!result.isSuccess()) {
System.out.println(
"No session: " + result.getErrorMessage() + " : " + result.getStatus() + " : " + result.getData() + " : " + result.getException());
Throwable exception = result.getException();
if (exception != null) {
throw exception;
@@ -226,55 +193,6 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel {
}
}
private void updateRootComponent(RadViewComponent[] rootComponents, List<ViewInfo> views, JComponent nativeComponent) {
RadViewComponent rootComponent = rootComponents[0];
if (views.size() == 1) {
RadViewComponent newRootComponent = new RadViewComponent(null);
newRootComponent.setMetaModel(ViewsMetaManager.getInstance(getProject()).getModelByTag("<root>"));
newRootComponent.getChildren().add(rootComponent);
rootComponent.setParent(newRootComponent);
updateComponent(rootComponent, views.get(0), nativeComponent, 0, 0);
rootComponents[0] = newRootComponent;
newRootComponent.setNativeComponent(nativeComponent);
newRootComponent.setBounds(0, 0, nativeComponent.getWidth(), nativeComponent.getHeight());
}
else {
updateRootComponent(rootComponent, views, nativeComponent);
}
}
private static void updateRootComponent(RadViewComponent rootComponent, List<ViewInfo> views, JComponent nativeComponent) {
int size = views.size();
List<RadComponent> children = rootComponent.getChildren();
for (int i = 0; i < size; i++) {
updateComponent((RadViewComponent)children.get(i), views.get(i), nativeComponent, 0, 0);
}
rootComponent.setNativeComponent(nativeComponent);
rootComponent.setBounds(0, 0, nativeComponent.getWidth(), nativeComponent.getHeight());
}
private static void updateComponent(RadViewComponent component, ViewInfo view, JComponent nativeComponent, int parentX, int parentY) {
component.setNativeComponent(nativeComponent);
int left = parentX + view.getLeft();
int top = parentY + view.getTop();
component.setBounds(left, top, view.getRight() - view.getLeft(), view.getBottom() - view.getTop());
List<ViewInfo> views = view.getChildren();
List<RadComponent> children = component.getChildren();
int size = views.size();
for (int i = 0; i < size; i++) {
updateComponent((RadViewComponent)children.get(i), views.get(i), nativeComponent, left, top);
}
}
private void createRenderer(final String layoutXmlText, final ThrowableRunnable<Throwable> runnable) {
if (mySession == null) {
ApplicationManager.getApplication().invokeLater(
@@ -407,9 +325,7 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel {
@Override
protected ComponentDecorator getRootSelectionDecorator() {
return new ResizeSelectionDecorator(Color.RED, 1, new DirectionResizePoint(Position.EAST, "top_resize_"),
new DirectionResizePoint(Position.SOUTH_EAST, "top_resize"),
new DirectionResizePoint(Position.SOUTH, "top_resize"));
return new NonResizeSelectionDecorator(Color.RED, 1);
}
@Override
@@ -420,26 +336,12 @@ public final class AndroidDesignerEditorPanel extends DesignerEditorPanel {
@Override
@NotNull
protected ComponentCreationFactory createCreationFactory(Item paletteItem) {
return new ComponentCreationFactory() {
@Override
@NotNull
public RadComponent create() throws Exception {
return new RadViewComponent(null);
}
};
//return null; // TODO: Auto-generated method stub
return null; // TODO: Auto-generated method stub
}
@Override
public ComponentPasteFactory createPasteFactory(String xmlComponents) {
return new ComponentPasteFactory() {
@NotNull
@Override
public List<RadComponent> create() throws Exception {
return Collections.<RadComponent>singletonList(new RadViewComponent(null));
}
};
//return null; // TODO: Auto-generated method stub
return null; // TODO: Auto-generated method stub
}
@Override
Binary file not shown.

After

Width:  |  Height:  |  Size: 842 B

@@ -0,0 +1,177 @@
/*
* 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;
import com.android.ide.common.rendering.api.ViewInfo;
import com.intellij.designer.model.MetaManager;
import com.intellij.designer.model.MetaModel;
import com.intellij.designer.model.RadComponent;
import com.intellij.designer.model.RadLayout;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Computable;
import com.intellij.psi.XmlRecursiveElementVisitor;
import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlTag;
import javax.swing.*;
import java.util.List;
/**
* @author Alexander Lobas
*/
public class ModelParser extends XmlRecursiveElementVisitor {
private final MetaManager myMetaManager;
private final XmlFile myXmlFile;
private RadViewComponent myRootComponent;
private RadViewComponent myComponent;
private String myLayoutXmlText;
public ModelParser(Project project, XmlFile xmlFile) {
myMetaManager = ViewsMetaManager.getInstance(project);
myXmlFile = xmlFile;
parse();
}
//////////////////////////////////////////////////////////////////////////////////////////
//
//
//
//////////////////////////////////////////////////////////////////////////////////////////
private void parse() {
myLayoutXmlText = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@Override
public String compute() {
XmlTag root = myXmlFile.getRootTag();
if (root != null) {
root.accept(ModelParser.this);
}
return myXmlFile.getText();
}
});
}
@Override
public void visitXmlTag(XmlTag tag) {
try {
MetaModel metaModel = myMetaManager.getModelByTag(tag.getName());
if (metaModel == null) {
metaModel = myMetaManager.getModelByTag("<unknown>");
}
RadViewComponent component = createComponent(tag, metaModel);
if (myRootComponent == null) {
myRootComponent = component;
}
component.setParent(myComponent);
if (myComponent != null) {
myComponent.getChildren().add(component);
}
myComponent = component;
super.visitXmlTag(tag);
myComponent = (RadViewComponent)component.getParent();
}
catch (Throwable e) {
throw new RuntimeException(e);
}
}
private static RadViewComponent createComponent(XmlTag tag, MetaModel metaModel) throws Exception {
RadViewComponent component = (RadViewComponent)metaModel.getModel().newInstance();
component.setMetaModel(metaModel);
component.setTag(tag);
Class<RadLayout> layout = metaModel.getLayout();
if (layout != null) {
component.setLayout(layout.newInstance());
}
return component;
}
//////////////////////////////////////////////////////////////////////////////////////////
//
//
//
//////////////////////////////////////////////////////////////////////////////////////////
public RadViewComponent getRootComponent() {
return myRootComponent;
}
public String getLayoutXmlText() {
return myLayoutXmlText;
}
public void updateRootComponent(List<ViewInfo> views, JComponent nativeComponent) throws Exception {
RadViewComponent rootComponent = myRootComponent;
if (views.size() == 1) {
RadViewComponent newRootComponent = createComponent(myXmlFile.getRootTag(), myMetaManager.getModelByTag("<root>"));
rootComponent.setParent(newRootComponent);
newRootComponent.getChildren().add(rootComponent);
updateComponent(rootComponent, views.get(0), nativeComponent, 0, 0);
newRootComponent.setNativeComponent(nativeComponent);
newRootComponent.setBounds(0, 0, nativeComponent.getWidth(), nativeComponent.getHeight());
myRootComponent = newRootComponent;
}
else {
updateRootComponent(rootComponent, views, nativeComponent);
}
}
public static void updateRootComponent(RadViewComponent rootComponent,
List<ViewInfo> views,
JComponent nativeComponent) {
int size = views.size();
List<RadComponent> children = rootComponent.getChildren();
for (int i = 0; i < size; i++) {
updateComponent((RadViewComponent)children.get(i), views.get(i), nativeComponent, 0, 0);
}
rootComponent.setNativeComponent(nativeComponent);
rootComponent.setBounds(0, 0, nativeComponent.getWidth(), nativeComponent.getHeight());
}
private static void updateComponent(RadViewComponent component,
ViewInfo view,
JComponent nativeComponent,
int parentX,
int parentY) {
component.setViewInfo(view);
component.setNativeComponent(nativeComponent);
int left = parentX + view.getLeft();
int top = parentY + view.getTop();
component.setBounds(left, top, view.getRight() - view.getLeft(), view.getBottom() - view.getTop());
List<ViewInfo> views = view.getChildren();
List<RadComponent> children = component.getChildren();
int size = views.size();
for (int i = 0; i < size; i++) {
updateComponent((RadViewComponent)children.get(i), views.get(i), nativeComponent, left, top);
}
}
}
@@ -0,0 +1,113 @@
/*
* 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;
import com.android.ide.common.rendering.api.ViewInfo;
import com.android.sdklib.IAndroidTarget;
import com.intellij.designer.model.MetaManager;
import com.intellij.designer.model.RadComponent;
import com.intellij.designer.propertyTable.Property;
import com.intellij.openapi.module.Module;
import org.jetbrains.android.dom.attrs.AttributeDefinition;
import org.jetbrains.android.dom.attrs.AttributeDefinitions;
import org.jetbrains.android.dom.attrs.StyleableDefinition;
import org.jetbrains.android.sdk.AndroidPlatform;
import org.jetbrains.android.sdk.AndroidTargetData;
import org.jetbrains.android.uipreview.ProjectClassLoader;
import org.jetbrains.android.uipreview.RenderServiceFactory;
import java.util.*;
/**
* @author Alexander Lobas
*/
@SuppressWarnings("unchecked")
public class PropertyParser {
private AttributeDefinitions myDefinitions;
private ProjectClassLoader myClassLoader;
private Map<String, List<AttributeDefinition>> myCachedAttributes;
public PropertyParser(Module module, IAndroidTarget target) throws Exception {
MetaManager metaManager = ViewsMetaManager.getInstance(module.getProject());
myCachedAttributes = (Map<String, List<AttributeDefinition>>)metaManager.getCache().get(target.hashString());
if (myCachedAttributes == null) {
myCachedAttributes = new HashMap<String, List<AttributeDefinition>>();
metaManager.getCache().put(target.hashString(), myCachedAttributes);
}
AndroidPlatform androidPlatform = AndroidPlatform.getInstance(module);
AndroidTargetData targetData = androidPlatform.getSdkData().getTargetData(target);
myDefinitions = targetData.getAttrDefs(module.getProject());
RenderServiceFactory factory = targetData.getRenderServiceFactory(module.getProject());
myClassLoader = new ProjectClassLoader(factory.getLibrary().getClassLoader(), module);
}
public void loadRecursive(RadViewComponent component) throws Exception {
load(component);
for (RadComponent child : component.getChildren()) {
loadRecursive((RadViewComponent)child);
}
}
public void load(RadViewComponent component) throws Exception {
List<Property> properties = new ArrayList<Property>();
component.setProperties(properties);
ViewInfo info = component.getViewInfo();
if (info == null) {
return;
}
List<AttributeDefinition> attributes = loadAttributes(myClassLoader.loadClass(info.getClassName()));
for (AttributeDefinition attribute : attributes) {
// TODO
}
}
private List<AttributeDefinition> loadAttributes(Class<?> componentClass) {
String component = componentClass.getSimpleName();
List<AttributeDefinition> attributes = myCachedAttributes.get(component);
if (attributes == null) {
attributes = new ArrayList<AttributeDefinition>();
StyleableDefinition attributeDefs = myDefinitions.getStyleableByName(component);
if (attributeDefs != null) {
attributes.addAll(attributeDefs.getAttributes());
}
Class<?> superComponentClass = componentClass.getSuperclass();
if (superComponentClass != null) {
attributes.addAll(loadAttributes(superComponentClass));
}
if (!attributes.isEmpty()) {
Collections.sort(attributes, new Comparator<AttributeDefinition>() {
@Override
public int compare(AttributeDefinition a1, AttributeDefinition a2) {
return a1.getName().compareTo(a2.getName());
}
});
}
myCachedAttributes.put(component, attributes);
}
return attributes;
}
}
@@ -0,0 +1,22 @@
/*
* 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;
/**
* @author Alexander Lobas
*/
public class RadLinearLayout extends RadViewLayout {
}
@@ -15,22 +15,10 @@
*/
package com.intellij.android.designer.model;
import com.android.ide.common.rendering.api.ViewInfo;
import com.intellij.designer.model.RadComponent;
import com.intellij.designer.propertyTable.Property;
import com.intellij.designer.propertyTable.PropertyEditor;
import com.intellij.designer.propertyTable.PropertyRenderer;
import com.intellij.designer.propertyTable.editors.BooleanEditor;
import com.intellij.designer.propertyTable.renderers.BooleanRenderer;
import com.intellij.designer.propertyTable.renderers.LabelPropertyRenderer;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import com.intellij.openapi.util.IconLoader;
import com.intellij.psi.xml.XmlAttribute;
import com.intellij.psi.xml.XmlTag;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
@@ -38,32 +26,16 @@ import java.util.ArrayList;
import java.util.List;
/**
* TODO: now dummy implementation for tests
*
* @author Alexander Lobas
*/
public class RadViewComponent extends RadComponent {
public static final AnAction LinearLayout =
new AnAction("Horizontal/Vertical", "LinearLayout", IconLoader.getIcon("/com/intellij/android/designer/icons/LinearLayout.png")) {
@Override
public void actionPerformed(AnActionEvent e) {
}
};
private final List<RadComponent> myChildren = new ArrayList<RadComponent>();
private ViewInfo myViewInfo;
private Component myNativeComponent;
private final Rectangle myBounds = new Rectangle();
private XmlTag myTag;
private List<Property> myProperties;
public RadViewComponent(RadViewComponent parent) {
setParent(parent);
if (parent != null) {
parent.getChildren().add(this);
}
setLayout(new RadViewLayout(this));
}
public XmlTag getTag() {
return myTag;
}
@@ -77,6 +49,14 @@ public class RadViewComponent extends RadComponent {
return myChildren;
}
public ViewInfo getViewInfo() {
return myViewInfo;
}
public void setViewInfo(ViewInfo viewInfo) {
myViewInfo = viewInfo;
}
@Override
public Rectangle getBounds() {
return myBounds;
@@ -105,92 +85,11 @@ public class RadViewComponent extends RadComponent {
}
@Override
public void addSelectionActions(DefaultActionGroup actionGroup, JComponent shortcuts, List<RadComponent> selection) {
if (myTag != null && myTag.getName().equals("LinearLayout") && selection.size() == 1 && selection.get(0) == this) {
AnAction action = new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
System.out.println("LinearLayout: " + e);
}
};
action.copyFrom(LinearLayout);
actionGroup.add(action);
}
public List<Property> getProperties() {
return myProperties;
}
@Override
public List<Property> getProperties() {
if (myProperties == null && myTag != null) {
myProperties = new ArrayList<Property>();
Property layout = new Property(null, "layout") {
private final BooleanRenderer myRenderer = new BooleanRenderer();
private final BooleanEditor myEditor = new BooleanEditor();
private final List<Property> myProperties = new ArrayList<Property>();
@Override
public List<Property> getChildren(@Nullable RadComponent component) {
return myProperties;
}
@Override
public Object getValue(RadComponent component) throws Exception {
return component.getClientProperty(getName());
}
@Override
public void setValue(RadComponent component, Object value) throws Exception {
component.putClientProperty(getName(), value);
}
@Override
public boolean isDefaultValue(RadComponent component) throws Exception {
return getValue(component) == null;
}
@Override
public void setDefaultValue(RadComponent component) throws Exception {
component.putClientProperty(getName(), null);
}
@NotNull
@Override
public PropertyRenderer getRenderer() {
return myRenderer;
}
@Override
public PropertyEditor getEditor() {
return myEditor;
}
};
layout.setImportant(true);
for (XmlAttribute attribute : myTag.getAttributes()) {
String name = attribute.getName();
if (name.equals("xmlns:android")) {
continue;
}
Property parent = name.equals("android:layout_width") || name.equals("android:layout_height") ? layout : null;
Property property = new AttributeProperty(parent, new String(name).replace("android:", "").replace('_', ' '), name);
property.setImportant(name.equals("android:text"));
property.setExpert(name.equals("android:id"));
if (name.equals("android:background")) {
property.setDeprecated(true);
property.setImportant(true);
}
if (parent == null) {
myProperties.add(property);
}
else {
layout.getChildren(null).add(property);
}
}
if (!layout.getChildren(null).isEmpty()) {
myProperties.add(0, layout);
}
}
return myProperties == null ? super.getProperties() : myProperties;
public void setProperties(List<Property> properties) {
myProperties = properties;
}
}
@@ -17,14 +17,9 @@ package com.intellij.android.designer.model;
import com.intellij.designer.designSurface.ComponentDecorator;
import com.intellij.designer.designSurface.selection.NonResizeSelectionDecorator;
import com.intellij.designer.model.MetaModel;
import com.intellij.designer.model.RadComponent;
import com.intellij.designer.model.RadLayout;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
import javax.swing.*;
import java.awt.*;
import java.util.List;
@@ -32,33 +27,8 @@ import java.util.List;
* @author Alexander Lobas
*/
public class RadViewLayout extends RadLayout {
private final RadViewComponent myContainer;
public RadViewLayout(RadViewComponent container) {
myContainer = container;
}
@Override
@Override
public ComponentDecorator getChildSelectionDecorator(RadComponent component, List<RadComponent> selection) {
return new NonResizeSelectionDecorator(Color.RED, 1);
}
@Override
public void addSelectionActions(DefaultActionGroup actionGroup, JComponent shortcuts, List<RadComponent> selection) {
if (myContainer.getTag() != null && myContainer.getTag().getName().equals("LinearLayout")) {
for (RadComponent component : selection) {
if (myContainer != component.getParent()) {
return;
}
}
AnAction action = new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
System.out.println("LinearLayout: " + e);
}
};
action.copyFrom(RadViewComponent.LinearLayout);
actionGroup.add(action);
}
}
}
@@ -1,17 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<meta-model>
<meta model="com.intellij.android.designer.model.RadViewComponent"
layout="com.intellij.android.designer.model.RadViewLayout"
tag="&lt;root&gt;">
<palette title="Device Screen" icon="/com/intellij/android/designer/icons/DeviceScreen.png"/>
</meta>
<meta model="com.intellij.android.designer.model.RadViewComponent"
layout="com.intellij.android.designer.model.RadViewLayout"
tag="merge">
<palette title="Device Screen (#merge)" icon="/com/intellij/android/designer/icons/DeviceScreen.png"/>
</meta>
<meta model="com.intellij.android.designer.model.RadViewComponent"
layout="com.intellij.android.designer.model.RadViewLayout"
tag="&lt;unknown&gt;">
<palette title="Unknown (%tag%)" icon="/com/intellij/android/designer/icons/unknown.png"/>
</meta>
<meta model="com.intellij.android.designer.model.RadViewComponent"
class="android.widget.Button"
tag="Button">
@@ -51,7 +60,7 @@
</meta>
<meta model="com.intellij.android.designer.model.RadViewComponent"
layout="com.intellij.android.designer.model.RadViewLayout"
layout="com.intellij.android.designer.model.RadLinearLayout"
class="android.widget.LinearLayout"
tag="LinearLayout">
@@ -70,14 +79,6 @@
</meta>
<palette>
<group name="Layouts">
<item tag="LinearLayout"/>
</group>
<group name="Widgets">
<item tag="Button"/>
<item tag="TextView"/>
</group>
</palette>
</meta-model>
@@ -21,7 +21,6 @@ import com.intellij.ide.palette.PaletteGroup;
import com.intellij.openapi.components.AbstractProjectComponent;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.util.containers.hash.HashMap;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
@@ -30,6 +29,7 @@ import org.jetbrains.annotations.Nullable;
import java.beans.PropertyChangeSupport;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -52,6 +52,8 @@ public abstract class MetaManager {
private PropertyChangeSupport myPaletteChangeSupport;
private Map<Object, Object> myCache = new HashMap<Object, Object>();
protected MetaManager(Project project, String name) {
try {
InputStream stream = getClass().getResourceAsStream(name);
@@ -119,6 +121,10 @@ public abstract class MetaManager {
myPaletteGroups.add(group);
}
public Map<Object, Object> getCache() {
return myCache;
}
@Nullable
public MetaModel getModelByTag(String tag) {
return myTag2Model.get(tag);