From 0669556ef1449cf37d92595f20da40d2ce4b0bc7 Mon Sep 17 00:00:00 2001 From: Alexander Lobas Date: Fri, 30 Mar 2012 22:17:20 +0400 Subject: [PATCH] FrameLayout --- .../layout/FrameLayoutOperation.java | 118 +++++------ .../designSurface/layout/Gravity.java | 116 ++++++++++- .../designSurface/layout/ResizeOperation.java | 195 ++++++++++++++++++ .../designer/model/PropertyParser.java | 10 +- .../designer/model/layout/RadFrameLayout.java | 6 +- .../designer/model/views-meta-model.xml | 4 +- .../designer/propertyTable/FlagProperty.java | 14 +- .../feedbacks/AlphaComponent.java | 3 +- .../feedbacks/RectangleComponent.java | 43 ++++ .../selection/ResizeSelectionDecorator.java | 17 +- .../designer/propertyTable/PropertyTable.java | 20 +- .../propertyTable/PropertyTablePanel.java | 2 +- 12 files changed, 463 insertions(+), 85 deletions(-) create mode 100644 plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/ResizeOperation.java create mode 100644 plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/feedbacks/RectangleComponent.java diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/FrameLayoutOperation.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/FrameLayoutOperation.java index 3c9cc580995f..d065b669ea97 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/FrameLayoutOperation.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/FrameLayoutOperation.java @@ -23,7 +23,6 @@ import com.intellij.designer.designSurface.feedbacks.AlphaComponent; import com.intellij.designer.model.RadComponent; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.util.Pair; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.IdeBorderFactory; import com.intellij.ui.LightColors; import com.intellij.util.containers.hash.HashSet; @@ -31,6 +30,7 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.awt.*; +import java.util.Collections; import java.util.Set; /** @@ -40,7 +40,7 @@ public class FrameLayoutOperation extends AbstractEditOperation { private GravityFeedback myFeedback; private JLabel myTextFeedback; private String myGravity; - private Set> myExcludes; + private Set> myExcludes = Collections.emptySet(); public FrameLayoutOperation(RadViewComponent container, OperationContext context) { super(container, context); @@ -50,23 +50,42 @@ public class FrameLayoutOperation extends AbstractEditOperation { for (RadComponent component : context.getComponents()) { String value = ((RadViewComponent)component).getTag().getAttributeValue("android:layout_gravity"); - if (StringUtil.isEmpty(value)) { - myExcludes.add(new Pair(Gravity.Left, Gravity.Top)); + int flags = Gravity.getFlags(value); + + Gravity horizontal = Gravity.left; + if ((flags & Gravity.LEFT) != 0) { + horizontal = Gravity.left; } - else { - for (String option : StringUtil.split(value, "|")) { - // TODO - } + else if ((flags & Gravity.CENTER_HORIZONTAL) != 0) { + horizontal = Gravity.center; } + else if ((flags & Gravity.RIGHT) != 0) { + horizontal = Gravity.right; + } + + Gravity vertical = Gravity.top; + if ((flags & Gravity.TOP) != 0) { + vertical = Gravity.top; + } + else if ((flags & Gravity.CENTER_VERTICAL) != 0) { + vertical = Gravity.center; + } + else if ((flags & Gravity.BOTTOM) != 0) { + vertical = Gravity.bottom; + } + + myExcludes.add(new Pair(horizontal, vertical)); } } } - private void createFeedback(FeedbackLayer layer, Rectangle bounds) { + private void createFeedback(Rectangle bounds) { if (myFeedback == null) { + FeedbackLayer layer = myContext.getArea().getFeedbackLayer(); + myFeedback = new GravityFeedback(); - layer.add(myFeedback); myFeedback.setBounds(bounds); + layer.add(myFeedback); myTextFeedback = new JLabel(); myTextFeedback.setFont(myTextFeedback.getFont().deriveFont(Font.BOLD)); @@ -81,23 +100,22 @@ public class FrameLayoutOperation extends AbstractEditOperation { @Override public void showFeedback() { - FeedbackLayer layer = myContext.getArea().getFeedbackLayer(); - Rectangle bounds = myContainer.getBounds(layer); + Rectangle bounds = myContainer.getBounds(myContext.getArea().getFeedbackLayer()); - createFeedback(layer, bounds); + createFeedback(bounds); Point location = myContext.getLocation(); Gravity horizontal = calculateHorizontal(bounds, location); Gravity vertical = calculateVertical(bounds, location); - if (myContext.isMove() && myExcludes.contains(new Pair(horizontal, vertical))) { + if (myContext.isMove() && exclude(horizontal, vertical)) { horizontal = vertical = null; } myFeedback.setGravity(horizontal, vertical); configureTextFeedback(bounds, horizontal, vertical); - configureGravity(horizontal, vertical); + myGravity = Gravity.getValue(horizontal, vertical); } private void configureTextFeedback(Rectangle bounds, Gravity horizontal, Gravity vertical) { @@ -120,13 +138,13 @@ public class FrameLayoutOperation extends AbstractEditOperation { double right = bounds.x + 2 * bounds.width / 3.0; if (location.x < left) { - horizontal = Gravity.Left; + horizontal = Gravity.left; } else if (left < location.x && location.x < right) { - horizontal = Gravity.Center; + horizontal = Gravity.center; } else if (location.x > right) { - horizontal = Gravity.Right; + horizontal = Gravity.right; } return horizontal; @@ -139,56 +157,26 @@ public class FrameLayoutOperation extends AbstractEditOperation { double bottom = bounds.y + 2 * bounds.height / 3.0; if (location.y < top) { - vertical = Gravity.Top; + vertical = Gravity.top; } else if (top < location.y && location.y < bottom) { - vertical = Gravity.Center; + vertical = Gravity.center; } else if (location.y > bottom) { - vertical = Gravity.Bottom; + vertical = Gravity.bottom; } return vertical; } - private void configureGravity(Gravity horizontal, Gravity vertical) { - StringBuffer gravity = new StringBuffer(); - - if (horizontal == Gravity.Center && vertical == Gravity.Center) { - gravity.append("center"); - } - else { - if (horizontal == Gravity.Left) { - gravity.append("left"); - } - else if (horizontal == Gravity.Center) { - gravity.append("center_horizontal"); - } - else if (horizontal == Gravity.Right) { - gravity.append("right"); - } - - if (vertical == Gravity.Top) { - if (gravity.length() > 0) { - gravity.append("|"); - } - gravity.append("top"); - } - else if (vertical == Gravity.Center) { - if (gravity.length() > 0) { - gravity.append("|"); - } - gravity.append("center_vertical"); - } - else if (vertical == Gravity.Bottom) { - if (gravity.length() > 0) { - gravity.append("|"); - } - gravity.append("bottom"); + private boolean exclude(Gravity horizontal, Gravity vertical) { + for (Pair p : myExcludes) { + if (p.first == horizontal && p.second == vertical) { + return true; } } - myGravity = gravity.length() == 0 ? null : gravity.toString(); + return false; } @Override @@ -227,10 +215,10 @@ public class FrameLayoutOperation extends AbstractEditOperation { // Feedback // ////////////////////////////////////////////////////////////////////////////////////////// + private static final Gravity[] HORIZONTAL = {Gravity.left, Gravity.center, Gravity.right}; + private static final Gravity[] VERTICAL = {Gravity.top, Gravity.center, Gravity.bottom}; - private static class GravityFeedback extends AlphaComponent { - private static final Gravity[] HORIZONTAL = {Gravity.Left, Gravity.Center, Gravity.Right}; - private static final Gravity[] VERTICAL = {Gravity.Top, Gravity.Center, Gravity.Bottom}; + private class GravityFeedback extends AlphaComponent { private static final int SPACE = 5; @@ -251,7 +239,9 @@ public class FrameLayoutOperation extends AbstractEditOperation { protected void paintOther1(Graphics2D g2d) { for (Gravity h : HORIZONTAL) { for (Gravity v : VERTICAL) { - paintCell(g2d, h, v, false); + if (!exclude(h, v)) { + paintCell(g2d, h, v, false); + } } } } @@ -273,17 +263,17 @@ public class FrameLayoutOperation extends AbstractEditOperation { int width = getWidth() / 3; int height = getHeight() / 3; - if (horizontal == Gravity.Center) { + if (horizontal == Gravity.center) { x = width; } - else if (horizontal == Gravity.Right) { + else if (horizontal == Gravity.right) { x = getWidth() - width; } - if (vertical == Gravity.Center) { + if (vertical == Gravity.center) { y = height; } - else if (vertical == Gravity.Bottom) { + else if (vertical == Gravity.bottom) { y = getHeight() - height; } diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/Gravity.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/Gravity.java index 600f893ad986..427a1fcc79ab 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/Gravity.java +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/Gravity.java @@ -15,9 +15,123 @@ */ package com.intellij.android.designer.designSurface.layout; +import com.intellij.openapi.util.text.StringUtil; +import org.jetbrains.annotations.Nullable; + /** * @author Alexander Lobas */ public enum Gravity { - Left, Right, Center, Top, Bottom + left, right, center, top, bottom; + + public static final int NONE = 0; + public static final int TOP = 1 << 0; + public static final int BOTTOM = 1 << 1; + public static final int LEFT = 1 << 2; + public static final int RIGHT = 1 << 3; + public static final int CENTER_VERTICAL = 1 << 4; + public static final int FILL_VERTICAL = 1 << 5; + public static final int CENTER_HORIZONTAL = 1 << 6; + public static final int FILL_HORIZONTAL = 1 << 7; + public static final int CENTER = CENTER_HORIZONTAL | CENTER_VERTICAL; + public static final int FILL = FILL_HORIZONTAL | FILL_VERTICAL; + public static final int CLIP_VERTICAL = 1 << 8; + public static final int CLIP_HORIZONTAL = 1 << 9; + public static final int START = (1 << 10) | LEFT; + public static final int END = (1 << 11) | RIGHT; + + @Nullable + public static String getValue(Gravity horizontal, Gravity vertical) { + StringBuilder gravity = new StringBuilder(); + + if (horizontal == center && vertical == center) { + gravity.append("center"); + } + else { + if (horizontal == left) { + gravity.append("left"); + } + else if (horizontal == center) { + gravity.append("center_horizontal"); + } + else if (horizontal == right) { + gravity.append("right"); + } + + if (vertical == top) { + if (gravity.length() > 0) { + gravity.append("|"); + } + gravity.append("top"); + } + else if (vertical == center) { + if (gravity.length() > 0) { + gravity.append("|"); + } + gravity.append("center_vertical"); + } + else if (vertical == bottom) { + if (gravity.length() > 0) { + gravity.append("|"); + } + gravity.append("bottom"); + } + } + + return gravity.length() == 0 ? null : gravity.toString(); + } + + public static int getFlags(String value) { + int flags = NONE; + + if (!StringUtil.isEmpty(value)) { + for (String option : StringUtil.split(value, "|")) { + option = option.trim(); + + if ("top".equals(option)) { + flags |= TOP; + } + else if ("bottom".equals(option)) { + flags |= BOTTOM; + } + else if ("left".equals(option)) { + flags |= LEFT; + } + else if ("right".equals(option)) { + flags |= RIGHT; + } + else if ("center_vertical".equals(option)) { + flags |= CENTER_VERTICAL; + } + else if ("fill_vertical".equals(option)) { + flags |= FILL_VERTICAL; + } + else if ("center_horizontal".equals(option)) { + flags |= CENTER_HORIZONTAL; + } + else if ("fill_horizontal".equals(option)) { + flags |= FILL_HORIZONTAL; + } + else if ("center".equals(option)) { + flags |= CENTER; + } + else if ("fill".equals(option)) { + flags |= FILL; + } + else if ("clip_vertical".equals(option)) { + flags |= CLIP_VERTICAL; + } + else if ("clip_horizontal".equals(option)) { + flags |= CLIP_HORIZONTAL; + } + else if ("start".equals(option)) { + flags |= START; + } + else if ("end".equals(option)) { + flags |= END; + } + } + } + return flags; + } } \ No newline at end of file diff --git a/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/ResizeOperation.java b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/ResizeOperation.java new file mode 100644 index 000000000000..c48383a330d9 --- /dev/null +++ b/plugins/android-designer/src/com/intellij/android/designer/designSurface/layout/ResizeOperation.java @@ -0,0 +1,195 @@ +/* + * 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.designSurface.layout; + +import com.intellij.android.designer.model.RadViewComponent; +import com.intellij.designer.designSurface.ComponentDecorator; +import com.intellij.designer.designSurface.EditOperation; +import com.intellij.designer.designSurface.FeedbackLayer; +import com.intellij.designer.designSurface.OperationContext; +import com.intellij.designer.designSurface.feedbacks.RectangleComponent; +import com.intellij.designer.designSurface.selection.DirectionResizePoint; +import com.intellij.designer.designSurface.selection.ResizeSelectionDecorator; +import com.intellij.designer.model.RadComponent; +import com.intellij.designer.utils.Position; +import com.intellij.ui.LightColors; + +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import java.awt.*; +import java.util.List; + +/** + * @author Alexander Lobas + */ +public class ResizeOperation implements EditOperation { + public static final String TYPE = "resize_children"; + + public static ComponentDecorator full() { + return new ResizeSelectionDecorator(Color.red, 1, + new DirectionResizePoint(Position.NORTH, TYPE), + new DirectionResizePoint(Position.EAST, TYPE), + new DirectionResizePoint(Position.WEST, TYPE), + new DirectionResizePoint(Position.SOUTH, TYPE), + new DirectionResizePoint(Position.NORTH_EAST, TYPE), + new DirectionResizePoint(Position.NORTH_WEST, TYPE), + new DirectionResizePoint(Position.SOUTH_EAST, TYPE), + new DirectionResizePoint(Position.SOUTH_WEST, TYPE)); + } + + private final OperationContext myContext; + private RadViewComponent myComponent; + + private RectangleComponent myFeedback; + private JLabel myTextFeedback; + private RectangleComponent myWrapFeedback; + + private String myStaticWidth; + private String myStaticHeight; + + private final Rectangle myWrapBounds = new Rectangle(); + + public ResizeOperation(OperationContext context) { + myContext = context; + } + + @Override + public void setComponent(RadComponent component) { + myComponent = (RadViewComponent)component; + int direction = myContext.getResizeDirection(); + + String width = myComponent.getTag().getAttributeValue("android:layout_width"); + String height = myComponent.getTag().getAttributeValue("android:layout_height"); + + if (direction == Position.EAST || direction == Position.WEST) { + myStaticHeight = height; + } + else if (direction == Position.NORTH || direction == Position.SOUTH) { + myStaticWidth = width; + } + + Rectangle bounds = myComponent.getBounds(myContext.getArea().getFeedbackLayer()); + + if ("wrap_content".equals(width)) { + myWrapBounds.width = bounds.width; + } + else { + myWrapBounds.width = (int)(bounds.width * 0.75); + } + + if ("wrap_content".equals(height)) { + myWrapBounds.height = bounds.height; + } + else { + myWrapBounds.height = (int)(bounds.height * 0.75); + } + } + + @Override + public void setComponents(List components) { + } + + private void createFeedback() { + if (myFeedback == null) { + FeedbackLayer layer = myContext.getArea().getFeedbackLayer(); + + myWrapFeedback = new RectangleComponent(Color.green, 1); + layer.add(myWrapFeedback); + + myFeedback = new RectangleComponent(Color.blue, 2); + layer.add(myFeedback); + + myTextFeedback = new JLabel(); + myTextFeedback.setBackground(LightColors.YELLOW); + myTextFeedback.setBorder(new EmptyBorder(0, 5, 3, 0) { + @Override + public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) { + Color oldColor = g.getColor(); + g.setColor(Color.darkGray); + g.drawRect(x, y, width - 1, height - 1); + g.setColor(oldColor); + } + }); + myTextFeedback.setOpaque(true); + layer.add(myTextFeedback); + + layer.repaint(); + } + } + + @Override + public void showFeedback() { + FeedbackLayer layer = myContext.getArea().getFeedbackLayer(); + + createFeedback(); + + Rectangle bounds = myContext.getTransformedRectangle(myComponent.getBounds(layer)); + myFeedback.setBounds(bounds); + + int direction = myContext.getResizeDirection(); + + if ((direction & Position.EAST) != 0) { + myWrapBounds.x = bounds.x; + } + else { + myWrapBounds.x = bounds.x + bounds.width - myWrapBounds.width; + } + + if ((direction & Position.SOUTH) != 0) { + myWrapBounds.y = bounds.y; + } + else { + myWrapBounds.y = bounds.y + bounds.height - myWrapBounds.height; + } + + myWrapFeedback.setBounds(myWrapBounds); + + myTextFeedback.setText(getSizeHint(myStaticWidth, bounds.width) + " x " + getSizeHint(myStaticHeight, bounds.height)); + Dimension textSize = myTextFeedback.getPreferredSize(); + Point location = myContext.getLocation(); + myTextFeedback.setBounds(location.x + 15, location.y + 15, textSize.width, textSize.height); + } + + private static String getSizeHint(String staticText, int size) { + return staticText != null ? staticText : Integer.toString(size) + "dp"; + } + + @Override + public void eraseFeedback() { + if (myFeedback != null) { + FeedbackLayer layer = myContext.getArea().getFeedbackLayer(); + layer.remove(myWrapFeedback); + layer.remove(myFeedback); + layer.remove(myTextFeedback); + + layer.repaint(); + + myWrapFeedback = null; + myFeedback = null; + myTextFeedback = null; + } + } + + @Override + public boolean canExecute() { + return true; // TODO: Auto-generated method stub + } + + @Override + public void execute() throws Exception { + // TODO: Auto-generated method stub + } +} \ 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 index e87ab8732618..b83859d02fcf 100644 --- a/plugins/android-designer/src/com/intellij/android/designer/model/PropertyParser.java +++ b/plugins/android-designer/src/com/intellij/android/designer/model/PropertyParser.java @@ -115,7 +115,7 @@ public class PropertyParser { } if (layoutParams != null) { - List properties = loadLayoutProperties(layoutParams, 0); + List properties = loadLayoutProperties(layoutParams, 0, parent.getMetaModel()); if (!properties.isEmpty()) { properties = new ArrayList(properties); @@ -148,7 +148,7 @@ public class PropertyParser { property = padding = new CompoundProperty(name, definition); } else if (formats.contains(AttributeFormat.Flag)) { - property = new FlagProperty(name, definition); + property = new FlagProperty(name, definition, model); } else { property = new AttributeProperty(name, definition); @@ -225,7 +225,7 @@ public class PropertyParser { return properties; } - private List loadLayoutProperties(String[] components, int index) throws Exception { + private List loadLayoutProperties(String[] components, int index, MetaModel model) throws Exception { String component = components[index]; List properties = myCachedProperties.get(component); @@ -256,7 +256,7 @@ public class PropertyParser { property = margin = new CompoundProperty(name, definition); } else if (formats.contains(AttributeFormat.Flag)) { - property = new FlagProperty(name, definition); + property = new FlagProperty(name, definition, model); } else { property = new AttributeProperty(name, definition); @@ -278,7 +278,7 @@ public class PropertyParser { } if (++index < components.length) { - for (Property property : loadLayoutProperties(components, index)) { + for (Property property : loadLayoutProperties(components, index, model)) { if (PropertyTable.findProperty(properties, property) == -1) { properties.add(property); } 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 e60fe70694ac..284a430368cd 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 @@ -17,6 +17,7 @@ package com.intellij.android.designer.model.layout; import com.intellij.android.designer.designSurface.TreeDropToOperation; import com.intellij.android.designer.designSurface.layout.FrameLayoutOperation; +import com.intellij.android.designer.designSurface.layout.ResizeOperation; import com.intellij.android.designer.model.RadViewComponent; import com.intellij.android.designer.model.RadViewLayoutWithData; import com.intellij.designer.designSurface.ComponentDecorator; @@ -48,12 +49,15 @@ public class RadFrameLayout extends RadViewLayoutWithData { } return new FrameLayoutOperation((RadViewComponent)myContainer, context); } + else if (context.is(ResizeOperation.TYPE)) { + return new ResizeOperation(context); + } return null; } @Override public ComponentDecorator getChildSelectionDecorator(RadComponent component, List selection) { - return super.getChildSelectionDecorator(component, selection); // TODO: Auto-generated method stub + return ResizeOperation.full(); } @Override 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 983065ad8c53..705340e17495 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 @@ -1012,7 +1012,9 @@ - + { private final AttributeDefinition myDefinition; private final List myOptions = new ArrayList(); - public FlagProperty(@NotNull String name, @NotNull AttributeDefinition definition) { + public FlagProperty(@NotNull String name, @NotNull AttributeDefinition definition, @Nullable MetaModel model) { super(null, name); myDefinition = definition; for (String option : definition.getValues()) { myOptions.add(new OptionProperty(this, option, option)); } + + if (model != null) { + for (Property option : myOptions) { + String optionName = name + "." + option.getName(); + option.setImportant(model.isImportantProperty(optionName)); + option.setExpert(model.isExpertProperty(optionName)); + option.setDeprecated(model.isDeprecatedProperty(optionName)); + } + } } @Override public Property createForNewPresentation() { - return new FlagProperty(getName(), myDefinition); + return new FlagProperty(getName(), myDefinition, null); } @Override diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/feedbacks/AlphaComponent.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/feedbacks/AlphaComponent.java index 97df7edc81e1..726526310c5f 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/feedbacks/AlphaComponent.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/feedbacks/AlphaComponent.java @@ -38,8 +38,9 @@ public class AlphaComponent extends JComponent { } protected void paintComponent(Graphics g) { - Graphics2D g2d = (Graphics2D)g; super.paintComponent(g); + + Graphics2D g2d = (Graphics2D)g; Composite oldComposite = g2d.getComposite(); Color oldColor = g2d.getColor(); diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/feedbacks/RectangleComponent.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/feedbacks/RectangleComponent.java new file mode 100644 index 000000000000..19512a1e8a4a --- /dev/null +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/feedbacks/RectangleComponent.java @@ -0,0 +1,43 @@ +/* + * 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.feedbacks; + +import javax.swing.*; +import java.awt.*; + +/** + * @author Alexander Lobas + */ +public class RectangleComponent extends JComponent { + private final Color myColor; + private final int myLine; + + public RectangleComponent(Color color, int line) { + myColor = color; + myLine = line; + } + + @Override + protected void paintComponent(Graphics g) { + super.paintComponent(g); + g.setColor(myColor); + + Dimension size = getSize(); + for (int i = 0; i < myLine; i++) { + g.drawRect(i, i, size.width - i - i - 1, size.height - i - i - 1); + } + } +} \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/selection/ResizeSelectionDecorator.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/selection/ResizeSelectionDecorator.java index 8de6308c973f..3b574a3215cf 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/selection/ResizeSelectionDecorator.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/designSurface/selection/ResizeSelectionDecorator.java @@ -15,7 +15,6 @@ */ package com.intellij.designer.designSurface.selection; -import com.intellij.designer.designSurface.ComponentDecorator; import com.intellij.designer.designSurface.DecorationLayer; import com.intellij.designer.designSurface.tools.InputTool; import com.intellij.designer.model.RadComponent; @@ -36,9 +35,11 @@ public class ResizeSelectionDecorator extends NonResizeSelectionDecorator { @Override public InputTool findTargetTool(DecorationLayer layer, RadComponent component, int x, int y) { for (ResizePoint point : myPoints) { - InputTool tracker = point.findTargetTool(layer, component, x, y); - if (tracker != null) { - return tracker; + if (visible(component, point)) { + InputTool tracker = point.findTargetTool(layer, component, x, y); + if (tracker != null) { + return tracker; + } } } @@ -50,7 +51,13 @@ public class ResizeSelectionDecorator extends NonResizeSelectionDecorator { super.decorate(layer, g, component); for (ResizePoint point : myPoints) { - point.decorate(layer, g, component); + if (visible(component, point)) { + point.decorate(layer, g, component); + } } } + + protected boolean visible(RadComponent component, ResizePoint point) { + return true; + } } \ No newline at end of file diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/propertyTable/PropertyTable.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/propertyTable/PropertyTable.java index f3e351146b67..587a662055ba 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/propertyTable/PropertyTable.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/propertyTable/PropertyTable.java @@ -164,7 +164,7 @@ public final class PropertyTable extends JBTable implements ComponentSelectionLi return myShowExpert; } - public void setShowExpert(boolean showExpert) { + public void showExpert(boolean showExpert) { myShowExpert = showExpert; updateProperties(); } @@ -389,6 +389,17 @@ public final class PropertyTable extends JBTable implements ComponentSelectionLi return property.getChildren(getCurrentComponent()); } + private List getFilterChildren(Property property) { + List properties = new ArrayList(getChildren(property)); + for (Iterator I = properties.iterator(); I.hasNext(); ) { + Property child = I.next(); + if (child.isExpert() && !myShowExpert) { + I.remove(); + } + } + return properties; + } + private boolean isDefault(Property property) throws Exception { for (RadComponent component : myComponents) { if (!property.isDefaultValue(component)) { @@ -424,7 +435,7 @@ public final class PropertyTable extends JBTable implements ComponentSelectionLi Property property = myProperties.get(rowIndex); LOG.assertTrue(myExpandedProperties.remove(property.getPath())); - int size = getChildren(property).size(); + int size = getFilterChildren(property).size(); for (int i = 0; i < size; i++) { myProperties.remove(rowIndex + 1); } @@ -447,10 +458,11 @@ public final class PropertyTable extends JBTable implements ComponentSelectionLi if (myExpandedProperties.contains(path)) { return; } - myExpandedProperties.add(path); - List properties = getChildren(property); + + List properties = getFilterChildren(property); myProperties.addAll(rowIndex + 1, properties); + myModel.fireTableDataChanged(); if (selectedRow != -1) { diff --git a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/propertyTable/PropertyTablePanel.java b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/propertyTable/PropertyTablePanel.java index 9d37f90a2cfa..854c5ad1afcd 100644 --- a/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/propertyTable/PropertyTablePanel.java +++ b/plugins/ui-designer/ui-designer-new/src/com/intellij/designer/propertyTable/PropertyTablePanel.java @@ -74,7 +74,7 @@ public final class PropertyTablePanel extends JPanel { @Override public void setSelected(AnActionEvent e, boolean state) { - myPropertyTable.setShowExpert(state); + myPropertyTable.showExpert(state); } }); }