/plugins/android-designer/src/com/intellij/android/designer/model/morphing/AbsoluteLayout.java

http://github.com/JetBrains/intellij-community · Java · 54 lines · 32 code · 4 blank · 18 comment · 5 complexity · 8ba402917e774a8860d866488ce23209 MD5 · raw file

  1. /*
  2. * Copyright 2000-2012 JetBrains s.r.o.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.intellij.android.designer.model.morphing;
  17. import com.android.SdkConstants;
  18. import com.intellij.android.designer.model.ComponentMorphingTool;
  19. import com.intellij.android.designer.model.RadViewComponent;
  20. import com.intellij.android.designer.model.layout.relative.RadRelativeLayout;
  21. import com.intellij.android.designer.model.layout.relative.RadRelativeLayoutComponent;
  22. import com.intellij.designer.model.MetaModel;
  23. import com.intellij.designer.model.RadComponent;
  24. import com.intellij.psi.xml.XmlAttribute;
  25. import com.intellij.psi.xml.XmlTag;
  26. /**
  27. * @author Alexander Lobas
  28. */
  29. public class AbsoluteLayout {
  30. public static RadViewComponent RelativeLayout(RadViewComponent component, MetaModel target) throws Exception {
  31. return new ComponentMorphingTool(component, new RadRelativeLayoutComponent(), target, new RadRelativeLayout()) {
  32. @Override
  33. protected void convertTag() {
  34. for (RadComponent childComponent : myNewComponent.getChildren()) {
  35. XmlTag tag = ((RadViewComponent)childComponent).getTag();
  36. XmlAttribute xAttribute = tag.getAttribute("layout_x", SdkConstants.NS_RESOURCES);
  37. if (xAttribute != null) {
  38. tag.setAttribute("layout_alignParentLeft", SdkConstants.NS_RESOURCES, "true");
  39. xAttribute.setName(xAttribute.getNamespacePrefix() + ":layout_marginLeft");
  40. }
  41. XmlAttribute yAttribute = tag.getAttribute("layout_y", SdkConstants.NS_RESOURCES);
  42. if (yAttribute != null) {
  43. tag.setAttribute("layout_alignParentTop", SdkConstants.NS_RESOURCES, "true");
  44. yAttribute.setName(yAttribute.getNamespacePrefix() + ":layout_marginTop");
  45. }
  46. }
  47. }
  48. }.result();
  49. }
  50. }