|
|
|
package com.fine.theme.utils;
|
|
|
|
|
|
|
|
import com.finebi.cbb.utils.StringUtils;
|
|
|
|
import com.formdev.flatlaf.FlatClientProperties;
|
|
|
|
|
|
|
|
import javax.swing.JComponent;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FR-UI中使用的各类属性
|
|
|
|
*
|
|
|
|
* @author Levy.Xie
|
|
|
|
* @since 11.0
|
|
|
|
* Created on 2023/12/15
|
|
|
|
*/
|
|
|
|
public interface FineClientProperties extends FlatClientProperties {
|
|
|
|
|
|
|
|
String BUTTON_TYPE_GROUP = "group";
|
|
|
|
|
|
|
|
String STYLE_PRIMARY = "primary";
|
|
|
|
String STYLE_SECONDARY = "secondary";
|
|
|
|
String STYLE_SIZE_MEDIUM = "medium";
|
|
|
|
String STYLE_SIZE_SMALL = "small";
|
|
|
|
|
|
|
|
String BUTTON_TYPE_LEFT_ROUND_RECT = "leftRoundRect";
|
|
|
|
String BUTTON_TYPE_RIGHT_ROUND_RECT = "rightRoundRect";
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 添加组件的样式类,类似css,该方法会接在原样式后方
|
|
|
|
* <code>
|
|
|
|
* FineClientProperties.appendStyle("primary small")
|
|
|
|
* </code>
|
|
|
|
*
|
|
|
|
* @param it 组件
|
|
|
|
* @param styleClass 样式字符串,支持连续添加类,用空格
|
|
|
|
*/
|
|
|
|
static void appendStyle(JComponent it, String styleClass) {
|
|
|
|
Object oriProperty = it.getClientProperty(FineClientProperties.STYLE_CLASS);
|
|
|
|
if (oriProperty instanceof String && StringUtils.isNotBlank((String) oriProperty)) {
|
|
|
|
styleClass = oriProperty + " " + styleClass;
|
|
|
|
}
|
|
|
|
it.putClientProperty(FineClientProperties.STYLE_CLASS, styleClass);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 设置组件的样式类,类似css,该方法会替换原样式
|
|
|
|
* <code>
|
|
|
|
* FineClientProperties.setStyle("primary small")
|
|
|
|
* </code>
|
|
|
|
*
|
|
|
|
* @param jComponent 组件
|
|
|
|
* @param styleClass 样式字符串,支持连续添加类,用空格
|
|
|
|
*/
|
|
|
|
static void setStyle(JComponent jComponent, String styleClass) {
|
|
|
|
jComponent.putClientProperty(FineClientProperties.STYLE_CLASS, styleClass);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 样式组合
|
|
|
|
*
|
|
|
|
* @param styleClasses 所有样式
|
|
|
|
* @return 样式列表
|
|
|
|
*/
|
|
|
|
static String join(String... styleClasses) {
|
|
|
|
final StringBuilder sb = new StringBuilder();
|
|
|
|
for (final String style : styleClasses) {
|
|
|
|
if (style == null) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (sb.length() > 0) {
|
|
|
|
sb.append(" ");
|
|
|
|
}
|
|
|
|
sb.append(style);
|
|
|
|
}
|
|
|
|
return sb.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 包含样式
|
|
|
|
*
|
|
|
|
* @param jComponent 组件
|
|
|
|
* @param styleClass 样式
|
|
|
|
* @return 是否包含指定的样式
|
|
|
|
*/
|
|
|
|
static boolean hasStyle(JComponent jComponent, String styleClass) {
|
|
|
|
Object style = jComponent.getClientProperty(FineClientProperties.STYLE_CLASS);
|
|
|
|
if (style instanceof String && StringUtils.isNotBlank((String) style)) {
|
|
|
|
return ((String) style).contains(styleClass);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|