|
|
|
@ -2,8 +2,6 @@ package com.fr.design.gui.icombocheckbox;
|
|
|
|
|
|
|
|
|
|
import com.fine.theme.icon.LazyIcon; |
|
|
|
|
import com.fine.theme.light.ui.FineRoundBorder; |
|
|
|
|
import com.fine.theme.utils.FineUIUtils; |
|
|
|
|
import com.formdev.flatlaf.util.ScaledEmptyBorder; |
|
|
|
|
import com.fr.design.event.GlobalNameListener; |
|
|
|
|
import com.fr.design.event.GlobalNameObserver; |
|
|
|
|
import com.fr.design.event.HoverAware; |
|
|
|
@ -17,15 +15,14 @@ import com.fr.stable.StringUtils;
|
|
|
|
|
import javax.swing.Icon; |
|
|
|
|
import javax.swing.JComboBox; |
|
|
|
|
import javax.swing.JComponent; |
|
|
|
|
import javax.swing.JFrame; |
|
|
|
|
import javax.swing.JPanel; |
|
|
|
|
import javax.swing.SwingUtilities; |
|
|
|
|
import javax.swing.event.PopupMenuEvent; |
|
|
|
|
import javax.swing.event.PopupMenuListener; |
|
|
|
|
import java.awt.BorderLayout; |
|
|
|
|
import java.awt.Color; |
|
|
|
|
import java.awt.Component; |
|
|
|
|
import java.awt.Dimension; |
|
|
|
|
import java.awt.FlowLayout; |
|
|
|
|
import java.awt.FontMetrics; |
|
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
|
import java.awt.event.ActionListener; |
|
|
|
@ -39,7 +36,6 @@ import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import static com.fine.theme.utils.FineUIStyle.OFFET_LEFT_TEXT_FIELD; |
|
|
|
|
import static com.fine.theme.utils.FineUIStyle.PLAIN_ARROW_BUTTON; |
|
|
|
|
import static com.fine.theme.utils.FineUIStyle.TRANSPARENT_TEXT_FIELD; |
|
|
|
|
import static com.fine.theme.utils.FineUIStyle.setStyle; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -143,7 +139,7 @@ public class UIComboCheckBox extends JComboBox implements UIObserver, GlobalName
|
|
|
|
|
initClickPane(); |
|
|
|
|
|
|
|
|
|
setLayoutAndAddComponents(); |
|
|
|
|
setText(); |
|
|
|
|
SwingUtilities.invokeLater(this::setText); |
|
|
|
|
|
|
|
|
|
addPopupListener(this); |
|
|
|
|
} |
|
|
|
@ -152,10 +148,12 @@ public class UIComboCheckBox extends JComboBox implements UIObserver, GlobalName
|
|
|
|
|
* 设置布局管理器并且添加组件 |
|
|
|
|
* 默认使用FlowLayout |
|
|
|
|
*/ |
|
|
|
|
protected void setLayoutAndAddComponents() { |
|
|
|
|
this.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); |
|
|
|
|
this.add(editor); |
|
|
|
|
this.add(arrowButton); |
|
|
|
|
private void setLayoutAndAddComponents() { |
|
|
|
|
// 使用BorderLayout,否则默认使用的FlowLayout会让整个下拉选框使用最小Size,然后TableCell这边会出现空白
|
|
|
|
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
|
|
|
|
JPanel pane = getClickPane(); |
|
|
|
|
pane.setOpaque(false); |
|
|
|
|
this.add(pane, BorderLayout.CENTER); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public UICheckListPopup getPopup() { |
|
|
|
@ -341,7 +339,10 @@ public class UIComboCheckBox extends JComboBox implements UIObserver, GlobalName
|
|
|
|
|
* @param text |
|
|
|
|
*/ |
|
|
|
|
protected void setEditorToolTipText(JComponent editor, String text) { |
|
|
|
|
// 默认不做设置
|
|
|
|
|
// 选项过多时,已选中的值会做省略显示处理,此处添加一个Tooltips,显示完整值
|
|
|
|
|
if (text != null) { |
|
|
|
|
editor.setToolTipText(text); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -360,6 +361,10 @@ public class UIComboCheckBox extends JComboBox implements UIObserver, GlobalName
|
|
|
|
|
String omitText = StringUtils.EMPTY; |
|
|
|
|
char[] chars = text.toCharArray(); |
|
|
|
|
|
|
|
|
|
if (textEditor.getWidth() == 0) { |
|
|
|
|
return text; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= chars.length; i++) { |
|
|
|
|
//如果原文本+省略号长度超过文本框
|
|
|
|
|
if (fontMetrics.charsWidth(chars, 0, i) + omitLength > textEditor.getWidth()) { |
|
|
|
@ -497,26 +502,4 @@ public class UIComboCheckBox extends JComboBox implements UIObserver, GlobalName
|
|
|
|
|
public String getUIClassID() { |
|
|
|
|
return UI_CLASS_ID; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 简单的测试demo |
|
|
|
|
* |
|
|
|
|
* @param args |
|
|
|
|
*/ |
|
|
|
|
public static void main(String args[]) { |
|
|
|
|
UIComboCheckBox comboBox = new UIComboCheckBox(new Object[] |
|
|
|
|
{"MATA", "HANA", "KAKA", "KUKA", "INFI", "LILY", "RIBO", "CUBE", "MATA", "HANA", "KAKA", "KUKA"}); |
|
|
|
|
|
|
|
|
|
comboBox.isShowOmitText(false); |
|
|
|
|
comboBox.setPopupMaxDisplayNumber(6); |
|
|
|
|
|
|
|
|
|
JPanel jPanel = FRGUIPaneFactory.createNormalFlowInnerContainer_S_Pane(); |
|
|
|
|
jPanel.add(comboBox); |
|
|
|
|
|
|
|
|
|
JFrame jFrame = new JFrame(); |
|
|
|
|
jFrame.setVisible(true); |
|
|
|
|
jFrame.setSize(600, 400); |
|
|
|
|
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
|
|
|
jFrame.add(jPanel, BorderLayout.CENTER); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|