|
|
@ -15,67 +15,103 @@ import java.util.Comparator; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
public class MultiSelectionArrangement { |
|
|
|
public class MultiSelectionArrangement { |
|
|
|
|
|
|
|
private static final int DEFAULT_GAP = 10; |
|
|
|
|
|
|
|
|
|
|
|
private FormDesigner designer; |
|
|
|
private FormDesigner designer; |
|
|
|
private XLayoutContainer parent; // 当前选中的那些组件所在父容器
|
|
|
|
|
|
|
|
private List<XCreator> selectedCreators; |
|
|
|
private List<XCreator> selectedCreators; |
|
|
|
private Rectangle rec; |
|
|
|
private Rectangle rec; |
|
|
|
|
|
|
|
|
|
|
|
public MultiSelectionArrangement(FormDesigner designer) { |
|
|
|
public MultiSelectionArrangement(FormDesigner designer) { |
|
|
|
this.designer = designer; |
|
|
|
this.designer = designer; |
|
|
|
update(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void leftAlign() { |
|
|
|
public void doArrangement(ArrangementType type) { |
|
|
|
|
|
|
|
doArrangement(type, DEFAULT_GAP); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void doArrangement(ArrangementType type, int gap) { |
|
|
|
|
|
|
|
updatePosition(); |
|
|
|
|
|
|
|
switch (type) { |
|
|
|
|
|
|
|
case RIGHT_ALIGN: |
|
|
|
|
|
|
|
rightAlign(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case TOP_ALIGN: |
|
|
|
|
|
|
|
topAlign(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case BOTTOM_ALIGN: |
|
|
|
|
|
|
|
bottomAlign(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case HORIZONTAL_CENTER_ALIGN: |
|
|
|
|
|
|
|
horizontalCenterAlign(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case VERTICAL_CENTER_ALIGN: |
|
|
|
|
|
|
|
verticalCenterAlign(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case HORIZONTAL_AUTO_DISTRIBUTION: |
|
|
|
|
|
|
|
horizontalAutoDistribution(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case HORIZONTAL_MANUAL_DISTRIBUTION: |
|
|
|
|
|
|
|
horizontalManualDistribution(gap); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case VERTICAL_AUTO_DISTRIBUTION: |
|
|
|
|
|
|
|
verticalAutoDistribution(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case VERTICAL_MANUAL_DISTRIBUTION: |
|
|
|
|
|
|
|
verticalManualDistribution(gap); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case LEFT_ALIGN: |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
leftAlign(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
updateModel(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void leftAlign() { |
|
|
|
for (XCreator creator : selectedCreators) { |
|
|
|
for (XCreator creator : selectedCreators) { |
|
|
|
creator.setLocation(rec.x, creator.getY()); |
|
|
|
creator.setLocation(rec.x, creator.getY()); |
|
|
|
} |
|
|
|
} |
|
|
|
update(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void rightAlign() { |
|
|
|
private void rightAlign() { |
|
|
|
for (XCreator creator : selectedCreators) { |
|
|
|
for (XCreator creator : selectedCreators) { |
|
|
|
creator.setLocation(rec.x + rec.width - creator.getWidth(), creator.getY()); |
|
|
|
creator.setLocation(rec.x + rec.width - creator.getWidth(), creator.getY()); |
|
|
|
} |
|
|
|
} |
|
|
|
update(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void topAlign() { |
|
|
|
private void topAlign() { |
|
|
|
for (XCreator creator : selectedCreators) { |
|
|
|
for (XCreator creator : selectedCreators) { |
|
|
|
creator.setLocation(creator.getX(), rec.y); |
|
|
|
creator.setLocation(creator.getX(), rec.y); |
|
|
|
} |
|
|
|
} |
|
|
|
update(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void bottomAlign() { |
|
|
|
private void bottomAlign() { |
|
|
|
for (XCreator creator : selectedCreators) { |
|
|
|
for (XCreator creator : selectedCreators) { |
|
|
|
creator.setLocation(creator.getX(), rec.y + rec.height - creator.getHeight()); |
|
|
|
creator.setLocation(creator.getX(), rec.y + rec.height - creator.getHeight()); |
|
|
|
} |
|
|
|
} |
|
|
|
update(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void horizontalCenterAlign() { |
|
|
|
private void horizontalCenterAlign() { |
|
|
|
for (XCreator creator : selectedCreators) { |
|
|
|
for (XCreator creator : selectedCreators) { |
|
|
|
creator.setLocation(rec.x + rec.width / 2 - creator.getWidth() / 2, creator.getY()); |
|
|
|
creator.setLocation(rec.x + rec.width / 2 - creator.getWidth() / 2, creator.getY()); |
|
|
|
} |
|
|
|
} |
|
|
|
update(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void verticalCenterAlign() { |
|
|
|
private void verticalCenterAlign() { |
|
|
|
for (XCreator creator : selectedCreators) { |
|
|
|
for (XCreator creator : selectedCreators) { |
|
|
|
creator.setLocation(creator.getX(), rec.y + rec.height / 2 - creator.getHeight() / 2); |
|
|
|
creator.setLocation(creator.getX(), rec.y + rec.height / 2 - creator.getHeight() / 2); |
|
|
|
} |
|
|
|
} |
|
|
|
update(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 水平分布,自动,间距由selectedCreators和border共同计算而来
|
|
|
|
// 水平分布,自动,间距由selectedCreators和border共同计算而来
|
|
|
|
public void horizontalAutoDistribution() { |
|
|
|
private void horizontalAutoDistribution() { |
|
|
|
sortHorizontal(); |
|
|
|
sortHorizontal(); |
|
|
|
int[] gaps = calculateHorizontalGaps(); |
|
|
|
int[] gaps = calculateHorizontalGaps(); |
|
|
|
horizontalDistribution(gaps); |
|
|
|
horizontalDistribution(gaps); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 水平分布,手动,传入一个间距,排列selectedCreators
|
|
|
|
// 水平分布,手动,传入一个间距,排列selectedCreators
|
|
|
|
public void horizontalManualDistribution(int gap) { |
|
|
|
private void horizontalManualDistribution(int gap) { |
|
|
|
sortHorizontal(); |
|
|
|
sortHorizontal(); |
|
|
|
reSizeRecByHorizontal(gap); |
|
|
|
reSizeRecByHorizontal(gap); |
|
|
|
horizontalDistribution(fillGaps(gap, selectedCreators.size() - 1)); |
|
|
|
horizontalDistribution(fillGaps(gap, selectedCreators.size() - 1)); |
|
|
@ -87,7 +123,6 @@ public class MultiSelectionArrangement { |
|
|
|
XCreator preCreator = selectedCreators.get(i - 1); |
|
|
|
XCreator preCreator = selectedCreators.get(i - 1); |
|
|
|
creator.setLocation(preCreator.getX() + preCreator.getWidth() + gaps[i - 1], creator.getY()); |
|
|
|
creator.setLocation(preCreator.getX() + preCreator.getWidth() + gaps[i - 1], creator.getY()); |
|
|
|
} |
|
|
|
} |
|
|
|
update(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void reSizeRecByHorizontal(int gap) { |
|
|
|
private void reSizeRecByHorizontal(int gap) { |
|
|
@ -145,13 +180,13 @@ public class MultiSelectionArrangement { |
|
|
|
return calculateIntegerGaps(distanceBetweenHeadAndTailCreators - sum, gapCount); |
|
|
|
return calculateIntegerGaps(distanceBetweenHeadAndTailCreators - sum, gapCount); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void verticalAutoDistribution() { |
|
|
|
private void verticalAutoDistribution() { |
|
|
|
sortVertical(); |
|
|
|
sortVertical(); |
|
|
|
int[] gaps = calculateVerticalGaps(); |
|
|
|
int[] gaps = calculateVerticalGaps(); |
|
|
|
verticalDistribution(gaps); |
|
|
|
verticalDistribution(gaps); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void verticalManualDistribution(int gap) { |
|
|
|
private void verticalManualDistribution(int gap) { |
|
|
|
sortVertical(); |
|
|
|
sortVertical(); |
|
|
|
reSizeRecByVertical(gap); |
|
|
|
reSizeRecByVertical(gap); |
|
|
|
verticalDistribution(fillGaps(gap, selectedCreators.size() - 1)); |
|
|
|
verticalDistribution(fillGaps(gap, selectedCreators.size() - 1)); |
|
|
@ -163,7 +198,6 @@ public class MultiSelectionArrangement { |
|
|
|
XCreator preCreator = selectedCreators.get(i - 1); |
|
|
|
XCreator preCreator = selectedCreators.get(i - 1); |
|
|
|
creator.setLocation(creator.getX(), preCreator.getY() + preCreator.getHeight() + gaps[i - 1]); |
|
|
|
creator.setLocation(creator.getX(), preCreator.getY() + preCreator.getHeight() + gaps[i - 1]); |
|
|
|
} |
|
|
|
} |
|
|
|
update(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void reSizeRecByVertical(int gap) { |
|
|
|
private void reSizeRecByVertical(int gap) { |
|
|
@ -252,12 +286,15 @@ public class MultiSelectionArrangement { |
|
|
|
return gaps; |
|
|
|
return gaps; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void update() { |
|
|
|
private void updatePosition() { |
|
|
|
FormSelection selection = designer.getSelectionModel().getSelection(); |
|
|
|
FormSelection selection = designer.getSelectionModel().getSelection(); |
|
|
|
this.selectedCreators = Arrays.asList(selection.getSelectedCreators()); |
|
|
|
this.selectedCreators = Arrays.asList(selection.getSelectedCreators()); |
|
|
|
this.rec = selection.getSelctionBounds(); |
|
|
|
this.rec = selection.getSelctionBounds(); |
|
|
|
this.parent = getParent(selection.getSelectedCreator()); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void updateModel() { |
|
|
|
|
|
|
|
FormSelection selection = designer.getSelectionModel().getSelection(); |
|
|
|
|
|
|
|
XLayoutContainer parent = getParent(selection.getSelectedCreator()); |
|
|
|
if (parent != null) { |
|
|
|
if (parent != null) { |
|
|
|
// 这里要修改修改engine里面的对象才能成功保存,光修改设计器对象没用
|
|
|
|
// 这里要修改修改engine里面的对象才能成功保存,光修改设计器对象没用
|
|
|
|
WLayout wabs = parent.toData(); |
|
|
|
WLayout wabs = parent.toData(); |
|
|
|