Browse Source

绝对布局基本功能2

master
zhouping 9 years ago
parent
commit
c3226b2659
  1. 192
      designer_base/src/com/fr/design/beans/location/Absorptionline.java
  2. 2
      designer_base/src/com/fr/design/beans/location/MoveUtils.java

192
designer_base/src/com/fr/design/beans/location/Absorptionline.java

@ -14,6 +14,7 @@ public class Absorptionline {
// 2.(x,y)(x±2根号3,y-2)(x±2根号3,y+2) // 2.(x,y)(x±2根号3,y-2)(x±2根号3,y+2)
private static int RECTANGLE_OFFSET_X = 2; private static int RECTANGLE_OFFSET_X = 2;
private static int RECTANGLE_OFFSET_Y = 3; private static int RECTANGLE_OFFSET_Y = 3;
private static int WIDGET_DISTANCE_MIN = 8;
//控件周围八个拖拽框的大小 //控件周围八个拖拽框的大小
private static int RESIZE_BOX_SIZE = 5; private static int RESIZE_BOX_SIZE = 5;
@ -238,114 +239,155 @@ public class Absorptionline {
//朝向上方的等距线 //朝向上方的等距线
private void paintTopEquidistantLine(Graphics g){ private void paintTopEquidistantLine(Graphics g){
int x1[] = { int x[] = {
equidistantStart.x + equidistantStart.width / 2, equidistantStart.x + equidistantStart.width / 2,
equidistantStart.x + equidistantStart.width / 2 - RECTANGLE_OFFSET_X, equidistantStart.x + equidistantStart.width / 2 - RECTANGLE_OFFSET_X,
equidistantStart.x + equidistantStart.width / 2 + RECTANGLE_OFFSET_X equidistantStart.x + equidistantStart.width / 2 + RECTANGLE_OFFSET_X
}; };
int y1[] = { int[] y1, y2;
top, if (equidistantStart.y - top > WIDGET_DISTANCE_MIN) {
top + RECTANGLE_OFFSET_Y, y1 = new int[] {
top + RECTANGLE_OFFSET_Y top,
}; top + RECTANGLE_OFFSET_Y,
int x2[] = { top + RECTANGLE_OFFSET_Y
equidistantStart.x + equidistantStart.width / 2, };
equidistantStart.x + equidistantStart.width / 2 + RECTANGLE_OFFSET_X, y2 = new int[]{
equidistantStart.x + equidistantStart.width / 2 - RECTANGLE_OFFSET_X equidistantStart.y - RESIZE_BOX_SIZE,
}; equidistantStart.y - RESIZE_BOX_SIZE - RECTANGLE_OFFSET_Y,
int y2[] = { equidistantStart.y - RESIZE_BOX_SIZE - RECTANGLE_OFFSET_Y
equidistantStart.y - RESIZE_BOX_SIZE, };
equidistantStart.y - RESIZE_BOX_SIZE - RECTANGLE_OFFSET_Y, }
equidistantStart.y - RESIZE_BOX_SIZE - RECTANGLE_OFFSET_Y else{
}; y1 = new int[] {
g.fillPolygon(x1, y1, 3); top,
g.fillPolygon(x2, y2, 3); top - RECTANGLE_OFFSET_Y,
top - RECTANGLE_OFFSET_Y
};
y2 = new int[] {
equidistantStart.y,
equidistantStart.y + RECTANGLE_OFFSET_Y,
equidistantStart.y + RECTANGLE_OFFSET_Y
};
}
g.fillPolygon(x, y1, 3);
g.fillPolygon(x, y2, 3);
GraphHelper.drawLine(g, GraphHelper.drawLine(g,
equidistantStart.x + equidistantStart.width / 2, top, equidistantStart.x + equidistantStart.width / 2, top,
equidistantStart.x + equidistantStart.width / 2, equidistantStart.y - RESIZE_BOX_SIZE); equidistantStart.x + equidistantStart.width / 2, equidistantStart.y - RESIZE_BOX_SIZE);
} }
//朝向左侧的等距线 //朝向左侧的等距线
private void paintLeftEquidistantLine(Graphics g){ private void paintLeftEquidistantLine(Graphics g){
int x1[] = { int y[] = {
left,
left + RECTANGLE_OFFSET_Y,
left + RECTANGLE_OFFSET_Y,
};
int y1[] = {
equidistantStart.y + equidistantStart.height / 2, equidistantStart.y + equidistantStart.height / 2,
equidistantStart.y + equidistantStart.height / 2 - RECTANGLE_OFFSET_X, equidistantStart.y + equidistantStart.height / 2 - RECTANGLE_OFFSET_X,
equidistantStart.y + equidistantStart.height / 2 + RECTANGLE_OFFSET_X, equidistantStart.y + equidistantStart.height / 2 + RECTANGLE_OFFSET_X,
}; };
int x2[] = { int[] x1, x2;
equidistantStart.x - RESIZE_BOX_SIZE, if (equidistantStart.x - left > WIDGET_DISTANCE_MIN) {
equidistantStart.x - RESIZE_BOX_SIZE - RECTANGLE_OFFSET_Y, x1 = new int[] {
equidistantStart.x - RESIZE_BOX_SIZE - RECTANGLE_OFFSET_Y left,
}; left + RECTANGLE_OFFSET_Y,
int y2[] = { left + RECTANGLE_OFFSET_Y,
equidistantStart.y + equidistantStart.height / 2, };
equidistantStart.y + equidistantStart.height / 2 + RECTANGLE_OFFSET_X,
equidistantStart.y + equidistantStart.height / 2 - RECTANGLE_OFFSET_X x2 = new int[] {
}; equidistantStart.x - RESIZE_BOX_SIZE,
g.fillPolygon(x1, y1, 3); equidistantStart.x - RESIZE_BOX_SIZE - RECTANGLE_OFFSET_Y,
g.fillPolygon(x2, y2, 3); equidistantStart.x - RESIZE_BOX_SIZE - RECTANGLE_OFFSET_Y
};
}
else{
x1 = new int[] {
left,
left - RECTANGLE_OFFSET_Y,
left - RECTANGLE_OFFSET_Y,
};
x2 = new int[] {
equidistantStart.x,
equidistantStart.x + RECTANGLE_OFFSET_Y,
equidistantStart.x + RECTANGLE_OFFSET_Y
};
}
g.fillPolygon(x1, y, 3);
g.fillPolygon(x2, y, 3);
GraphHelper.drawLine(g, GraphHelper.drawLine(g,
left, equidistantStart.y + equidistantStart.height / 2, left, equidistantStart.y + equidistantStart.height / 2,
equidistantStart.x - RESIZE_BOX_SIZE, equidistantStart.y + equidistantStart.height / 2); equidistantStart.x, equidistantStart.y + equidistantStart.height / 2);
} }
//朝向下方的等距线 //朝向下方的等距线
private void paintBottomEquidistantLine(Graphics g) { private void paintBottomEquidistantLine(Graphics g) {
int x1[] = { int x[] = {
equidistantStart.x + equidistantStart.width / 2, equidistantStart.x + equidistantStart.width / 2,
equidistantStart.x + equidistantStart.width / 2 + RECTANGLE_OFFSET_X, equidistantStart.x + equidistantStart.width / 2 + RECTANGLE_OFFSET_X,
equidistantStart.x + equidistantStart.width / 2 - RECTANGLE_OFFSET_X, equidistantStart.x + equidistantStart.width / 2 - RECTANGLE_OFFSET_X,
}; };
int y1[] = { int[] y1, y2;
equidistantStart.y + equidistantStart.height + RESIZE_BOX_SIZE, if (bottom - equidistantStart.y + equidistantStart.height > WIDGET_DISTANCE_MIN) {
equidistantStart.y + equidistantStart.height + RESIZE_BOX_SIZE + RECTANGLE_OFFSET_Y, y1 = new int[] {
equidistantStart.y + equidistantStart.height + RESIZE_BOX_SIZE + RECTANGLE_OFFSET_Y, equidistantStart.y + equidistantStart.height + RESIZE_BOX_SIZE,
}; equidistantStart.y + equidistantStart.height + RESIZE_BOX_SIZE + RECTANGLE_OFFSET_Y,
int x2[] = { equidistantStart.y + equidistantStart.height + RESIZE_BOX_SIZE + RECTANGLE_OFFSET_Y,
equidistantStart.x + equidistantStart.width / 2, };
equidistantStart.x + equidistantStart.width / 2 + RECTANGLE_OFFSET_X, y2 = new int[] {
equidistantStart.x + equidistantStart.width / 2 - RECTANGLE_OFFSET_X bottom,
}; bottom - RECTANGLE_OFFSET_Y,
int y2[] = { bottom - RECTANGLE_OFFSET_Y
bottom, };
bottom - RECTANGLE_OFFSET_Y, }
bottom - RECTANGLE_OFFSET_Y else{
}; y1 = new int[] {
g.fillPolygon(x1, y1, 3); equidistantStart.y + equidistantStart.height,
g.fillPolygon(x2, y2, 3); equidistantStart.y + equidistantStart.height - RECTANGLE_OFFSET_Y,
equidistantStart.y + equidistantStart.height - RECTANGLE_OFFSET_Y,
};
y2 = new int[] {
bottom,
bottom + RECTANGLE_OFFSET_Y,
bottom + RECTANGLE_OFFSET_Y
};
}
g.fillPolygon(x, y1, 3);
g.fillPolygon(x, y2, 3);
GraphHelper.drawLine(g, GraphHelper.drawLine(g,
equidistantStart.x + equidistantStart.width / 2, equidistantStart.y + equidistantStart.height + RESIZE_BOX_SIZE, equidistantStart.x + equidistantStart.width / 2, equidistantStart.y + equidistantStart.height,
equidistantStart.x + equidistantStart.width / 2, bottom); equidistantStart.x + equidistantStart.width / 2, bottom);
} }
//朝向右侧的等距线 //朝向右侧的等距线
private void paintRightEquidistantLine(Graphics g){ private void paintRightEquidistantLine(Graphics g){
int x1[] = { int y[] = {
right,
right - 3,
right - 3
};
int y1[] = {
equidistantStart.y + equidistantStart.height / 2, equidistantStart.y + equidistantStart.height / 2,
equidistantStart.y + equidistantStart.height / 2 - RECTANGLE_OFFSET_X, equidistantStart.y + equidistantStart.height / 2 - RECTANGLE_OFFSET_X,
equidistantStart.y + equidistantStart.height / 2 + RECTANGLE_OFFSET_X equidistantStart.y + equidistantStart.height / 2 + RECTANGLE_OFFSET_X
}; };
int x2[] = { int[] x1, x2;
equidistantStart.x + equidistantStart.width + RESIZE_BOX_SIZE, if(right - equidistantStart.x > WIDGET_DISTANCE_MIN) {
equidistantStart.x + equidistantStart.width + RESIZE_BOX_SIZE + RECTANGLE_OFFSET_Y, x1 = new int[]{
equidistantStart.x + equidistantStart.width + RESIZE_BOX_SIZE + RECTANGLE_OFFSET_Y right,
}; right - RECTANGLE_OFFSET_Y,
int y2[] = { right - RECTANGLE_OFFSET_Y
equidistantStart.y + equidistantStart.height / 2, };
equidistantStart.y + equidistantStart.height / 2 - RECTANGLE_OFFSET_X, x2 = new int[]{
equidistantStart.y + equidistantStart.height / 2 + RECTANGLE_OFFSET_X, equidistantStart.x + equidistantStart.width + RESIZE_BOX_SIZE,
}; equidistantStart.x + equidistantStart.width + RESIZE_BOX_SIZE + RECTANGLE_OFFSET_Y,
g.fillPolygon(x1, y1, 3); equidistantStart.x + equidistantStart.width + RESIZE_BOX_SIZE + RECTANGLE_OFFSET_Y
g.fillPolygon(x2, y2, 3); };
}
else{
x1 = new int[]{
right,
right + RECTANGLE_OFFSET_Y,
right + RECTANGLE_OFFSET_Y
};
x2 = new int[]{
equidistantStart.x + equidistantStart.width,
equidistantStart.x + equidistantStart.width - RECTANGLE_OFFSET_Y,
equidistantStart.x + equidistantStart.width - RECTANGLE_OFFSET_Y
};
}
g.fillPolygon(x1, y, 3);
g.fillPolygon(x2, y, 3);
GraphHelper.drawLine(g, GraphHelper.drawLine(g,
equidistantStart.x + equidistantStart.width + RESIZE_BOX_SIZE, equidistantStart.y + equidistantStart.height / 2, equidistantStart.x + equidistantStart.width, equidistantStart.y + equidistantStart.height / 2,
right, equidistantStart.y + equidistantStart.height / 2); right, equidistantStart.y + equidistantStart.height / 2);
} }
} }

2
designer_base/src/com/fr/design/beans/location/MoveUtils.java

@ -468,6 +468,7 @@ public class MoveUtils {
equidistantLines.add(equidistantLines1[0]); equidistantLines.add(equidistantLines1[0]);
equidistantLines.add(equidistantLines1[2]); equidistantLines.add(equidistantLines1[2]);
pEquidistantY.palce = operatingRectangle.y - offset / 2; pEquidistantY.palce = operatingRectangle.y - offset / 2;
operatingRectangle.y = pEquidistantY.palce;
} }
} }
if (equidistantLines1[1] != null && equidistantLines1[3] != null){//left, right if (equidistantLines1[1] != null && equidistantLines1[3] != null){//left, right
@ -477,6 +478,7 @@ public class MoveUtils {
equidistantLines.add(equidistantLines1[1]); equidistantLines.add(equidistantLines1[1]);
equidistantLines.add(equidistantLines1[3]); equidistantLines.add(equidistantLines1[3]);
pEquidistantX.palce = operatingRectangle.x - offset / 2; pEquidistantX.palce = operatingRectangle.x - offset / 2;
operatingRectangle.x = pEquidistantX.palce;
} }
} }
} }

Loading…
Cancel
Save