|
|
|
@ -1,6 +1,5 @@
|
|
|
|
|
package com.fr.design.gui.ilable; |
|
|
|
|
|
|
|
|
|
import com.fr.base.i18n.BidiUtils; |
|
|
|
|
import com.fr.design.gui.core.UITextComponent; |
|
|
|
|
import com.fr.design.utils.gui.GUICoreUtils; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
@ -28,23 +27,19 @@ public class UILabel extends JLabel implements UITextComponent {
|
|
|
|
|
if (image != null && text != null) { |
|
|
|
|
setIconTextGap(4); |
|
|
|
|
} |
|
|
|
|
adjustLabelTextForRTL(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public UILabel(String text, int horizontalAlignment) { |
|
|
|
|
super(text, horizontalAlignment); |
|
|
|
|
adjustLabelTextForRTL(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public UILabel(String text) { |
|
|
|
|
super(text); |
|
|
|
|
adjustLabelTextForRTL(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public UILabel(String text, boolean enable) { |
|
|
|
|
super(text); |
|
|
|
|
this.setEnabled(enable); |
|
|
|
|
adjustLabelTextForRTL(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public UILabel(Icon image, int horizontalAlignment) { |
|
|
|
@ -69,27 +64,6 @@ public class UILabel extends JLabel implements UITextComponent {
|
|
|
|
|
return preferredSize; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 调整label的名称以适配RTL |
|
|
|
|
* <p/> |
|
|
|
|
* 代码中有大量的国际化文本拼接冒号或者其他硬编码字符串创建Label的行为,RTL时名称需要分段反转,把一部分放在UILabel构造方法中进行调整,目前处理的场景如下: |
|
|
|
|
* <ul> |
|
|
|
|
* <li>label名+冒号(:)</li> |
|
|
|
|
* <li>Item 2</li> |
|
|
|
|
* <li>Item 3</li> |
|
|
|
|
* </ul> |
|
|
|
|
*/ |
|
|
|
|
private void adjustLabelTextForRTL() { |
|
|
|
|
if (!BidiUtils.rtl()) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
String text = this.getText(); |
|
|
|
|
if (StringUtils.isNotEmpty(text) && text.length() > 1 && StringUtils.equals(String.valueOf(text.charAt(text.length() - 1)), COLON)) { |
|
|
|
|
text = COLON + text.substring(0, text.length() - 1); |
|
|
|
|
this.setText(text); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
|
// UILabel label = new UILabel("shishi",SwingConstants.LEFT);
|
|
|
|
|
JFrame frame = new JFrame("Test"); |
|
|
|
|