Browse Source

REPORT-100623 优化下代码

newui
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); ComponentAdapter adapter = AdapterBus.getComponentAdapter(designer, this);
editingMouseListener.startEditing(this, adapter.getDesignerEditor(), adapter); editingMouseListener.startEditing(this, adapter.getDesignerEditor(), adapter);
Rectangle rect = this.getBounds(); Rectangle rect = this.getBounds();
if (mouseEditRangeValid(e, rect, editingMouseListener)) { if (checkMouseEditRangeValid(e, rect, editingMouseListener)) {
ToolTipEditor.getInstance().showToolTip((XEditorHolder) this, e.getXOnScreen(), ToolTipEditor.getInstance().showToolTip((XEditorHolder) this, e.getXOnScreen(),
e.getYOnScreen()); e.getYOnScreen());
} }
@ -60,14 +60,19 @@ public class XEditorHolder extends XWidgetCreator {
* @param editingMouseListener 位置处理器 * @param editingMouseListener 位置处理器
* @return 是否位于可编辑区 * @return 是否位于可编辑区
*/ */
private boolean mouseEditRangeValid(MouseEvent e, Rectangle rect, EditingMouseListener editingMouseListener) { private boolean checkMouseEditRangeValid(MouseEvent e, Rectangle rect, EditingMouseListener editingMouseListener) {
int minHorizontal = rect.x + rect.width / 2 - editingMouseListener.getMinMoveSize(); int horizontalValue = editingMouseListener.getDesigner().getHorizontalScaleValue();
int maxHorizontal = rect.x + rect.width / 2 + editingMouseListener.getMinMoveSize(); int verticalValue = editingMouseListener.getDesigner().getVerticalScaleValue();
int minVertical = rect.y + rect.height / 2 - editingMouseListener.getMinMoveSize(); int minMoveSize = editingMouseListener.getMinMoveSize();
int maxVertical = rect.y + rect.height / 2 + editingMouseListener.getMinMoveSize();
int minHorizontal = rect.x + rect.width / 2 - minMoveSize - horizontalValue;
return e.getX() + editingMouseListener.getDesigner().getHorizontalScaleValue() > minHorizontal && e.getX() + editingMouseListener.getDesigner().getHorizontalScaleValue() < maxHorizontal int maxHorizontal = rect.x + rect.width / 2 + minMoveSize - horizontalValue;
&& e.getY() + editingMouseListener.getDesigner().getVerticalScaleValue() > minVertical && e.getY() + editingMouseListener.getDesigner().getVerticalScaleValue() < maxVertical; 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 @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) { if (component instanceof XEditorHolder) {
XEditorHolder xcreator = (XEditorHolder) component; XEditorHolder xcreator = (XEditorHolder) component;
Rectangle rect = xcreator.getBounds(); Rectangle rect = xcreator.getBounds();
if (creatorRangeValid(e, rect)) { if (checkCreatorRangeValid(e, rect)) {
if (designer.getCursor().getType() != Cursor.HAND_CURSOR) { if (designer.getCursor().getType() != Cursor.HAND_CURSOR) {
designer.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); designer.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
} }
@ -748,12 +748,16 @@ public class EditingMouseListener extends MouseInputAdapter {
/** /**
* 判断当前鼠标移动事件是否在Creator有效范围内 * 判断当前鼠标移动事件是否在Creator有效范围内
*/ */
private boolean creatorRangeValid(MouseEvent e, Rectangle rect) { private boolean checkCreatorRangeValid(MouseEvent e, Rectangle rect) {
int minHorizontal = rect.x + rect.width / 2 - minMoveSize; int horizontalValue = designer.getHorizontalScaleValue();
int maxHorizontal = rect.x + rect.width / 2 + minMoveSize; int verticalValue = designer.getVerticalScaleValue();
int minVertical = rect.y + rect.height / 2 - minMoveSize;
int maxVertical = rect.y + rect.height / 2 + minMoveSize; int minHorizontal = rect.x + rect.width / 2 - minMoveSize - horizontalValue;
return e.getX() + designer.getHorizontalScaleValue() > minHorizontal && e.getX() + designer.getHorizontalScaleValue() < maxHorizontal int maxHorizontal = rect.x + rect.width / 2 + minMoveSize - horizontalValue;
&& e.getY() + designer.getVerticalScaleValue() > minVertical && e.getY() + designer.getVerticalScaleValue() < maxVertical; 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