Browse Source

REPORT-100623 优化下代码

release/11.0
obo 1 year ago
parent
commit
a28fc37a8a
  1. 23
      designer-form/src/main/java/com/fr/design/designer/creator/XEditorHolder.java
  2. 20
      designer-form/src/main/java/com/fr/design/mainframe/EditingMouseListener.java

23
designer-form/src/main/java/com/fr/design/designer/creator/XEditorHolder.java

@ -44,7 +44,7 @@ public class XEditorHolder extends XWidgetCreator {
ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this);
editingMouseListener.startEditing(this, adapter.getDesignerEditor(), adapter);
Rectangle rect = this.getBounds();
if (mouseEditRangeValid(e, rect, editingMouseListener)) {
if (checkMouseEditRangeValid(e, rect, editingMouseListener)) {
ToolTipEditor.getInstance().showToolTip((XEditorHolder) this, e.getXOnScreen(),
e.getYOnScreen());
}
@ -60,14 +60,19 @@ public class XEditorHolder extends XWidgetCreator {
* @param editingMouseListener 位置处理器
* @return 是否位于可编辑区
*/
private boolean mouseEditRangeValid(MouseEvent e, Rectangle rect, EditingMouseListener editingMouseListener) {
int minHorizontal = rect.x + rect.width / 2 - editingMouseListener.getMinMoveSize();
int maxHorizontal = rect.x + rect.width / 2 + editingMouseListener.getMinMoveSize();
int minVertical = rect.y + rect.height / 2 - editingMouseListener.getMinMoveSize();
int maxVertical = rect.y + rect.height / 2 + editingMouseListener.getMinMoveSize();
return e.getX() + editingMouseListener.getDesigner().getHorizontalScaleValue() > minHorizontal && e.getX() + editingMouseListener.getDesigner().getHorizontalScaleValue() < maxHorizontal
&& e.getY() + editingMouseListener.getDesigner().getVerticalScaleValue() > minVertical && e.getY() + editingMouseListener.getDesigner().getVerticalScaleValue() < maxVertical;
private boolean checkMouseEditRangeValid(MouseEvent e, Rectangle rect, EditingMouseListener editingMouseListener) {
int horizontalValue = editingMouseListener.getDesigner().getHorizontalScaleValue();
int verticalValue = editingMouseListener.getDesigner().getVerticalScaleValue();
int minMoveSize = editingMouseListener.getMinMoveSize();
int minHorizontal = rect.x + rect.width / 2 - minMoveSize - horizontalValue;
int maxHorizontal = rect.x + rect.width / 2 + minMoveSize - horizontalValue;
int minVertical = rect.y + rect.height / 2 - minMoveSize - verticalValue;
int maxVertical = rect.y + rect.height / 2 + minMoveSize - verticalValue;
boolean xRangeValid = e.getX() > minHorizontal && e.getX() < maxHorizontal;
boolean yRangeValid = e.getY() > minVertical && e.getY() < maxVertical;
return xRangeValid && yRangeValid;
}
@Override

20
designer-form/src/main/java/com/fr/design/mainframe/EditingMouseListener.java

@ -279,7 +279,7 @@ public class EditingMouseListener extends MouseInputAdapter {
if (component instanceof XEditorHolder) {
XEditorHolder xcreator = (XEditorHolder) component;
Rectangle rect = xcreator.getBounds();
if (creatorRangeValid(e, rect)) {
if (checkCreatorRangeValid(e, rect)) {
if (designer.getCursor().getType() != Cursor.HAND_CURSOR) {
designer.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
@ -748,12 +748,16 @@ public class EditingMouseListener extends MouseInputAdapter {
/**
* 判断当前鼠标移动事件是否在Creator有效范围内
*/
private boolean creatorRangeValid(MouseEvent e, Rectangle rect) {
int minHorizontal = rect.x + rect.width / 2 - minMoveSize;
int maxHorizontal = rect.x + rect.width / 2 + minMoveSize;
int minVertical = rect.y + rect.height / 2 - minMoveSize;
int maxVertical = rect.y + rect.height / 2 + minMoveSize;
return e.getX() + designer.getHorizontalScaleValue() > minHorizontal && e.getX() + designer.getHorizontalScaleValue() < maxHorizontal
&& e.getY() + designer.getVerticalScaleValue() > minVertical && e.getY() + designer.getVerticalScaleValue() < maxVertical;
private boolean checkCreatorRangeValid(MouseEvent e, Rectangle rect) {
int horizontalValue = designer.getHorizontalScaleValue();
int verticalValue = designer.getVerticalScaleValue();
int minHorizontal = rect.x + rect.width / 2 - minMoveSize - horizontalValue;
int maxHorizontal = rect.x + rect.width / 2 + minMoveSize - horizontalValue;
int minVertical = rect.y + rect.height / 2 - minMoveSize - verticalValue;
int maxVertical = rect.y + rect.height / 2 + minMoveSize - verticalValue;
boolean xRangeValid = e.getX() > minHorizontal && e.getX() < maxHorizontal;
boolean yRangeValid = e.getY() > minVertical && e.getY() < maxVertical;
return xRangeValid && yRangeValid;
}
}

Loading…
Cancel
Save