📄 sdabasecontrol.java
字号:
//上
for (int i = 0; i < ctrlList.size(); i++) {
ctrl = (SDABaseControl) ctrlList.elementAt(i);
if (!ctrl.visible) {
continue;
}
if (ctrl.dock == SDAConsts.dsTop) {
ctrl.left = 0;
ctrl.top = docktop;
ctrl.width = getWidth();
docktop += ctrl.getHeight();
if (ctrl instanceof SDASpliter) {
if (oldctrl != null) {
((SDASpliter) ctrl).setChangeControl(oldctrl);
}
}
oldctrl = ctrl;
}
}
//右
for (int i = 0; i < ctrlList.size(); i++) {
ctrl = (SDABaseControl) ctrlList.elementAt(i);
if (!ctrl.visible) {
continue;
}
if (ctrl.dock == SDAConsts.dsRight) {
ctrl.left = getWidth() - ctrl.getWidth();
ctrl.top = docktop;
ctrl.height = dockbottom - docktop > 0 ? dockbottom - docktop : 0;
dockright -= ctrl.getWidth();
if (ctrl instanceof SDASpliter) {
if (oldctrl != null) {
((SDASpliter) ctrl).setChangeControl(oldctrl);
}
}
oldctrl = ctrl;
}
}
//左
for (int i = 0; i < ctrlList.size(); i++) {
ctrl = (SDABaseControl) ctrlList.elementAt(i);
if (!ctrl.visible) {
continue;
}
if (ctrl.dock == SDAConsts.dsLeft) {
ctrl.left = dockleft;
ctrl.top = docktop;
ctrl.height = dockbottom - docktop > 0 ? dockbottom - docktop : 0;
dockleft += ctrl.getWidth();
if (ctrl instanceof SDASpliter) {
if (oldctrl != null) {
((SDASpliter) ctrl).setChangeControl(oldctrl);
}
}
oldctrl = ctrl;
}
}
//中
for (int i = 0; i < ctrlList.size(); i++) {
ctrl = (SDABaseControl) ctrlList.elementAt(i);
if (!ctrl.visible) {
continue;
}
if (ctrl.dock == SDAConsts.dsFill) {
ctrl.left = dockleft;
ctrl.top = docktop;
ctrl.height = dockbottom - docktop > 0 ? dockbottom - docktop : 0;
ctrl.width = dockright - dockleft > 0 ? dockright - dockleft : 0;
}
}
}
//加入布局
public void setAlignment(SDABaseControl referControl,
SDABaseControl[] arrayControl, int alignType,
int paramValue) {
internalSetAlignment(referControl, arrayControl, alignType, paramValue);
}
public void setAlignment(SDABaseControl referControl,
SDABaseControl arrayControl, int alignType,
int paramValue) {
internalSetAlignment(referControl, new SDABaseControl[]{arrayControl},
alignType, paramValue);
}
private void internalSetAlignment(SDABaseControl referControl,
SDABaseControl[] arrayControl,
int alignType, int paramValue) {
if ((referControl == null) || (arrayControl.length == 0)) {
return;
}
//加入到列表
Align alignItem = new Align();
alignItem.referControl = referControl;
alignItem.arrayControl = arrayControl;
alignItem.alignType = alignType;
alignItem.paramValue = paramValue;
AlignmentList.addElement(alignItem);
}
//执行布局
protected void setChildsAlign() {
if (AlignmentList.size() == 0) {
return;
}
Align alignItem = null;
SDABaseControl referControl = null;
SDABaseControl[] arrayControl = null;
SDABaseControl ctrl = null;
int alignType = -1;
int paramValue = 0;
int refLeft = 0;
int refTop = 0;
int refWidth = 0;
int refHeight = 0;
int minLeft = 0;
int minTop = 0;
int maxRight = 0;
int maxBottom = 0;
for (int j = 0; j < AlignmentList.size(); j++) {
alignItem = (Align) AlignmentList.elementAt(j);
if (!alignItem.referControl.visible) {
continue;
}
referControl = alignItem.referControl;
arrayControl = alignItem.arrayControl;
alignType = alignItem.alignType;
paramValue = alignItem.paramValue;
refLeft = referControl.getLeft();
refTop = referControl.getTop();
refWidth = referControl.getWidth();
refHeight = referControl.getHeight();
//居中
minLeft = Integer.MAX_VALUE;
minTop = Integer.MAX_VALUE;
maxRight = Integer.MIN_VALUE;
maxBottom = Integer.MIN_VALUE;
//相对于参照组件水平居中
if (alignType == SDAConsts.amhInCenter) {
refLeft = 0;
refTop = 0;
for (int i = 0; i < arrayControl.length; i++) {
ctrl = arrayControl[i];
if (!ctrl.visible) {
continue;
}
if (ctrl != referControl) {
minLeft = ctrl.getLeft() < minLeft ? ctrl.getLeft() : minLeft;
maxRight = ctrl.getLeft() + ctrl.getWidth() > maxRight ? ctrl.getLeft() + ctrl.getWidth() : maxRight;
}
}
//中线比较
int stepx = refWidth / 2 + refLeft -
((maxRight - minLeft) / 2 + minLeft);
//全部重新定位
for (int i = 0; i < arrayControl.length; i++) {
ctrl = arrayControl[i];
if (!ctrl.visible) {
continue;
}
if (ctrl != referControl) {
if (ctrl.dock == SDAConsts.dsNone) {
ctrl.left += stepx;
}
}
}
} else if (alignType == SDAConsts.amvInCenter) { //相对于参照组件垂直居中
refLeft = 0;
refTop = 0;
for (int i = 0; i < arrayControl.length; i++) {
ctrl = arrayControl[i];
if (!ctrl.visible) {
continue;
}
if (ctrl != referControl) {
minTop = ctrl.getTop() < minTop ? ctrl.getTop() : minTop;
maxBottom = ctrl.getTop() + ctrl.getHeight() >
maxBottom ? ctrl.getTop() + ctrl.getHeight() : maxBottom;
}
}
//中线比较
int stepy = refHeight / 2 + refTop -
((maxBottom - minTop) / 2 + minTop);
//全部重新定位
for (int i = 0; i < arrayControl.length; i++) {
ctrl = arrayControl[i];
if (!ctrl.visible) {
continue;
}
if (ctrl != referControl) {
if (ctrl.dock == SDAConsts.dsNone) {
ctrl.top += stepy;
}
}
}
} else if (alignType == SDAConsts.amParenLeftSpace) {
refLeft = 0;
refTop = 0;
for (int i = 0; i < arrayControl.length; i++) {
ctrl = arrayControl[i];
if (!ctrl.visible) {
continue;
}
if (ctrl != referControl) {
minLeft = ctrl.getLeft() < minLeft ? ctrl.getLeft() : minLeft;
//maxRight = ctrl.getLeft() + ctrl.getWidth() > maxRight ? ctrl.getLeft() + ctrl.getWidth() : maxRight;
}
}
//比较
int stepx = minLeft - paramValue;
//全部重新定位
for (int i = 0; i < arrayControl.length; i++) {
ctrl = arrayControl[i];
if (!ctrl.visible) {
continue;
}
if (ctrl != referControl) {
if (ctrl.dock == SDAConsts.dsNone) {
ctrl.left -= stepx;
}
}
}
} else if (alignType == SDAConsts.amParentRightSpace) {
refLeft = 0;
refTop = 0;
for (int i = 0; i < arrayControl.length; i++) {
ctrl = arrayControl[i];
if (!ctrl.visible) {
continue;
}
if (ctrl != referControl) {
//minLeft = ctrl.getLeft() < minLeft ? ctrl.getLeft() : minLeft;
maxRight = ctrl.getLeft() + ctrl.getWidth() > maxRight ? ctrl.getLeft() + ctrl.getWidth() : maxRight;
}
}
//比较
int stepx = getWidth() - maxRight - paramValue;
//全部重新定位
for (int i = 0; i < arrayControl.length; i++) {
ctrl = arrayControl[i];
if (!ctrl.visible) {
continue;
}
if (ctrl != referControl) {
if (ctrl.dock == SDAConsts.dsNone) {
ctrl.left += stepx;
}
}
}
} else if (alignType == SDAConsts.amParentTopSpace) {
refLeft = 0;
refTop = 0;
for (int i = 0; i < arrayControl.length; i++) {
ctrl = arrayControl[i];
if (!ctrl.visible) {
continue;
}
if (ctrl != referControl) {
minTop = ctrl.getTop() < minTop ? ctrl.getTop() : minTop;
//maxBottom = ctrl.getTop() + ctrl.getHeight() > maxBottom ? ctrl.getTop() + ctrl.getHeight() : maxBottom;
}
}
//中线比较
int stepy = minTop - paramValue;
//全部重新定位
for (int i = 0; i < arrayControl.length; i++) {
ctrl = arrayControl[i];
if (!ctrl.visible) {
continue;
}
if (ctrl != referControl) {
if (ctrl.dock == SDAConsts.dsNone) {
ctrl.top -= stepy;
}
}
}
} else if (alignType == SDAConsts.amParentBottomSpace) {
refLeft = 0;
refTop = 0;
for (int i = 0; i < arrayControl.length; i++) {
ctrl = arrayControl[i];
if (!ctrl.visible) {
continue;
}
if (ctrl != referControl) {
//minTop = ctrl.getTop() < minTop ? ctrl.getTop() : minTop;
maxBottom = ctrl.getTop() + ctrl.getHeight() >
maxBottom ? ctrl.getTop() + ctrl.getHeight() : maxBottom;
}
}
//中线比较
int stepy = getHeight() - maxBottom - paramValue;
//全部重新定位
for (int i = 0; i < arrayControl.length; i++) {
ctrl = arrayControl[i];
if (!ctrl.visible) {
continue;
}
if (ctrl != referControl) {
if (ctrl.dock == SDAConsts.dsNone) {
ctrl.top += stepy;
}
}
}
} else {
for (int i = 0; i < arrayControl.length; i++) {
ctrl = arrayControl[i];
if (!ctrl.visible) {
continue;
}
if (ctrl != referControl) {
//左对齐
if (alignType == SDAConsts.amhleft) {
if (ctrl.dock == SDAConsts.dsNone) {
ctrl.setLeft(refLeft);
}
}
//右对齐
if (alignType == SDAConsts.amhRight) {
if (ctrl.dock == SDAConsts.dsNone) {
ctrl.setLeft(refLeft +
(refWidth - ctrl.getWidth()));
}
}
//平移居中对齐
if (alignType == SDAConsts.amhCenter) {
if (ctrl.dock == SDAConsts.dsNone) {
ctrl.setLeft(refLeft +
(refWidth - ctrl.getWidth()) / 2);
}
}
//上对齐
if (alignType == SDAConsts.amvTop) {
if (ctrl.dock == SDAConsts.dsNone) {
ctrl.setTop(refTop);
}
}
//下对齐
if (alignType == SDAConsts.amvBottom) {
if (ctrl.dock == SDAConsts.dsNone) {
ctrl.setTop(refTop +
(refHeight - ctrl.getHeight()));
}
}
//垂直移动居中对齐
if (alignType == SDAConsts.amvCenter) {
if (ctrl.dock == SDAConsts.dsNone) {
ctrl.setTop(refTop +
(refHeight - ctrl.getHeight()) / 2);
}
}
//水平平移等距排列
if (alignType == SDAConsts.amhSpaceEqually) {
if (ctrl.dock == SDAConsts.dsNone) {
ctrl.setLeft(refLeft + refWidth + paramValue);
refLeft += refWidth + paramValue;
refWidth = ctrl.getWidth();
}
}
//垂直移动等距排列
if (alignType == SDAConsts.amvSpaceEqually) {
if (ctrl.dock == SDAConsts.dsNone) {
ctrl.setTop(refTop + refHeight + paramValue);
refTop += refHeight + paramValue;
refHeight = ctrl.getHeight();
}
}
//等宽
if (alignType == SDAConsts.amWidthEqually) {
if (ctrl.dock == SDAConsts.dsNone) {
ctrl.setWidth(refWidth);
}
}
//等高
if (alignType == SDAConsts.amHeightEqually) {
if (ctrl.dock == SDAConsts.dsNone) {
ctrl.setHeight(refHeight);
}
}
}
}
}
}
}
protected boolean InScreenRect(int x, int y) {
return (x >= this.originLeft && x <= this.originLeft + this.width) &&
(y >= this.originTop && y <= this.originTop + this.height);
}
protected boolean InClientRect(int x, int y) {
return (x >= this.left && x <= this.left + this.width) &&
(y >= this.top && y <= this.top + this.height);
}
protected boolean InClientRect(int x, int y, int left, int top, int width,
int height) {
return (x >= left) && (x <= left + width) && (y >= top) &&
(y <= top + height);
}
//坐标系转换
public int screenXToClient(int x) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -