forked from fanruan/design
Browse Source
【问题原因】 表格中处理触摸板滚动和缩放虽然用的都是MouseWheelListener接口,但是是分开注册。 其中处理纵向滚动的是逻辑是在GridMouseAdapter中实现,而处理缩放的逻辑则是在 FormReportComponentComposite.java(表单报表块)和 ReportComponentComposite.java(报表) 中实现。 所以删除GridMouseAdapter中处理鼠标纵向滚动的的代码后,表单报表块就无法处理鼠标纵向滚动了。 目前排查了下,发现还有FormReportComponentComposite(表单报表块)以及PreviewPane(组件快捷配置) 还未实现触摸板双向滚动,所以一起处理下,将原来添加缩放的逻辑替换为双向滚动 + 缩放. 【改动思路】 同上feature/x
4 changed files with 156 additions and 36 deletions
@ -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(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -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; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue