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 7738eaab0d47..af65241836cb 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 @@ -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()); } } \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java index e02de1ae423f..fe9a90bb7f99 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/AndroidDesignerEditorPanel.java @@ -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() { - 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() { + private void parseFile(final Runnable runnable) throws Exception { + final ModelParser parser = new ModelParser(getProject(), myXmlFile); + createRenderer(parser.getLayoutXmlText(), new ThrowableRunnable() { @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 views, JComponent nativeComponent) { - RadViewComponent rootComponent = rootComponents[0]; - - if (views.size() == 1) { - RadViewComponent newRootComponent = new RadViewComponent(null); - newRootComponent.setMetaModel(ViewsMetaManager.getInstance(getProject()).getModelByTag("")); - 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 views, JComponent nativeComponent) { - int size = views.size(); - List 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 views = view.getChildren(); - List 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 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 create() throws Exception { - return Collections.singletonList(new RadViewComponent(null)); - } - }; - //return null; // TODO: Auto-generated method stub + return null; // TODO: Auto-generated method stub } @Override diff --git a/plugins/android-designer/src/com/intellij/android/designer/icons/unknown.png b/plugins/android-designer/src/com/intellij/android/designer/icons/unknown.png new file mode 100644 index 000000000000..f3556e079758 Binary files /dev/null and b/plugins/android-designer/src/com/intellij/android/designer/icons/unknown.png differ diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/ModelParser.java b/plugins/android-designer/src/com/intellij/android/designer/model/ModelParser.java new file mode 100644 index 000000000000..7445dcd87f48 --- /dev/null +++ b/plugins/android-designer/src/com/intellij/android/designer/model/ModelParser.java @@ -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() { + @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(""); + } + + 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 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 views, JComponent nativeComponent) throws Exception { + RadViewComponent rootComponent = myRootComponent; + + if (views.size() == 1) { + RadViewComponent newRootComponent = createComponent(myXmlFile.getRootTag(), myMetaManager.getModelByTag("")); + 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 views, + JComponent nativeComponent) { + int size = views.size(); + List 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 views = view.getChildren(); + List 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); + } + } +} \ No newline at end of file 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 new file mode 100644 index 000000000000..d89c38a908f0 --- /dev/null +++ b/plugins/android-designer/src/com/intellij/android/designer/model/PropertyParser.java @@ -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> myCachedAttributes; + + public PropertyParser(Module module, IAndroidTarget target) throws Exception { + MetaManager metaManager = ViewsMetaManager.getInstance(module.getProject()); + myCachedAttributes = (Map>)metaManager.getCache().get(target.hashString()); + if (myCachedAttributes == null) { + myCachedAttributes = new HashMap>(); + 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 properties = new ArrayList(); + component.setProperties(properties); + + ViewInfo info = component.getViewInfo(); + if (info == null) { + return; + } + + List attributes = loadAttributes(myClassLoader.loadClass(info.getClassName())); + for (AttributeDefinition attribute : attributes) { + // TODO + } + } + + private List loadAttributes(Class componentClass) { + String component = componentClass.getSimpleName(); + List attributes = myCachedAttributes.get(component); + + if (attributes == null) { + attributes = new ArrayList(); + + 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() { + @Override + public int compare(AttributeDefinition a1, AttributeDefinition a2) { + return a1.getName().compareTo(a2.getName()); + } + }); + } + + myCachedAttributes.put(component, attributes); + } + + return attributes; + } +} \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/RadLinearLayout.java b/plugins/android-designer/src/com/intellij/android/designer/model/RadLinearLayout.java new file mode 100644 index 000000000000..1d9f893bfc41 --- /dev/null +++ b/plugins/android-designer/src/com/intellij/android/designer/model/RadLinearLayout.java @@ -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 { +} \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/RadViewComponent.java b/plugins/android-designer/src/com/intellij/android/designer/model/RadViewComponent.java index 5693abda2e5a..c5284df9f637 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/RadViewComponent.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/RadViewComponent.java @@ -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 myChildren = new ArrayList(); + private ViewInfo myViewInfo; private Component myNativeComponent; private final Rectangle myBounds = new Rectangle(); private XmlTag myTag; private List 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 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 getProperties() { + return myProperties; } - @Override - public List getProperties() { - if (myProperties == null && myTag != null) { - myProperties = new ArrayList(); - Property layout = new Property(null, "layout") { - private final BooleanRenderer myRenderer = new BooleanRenderer(); - private final BooleanEditor myEditor = new BooleanEditor(); - private final List myProperties = new ArrayList(); - - @Override - public List 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 properties) { + myProperties = properties; } } \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/RadViewLayout.java b/plugins/android-designer/src/com/intellij/android/designer/model/RadViewLayout.java index c9872c80f061..97ff2f279b70 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/RadViewLayout.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/RadViewLayout.java @@ -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 selection) { return new NonResizeSelectionDecorator(Color.RED, 1); } - - @Override - public void addSelectionActions(DefaultActionGroup actionGroup, JComponent shortcuts, List 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); - } - } } \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/views-meta-model.xml b/plugins/android-designer/src/com/intellij/android/designer/model/views-meta-model.xml index 449fc164cf2c..3c22363a76ce 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/views-meta-model.xml +++ b/plugins/android-designer/src/com/intellij/android/designer/model/views-meta-model.xml @@ -1,17 +1,26 @@ + + + + + @@ -51,7 +60,7 @@ @@ -70,14 +79,6 @@ - - - - - - - - \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/MetaManager.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/MetaManager.java index 22d11dae714c..fdc64b146f98 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/MetaManager.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/MetaManager.java @@ -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 myCache = new HashMap(); + 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 getCache() { + return myCache; + } + @Nullable public MetaModel getModelByTag(String tag) { return myTag2Model.get(tag);