|
|
@ -2,16 +2,21 @@ package com.fine.theme.light.ui; |
|
|
|
|
|
|
|
|
|
|
|
import com.fine.theme.utils.FineClientProperties; |
|
|
|
import com.fine.theme.utils.FineClientProperties; |
|
|
|
import com.fine.theme.utils.FineUIScale; |
|
|
|
import com.fine.theme.utils.FineUIScale; |
|
|
|
|
|
|
|
import com.fine.theme.utils.FineUIUtils; |
|
|
|
import com.formdev.flatlaf.ui.FlatComboBoxUI; |
|
|
|
import com.formdev.flatlaf.ui.FlatComboBoxUI; |
|
|
|
import com.formdev.flatlaf.ui.FlatUIUtils; |
|
|
|
import com.formdev.flatlaf.ui.FlatUIUtils; |
|
|
|
import org.jetbrains.annotations.Nullable; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.swing.JButton; |
|
|
|
import javax.swing.JButton; |
|
|
|
|
|
|
|
import javax.swing.JComboBox; |
|
|
|
import javax.swing.JComponent; |
|
|
|
import javax.swing.JComponent; |
|
|
|
|
|
|
|
import javax.swing.JScrollPane; |
|
|
|
|
|
|
|
import javax.swing.ScrollPaneConstants; |
|
|
|
import javax.swing.SwingConstants; |
|
|
|
import javax.swing.SwingConstants; |
|
|
|
import javax.swing.plaf.ComponentUI; |
|
|
|
import javax.swing.plaf.ComponentUI; |
|
|
|
|
|
|
|
import javax.swing.plaf.basic.ComboPopup; |
|
|
|
import java.awt.Dimension; |
|
|
|
import java.awt.Dimension; |
|
|
|
import java.awt.Graphics2D; |
|
|
|
import java.awt.Graphics2D; |
|
|
|
|
|
|
|
import java.awt.Rectangle; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 提供 {@link javax.swing.JComboBox} 的UI类 |
|
|
|
* 提供 {@link javax.swing.JComboBox} 的UI类 |
|
|
@ -47,8 +52,10 @@ public class FineComboBoxUI extends FlatComboBoxUI { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Dimension getMinimumSize(JComponent c) { |
|
|
|
public Dimension getMinimumSize(JComponent c) { |
|
|
|
// ComboBox基于子组件计算适配尺寸性能一般,仅考虑部分ComboBox进行适配计算,其他采用默认值
|
|
|
|
// ComboBox基于子组件计算适配尺寸性能一般,仅考虑部分ComboBox进行适配计算,其他采用默认值
|
|
|
|
if (FineClientProperties.ADAPTIVE_COMBO_BOX.equals(getComboBoxTypeStr(c))) { |
|
|
|
if (isAdaptiveComboBox(c)) { |
|
|
|
return super.getMinimumSize(c); |
|
|
|
Dimension dimension = super.getMinimumSize(c); |
|
|
|
|
|
|
|
return new Dimension(Math.min(dimension.width, |
|
|
|
|
|
|
|
FineUIUtils.getAndScaleInt("ComboBox.maximumWidth", 400)), dimension.height); |
|
|
|
} |
|
|
|
} |
|
|
|
return FineUIScale.scale(new Dimension( |
|
|
|
return FineUIScale.scale(new Dimension( |
|
|
|
FlatUIUtils.getUIInt("ComboBox.minimumWidth", 72), |
|
|
|
FlatUIUtils.getUIInt("ComboBox.minimumWidth", 72), |
|
|
@ -56,12 +63,41 @@ public class FineComboBoxUI extends FlatComboBoxUI { |
|
|
|
)); |
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Nullable |
|
|
|
static boolean isAdaptiveComboBox(JComponent c) { |
|
|
|
static String getComboBoxTypeStr(JComponent c) { |
|
|
|
|
|
|
|
Object value = c.getClientProperty(FineClientProperties.COMBO_BOX_TYPE); |
|
|
|
Object value = c.getClientProperty(FineClientProperties.COMBO_BOX_TYPE); |
|
|
|
if (value instanceof String) { |
|
|
|
if (value instanceof String) { |
|
|
|
return (String) value; |
|
|
|
return FineClientProperties.ADAPTIVE_COMBO_BOX.equals(value); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected ComboPopup createPopup() { |
|
|
|
|
|
|
|
return new FineComboPopup(this.comboBox); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected class FineComboPopup extends FlatComboPopup { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected FineComboPopup(JComboBox combo) { |
|
|
|
|
|
|
|
super(combo); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected Rectangle computePopupBounds(int px, int py, int pw, int ph) { |
|
|
|
|
|
|
|
Rectangle fitRectangle = super.computePopupBounds(px, py, pw, ph); |
|
|
|
|
|
|
|
// 限制最大宽度,如超出则高度预留展示横向滚动条所需宽度
|
|
|
|
|
|
|
|
int comboWidth = comboBox.getWidth(); |
|
|
|
|
|
|
|
if (fitRectangle.width > comboWidth) { |
|
|
|
|
|
|
|
return new Rectangle(px, py, comboWidth, fitRectangle.height + FlatUIUtils.getUIInt("ScrollBar.width", 10)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return fitRectangle; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected JScrollPane createScroller() { |
|
|
|
|
|
|
|
return new JScrollPane( list, |
|
|
|
|
|
|
|
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, |
|
|
|
|
|
|
|
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); |
|
|
|
} |
|
|
|
} |
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|