Browse Source
Merge in DESIGN/design from ~LEVY.XIE/design:newui to newui * commit '824b8953a4d1fd508c7edde6cbc608955b823b69': REPORT-111995 弹出面板适配DPI缩放 REPORT-111995 提供仅悬浮时显示滚动条的滚动面板组件newui
Levy.Xie-解安森
10 months ago
6 changed files with 140 additions and 38 deletions
@ -0,0 +1,73 @@ |
|||||||
|
package com.fine.theme.light.ui; |
||||||
|
|
||||||
|
import com.fr.design.gui.icontainer.UIScrollPane; |
||||||
|
|
||||||
|
import javax.swing.JComponent; |
||||||
|
import javax.swing.JLayer; |
||||||
|
import javax.swing.JScrollPane; |
||||||
|
import javax.swing.ScrollPaneConstants; |
||||||
|
import javax.swing.plaf.LayerUI; |
||||||
|
import java.awt.AWTEvent; |
||||||
|
import java.awt.Component; |
||||||
|
import java.awt.event.MouseEvent; |
||||||
|
|
||||||
|
/** |
||||||
|
* 滚动面板的装饰层UI,支持滚动条仅当悬浮时显示 |
||||||
|
* 使用见工具类: {@link com.fine.theme.utils.FineUIUtils#createCollapsibleScrollBarLayer(Component)} |
||||||
|
* |
||||||
|
* @author Levy.Xie |
||||||
|
* @since 11.0 |
||||||
|
* Created on 2024/01/25 |
||||||
|
*/ |
||||||
|
public class CollapsibleScrollBarLayerUI extends LayerUI<UIScrollPane> { |
||||||
|
private final int verticalPolicy; |
||||||
|
private final int horizontalPolicy; |
||||||
|
|
||||||
|
public CollapsibleScrollBarLayerUI() { |
||||||
|
this(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
||||||
|
} |
||||||
|
|
||||||
|
public CollapsibleScrollBarLayerUI(int verticalPolicy, int horizontalPolicy) { |
||||||
|
this.verticalPolicy = verticalPolicy; |
||||||
|
this.horizontalPolicy = horizontalPolicy; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void installUI(JComponent c) { |
||||||
|
super.installUI(c); |
||||||
|
if (c instanceof JLayer) { |
||||||
|
((JLayer<?>) c).setLayerEventMask(AWTEvent.MOUSE_EVENT_MASK); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void uninstallUI(JComponent c) { |
||||||
|
if (c instanceof JLayer) { |
||||||
|
((JLayer<?>) c).setLayerEventMask(0); |
||||||
|
} |
||||||
|
super.uninstallUI(c); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected void processMouseEvent(MouseEvent e, JLayer<? extends UIScrollPane> l) { |
||||||
|
JScrollPane view = l.getView(); |
||||||
|
switch (e.getID()) { |
||||||
|
case MouseEvent.MOUSE_ENTERED: |
||||||
|
// 在鼠标进入时恢复滚动条显示策略
|
||||||
|
if (view != null) { |
||||||
|
view.setVerticalScrollBarPolicy(verticalPolicy); |
||||||
|
view.setHorizontalScrollBarPolicy(horizontalPolicy); |
||||||
|
} |
||||||
|
break; |
||||||
|
case MouseEvent.MOUSE_EXITED: |
||||||
|
// 在鼠标退出时隐藏滚动条
|
||||||
|
if (view != null) { |
||||||
|
view.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); |
||||||
|
view.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
||||||
|
} |
||||||
|
break; |
||||||
|
default: |
||||||
|
break; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue