obo
4 months ago
20 changed files with 212 additions and 47 deletions
@ -0,0 +1,61 @@
|
||||
package com.fr.base.i18n; |
||||
|
||||
import java.awt.BorderLayout; |
||||
import java.awt.ComponentOrientation; |
||||
import java.awt.Container; |
||||
import java.awt.FlowLayout; |
||||
import java.util.Locale; |
||||
|
||||
/** |
||||
* 根据国际化获取组件方向 |
||||
* |
||||
* @author obo |
||||
* @since 11.0 |
||||
* Created on 2024/07/17 |
||||
*/ |
||||
public class BidiUtils { |
||||
|
||||
private static final Locale ar = new Locale("ar", "SA"); |
||||
private static final Locale cn = Locale.CHINA; |
||||
|
||||
private BidiUtils() { |
||||
} |
||||
|
||||
public static ComponentOrientation getOrientationByLocale() { |
||||
return ComponentOrientation.getOrientation(ar); |
||||
} |
||||
|
||||
public static void applyOrientationByLocale(Container component) { |
||||
component.applyComponentOrientation(ComponentOrientation.getOrientation(ar)); |
||||
} |
||||
|
||||
public static void applyOrientationByLocale(Container ...component) { |
||||
for (Container container : component) { |
||||
container.applyComponentOrientation(ComponentOrientation.getOrientation(ar)); |
||||
} |
||||
} |
||||
|
||||
public static boolean rtl() { |
||||
return ComponentOrientation.getOrientation(ar) == ComponentOrientation.RIGHT_TO_LEFT; |
||||
} |
||||
|
||||
public static String getBorderLayoutWest() { |
||||
return BidiUtils.rtl() ? BorderLayout.EAST : BorderLayout.WEST; |
||||
} |
||||
|
||||
public static String getBorderLayoutEast() { |
||||
return BidiUtils.rtl() ? BorderLayout.WEST : BorderLayout.EAST; |
||||
} |
||||
|
||||
public static int getFlowLayoutLeft() { |
||||
return BidiUtils.rtl() ? FlowLayout.RIGHT : FlowLayout.LEFT; |
||||
} |
||||
|
||||
public static int getFlowLayoutRight() { |
||||
return BidiUtils.rtl() ? FlowLayout.LEFT : FlowLayout.RIGHT; |
||||
} |
||||
|
||||
public static int getStableConstantsRight() { |
||||
return BidiUtils.rtl() ? com.fr.stable.Constants.LEFT : com.fr.stable.Constants.RIGHT; |
||||
} |
||||
} |
@ -0,0 +1,51 @@
|
||||
package com.fr.design.gui.ilable; |
||||
|
||||
import com.fr.base.i18n.BidiUtils; |
||||
|
||||
import javax.swing.Icon; |
||||
import javax.swing.JLabel; |
||||
|
||||
/** |
||||
* description |
||||
* |
||||
* @author obo |
||||
* @since 11.0 |
||||
* Created on 2024/07/16 |
||||
*/ |
||||
public class LocaleOrientationLabel extends JLabel { |
||||
|
||||
public LocaleOrientationLabel(String text, Icon image, int horizontalAlignment) { |
||||
super(text, image, horizontalAlignment); |
||||
if (image != null && text != null) { |
||||
setIconTextGap(4); |
||||
} |
||||
this.setComponentOrientation(BidiUtils.getOrientationByLocale()); |
||||
} |
||||
|
||||
public LocaleOrientationLabel(String text, int horizontalAlignment) { |
||||
super(text, horizontalAlignment); |
||||
this.setComponentOrientation(BidiUtils.getOrientationByLocale()); |
||||
} |
||||
|
||||
public LocaleOrientationLabel(String text) { |
||||
super(text); |
||||
this.setComponentOrientation(BidiUtils.getOrientationByLocale()); |
||||
} |
||||
|
||||
public LocaleOrientationLabel(Icon image, int horizontalAlignment) { |
||||
super(image, horizontalAlignment); |
||||
this.setComponentOrientation(BidiUtils.getOrientationByLocale()); |
||||
} |
||||
|
||||
public LocaleOrientationLabel(Icon image) { |
||||
super(image); |
||||
this.setComponentOrientation(BidiUtils.getOrientationByLocale()); |
||||
} |
||||
|
||||
public LocaleOrientationLabel() { |
||||
super(); |
||||
this.setComponentOrientation(BidiUtils.getOrientationByLocale()); |
||||
} |
||||
|
||||
|
||||
} |
Loading…
Reference in new issue