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 8f4f39ff0b7f..7334316add0b 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 @@ -17,6 +17,7 @@ package com.intellij.android.designer.model; import com.android.ide.common.rendering.api.ViewInfo; import com.intellij.designer.designSurface.DesignerEditorPanel; +import com.intellij.designer.designSurface.StaticDecorator; import com.intellij.designer.model.RadComponent; import com.intellij.designer.propertyTable.Property; import com.intellij.openapi.actionSystem.DefaultActionGroup; @@ -156,6 +157,14 @@ public class RadViewComponent extends RadComponent { } } + @Override + public void addStaticDecorators(List decorators, List selection) { + RadViewLayout layout = (RadViewLayout)getLayout(); + if (layout != null) { + layout.addStaticDecorators(decorators, selection); + } + } + @Override public void addSelectionActions(DesignerEditorPanel designer, DefaultActionGroup actionGroup, diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/layout/RadFrameLayout.java b/plugins/android-designer/src/com/intellij/android/designer/model/layout/RadFrameLayout.java index 87b26572427a..b4c1a1c0a68d 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/layout/RadFrameLayout.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/layout/RadFrameLayout.java @@ -50,6 +50,7 @@ public class RadFrameLayout extends RadViewLayoutWithData { private static final String[] LAYOUT_PARAMS = {"FrameLayout_Layout", "ViewGroup_MarginLayout"}; @Override + @NotNull public String[] getLayoutParams() { return LAYOUT_PARAMS; } diff --git a/plugins/android-designer/src/com/intellij/android/designer/model/layout/RadLinearLayout.java b/plugins/android-designer/src/com/intellij/android/designer/model/layout/RadLinearLayout.java index 28d004dae869..27cbba17cdf6 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/layout/RadLinearLayout.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/layout/RadLinearLayout.java @@ -15,21 +15,13 @@ */ package com.intellij.android.designer.model.layout; -import com.intellij.android.designer.model.ModelParser; -import com.intellij.android.designer.model.RadViewComponent; import com.intellij.android.designer.model.RadViewLayoutWithData; -import com.intellij.designer.componentTree.TreeEditOperation; -import com.intellij.designer.designSurface.DesignerEditorPanel; -import com.intellij.designer.designSurface.EditOperation; -import com.intellij.designer.designSurface.FeedbackLayer; -import com.intellij.designer.designSurface.OperationContext; -import com.intellij.designer.designSurface.feedbacks.AlphaComponent; +import com.intellij.designer.designSurface.*; import com.intellij.designer.model.RadComponent; import com.intellij.openapi.actionSystem.DefaultActionGroup; -import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.NotNull; import javax.swing.*; -import java.awt.*; import java.util.List; /** @@ -39,18 +31,26 @@ public class RadLinearLayout extends RadViewLayoutWithData { private static final String[] LAYOUT_PARAMS = {"LinearLayout_Layout", "ViewGroup_MarginLayout"}; @Override + @NotNull public String[] getLayoutParams() { return LAYOUT_PARAMS; } @Override public EditOperation processChildOperation(OperationContext context) { - if (context.isCreate()) { - return context.isTree() ? new TreeCreateOperation(myContainer, context) : new CreateOperation(context); - } return null; } + @Override + public void addStaticDecorators(List decorators, List selection) { + super.addStaticDecorators(decorators, selection); // TODO: Auto-generated method stub + } + + @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, @@ -66,70 +66,4 @@ public class RadLinearLayout extends RadViewLayoutWithData { List selection) { super.addSelectionActions(designer, actionGroup, shortcuts, selection); // TODO: Auto-generated method stub } - - private void addNewComponent(RadViewComponent newComponent, @Nullable RadViewComponent insertBefore) throws Exception { - ModelParser.addComponent((RadViewComponent)myContainer, newComponent, insertBefore); - } - - private class TreeCreateOperation extends TreeEditOperation { - public TreeCreateOperation(RadComponent host, OperationContext context) { - super(host, context); - } - - @Override - protected void execute(RadComponent insertBefore) throws Exception { - addNewComponent((RadViewComponent)myComponents.get(0), (RadViewComponent)insertBefore); - } - } - - private class CreateOperation implements EditOperation { - private final OperationContext myContext; - private RadComponent myComponent; - private JComponent myFeedback; - - private CreateOperation(OperationContext context) { - myContext = context; - } - - @Override - public void setComponent(RadComponent component) { - myComponent = component; - } - - @Override - public void setComponents(List components) { - } - - @Override - public void showFeedback() { - FeedbackLayer layer = myContext.getArea().getFeedbackLayer(); - - if (myFeedback == null) { - myFeedback = new AlphaComponent(Color.green); - layer.add(myFeedback); - myFeedback.setBounds(myContainer.getBounds(layer)); - layer.repaint(); - } - } - - @Override - public void eraseFeedback() { - if (myFeedback != null) { - FeedbackLayer layer = myContext.getArea().getFeedbackLayer(); - layer.remove(myFeedback); - layer.repaint(); - myFeedback = null; - } - } - - @Override - public boolean canExecute() { - return true; - } - - @Override - public void execute() throws Exception { - addNewComponent((RadViewComponent)myComponent, null); - } - } } \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/DesignerActionPanel.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/DesignerActionPanel.java index 2705d49328bb..04e164bc4f8d 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/DesignerActionPanel.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/actions/DesignerActionPanel.java @@ -22,7 +22,6 @@ import com.intellij.designer.model.RadComponent; import com.intellij.openapi.actionSystem.*; import com.intellij.ui.IdeBorderFactory; import com.intellij.ui.SideBorder; -import com.intellij.util.containers.hash.HashSet; import org.jetbrains.annotations.NonNls; import javax.swing.*; @@ -121,14 +120,7 @@ public class DesignerActionPanel implements DataProvider { } myDynamicGroup.removeAll(); - Set parents = new HashSet(); - for (RadComponent component : selection) { - RadComponent parent = component.getParent(); - if (parent != null) { - parents.add(parent); - } - } - + Set parents = RadComponent.getParents(selection); for (RadComponent parent : parents) { parent.getLayout().addSelectionActions(myDesigner, myDynamicGroup, myShortcuts, selection); } diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DecorationLayer.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DecorationLayer.java index e4cd92e73e1a..618c13116887 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DecorationLayer.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/DecorationLayer.java @@ -21,7 +21,9 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; +import java.util.ArrayList; import java.util.List; +import java.util.Set; /** * @author Alexander Lobas @@ -56,12 +58,30 @@ public class DecorationLayer extends JComponent { @Override public void paint(Graphics g) { + Graphics2D g2d = (Graphics2D)g; + paintStatic(g2d); if (myShowSelection) { - painSelection((Graphics2D)g); + paintSelection(g2d); } } - private void painSelection(Graphics2D g) { + private void paintStatic(Graphics2D g) { + List decorators = new ArrayList(); + List selection = myArea.getSelection(); + Set parents = RadComponent.getParents(selection); + + for (RadComponent parent : parents) { + parent.getLayout().addStaticDecorators(decorators, selection); + } + for (RadComponent component : selection) { + component.addStaticDecorators(decorators, selection); + } + for (StaticDecorator decorator : decorators) { + decorator.decorate(this, g); + } + } + + private void paintSelection(Graphics2D g) { List selection = myArea.getSelection(); for (RadComponent component : selection) { ComponentDecorator decorator = getDecorator(component, selection); diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/StaticDecorator.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/StaticDecorator.java new file mode 100644 index 000000000000..918c0465bce2 --- /dev/null +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/StaticDecorator.java @@ -0,0 +1,41 @@ +/* + * 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.designer.designSurface; + +import com.intellij.designer.designSurface.tools.InputTool; +import com.intellij.designer.model.RadComponent; + +import java.awt.*; + +/** + * @author Alexander Lobas + */ +public abstract class StaticDecorator extends ComponentDecorator { + private final RadComponent myComponent; + + public StaticDecorator(RadComponent component) { + myComponent = component; + } + + @Override + public final InputTool findTargetTool(DecorationLayer layer, RadComponent component, int x, int y) { + return null; + } + + public void decorate(DecorationLayer layer, Graphics2D host) { + decorate(layer, host, myComponent); + } +} \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java index 3a503df9406b..38eddd7d53b3 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadComponent.java @@ -17,6 +17,7 @@ package com.intellij.designer.model; import com.intellij.designer.designSurface.DesignerEditorPanel; import com.intellij.designer.designSurface.OperationContext; +import com.intellij.designer.designSurface.StaticDecorator; import com.intellij.designer.designSurface.tools.DragTracker; import com.intellij.designer.designSurface.tools.InputTool; import com.intellij.designer.propertyTable.Property; @@ -104,6 +105,9 @@ public abstract class RadComponent { public void processDropOperation(OperationContext context) { } + public void addStaticDecorators(List decorators, List selection) { + } + public void addSelectionActions(DesignerEditorPanel designer, DefaultActionGroup actionGroup, JComponent shortcuts, @@ -200,6 +204,17 @@ public abstract class RadComponent { // ////////////////////////////////////////////////////////////////////////////////////////// + public static Set getParents(List components) { + Set parents = new HashSet(); + for (RadComponent component : components) { + RadComponent parent = component.getParent(); + if (parent != null) { + parents.add(parent); + } + } + return parents; + } + public static boolean isParentsContainedIn(List components, RadComponent component) { RadComponent parent = component.getParent(); while (parent != null) { diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadLayout.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadLayout.java index 50f5a59356f3..01d30d72e848 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadLayout.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/model/RadLayout.java @@ -15,10 +15,7 @@ */ package com.intellij.designer.model; -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.*; import com.intellij.openapi.actionSystem.DefaultActionGroup; import org.jetbrains.annotations.Nullable; @@ -42,6 +39,9 @@ public abstract class RadLayout { return null; } + public void addStaticDecorators(List decorators, List selection) { + } + public void addSelectionActions(DesignerEditorPanel designer, DefaultActionGroup actionGroup, JComponent shortcuts,