|
|
|
package com.fr.base.i18n;
|
|
|
|
|
|
|
|
import com.fr.design.DesignerEnvManager;
|
|
|
|
|
|
|
|
import javax.swing.border.TitledBorder;
|
|
|
|
import java.awt.Component;
|
|
|
|
import java.awt.ComponentOrientation;
|
|
|
|
import java.awt.Container;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 根据国际化获取组件方向
|
|
|
|
*
|
|
|
|
* @author obo
|
|
|
|
* @since 11.0
|
|
|
|
* Created on 2024/07/17
|
|
|
|
*/
|
|
|
|
public class BidiUtils {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 设计器国际化
|
|
|
|
*/
|
|
|
|
private static final Locale LOCALE = DesignerEnvManager.getEnvManager().getLanguage();
|
|
|
|
|
|
|
|
private BidiUtils() {
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 获取当前设计器语言的组件方向值
|
|
|
|
*/
|
|
|
|
public static ComponentOrientation getOrientationByLocale() {
|
|
|
|
return ComponentOrientation.getOrientation(LOCALE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 把当前设计器国际化的组件方向应用到组件,影响子组件
|
|
|
|
*
|
|
|
|
* @param component 组件
|
|
|
|
* @return 组件对象
|
|
|
|
* @param <T> Component子类
|
|
|
|
*/
|
|
|
|
public static <T extends Component> T applyOrientationByLocale(T component) {
|
|
|
|
component.applyComponentOrientation(ComponentOrientation.getOrientation(LOCALE));
|
|
|
|
return component;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 把当前设计器国际化的组件方向设置到组件,不影响子组件
|
|
|
|
*
|
|
|
|
* @param component 组件
|
|
|
|
* @return 组件对象
|
|
|
|
* @param <T> Component子类
|
|
|
|
*/
|
|
|
|
public static <T extends Component> T setOrientationByLocale(T component) {
|
|
|
|
component.setComponentOrientation(ComponentOrientation.getOrientation(LOCALE));
|
|
|
|
return component;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 设置设计器国际化组件方向到多个组件,不影响子组件
|
|
|
|
*
|
|
|
|
* @param components 组件数组
|
|
|
|
*/
|
|
|
|
public static void setOrientationByLocale(Component... components) {
|
|
|
|
for (Component component : components) {
|
|
|
|
component.setComponentOrientation(ComponentOrientation.getOrientation(LOCALE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 应用设计器国际化组件方向到多个组件,影响子组件
|
|
|
|
*
|
|
|
|
* @param components 组件数组
|
|
|
|
*/
|
|
|
|
public static void applyOrientationByLocale(Component... components) {
|
|
|
|
for (Component component : components) {
|
|
|
|
component.applyComponentOrientation(ComponentOrientation.getOrientation(LOCALE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 判断当前设计器组件方向是否为rtl
|
|
|
|
*/
|
|
|
|
public static boolean rtl() {
|
|
|
|
return ComponentOrientation.getOrientation(LOCALE) == ComponentOrientation.RIGHT_TO_LEFT;
|
|
|
|
}
|
|
|
|
public static String concatenateStrings(String... strs) {
|
|
|
|
StringBuilder result = new StringBuilder();
|
|
|
|
|
|
|
|
if (rtl()) {
|
|
|
|
for (int i = strs.length - 1; i >= 0; i--) {
|
|
|
|
result.append(strs[i]);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (int i = 0; i <= strs.length - 1; i++) {
|
|
|
|
result.append(strs[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 根据组件方向调整titleBorder的标题位置
|
|
|
|
* @param titledBorder
|
|
|
|
* @return
|
|
|
|
* @param <T>
|
|
|
|
*/
|
|
|
|
public static <T extends TitledBorder> T applyTitledBorderJustification(T titledBorder) {
|
|
|
|
titledBorder.setTitleJustification(BidiUtils.rtl() ? TitledBorder.RIGHT : TitledBorder.LEFT);
|
|
|
|
return titledBorder;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 镜像BoxLayout布局组件
|
|
|
|
*/
|
|
|
|
public static void mirrorBoxLayout(Container container) {
|
|
|
|
Component[] components = container.getComponents();
|
|
|
|
for (int i = components.length - 1; i >= 0; i--) {
|
|
|
|
Component component = components[i];
|
|
|
|
container.remove(i);
|
|
|
|
container.add(component);
|
|
|
|
}
|
|
|
|
container.revalidate();
|
|
|
|
container.repaint();
|
|
|
|
}
|
|
|
|
}
|