diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/location/AccessDirection.java b/designer-form/src/main/java/com/fr/design/designer/beans/location/AccessDirection.java index be44eae81..adb0c6017 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/location/AccessDirection.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/location/AccessDirection.java @@ -195,8 +195,11 @@ public abstract class AccessDirection implements Direction { if (type != formEditor.getCursor().getType()) { // 设置当前形状 formEditor.setCursor(Cursor.getPredefinedCursor(type)); + + FormSelection selection = formEditor.getSelectionModel().getSelection(); + boolean canLockAspectRatioOnlyByShift = !selection.isCreatorAspectRatioLockedInAbsLayout(formEditor) && selection.isCreatorInAbsLayout(formEditor); ServerPreferenceConfig config = ServerPreferenceConfig.getInstance(); - if (!config.isHasShownLockedAspectRatioResizingToolTip()) { + if (canLockAspectRatioOnlyByShift && !config.isHasShownLockedAspectRatioResizingToolTip()) { formEditor.setToolTipText(getTooltip()); config.setHasShownLockedAspectRatioResizingToolTip(true); } diff --git a/designer-form/src/main/java/com/fr/design/designer/beans/models/StateModel.java b/designer-form/src/main/java/com/fr/design/designer/beans/models/StateModel.java index 34b03bc52..3b676921b 100644 --- a/designer-form/src/main/java/com/fr/design/designer/beans/models/StateModel.java +++ b/designer-form/src/main/java/com/fr/design/designer/beans/models/StateModel.java @@ -15,6 +15,7 @@ import com.fr.design.designer.creator.XLayoutContainer; import com.fr.design.designer.creator.XWAbsoluteBodyLayout; import com.fr.design.designer.creator.XWAbsoluteLayout; import com.fr.design.mainframe.FormDesigner; +import com.fr.design.mainframe.FormSelection; import com.fr.design.mainframe.FormSelectionUtils; import com.fr.design.utils.ComponentUtils; @@ -486,12 +487,14 @@ 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(); + + FormSelection selection = this.selectionModel.getSelection(); + this.aspectRatioLocked = selection.isCreatorAspectRatioLockedInAbsLayout(designer) || + (this.selectionModel.getSelection().isCreatorInAbsLayout(designer) && e.isShiftDown()); driection.drag(getMouseXY(e).x - currentX, getMouseXY(e).y - currentY, designer); this.dragging = true; } diff --git a/designer-form/src/main/java/com/fr/design/mainframe/FormSelection.java b/designer-form/src/main/java/com/fr/design/mainframe/FormSelection.java index 956e1cb66..54ab34a4f 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/FormSelection.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/FormSelection.java @@ -300,6 +300,16 @@ public class FormSelection { return false; } + public boolean isCreatorInAbsLayout(FormDesigner designer) { + for (XCreator creator : selection) { + LayoutAdapter layoutAdapter = AdapterBus.searchLayoutAdapter(designer, creator); + if (layoutAdapter instanceof FRAbsoluteLayoutAdapter) { + return true; + } + } + return false; + } + /** * @Description 重置报表块缩略图 * @param: creator diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetAbsoluteBoundPane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetAbsoluteBoundPane.java index 30c90b326..e8aeb994d 100644 --- a/designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetAbsoluteBoundPane.java +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetAbsoluteBoundPane.java @@ -29,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); + ratioLockedButton = new AspectRatioLockedButton(width, height); 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")); + ratioLockedButton.setGlobalName(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Form_Coords_And_Size")); this.add(WidgetBoundsPaneFactory.createAbsoluteBoundsPane(x, y, width, height, ratioLockedButton, WidgetBoundsPaneFactory.NameAttribute.WIDGET)); } diff --git a/designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetBoundPane.java b/designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetBoundPane.java index 5e1c8dee7..e963bf713 100644 --- a/designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetBoundPane.java +++ b/designer-form/src/main/java/com/fr/design/widget/ui/designer/component/WidgetBoundPane.java @@ -11,8 +11,11 @@ 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.event.GlobalNameListener; +import com.fr.design.event.GlobalNameObserver; +import com.fr.design.event.UIObserver; +import com.fr.design.event.UIObserverListener; 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; @@ -81,7 +84,8 @@ public class WidgetBoundPane extends BasicPane { JTemplate jTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); if (jTemplate.isJWorkBook() || !((JForm)jTemplate).isSelectRootPane()) { - ratioLockedButton = new AspectRatioLockedButton(width, height, creator); + ratioLockedButton = new AspectRatioLockedButton(width, height); + ratioLockedButton.setGlobalName(i18nText("Fine-Design_Form_Coords_And_Size")); ratioLockedButton.setLockEnabled(false); } @@ -121,7 +125,7 @@ public class WidgetBoundPane extends BasicPane { limitHeight(wabs, h, bounds, rec); } if (ratioLockedButton != null) { - ratioLockedButton.setLocked(creator.toData().isAspectRatioLocked()); + ratioLockedButton.update(creator); } } @@ -191,21 +195,24 @@ public class WidgetBoundPane extends BasicPane { } - protected static class AspectRatioLockedButton extends UIButton { + protected static class AspectRatioLockedButton extends JButton implements UIObserver, GlobalNameObserver { 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; + private UIObserverListener uiObserverListener; + private GlobalNameListener globalNameListener; + private String globalName = null; + + private final UISpinner mWidthSpinner; + private final UISpinner mHeightSpinner; protected double width4Backup = 0; protected double height4Backup = 0; - public AspectRatioLockedButton(UISpinner widthSpinner, UISpinner heightSpinner, XCreator creator) { + public AspectRatioLockedButton(UISpinner widthSpinner, UISpinner heightSpinner) { setUI(new BasicButtonUI()); setBorderPainted(false); setBorder(null); @@ -214,25 +221,25 @@ public class WidgetBoundPane extends BasicPane { 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")); + // 改变图标icon + setLocked(!isLocked()); if (isLocked() && isLockEnabled()) { width4Backup = mWidthSpinner.getValue(); height4Backup = mHeightSpinner.getValue(); } + + if (globalNameListener != null) { + globalNameListener.setGlobalName(globalName); + } + + if (uiObserverListener != null) { + uiObserverListener.doChange(); + } } }); @@ -285,15 +292,44 @@ public class WidgetBoundPane extends BasicPane { public void setLockEnabled(boolean enabled) { this.setEnabled(enabled); + setToolTipText(isLockEnabled() ? null : i18nText("Fine-Design_Form_Widget_Lock_Aspect_Ratio_Button_ToolTip")); } 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()); } + + public void update(XCreator creator) { + creator.toData().setAspectRatioLocked(this.isLocked()); + } + + @Override + public void registerChangeListener(UIObserverListener listener) { + uiObserverListener = listener; + } + + @Override + public boolean shouldResponseChangeListener() { + return true; + } + + @Override + public void registerNameListener(GlobalNameListener listener) { + this.globalNameListener = listener; + } + + @Override + public boolean shouldResponseNameListener() { + return true; + } + + @Override + public void setGlobalName(String name) { + this.globalName = name; + } } }