From 83d78aaa9136f8101c3cb92f268070e4e36197f9 Mon Sep 17 00:00:00 2001 From: Starryi Date: Wed, 19 Jan 2022 15:37:23 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-65989=20frm=E6=8A=A5=E8=A1=A8=E5=9D=97?= =?UTF-8?q?=E5=86=8510.0=E6=A8=A1=E6=9D=BF=E5=9C=A811.0=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=E5=99=A8=E6=89=93=E5=BC=80=E5=90=8E=E6=97=A0=E6=B3=95=E4=BD=BF?= =?UTF-8?q?=E7=94=A8=E9=BC=A0=E6=A0=87=E6=BB=9A=E8=BD=AE=E6=BB=91=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 表格中处理触摸板滚动和缩放虽然用的都是MouseWheelListener接口,但是是分开注册。 其中处理纵向滚动的是逻辑是在GridMouseAdapter中实现,而处理缩放的逻辑则是在 FormReportComponentComposite.java(表单报表块)和 ReportComponentComposite.java(报表) 中实现。 所以删除GridMouseAdapter中处理鼠标纵向滚动的的代码后,表单报表块就无法处理鼠标纵向滚动了。 目前排查了下,发现还有FormReportComponentComposite(表单报表块)以及PreviewPane(组件快捷配置) 还未实现触摸板双向滚动,所以一起处理下,将原来添加缩放的逻辑替换为双向滚动 + 缩放. 【改动思路】 同上 --- .../form/FormReportComponentComposite.java | 19 ++--- ...rtComponentCompositeMouseWheelHandler.java | 79 +++++++++++++++++++ .../design/share/ui/effect/PreviewPane.java | 25 +----- .../effect/PreviewPaneMouseWheelHandler.java | 69 ++++++++++++++++ 4 files changed, 156 insertions(+), 36 deletions(-) create mode 100644 designer-realize/src/main/java/com/fr/design/mainframe/form/FormReportComponentCompositeMouseWheelHandler.java create mode 100644 designer-realize/src/main/java/com/fr/design/share/ui/effect/PreviewPaneMouseWheelHandler.java diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/form/FormReportComponentComposite.java b/designer-realize/src/main/java/com/fr/design/mainframe/form/FormReportComponentComposite.java index 67235ee7b2..05c3b13ec0 100644 --- a/designer-realize/src/main/java/com/fr/design/mainframe/form/FormReportComponentComposite.java +++ b/designer-realize/src/main/java/com/fr/design/mainframe/form/FormReportComponentComposite.java @@ -12,6 +12,8 @@ import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.DesignerUIModeConfig; import com.fr.design.mainframe.ElementCasePane; import com.fr.design.mainframe.JFormSliderPane; +import com.fr.design.mainframe.ReportComponent; +import com.fr.design.mainframe.ReportComponentCompositeMouseWheelHandler; import com.fr.design.mainframe.toolbar.ToolBarMenuDockPlus; import com.fr.form.FormElementCaseContainerProvider; import com.fr.form.FormElementCaseProvider; @@ -53,23 +55,11 @@ public class FormReportComponentComposite extends JComponent implements TargetMo sheetNameTab = new FormTabPane(ecContainer, jform); this.add(createSouthControlPane(), BorderLayout.SOUTH); jSliderContainer.addValueChangeListener(showValSpinnerChangeListener); - this.elementCaseDesigner.elementCasePane.getGrid().addMouseWheelListener(showValSpinnerMouseWheelListener); + this.elementCaseDesigner.elementCasePane.getGrid().addMouseWheelListener(new FormReportComponentCompositeMouseWheelHandler(this)); elementCaseDesigner.addTargetModifiedListener(this); this.jSliderContainer.setShowValue((ScreenResolution.getScreenResolution() * HUND) / Constants.DEFAULT_WEBWRITE_AND_SCREEN_RESOLUTION); } - MouseWheelListener showValSpinnerMouseWheelListener = new MouseWheelListener() { - @Override - public void mouseWheelMoved(MouseWheelEvent e) { - if (InputEventBaseOnOS.isControlDown(e)) { - int dir = e.getWheelRotation(); - int old_resolution = jSliderContainer.getShowValue(); - jSliderContainer.setShowValue(old_resolution - (dir * DIR)); - } - } - }; - - ChangeListener showValSpinnerChangeListener = new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { @@ -195,5 +185,8 @@ public class FormReportComponentComposite extends JComponent implements TargetMo jForm.fireTargetModified(); } + public JFormSliderPane getSliderContainer() { + return this.jSliderContainer; + } } diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/form/FormReportComponentCompositeMouseWheelHandler.java b/designer-realize/src/main/java/com/fr/design/mainframe/form/FormReportComponentCompositeMouseWheelHandler.java new file mode 100644 index 0000000000..7e8da60dc5 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/mainframe/form/FormReportComponentCompositeMouseWheelHandler.java @@ -0,0 +1,79 @@ +package com.fr.design.mainframe.form; + +import com.fr.common.inputevent.InputEventBaseOnOS; +import com.fr.design.mainframe.DesignerScaleMouseWheelHandler; +import com.fr.design.mainframe.DesignerTranslateMouseWheelHandler; +import com.fr.design.mainframe.JFormSliderPane; +import com.fr.design.mainframe.ReportComponentComposite; + +import javax.swing.JScrollBar; +import javax.swing.JViewport; +import java.awt.event.MouseWheelEvent; +import java.awt.event.MouseWheelListener; + +/** + * @author Starryi + * @version 1.0 + * Created by Starryi on 2021/9/24 + */ +public class FormReportComponentCompositeMouseWheelHandler implements MouseWheelListener { + private final DesignerTranslateMouseWheelHandler translateMouseWheelHandler; + private final DesignerScaleMouseWheelHandler scaleMouseWheelHandler; + + public FormReportComponentCompositeMouseWheelHandler(FormReportComponentComposite componentComposite) { + translateMouseWheelHandler = new DesignerTranslateMouseWheelHandler(new ScrollPaneAdapter(componentComposite)); + scaleMouseWheelHandler = new DesignerScaleMouseWheelHandler(new ScalePaneAdapter(componentComposite), ReportComponentComposite.DIR); + } + + @Override + public void mouseWheelMoved(MouseWheelEvent e) { + if (InputEventBaseOnOS.isControlDown(e)) { + scaleMouseWheelHandler.mouseWheelMoved(e); + } else { + translateMouseWheelHandler.mouseWheelMoved(e); + } + } + + private static class ScrollPaneAdapter implements DesignerTranslateMouseWheelHandler.ScrollPane { + private final FormReportComponentComposite componentComposite; + private JViewport viewport; + + public ScrollPaneAdapter(FormReportComponentComposite componentComposite) { + this.componentComposite = componentComposite; + this.viewport = new JViewport(); + } + + @Override + public boolean isWheelScrollingEnabled() { + return true; + } + + @Override + public JScrollBar getVerticalScrollBar() { + return componentComposite.elementCaseDesigner.getVerticalScrollBar(); + } + + @Override + public JScrollBar getHorizontalScrollBar() { + return componentComposite.elementCaseDesigner.getHorizontalScrollBar(); + } + + @Override + public JViewport getViewport() { + return viewport; + } + } + + private static class ScalePaneAdapter implements DesignerScaleMouseWheelHandler.ScalePane { + private final FormReportComponentComposite componentComposite; + + public ScalePaneAdapter(FormReportComponentComposite componentComposite) { + this.componentComposite = componentComposite; + } + + @Override + public JFormSliderPane getSlidePane() { + return componentComposite.getSliderContainer(); + } + } +} diff --git a/designer-realize/src/main/java/com/fr/design/share/ui/effect/PreviewPane.java b/designer-realize/src/main/java/com/fr/design/share/ui/effect/PreviewPane.java index 68cd025e30..a9a7a85124 100644 --- a/designer-realize/src/main/java/com/fr/design/share/ui/effect/PreviewPane.java +++ b/designer-realize/src/main/java/com/fr/design/share/ui/effect/PreviewPane.java @@ -70,7 +70,6 @@ public class PreviewPane extends JPanel implements CallbackEvent{ private static final int MAX = 400; private static final int HUND = 100; private static final int MIN = 10; - private static final int DIR = 10; private static final double MIN_TIME = 0.4; private Widget widget; @@ -194,27 +193,7 @@ public class PreviewPane extends JPanel implements CallbackEvent{ grid.removeMouseMotionListener(grid.getGridMouseAdapter()); grid.removeMouseListener(grid.getGridMouseAdapter()); - grid.addMouseWheelListener(new MouseWheelListener() { - @Override - public void mouseWheelMoved(MouseWheelEvent e) { - if (!InputEventBaseOnOS.isControlDown(e)) { - ElementCasePane reportPane = grid.getElementCasePane(); - if (reportPane.isVerticalScrollBarVisible()) { - JScrollBar scrollBar = reportPane.getVerticalScrollBar(); - int maxValue = scrollBar.getModel().getMaximum(); - int newValue = reportPane.getVerticalScrollBar().getValue() + e.getWheelRotation(); - int extendValue = GridUtils.getExtentValue(newValue, elementCase.getRowHeightList_DEC(), grid.getHeight(), getResolution()); - if (extendValue <= maxValue) { - reportPane.getVerticalScrollBar().setValue(newValue); - } - } - } else { - int dir = e.getWheelRotation(); - addScale( - dir * DIR); - grid.setCursor(SCALE_CURSOR); - } - } - }); + grid.addMouseWheelListener(new PreviewPaneMouseWheelHandler(this)); grid.addMouseMotionListener(new MouseMotionAdapter() { @Override @@ -320,7 +299,7 @@ public class PreviewPane extends JPanel implements CallbackEvent{ elementCasePane.repaint(); } - private void addScale(int step) { + public void addScale(int step) { scaleValue += step; scaleValue = fixedScale(scaleValue); plusButton.setEnabled(scaleValue < MAX); diff --git a/designer-realize/src/main/java/com/fr/design/share/ui/effect/PreviewPaneMouseWheelHandler.java b/designer-realize/src/main/java/com/fr/design/share/ui/effect/PreviewPaneMouseWheelHandler.java new file mode 100644 index 0000000000..56e73955d1 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/design/share/ui/effect/PreviewPaneMouseWheelHandler.java @@ -0,0 +1,69 @@ +package com.fr.design.share.ui.effect; + +import com.fr.common.inputevent.InputEventBaseOnOS; +import com.fr.design.mainframe.DesignerTranslateMouseWheelHandler; + +import javax.swing.JScrollBar; +import javax.swing.JViewport; +import java.awt.event.MouseWheelEvent; +import java.awt.event.MouseWheelListener; + +import static com.fr.design.share.ui.effect.PreviewPane.SCALE_CURSOR; + +/** + * @author Starryi + * @version 1.0 + * Created by Starryi on 2021/9/24 + */ +public class PreviewPaneMouseWheelHandler implements MouseWheelListener { + private static final int DIR = 10; + + private final DesignerTranslateMouseWheelHandler translateMouseWheelHandler; + private final PreviewPane previewPane; + + public PreviewPaneMouseWheelHandler(PreviewPane previewPane) { + this.translateMouseWheelHandler = new DesignerTranslateMouseWheelHandler(new PreviewPaneScrollPaneAdapter(previewPane)); + this.previewPane = previewPane; + } + + @Override + public void mouseWheelMoved(MouseWheelEvent e) { + if (InputEventBaseOnOS.isControlDown(e)) { + int dir = e.getWheelRotation(); + previewPane.addScale( - dir * DIR); + previewPane.getElementCasePane().getGrid().setCursor(SCALE_CURSOR); + } else { + translateMouseWheelHandler.mouseWheelMoved(e); + } + } + + private static class PreviewPaneScrollPaneAdapter implements DesignerTranslateMouseWheelHandler.ScrollPane { + private final PreviewPane previewPane; + private final JViewport viewport; + + public PreviewPaneScrollPaneAdapter(PreviewPane previewPane) { + this.previewPane = previewPane; + this.viewport = new JViewport(); + } + + @Override + public boolean isWheelScrollingEnabled() { + return true; + } + + @Override + public JScrollBar getVerticalScrollBar() { + return previewPane.getElementCasePane().getVerticalScrollBar(); + } + + @Override + public JScrollBar getHorizontalScrollBar() { + return previewPane.getElementCasePane().getHorizontalScrollBar(); + } + + @Override + public JViewport getViewport() { + return this.viewport; + } + } +}