mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
FrameLayout
This commit is contained in:
+54
-64
@@ -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<Pair<Gravity, Gravity>> myExcludes;
|
||||
private Set<Pair<Gravity, Gravity>> 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, Gravity>(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<Gravity, Gravity>(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<Gravity, Gravity>(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<Gravity, Gravity> 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;
|
||||
}
|
||||
|
||||
|
||||
+115
-1
@@ -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;
|
||||
}
|
||||
}
|
||||
+195
@@ -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<RadComponent> 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
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -115,7 +115,7 @@ public class PropertyParser {
|
||||
}
|
||||
|
||||
if (layoutParams != null) {
|
||||
List<Property> properties = loadLayoutProperties(layoutParams, 0);
|
||||
List<Property> properties = loadLayoutProperties(layoutParams, 0, parent.getMetaModel());
|
||||
|
||||
if (!properties.isEmpty()) {
|
||||
properties = new ArrayList<Property>(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<Property> loadLayoutProperties(String[] components, int index) throws Exception {
|
||||
private List<Property> loadLayoutProperties(String[] components, int index, MetaModel model) throws Exception {
|
||||
String component = components[index];
|
||||
|
||||
List<Property> 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);
|
||||
}
|
||||
|
||||
+5
-1
@@ -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<RadComponent> selection) {
|
||||
return super.getChildSelectionDecorator(component, selection); // TODO: Auto-generated method stub
|
||||
return ResizeOperation.full();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-1
@@ -1012,7 +1012,9 @@
|
||||
<palette title="FrameLayout" icon="/com/intellij/android/designer/icons/FrameLayout.png"
|
||||
tooltip="FrameLayout is designed to block out an area on the screen to display a single item."/>
|
||||
|
||||
<properties important="foreground foregroundGravity"/>
|
||||
<properties important="foreground foregroundGravity"
|
||||
expert="layout:gravity.fill layout:gravity.fill_horizontal layout:gravity.fill_vertical layout:gravity.clip_vertical layout:gravity.clip_horizontal"
|
||||
/>
|
||||
|
||||
<creation>
|
||||
<![CDATA[
|
||||
|
||||
+12
-2
@@ -16,6 +16,7 @@
|
||||
package com.intellij.android.designer.propertyTable;
|
||||
|
||||
import com.intellij.android.designer.model.RadViewComponent;
|
||||
import com.intellij.designer.model.MetaModel;
|
||||
import com.intellij.designer.propertyTable.Property;
|
||||
import com.intellij.designer.propertyTable.PropertyEditor;
|
||||
import com.intellij.designer.propertyTable.PropertyRenderer;
|
||||
@@ -39,18 +40,27 @@ public class FlagProperty extends Property<RadViewComponent> {
|
||||
private final AttributeDefinition myDefinition;
|
||||
private final List<Property> myOptions = new ArrayList<Property>();
|
||||
|
||||
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
|
||||
|
||||
+2
-1
@@ -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();
|
||||
|
||||
|
||||
+43
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
-5
@@ -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;
|
||||
}
|
||||
}
|
||||
+16
-4
@@ -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<Property> getFilterChildren(Property property) {
|
||||
List<Property> properties = new ArrayList<Property>(getChildren(property));
|
||||
for (Iterator<Property> 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<Property> properties = getChildren(property);
|
||||
|
||||
List<Property> properties = getFilterChildren(property);
|
||||
myProperties.addAll(rowIndex + 1, properties);
|
||||
|
||||
myModel.fireTableDataChanged();
|
||||
|
||||
if (selectedRow != -1) {
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ public final class PropertyTablePanel extends JPanel {
|
||||
|
||||
@Override
|
||||
public void setSelected(AnActionEvent e, boolean state) {
|
||||
myPropertyTable.setShowExpert(state);
|
||||
myPropertyTable.showExpert(state);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user