LinearLayout

This commit is contained in:
Alexander Lobas
2012-04-05 20:50:50 +04:00
parent a728073128
commit 02e0f6c594
8 changed files with 106 additions and 94 deletions
@@ -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<StaticDecorator> decorators, List<RadComponent> selection) {
RadViewLayout layout = (RadViewLayout)getLayout();
if (layout != null) {
layout.addStaticDecorators(decorators, selection);
}
}
@Override
public void addSelectionActions(DesignerEditorPanel designer,
DefaultActionGroup actionGroup,
@@ -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;
}
@@ -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<StaticDecorator> decorators, List<RadComponent> selection) {
super.addStaticDecorators(decorators, selection); // TODO: Auto-generated method stub
}
@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,
@@ -66,70 +66,4 @@ public class RadLinearLayout extends RadViewLayoutWithData {
List<RadComponent> 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<RadComponent> 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);
}
}
}
@@ -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<RadComponent> parents = new HashSet<RadComponent>();
for (RadComponent component : selection) {
RadComponent parent = component.getParent();
if (parent != null) {
parents.add(parent);
}
}
Set<RadComponent> parents = RadComponent.getParents(selection);
for (RadComponent parent : parents) {
parent.getLayout().addSelectionActions(myDesigner, myDynamicGroup, myShortcuts, selection);
}
@@ -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<StaticDecorator> decorators = new ArrayList<StaticDecorator>();
List<RadComponent> selection = myArea.getSelection();
Set<RadComponent> 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<RadComponent> selection = myArea.getSelection();
for (RadComponent component : selection) {
ComponentDecorator decorator = getDecorator(component, selection);
@@ -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);
}
}
@@ -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<StaticDecorator> decorators, List<RadComponent> selection) {
}
public void addSelectionActions(DesignerEditorPanel designer,
DefaultActionGroup actionGroup,
JComponent shortcuts,
@@ -200,6 +204,17 @@ public abstract class RadComponent {
//
//////////////////////////////////////////////////////////////////////////////////////////
public static Set<RadComponent> getParents(List<RadComponent> components) {
Set<RadComponent> parents = new HashSet<RadComponent>();
for (RadComponent component : components) {
RadComponent parent = component.getParent();
if (parent != null) {
parents.add(parent);
}
}
return parents;
}
public static boolean isParentsContainedIn(List<RadComponent> components, RadComponent component) {
RadComponent parent = component.getParent();
while (parent != null) {
@@ -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<StaticDecorator> decorators, List<RadComponent> selection) {
}
public void addSelectionActions(DesignerEditorPanel designer,
DefaultActionGroup actionGroup,
JComponent shortcuts,