Browse Source

REPORT-54116 设计器绝对布局内可锁定组件宽高比例

绝对布局内的组件,按下Shift键拖拽改变组件尺寸或在设计器右侧栏
编辑组件尺寸大小时,可以保持组件宽高比例不变,优化用户体验

按下Shift键鼠标拖拽改变组件尺寸时锁定宽高比例的逻辑,
也对参数面板内控件和表格浮动元素生效
feature/10.0
Starryi 3 years ago
parent
commit
f1cfb52102
  1. 48
      designer-base/src/main/java/com/fr/design/widget/WidgetBoundsPaneFactory.java
  2. BIN
      designer-base/src/main/resources/com/fr/design/images/buttonicon/icon_lock_disabled.png
  3. BIN
      designer-base/src/main/resources/com/fr/design/images/buttonicon/icon_lock_enabled.png
  4. BIN
      designer-base/src/main/resources/com/fr/design/images/buttonicon/icon_unlock_disabled.png
  5. BIN
      designer-base/src/main/resources/com/fr/design/images/buttonicon/icon_unlock_enabled.png
  6. 5
      designer-form/src/main/java/com/fr/design/designer/beans/location/AccessDirection.java
  7. 11
      designer-form/src/main/java/com/fr/design/designer/beans/location/Bottom.java
  8. 11
      designer-form/src/main/java/com/fr/design/designer/beans/location/Left.java
  9. 20
      designer-form/src/main/java/com/fr/design/designer/beans/location/LeftBottom.java
  10. 23
      designer-form/src/main/java/com/fr/design/designer/beans/location/LeftTop.java
  11. 13
      designer-form/src/main/java/com/fr/design/designer/beans/location/Right.java
  12. 18
      designer-form/src/main/java/com/fr/design/designer/beans/location/RightBottom.java
  13. 20
      designer-form/src/main/java/com/fr/design/designer/beans/location/RightTop.java
  14. 11
      designer-form/src/main/java/com/fr/design/designer/beans/location/Top.java
  15. 11
      designer-form/src/main/java/com/fr/design/designer/beans/models/StateModel.java
  16. 7
      designer-form/src/main/java/com/fr/design/mainframe/EditingMouseListener.java
  17. 12
      designer-form/src/main/java/com/fr/design/mainframe/FormEditorKeyListener.java
  18. 13
      designer-form/src/main/java/com/fr/design/mainframe/FormSelection.java
  19. 6
      designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetAbsoluteBoundPane.java
  20. 149
      designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetBoundPane.java
  21. 81
      designer-realize/src/main/java/com/fr/grid/GridMouseAdapter.java

48
designer-base/src/main/java/com/fr/design/widget/WidgetBoundsPaneFactory.java

@ -10,6 +10,7 @@ import com.fr.design.layout.TableLayout;
import com.fr.design.layout.TableLayoutHelper;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import java.awt.BorderLayout;
@ -45,23 +46,28 @@ public class WidgetBoundsPaneFactory {
private static final int RIGHT_PANE_WIDTH = 145;
public static UIExpandablePane createBoundsPane(UISpinner width, UISpinner height) {
public static UIExpandablePane createBoundsPane(UISpinner width, UISpinner height, JComponent ratioLocked) {
JPanel boundsPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
double f = TableLayout.FILL;
double p = TableLayout.PREFERRED;
Component[][] components = new Component[][]{
new Component[]{FRWidgetFactory.createLineWrapLabel(Toolkit.i18nText("Fine-Design_Basic_Component_Size")), createRightPane(width, height)},
new Component[]{FRWidgetFactory.createLineWrapLabel(Toolkit.i18nText("Fine-Design_Basic_Component_Size")),
ratioLocked != null ? createRightPane(width, ratioLocked, height) : createRightPane(width, height)},
new Component[]{null, createRightPane(new UILabel(Toolkit.i18nText("Fine-Design_Basic_Tree_Width"), SwingConstants.CENTER), new UILabel(Toolkit.i18nText("Fine-Design_Basic_Tree_Height"), SwingConstants.CENTER))},
};
double[] rowSize = {p, p};
double[] columnSize = {f, RIGHT_PANE_WIDTH};
int[][] rowCount = {{1, 1}, {1, 1}};
int[][] rowCount = ratioLocked != null ? new int[][]{{1, 1}, {1, 1, 1}} : new int[][]{{1, 1}, {1, 1}};
final JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, IntervalConstants.INTERVAL_W5, IntervalConstants.INTERVAL_L6);
panel.setBorder(BorderFactory.createEmptyBorder(10, 0, 10, 0));
boundsPane.add(panel);
return new UIExpandablePane(Toolkit.i18nText("Fine-Design_Form_Coords_And_Size"), 280, 24, boundsPane);
}
public static UIExpandablePane createBoundsPane(UISpinner width, UISpinner height) {
return createBoundsPane(width, height, null);
}
public static JPanel createRightPane(Component com1, Component com2) {
double f = TableLayout.FILL;
double p = TableLayout.PREFERRED;
@ -74,21 +80,41 @@ public class WidgetBoundsPaneFactory {
return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, IntervalConstants.INTERVAL_L6, IntervalConstants.INTERVAL_L1);
}
public static UIExpandablePane createAbsoluteBoundsPane(UISpinner x, UISpinner y, UISpinner width, UISpinner height, NameAttribute nameAttribute) {
public static JPanel createRightPane(Component com1, Component com2, Component com3) {
double f = TableLayout.FILL;
double p = TableLayout.PREFERRED;
double[] rowSize = {p};
double[] columnSize = {f, 24, f};
int[][] rowCount = {{1, 1, 1}};
Component[][] components = new Component[][]{
new Component[]{com1, com2, com3}
};
return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, 0, IntervalConstants.INTERVAL_L1);
}
public static UIExpandablePane createAbsoluteBoundsPane(UISpinner x, UISpinner y, UISpinner width, UISpinner height, JComponent ratioLocked, NameAttribute nameAttribute) {
double f = TableLayout.FILL;
double p = TableLayout.PREFERRED;
UILabel positionLabel = FRWidgetFactory.createLineWrapLabel(nameAttribute.getPositionName());
UILabel xLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_X_Coordinate"), SwingConstants.CENTER);
UILabel yLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Y_Coordinate"), SwingConstants.CENTER);
UILabel sizeLabel = FRWidgetFactory.createLineWrapLabel(nameAttribute.getSizeName());
UILabel widthLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Tree_Width"), SwingConstants.CENTER);
UILabel heightLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Tree_Height"), SwingConstants.CENTER);
Component[][] northComponents = new Component[][]{
new Component[]{FRWidgetFactory.createLineWrapLabel(nameAttribute.getPositionName()), createRightPane(x, y)},
new Component[]{null, createRightPane(new UILabel(Toolkit.i18nText("Fine-Design_Basic_X_Coordinate"), SwingConstants.CENTER), new UILabel(Toolkit.i18nText("Fine-Design_Basic_Y_Coordinate"), SwingConstants.CENTER))},
new Component[]{positionLabel, ratioLocked != null ? createRightPane(x, null, y) : createRightPane(x, y)},
new Component[]{null, ratioLocked != null ? createRightPane(xLabel, null, yLabel) : createRightPane(xLabel, yLabel)},
};
Component[][] centerComponents = new Component[][]{
new Component[]{FRWidgetFactory.createLineWrapLabel(nameAttribute.getSizeName()), createRightPane(width, height)},
new Component[]{null, createRightPane(new UILabel(Toolkit.i18nText("Fine-Design_Basic_Tree_Width"), SwingConstants.CENTER), new UILabel(Toolkit.i18nText("Fine-Design_Basic_Tree_Height"), SwingConstants.CENTER))},
new Component[]{sizeLabel, ratioLocked != null ? createRightPane(width, ratioLocked, height) : createRightPane(width, height)},
new Component[]{null, ratioLocked != null ? createRightPane(widthLabel, null, heightLabel) : createRightPane(widthLabel, heightLabel)},
};
double[] rowSize = {p, p};
double[] columnSize = {f, RIGHT_PANE_WIDTH};
int[][] rowCount = {{1, 1}, {1, 1}};
int[][] rowCount = ratioLocked != null ? new int[][]{{1, 1, 1}, {1, 1, 1}} : new int[][]{{1, 1}, {1, 1}};
final JPanel northPanel = TableLayoutHelper.createGapTableLayoutPane(northComponents, rowSize, columnSize, rowCount, IntervalConstants.INTERVAL_W5, IntervalConstants.INTERVAL_L6);
final JPanel centerPanel = TableLayoutHelper.createGapTableLayoutPane(centerComponents, rowSize, columnSize, rowCount, IntervalConstants.INTERVAL_W5, IntervalConstants.INTERVAL_L6);
JPanel boundsPane = FRGUIPaneFactory.createBorderLayout_S_Pane();
@ -99,6 +125,10 @@ public class WidgetBoundsPaneFactory {
return new UIExpandablePane(Toolkit.i18nText("Fine-Design_Form_Coords_And_Size"), 230, 24, boundsPane);
}
public static UIExpandablePane createAbsoluteBoundsPane(UISpinner x, UISpinner y, UISpinner width, UISpinner height, NameAttribute nameAttribute) {
return createAbsoluteBoundsPane(x, y, width, height, null, nameAttribute);
}
public static UIExpandablePane createAbsoluteBoundsPane(UISpinner x, UISpinner y, UISpinner width, UISpinner height) {
return createAbsoluteBoundsPane(x, y, width, height, NameAttribute.DEFAULT);
}

BIN
designer-base/src/main/resources/com/fr/design/images/buttonicon/icon_lock_disabled.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

BIN
designer-base/src/main/resources/com/fr/design/images/buttonicon/icon_lock_enabled.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 B

BIN
designer-base/src/main/resources/com/fr/design/images/buttonicon/icon_unlock_disabled.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 226 B

BIN
designer-base/src/main/resources/com/fr/design/images/buttonicon/icon_unlock_enabled.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 229 B

5
designer-form/src/main/java/com/fr/design/designer/beans/location/AccessDirection.java

@ -193,8 +193,13 @@ public abstract class AccessDirection implements Direction {
if (type != formEditor.getCursor().getType()) {
// 设置当前形状
formEditor.setCursor(Cursor.getPredefinedCursor(type));
formEditor.setToolTipText(getTooltip());
}
}
public String getTooltip() {
return null;
}
/**
* 生成组件备用的bound

11
designer-form/src/main/java/com/fr/design/designer/beans/location/Bottom.java

@ -15,6 +15,12 @@ public class Bottom extends AccessDirection {
Rectangle oldbounds) {
current_bounds.height = sorption(0, oldbounds.height + dy + oldbounds.y, current_bounds, designer)[1]
- oldbounds.y;
if (designer.getStateModel().isAspectRatioLocked()) {
Rectangle backupBounds = designer.getSelectionModel().getSelection().getBackupBounds();
current_bounds.width = (int) (backupBounds.width * current_bounds.height / backupBounds.height * 1.0);
}
return current_bounds;
}
@ -23,6 +29,11 @@ public class Bottom extends AccessDirection {
return Cursor.S_RESIZE_CURSOR;
}
@Override
public String getTooltip() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Lock_Aspect_Ratio_Mouse_ToolTip");
}
@Override
public int getActual() {
return Direction.BOTTOM;

11
designer-form/src/main/java/com/fr/design/designer/beans/location/Left.java

@ -15,6 +15,12 @@ public class Left extends AccessDirection {
Rectangle oldbounds) {
current_bounds.x = sorption(oldbounds.x + dx, 0, current_bounds, designer)[0];
current_bounds.width = oldbounds.width - current_bounds.x + oldbounds.x;
if (designer.getStateModel().isAspectRatioLocked()) {
Rectangle backupBounds = designer.getSelectionModel().getSelection().getBackupBounds();
current_bounds.height = (int) (backupBounds.height * current_bounds.width / backupBounds.width * 1.0);
}
return current_bounds;
}
@ -23,6 +29,11 @@ public class Left extends AccessDirection {
return Cursor.W_RESIZE_CURSOR;
}
@Override
public String getTooltip() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Lock_Aspect_Ratio_Mouse_ToolTip");
}
@Override
public int getActual() {
return Direction.LEFT;

20
designer-form/src/main/java/com/fr/design/designer/beans/location/LeftBottom.java

@ -17,6 +17,21 @@ public class LeftBottom extends AccessDirection {
current_bounds.x = xy[0];
current_bounds.width = oldbounds.width - current_bounds.x + oldbounds.x;
current_bounds.height = xy[1] - oldbounds.y;
if (designer.getStateModel().isAspectRatioLocked()) {
Rectangle backupBounds = designer.getSelectionModel().getSelection().getBackupBounds();
double current_diagonal = Math.pow(current_bounds.width, 2) + Math.pow(current_bounds.height, 2);
double backup_diagonal = Math.pow(backupBounds.width, 2) + Math.pow(backupBounds.height, 2);
int width = (int) (Math.sqrt((current_diagonal / backup_diagonal) * (Math.pow(backupBounds.width, 2))));
int height = (int) (Math.sqrt((current_diagonal / backup_diagonal) * (Math.pow(backupBounds.height, 2))));
int currentRight = current_bounds.x + current_bounds.width;
current_bounds.width = width;
current_bounds.height = height;
current_bounds.x = currentRight - width;
}
return current_bounds;
}
@ -25,6 +40,11 @@ public class LeftBottom extends AccessDirection {
return Cursor.SW_RESIZE_CURSOR;
}
@Override
public String getTooltip() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Lock_Aspect_Ratio_Mouse_ToolTip");
}
@Override
public int getActual() {
return Direction.LEFT_BOTTOM;

23
designer-form/src/main/java/com/fr/design/designer/beans/location/LeftTop.java

@ -6,6 +6,7 @@ import java.awt.Rectangle;
import com.fr.design.mainframe.FormDesigner;
public class LeftTop extends AccessDirection {
public LeftTop() {
}
@ -17,6 +18,23 @@ public class LeftTop extends AccessDirection {
current_bounds.y = xy[1];
current_bounds.width = oldbounds.width - current_bounds.x + oldbounds.x;
current_bounds.height = oldbounds.height - current_bounds.y + oldbounds.y;
if (designer.getStateModel().isAspectRatioLocked()) {
Rectangle backupBounds = designer.getSelectionModel().getSelection().getBackupBounds();
double current_diagonal = Math.pow(current_bounds.width, 2) + Math.pow(current_bounds.height, 2);
double backup_diagonal = Math.pow(backupBounds.width, 2) + Math.pow(backupBounds.height, 2);
int width = (int) (Math.sqrt((current_diagonal / backup_diagonal) * (Math.pow(backupBounds.width, 2))));
int height = (int) (Math.sqrt((current_diagonal / backup_diagonal) * (Math.pow(backupBounds.height, 2))));
int currentRight = current_bounds.x + current_bounds.width;
int currentBottom = current_bounds.y + current_bounds.height;
current_bounds.width = width;
current_bounds.height = height;
current_bounds.x = currentRight - width;
current_bounds.y = currentBottom - height;
}
return current_bounds;
}
@ -25,6 +43,11 @@ public class LeftTop extends AccessDirection {
return Cursor.NW_RESIZE_CURSOR;
}
@Override
public String getTooltip() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Lock_Aspect_Ratio_Mouse_ToolTip");
}
@Override
public int getActual() {
return Direction.LEFT_TOP;

13
designer-form/src/main/java/com/fr/design/designer/beans/location/Right.java

@ -3,7 +3,9 @@ package com.fr.design.designer.beans.location;
import java.awt.Cursor;
import java.awt.Rectangle;
import com.fr.design.designer.creator.XCreator;
import com.fr.design.mainframe.FormDesigner;
import com.fr.form.ui.Widget;
public class Right extends AccessDirection {
@ -15,6 +17,12 @@ public class Right extends AccessDirection {
Rectangle oldbounds) {
current_bounds.width = sorption(oldbounds.x + dx + oldbounds.width, 0, current_bounds, designer)[0]
- oldbounds.x;
if (designer.getStateModel().isAspectRatioLocked()) {
Rectangle backupBounds = designer.getSelectionModel().getSelection().getBackupBounds();
current_bounds.height = (int) (backupBounds.height * current_bounds.width / backupBounds.width * 1.0);
}
return current_bounds;
}
@ -23,6 +31,11 @@ public class Right extends AccessDirection {
return Cursor.E_RESIZE_CURSOR;
}
@Override
public String getTooltip() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Lock_Aspect_Ratio_Mouse_ToolTip");
}
@Override
public int getActual() {
return Direction.RIGHT;

18
designer-form/src/main/java/com/fr/design/designer/beans/location/RightBottom.java

@ -16,6 +16,19 @@ public class RightBottom extends AccessDirection {
int[] xy = sorption(oldbounds.x + dx + oldbounds.width, oldbounds.height + dy + oldbounds.y, current_bounds, designer);
current_bounds.width = xy[0] - oldbounds.x;
current_bounds.height = xy[1] - oldbounds.y;
if (designer.getStateModel().isAspectRatioLocked()) {
Rectangle backupBounds = designer.getSelectionModel().getSelection().getBackupBounds();
double current_diagonal = Math.pow(current_bounds.width, 2) + Math.pow(current_bounds.height, 2);
double backup_diagonal = Math.pow(backupBounds.width, 2) + Math.pow(backupBounds.height, 2);
int width = (int) (Math.sqrt((current_diagonal / backup_diagonal) * (Math.pow(backupBounds.width, 2))));
int height = (int) (Math.sqrt((current_diagonal / backup_diagonal) * (Math.pow(backupBounds.height, 2))));
current_bounds.width = width;
current_bounds.height = height;
}
return current_bounds;
}
@ -24,6 +37,11 @@ public class RightBottom extends AccessDirection {
return Cursor.SE_RESIZE_CURSOR;
}
@Override
public String getTooltip() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Lock_Aspect_Ratio_Mouse_ToolTip");
}
@Override
public int getActual() {
return Direction.RIGHT_BOTTOM;

20
designer-form/src/main/java/com/fr/design/designer/beans/location/RightTop.java

@ -16,6 +16,21 @@ public class RightTop extends AccessDirection {
current_bounds.y = xy[1];
current_bounds.height = oldbounds.height - current_bounds.y + oldbounds.y;
current_bounds.width = xy[0] - oldbounds.x;
if (designer.getStateModel().isAspectRatioLocked()) {
Rectangle backupBounds = designer.getSelectionModel().getSelection().getBackupBounds();
double current_diagonal = Math.pow(current_bounds.width, 2) + Math.pow(current_bounds.height, 2);
double backup_diagonal = Math.pow(backupBounds.width, 2) + Math.pow(backupBounds.height, 2);
int width = (int) (Math.sqrt((current_diagonal / backup_diagonal) * (Math.pow(backupBounds.width, 2))));
int height = (int) (Math.sqrt((current_diagonal / backup_diagonal) * (Math.pow(backupBounds.height, 2))));
int currentBottom = current_bounds.y + current_bounds.height;
current_bounds.width = width;
current_bounds.height = height;
current_bounds.y = currentBottom - height;
}
return current_bounds;
}
@ -24,6 +39,11 @@ public class RightTop extends AccessDirection {
return Cursor.NE_RESIZE_CURSOR;
}
@Override
public String getTooltip() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Lock_Aspect_Ratio_Mouse_ToolTip");
}
@Override
public int getActual() {
return Direction.RIGHT_TOP;

11
designer-form/src/main/java/com/fr/design/designer/beans/location/Top.java

@ -15,6 +15,12 @@ public class Top extends AccessDirection {
Rectangle oldbounds) {
current_bounds.y = sorption(0, dy + oldbounds.y, current_bounds, designer)[1];
current_bounds.height = oldbounds.height - current_bounds.y + oldbounds.y;
if (designer.getStateModel().isAspectRatioLocked()) {
Rectangle backupBounds = designer.getSelectionModel().getSelection().getBackupBounds();
current_bounds.width = (int) (backupBounds.width * current_bounds.height / backupBounds.height * 1.0);
}
return current_bounds;
}
@ -23,6 +29,11 @@ public class Top extends AccessDirection {
return Cursor.N_RESIZE_CURSOR;
}
@Override
public String getTooltip() {
return com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Widget_Lock_Aspect_Ratio_Mouse_ToolTip");
}
@Override
public int getActual() {
return Direction.TOP;

11
designer-form/src/main/java/com/fr/design/designer/beans/models/StateModel.java

@ -55,6 +55,8 @@ public class StateModel {
// 当前是否处于拖拽选择状态
private boolean selecting;
private boolean dragging;
// 拖拽时需要保持组件尺寸比例
private boolean aspectRatioLocked;
private boolean addable;
@ -83,6 +85,10 @@ public class StateModel {
return selecting;
}
public boolean isAspectRatioLocked() {
return this.aspectRatioLocked;
}
/**
* 是否能拖拽
*
@ -393,6 +399,7 @@ public class StateModel {
* 重置model
*/
public void resetModel() {
aspectRatioLocked = false;
dragging = false;
selecting = false;
}
@ -402,6 +409,7 @@ public class StateModel {
*/
public void reset() {
driection = Location.outer;
aspectRatioLocked = false;
dragging = false;
selecting = false;
}
@ -478,10 +486,12 @@ public class StateModel {
public void dragging(MouseEvent e) {
//进入dragging状态时备份组件大小和位置
if (!dragging) {
this.aspectRatioLocked = this.selectionModel.getSelection().isCreatorAspectRatioLockedInAbsLayout(designer);
selectedPositionBackup = selectionModel.getSelection().getRelativeBounds();
}
checkAddable(e);
setDependLinePainter(e);
this.aspectRatioLocked = this.aspectRatioLocked || e.isShiftDown();
driection.drag(getMouseXY(e).x - currentX, getMouseXY(e).y - currentY, designer);
this.dragging = true;
}
@ -508,6 +518,7 @@ public class StateModel {
* @param e 鼠标事件
*/
public void releaseDragging(MouseEvent e) {
this.aspectRatioLocked = false;
this.dragging = false;
if (addable) {
adding(e.getX(), e.getY());

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

@ -475,7 +475,12 @@ public class EditingMouseListener extends MouseInputAdapter {
if (DesignerMode.isAuthorityEditing()) {
return;
}
if ((e.isShiftDown() || InputEventBaseOnOS.isControlDown(e)) && !stateModel.isSelecting()) {
boolean shiftSelecting = e.isShiftDown();
boolean ctrlSelecting = InputEventBaseOnOS.isControlDown(e);
int currentCursorType = this.designer.getCursor().getType();
boolean shiftResizing = e.isShiftDown() && ( Cursor.SW_RESIZE_CURSOR <= currentCursorType && currentCursorType <= Cursor.E_RESIZE_CURSOR);
if ((shiftSelecting || ctrlSelecting) && !shiftResizing && !stateModel.isSelecting()) {
stateModel.startSelecting(e);
}
// 如果当前是左键拖拽状态,拖拽组件

12
designer-form/src/main/java/com/fr/design/mainframe/FormEditorKeyListener.java

@ -27,7 +27,11 @@ public class FormEditorKeyListener extends KeyAdapter{
@Override
public void keyPressed(KeyEvent e) {
if(e.isShiftDown() || InputEventBaseOnOS.isControlDown(e)) {
boolean shiftSelecting = e.isShiftDown();
boolean ctrlSelecting = InputEventBaseOnOS.isControlDown(e);
int currentCursorType = this.designer.getCursor().getType();
boolean shiftResizing = e.isShiftDown() && ( Cursor.SW_RESIZE_CURSOR <= currentCursorType && currentCursorType <= Cursor.E_RESIZE_CURSOR);
if((shiftSelecting || ctrlSelecting) && !shiftResizing) {
designer.setCursor(ADDCURSOR);
}
int code = e.getKeyCode();
@ -57,7 +61,11 @@ public class FormEditorKeyListener extends KeyAdapter{
}
public void keyReleased(KeyEvent e) {
if(!(e.isShiftDown() || InputEventBaseOnOS.isControlDown(e))) {
boolean shiftSelecting = e.isShiftDown();
boolean ctrlSelecting = InputEventBaseOnOS.isControlDown(e);
int currentCursorType = this.designer.getCursor().getType();
boolean shiftResizing = e.getKeyCode() == KeyEvent.VK_SHIFT && ( Cursor.SW_RESIZE_CURSOR <= currentCursorType && currentCursorType <= Cursor.E_RESIZE_CURSOR);
if(!(shiftSelecting || ctrlSelecting) && !shiftResizing) {
designer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
if (moved) {

13
designer-form/src/main/java/com/fr/design/mainframe/FormSelection.java

@ -2,6 +2,7 @@ package com.fr.design.mainframe;
import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.adapters.layout.FRAbsoluteLayoutAdapter;
import com.fr.design.designer.beans.location.Direction;
import com.fr.design.designer.creator.XComponent;
import com.fr.design.designer.creator.XCreator;
@ -287,6 +288,18 @@ public class FormSelection {
}
}
public boolean isCreatorAspectRatioLockedInAbsLayout(FormDesigner designer) {
for (XCreator creator : selection) {
LayoutAdapter layoutAdapter = AdapterBus.searchLayoutAdapter(designer, creator);
if (layoutAdapter instanceof FRAbsoluteLayoutAdapter) {
if (creator.toData().isAspectRatioLocked()) {
return true;
}
}
}
return false;
}
/**
* @Description 重置报表块缩略图
* @param: creator

6
designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetAbsoluteBoundPane.java

@ -9,8 +9,7 @@ import com.fr.design.utils.gui.LayoutUtils;
import com.fr.design.widget.WidgetBoundsPaneFactory;
import com.fr.form.ui.container.WLayout;
import java.awt.Rectangle;
import java.awt.*;
/**
@ -30,11 +29,12 @@ public class WidgetAbsoluteBoundPane extends WidgetBoundPane {
y = new UIBoundSpinner(0, Integer.MAX_VALUE, 1, 0d);
width = new UIBoundSpinner(0, Integer.MAX_VALUE, 1, 0d);
height = new UIBoundSpinner(0, Integer.MAX_VALUE, 1, 0d);
ratioLockedButton = new AspectRatioLockedButton(width, height, creator);
x.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Coords_And_Size"));
y.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Coords_And_Size"));
width.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Coords_And_Size"));
height.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Coords_And_Size"));
this.add(WidgetBoundsPaneFactory.createAbsoluteBoundsPane(x, y, width, height, WidgetBoundsPaneFactory.NameAttribute.WIDGET));
this.add(WidgetBoundsPaneFactory.createAbsoluteBoundsPane(x, y, width, height, ratioLockedButton, WidgetBoundsPaneFactory.NameAttribute.WIDGET));
}
@Override

149
designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetBoundPane.java

@ -11,19 +11,31 @@ import com.fr.design.designer.creator.cardlayout.XWCardLayout;
import com.fr.design.designer.creator.cardlayout.XWCardTagLayout;
import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.FineJOptionPane;
import com.fr.design.file.HistoryTemplateListCache;
import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ispinner.UISpinner;
import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.mainframe.FormDesigner;
import com.fr.design.mainframe.JForm;
import com.fr.design.mainframe.JTemplate;
import com.fr.design.mainframe.WidgetPropertyPane;
import com.fr.design.utils.ComponentUtils;
import com.fr.design.widget.WidgetBoundsPaneFactory;
import com.fr.form.ui.PaddingMargin;
import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WFitLayout;
import com.fr.form.ui.container.WLayout;
import com.fr.general.IOUtils;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.plaf.basic.BasicButtonUI;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JOptionPane;
import java.awt.Rectangle;
import static com.fr.design.i18n.Toolkit.i18nText;
/**
@ -37,6 +49,7 @@ public class WidgetBoundPane extends BasicPane {
protected XCreator creator;
protected UISpinner width;
protected UISpinner height;
protected AspectRatioLockedButton ratioLockedButton;
public WidgetBoundPane(XCreator source) {
this.setLayout(FRGUIPaneFactory.createBorderLayout());
@ -59,13 +72,20 @@ public class WidgetBoundPane extends BasicPane {
public void initBoundPane() {
width = new UIBoundSpinner(0, Integer.MAX_VALUE, 1, 0d);
height = new UIBoundSpinner(0, Integer.MAX_VALUE, 1, 0d);
width.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Coords_And_Size"));
height.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Coords_And_Size"));
width.setGlobalName(i18nText("Fine-Design_Form_Coords_And_Size"));
height.setGlobalName(i18nText("Fine-Design_Form_Coords_And_Size"));
if (creator.acceptType(XWCardLayout.class)) {
width.setEnabled(false);
height.setEnabled(false);
}
this.add(WidgetBoundsPaneFactory.createBoundsPane(width, height));
JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate();
if (jTemplate.isJWorkBook() || !((JForm)jTemplate).isSelectRootPane()) {
ratioLockedButton = new AspectRatioLockedButton(width, height, creator);
ratioLockedButton.setLockEnabled(false);
}
this.add(WidgetBoundsPaneFactory.createBoundsPane(width, height, ratioLockedButton));
}
@ -82,6 +102,9 @@ public class WidgetBoundPane extends BasicPane {
Rectangle bounds = new Rectangle(creator.getBounds());
width.setValue(bounds.width);
height.setValue(bounds.height);
if (ratioLockedButton != null) {
ratioLockedButton.populate(creator);
}
}
public void fix() {
@ -97,6 +120,9 @@ public class WidgetBoundPane extends BasicPane {
if (bounds.height != h) {
limitHeight(wabs, h, bounds, rec);
}
if (ratioLockedButton != null) {
ratioLockedButton.setLocked(creator.toData().isAspectRatioLocked());
}
}
@ -116,11 +142,11 @@ public class WidgetBoundPane extends BasicPane {
PaddingMargin margin = wabs.getMargin();
if (bounds.width != w) {
if (bounds.width == rec.width - margin.getLeft() - margin.getRight()) {
FineJOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Beyond_Bounds"));
FineJOptionPane.showMessageDialog(null, i18nText("Fine-Design_Form_Beyond_Bounds"));
width.setValue(bounds.width);
return;
} else if (w < minWidth) {
FineJOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Min_Width") + Integer.toString(minWidth));
FineJOptionPane.showMessageDialog(null, i18nText("Fine-Design_Form_Min_Width") + Integer.toString(minWidth));
width.setValue(bounds.width);
return;
}
@ -137,11 +163,11 @@ public class WidgetBoundPane extends BasicPane {
int minHeight = (int) (MINHEIGHT * ((WFitLayout) wabs).getResolutionScaling());
if (bounds.height != h) {
if (bounds.height == rec.height - margin.getTop() - margin.getBottom()) {
FineJOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Beyond_Bounds"));
FineJOptionPane.showMessageDialog(null, i18nText("Fine-Design_Form_Beyond_Bounds"));
height.setValue(bounds.height);
return;
} else if (h < minHeight) {
FineJOptionPane.showMessageDialog(null, com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Min_Height") + Integer.toString(minHeight));
FineJOptionPane.showMessageDialog(null, i18nText("Fine-Design_Form_Min_Height") + Integer.toString(minHeight));
height.setValue(bounds.height);
return;
}
@ -165,4 +191,109 @@ public class WidgetBoundPane extends BasicPane {
}
protected static class AspectRatioLockedButton extends UIButton {
private final Icon enabledLocked = IOUtils.readIcon("/com/fr/design/images/buttonicon/icon_lock_enabled.png");
private final Icon disabledLocked = IOUtils.readIcon("/com/fr/design/images/buttonicon/icon_lock_disabled.png");
private final Icon enabledUnLocked = IOUtils.readIcon("/com/fr/design/images/buttonicon/icon_unlock_enabled.png");
private final Icon disabledUnLocked = IOUtils.readIcon("/com/fr/design/images/buttonicon/icon_unlock_disabled.png");
private UISpinner mWidthSpinner;
private UISpinner mHeightSpinner;
private XCreator mCreator;
protected double width4Backup = 0;
protected double height4Backup = 0;
public AspectRatioLockedButton(UISpinner widthSpinner, UISpinner heightSpinner, XCreator creator) {
setUI(new BasicButtonUI());
setBorderPainted(false);
setBorder(null);
setContentAreaFilled(false);
setPreferredSize(new Dimension(24, 24));
this.mWidthSpinner = widthSpinner;
this.mHeightSpinner = heightSpinner;
this.mCreator = creator;
addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setSelected(!isSelected());
}
});
addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
mCreator.toData().setAspectRatioLocked(isLocked());
setToolTipText(isLockEnabled() ? null : i18nText("Fine-Design_Form_Widget_Lock_Aspect_Ratio_Button_ToolTip"));
if (isLocked() && isLockEnabled()) {
width4Backup = mWidthSpinner.getValue();
height4Backup = mHeightSpinner.getValue();
}
}
});
mWidthSpinner.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (isLockEnabled() && isLocked() && width4Backup > 0 && height4Backup > 0) {
mHeightSpinner.setValue(mWidthSpinner.getValue() * width4Backup / height4Backup, false);
}
}
});
mHeightSpinner.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (isLockEnabled() && isLocked() && width4Backup > 0 && height4Backup > 0) {
mWidthSpinner.setValue(mHeightSpinner.getValue() * height4Backup / width4Backup, false);
}
}
});
}
@Override
public Icon getIcon() {
if (this.isLocked()) {
if (this.isLockEnabled()) {
return enabledLocked;
} else {
return disabledLocked;
}
} else {
if (this.isLockEnabled()) {
return enabledUnLocked;
} else {
return disabledUnLocked;
}
}
}
public void setLocked(boolean locked) {
this.setSelected(locked);
}
public boolean isLocked() {
return this.isSelected();
}
public boolean isLockEnabled() {
return this.isEnabled();
}
public void setLockEnabled(boolean enabled) {
this.setEnabled(enabled);
}
public void populate(XCreator creator) {
Rectangle bounds = new Rectangle(creator.getBounds());
mCreator = creator;
width4Backup = bounds.width;
height4Backup = bounds.height;
Widget widget = creator.toData();
setLocked(widget.isAspectRatioLocked());
}
}
}

81
designer-realize/src/main/java/com/fr/grid/GridMouseAdapter.java

@ -75,6 +75,8 @@ public class GridMouseAdapter implements MouseListener, MouseWheelListener, Mous
private int resolution = ScreenResolution.getScreenResolution();
private int[] resizingBackupBounds = null;
protected GridMouseAdapter(Grid grid) {
this.grid = grid;
}
@ -338,6 +340,7 @@ public class GridMouseAdapter implements MouseListener, MouseWheelListener, Mous
}
boolean isControlDown = InputEventBaseOnOS.isControlDown(evt);
boolean isShiftDown = evt.isShiftDown();
long systemCurrentTime = System.currentTimeMillis();
if (systemCurrentTime - lastMouseMoveTime <= DRAG_REFRESH_TIME) {// alex:Drag
@ -351,10 +354,10 @@ public class GridMouseAdapter implements MouseListener, MouseWheelListener, Mous
return;
}
doWithMouseDragged(evt.getX(), evt.getY(), isControlDown);
doWithMouseDragged(evt.getX(), evt.getY(), isControlDown, isShiftDown);
}
private void doWithMouseDragged(int evtX, int evtY, boolean isControlDown) {
private void doWithMouseDragged(int evtX, int evtY, boolean isControlDown, boolean isShiftDown) {
ElementCasePane reportPane = grid.getElementCasePane();
if (reportPane.mustInVisibleRange()) {
@ -366,7 +369,7 @@ public class GridMouseAdapter implements MouseListener, MouseWheelListener, Mous
Selection selection = reportPane.getSelection();
if (selection instanceof FloatSelection && !DesignerMode.isAuthorityEditing()) {
doWithFloatElementDragged(evtX, evtY, (FloatSelection) selection);
doWithFloatElementDragged(evtX, evtY, (FloatSelection) selection, isShiftDown);
grid.setDragType(GridUtils.DRAG_FLOAT);
} else if (grid.getDragType() == GridUtils.DRAG_CELLSELECTION_BOTTOMRIGHT_CORNER && !DesignerMode.isAuthorityEditing()) {
doWithCellElementDragged(evtX, evtY, (CellSelection) selection);
@ -391,36 +394,83 @@ public class GridMouseAdapter implements MouseListener, MouseWheelListener, Mous
* @param fs
*/
private void doWithFloatElementDragged(int evtX, int evtY, FloatSelection fs) {
private void doWithFloatElementDragged(int evtX, int evtY, FloatSelection fs, boolean aspectRatio) {
ElementCase report = grid.getElementCasePane().getEditingElementCase();
// int resolution = ScreenResolution.getScreenResolution();
String floatName = fs.getSelectedFloatName();
FloatElement floatElement = report.getFloatElement(floatName);
int cursorType = grid.getCursor().getType();
int currentLeft = Math.min(oldEvtX, evtX);
int currentTop = Math.min(oldEvtY, evtY);
int currentRight = Math.max(oldEvtX, evtX);
int currentBottom = Math.max(oldEvtY, evtY);
int currentWidth = currentRight - currentLeft;
int currentHeight = currentBottom - currentTop;
int backupWidth= resizingBackupBounds[2];
int backupHeight= resizingBackupBounds[3];
if (cursorType == Cursor.NW_RESIZE_CURSOR || cursorType == Cursor.NE_RESIZE_CURSOR || cursorType == Cursor.SE_RESIZE_CURSOR || cursorType == Cursor.SW_RESIZE_CURSOR) {
if (aspectRatio) {
double currentDiagonal = Math.pow(currentWidth, 2) + Math.pow(currentHeight, 2);
double backupDiagonal = Math.pow(backupWidth, 2) + Math.pow(backupHeight, 2);
int newWidth = (int) (Math.sqrt((currentDiagonal / backupDiagonal) * (Math.pow(backupWidth, 2))));
int newHeight = (int) (Math.sqrt((currentDiagonal / backupDiagonal) * (Math.pow(backupHeight, 2))));
if (cursorType == Cursor.NW_RESIZE_CURSOR) {
currentLeft = currentRight - newWidth;
currentTop = currentBottom - newHeight;
} else if (cursorType == Cursor.NE_RESIZE_CURSOR) {
currentRight = currentLeft + newWidth;
currentTop = currentBottom - newHeight;
} else if (cursorType == Cursor.SW_RESIZE_CURSOR) {
currentLeft = currentRight - newWidth;
currentBottom = currentTop + newHeight;
} else if (cursorType == Cursor.SE_RESIZE_CURSOR){
currentRight = currentLeft + newWidth;
currentBottom = currentTop + newHeight;
}
}
DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report);
DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report);
FU floatX1_fu = FU.valueOfPix(Math.min(oldEvtX, evtX), resolution);
FU floatY1_fu = FU.valueOfPix(Math.min(oldEvtY, evtY), resolution);
FU floatX1_fu = FU.valueOfPix(currentLeft, resolution);
FU floatY1_fu = FU.valueOfPix(currentTop, resolution);
FU leftDistance = floatX1_fu.add(columnWidthList.getRangeValue(0, grid.getHorizontalValue()));
FU topDistance = floatY1_fu.add(rowHeightList.getRangeValue(0, grid.getVerticalValue()));
floatElement.setLeftDistance(leftDistance);
floatElement.setTopDistance(topDistance);
floatElement.setWidth(FU.valueOfPix(Math.max(oldEvtX, evtX), resolution).subtract(floatX1_fu));
floatElement.setHeight(FU.valueOfPix(Math.max(oldEvtY, evtY), resolution).subtract(floatY1_fu));
floatElement.setWidth(FU.valueOfPix(currentRight, resolution).subtract(floatX1_fu));
floatElement.setHeight(FU.valueOfPix(currentBottom, resolution).subtract(floatY1_fu));
} else if (cursorType == Cursor.S_RESIZE_CURSOR || cursorType == Cursor.N_RESIZE_CURSOR) {
DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report);
FU floatY1_fu = FU.valueOfPix(Math.min(oldEvtY, evtY), resolution);
FU floatY1_fu = FU.valueOfPix(currentTop, resolution);
FU topDistance = floatY1_fu.add(rowHeightList.getRangeValue(0, grid.getVerticalValue()));
floatElement.setTopDistance(topDistance);
floatElement.setHeight(FU.valueOfPix(Math.max(oldEvtY, evtY), resolution).subtract(floatY1_fu));
floatElement.setHeight(FU.valueOfPix(currentBottom, resolution).subtract(floatY1_fu));
if (aspectRatio) {
currentWidth = backupWidth * currentHeight / backupHeight;
currentRight = currentLeft + currentWidth;
FU floatX1_fu = FU.valueOfPix(currentLeft, resolution);
floatElement.setWidth(FU.valueOfPix(currentRight, resolution).subtract(floatX1_fu));
}
} else if (cursorType == Cursor.W_RESIZE_CURSOR || cursorType == Cursor.E_RESIZE_CURSOR) {
DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report);
FU floatX1_fu = FU.valueOfPix(Math.min(oldEvtX, evtX), resolution);
FU floatX1_fu = FU.valueOfPix(currentLeft, resolution);
FU leftDistance = floatX1_fu.add(columnWidthList.getRangeValue(0, grid.getHorizontalValue()));
floatElement.setLeftDistance(leftDistance);
floatElement.setWidth(FU.valueOfPix(Math.max(oldEvtX, evtX), resolution).subtract(floatX1_fu));
floatElement.setWidth(FU.valueOfPix(currentRight, resolution).subtract(floatX1_fu));
if (aspectRatio) {
currentHeight = backupHeight * currentWidth / backupWidth;
currentBottom = currentTop + currentHeight;
FU floatY1_fu = FU.valueOfPix(currentTop, resolution);
floatElement.setHeight(FU.valueOfPix(currentBottom, resolution).subtract(floatY1_fu));
}
} else if (cursorType == Cursor.MOVE_CURSOR) {
DynamicUnitList columnWidthList = ReportHelper.getColumnWidthList(report);
DynamicUnitList rowHeightList = ReportHelper.getRowHeightList(report);
@ -799,6 +849,13 @@ public class GridMouseAdapter implements MouseListener, MouseWheelListener, Mous
} else if (cursorType == Cursor.E_RESIZE_CURSOR) {
setOld_X_AndOld_Y(floatArray[0], floatArray[1]);
}
if (Cursor.SW_RESIZE_CURSOR <= cursorType && cursorType <= Cursor.E_RESIZE_CURSOR) {
resizingBackupBounds = new int[] {
(int) floatArray[0], (int)floatArray[1],
(int) floatArray[2] - (int) floatArray[0], (int) floatArray[3] - (int) floatArray[1]
};
}
}
private void setOld_X_AndOld_Y(double x, double y) {

Loading…
Cancel
Save