From c3d397bee3cf76a9112c9fa4f4a7bab9828703d6 Mon Sep 17 00:00:00 2001 From: Maksim Date: Mon, 16 Mar 2020 17:30:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E6=98=BE=E7=A4=BA=E7=9A=84?= =?UTF-8?q?=E9=95=BF=E5=BA=A6=E6=9D=A5=E5=AE=9A=E4=B9=89=E9=97=B4=E9=9A=94?= =?UTF-8?q?=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/EnvChangeEntrance.java | 2 +- .../submit => env}/CheckServiceDialog.java | 8 ++- .../java/com/fr/env/utils/DisplayUtils.java | 39 ++++++++++++++ .../com/fr/design/EnvChangeEntranceTest.java | 2 +- .../com/fr/env/utils/DisplayUtilsTest.java | 52 +++++++++++++++++++ 5 files changed, 99 insertions(+), 4 deletions(-) rename designer-base/src/main/java/com/fr/{design/write/submit => env}/CheckServiceDialog.java (94%) create mode 100644 designer-base/src/main/java/com/fr/env/utils/DisplayUtils.java create mode 100644 designer-base/src/test/java/com/fr/env/utils/DisplayUtilsTest.java diff --git a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java index 6febf8785..076d59f8b 100644 --- a/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java +++ b/designer-base/src/main/java/com/fr/design/EnvChangeEntrance.java @@ -14,7 +14,7 @@ import com.fr.design.i18n.Toolkit; import com.fr.design.mainframe.DesignerContext; import com.fr.design.mainframe.JTemplate; import com.fr.design.utils.DesignUtils; -import com.fr.design.write.submit.CheckServiceDialog; +import com.fr.env.CheckServiceDialog; import com.fr.env.EnvListPane; import com.fr.exit.DesignerExiter; import com.fr.general.GeneralContext; diff --git a/designer-base/src/main/java/com/fr/design/write/submit/CheckServiceDialog.java b/designer-base/src/main/java/com/fr/env/CheckServiceDialog.java similarity index 94% rename from designer-base/src/main/java/com/fr/design/write/submit/CheckServiceDialog.java rename to designer-base/src/main/java/com/fr/env/CheckServiceDialog.java index 177d6123e..0389d7d58 100644 --- a/designer-base/src/main/java/com/fr/design/write/submit/CheckServiceDialog.java +++ b/designer-base/src/main/java/com/fr/env/CheckServiceDialog.java @@ -1,4 +1,4 @@ -package com.fr.design.write.submit; +package com.fr.env; import com.fr.design.DesignerEnvManager; import com.fr.design.env.RemoteDesignerWorkspaceInfo; @@ -7,6 +7,7 @@ import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.utils.gui.GUICoreUtils; +import com.fr.env.utils.DisplayUtils; import com.fr.general.FRFont; import com.fr.general.GeneralContext; import com.fr.general.IOUtils; @@ -56,7 +57,10 @@ public class CheckServiceDialog extends JDialog implements ActionListener { JLabel label = new JLabel(Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Branch_Inconsistency")); label.setFont(font); label.setPreferredSize(new Dimension(650,30)); - String delimiter = GeneralContext.getLocale().equals(Locale.US)? "
":"/"; + + String text = Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Local_Designer") + localBranch + + Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Remote_Server") + remoteBranch; + String delimiter = DisplayUtils.getDisplayLength(text) > 70? "
":"/"; JLabel label2 = new JLabel(""+Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Local_Designer") + localBranch + delimiter + Toolkit.i18nText("Fine-Design_Basic_Remote_Design_Remote_Server") + remoteBranch+""); label2.setPreferredSize(new Dimension(600,30)); diff --git a/designer-base/src/main/java/com/fr/env/utils/DisplayUtils.java b/designer-base/src/main/java/com/fr/env/utils/DisplayUtils.java new file mode 100644 index 000000000..1795c5fb1 --- /dev/null +++ b/designer-base/src/main/java/com/fr/env/utils/DisplayUtils.java @@ -0,0 +1,39 @@ +package com.fr.env.utils; + +/** + * @author: Maksim + * @Date: Created in 2020/3/16 + * @Description: + */ +public class DisplayUtils { + + /** + * 获取字符串显示时的计算长度 + * @param text 被计算的字符串 + * @return 计算长度 + */ + public static int getDisplayLength(String text){ + if (text == null) { + return 0; + } + char[] c = text.toCharArray(); + int len = 0; + for (int i = 0; i < c.length; i++) { + len++; + if(!isLetter(c[i])){ + len++; + }; + } + return len; + } + + /** + * 判断字符是否为字母、数字、英文符号 + * @param c 传入的字符 + * @return 如果符合上述条件,返回true + */ + public static boolean isLetter(char c) { + int k = 0x80; + return c / k == 0; + } +} diff --git a/designer-base/src/test/java/com/fr/design/EnvChangeEntranceTest.java b/designer-base/src/test/java/com/fr/design/EnvChangeEntranceTest.java index 360bdfd9f..f37c6e73d 100644 --- a/designer-base/src/test/java/com/fr/design/EnvChangeEntranceTest.java +++ b/designer-base/src/test/java/com/fr/design/EnvChangeEntranceTest.java @@ -2,7 +2,7 @@ package com.fr.design; import com.fr.design.env.DesignerWorkspaceInfo; import com.fr.design.env.DesignerWorkspaceType; -import com.fr.design.write.submit.CheckServiceDialog; +import com.fr.env.CheckServiceDialog; import com.fr.workspace.connect.WorkspaceConnectionInfo; import com.fr.workspace.engine.channel.http.FunctionalHttpRequest; import org.easymock.EasyMock; diff --git a/designer-base/src/test/java/com/fr/env/utils/DisplayUtilsTest.java b/designer-base/src/test/java/com/fr/env/utils/DisplayUtilsTest.java new file mode 100644 index 000000000..181bd9788 --- /dev/null +++ b/designer-base/src/test/java/com/fr/env/utils/DisplayUtilsTest.java @@ -0,0 +1,52 @@ +package com.fr.env.utils; + +import org.junit.Assert; +import org.junit.Test; + + +/** + * @author: Maksim + * @Date: Created in 2020/3/16 + * @Description: + */ +public class DisplayUtilsTest { + + @Test + public void getDisplayLengthTest() { + String s1 = "本地设计器"; + String s2 = "リモートサーバ"; + String s3 = "Local Designer:"; + String s4 = "本地,设,计器: persist-2020.01.15"; + String s5 = "ローカルデザイナrelease-2020.03.03 ... Remote Server:persist-2020.01.15"; + String s6 = "本地 00:00ロ ーカDE / abc "; + + int length1 = DisplayUtils.getDisplayLength(s1); + int length2 = DisplayUtils.getDisplayLength(s2); + int length3 = DisplayUtils.getDisplayLength(s3); + int length4 = DisplayUtils.getDisplayLength(s4); + int length5 = DisplayUtils.getDisplayLength(s5); + int length6 = DisplayUtils.getDisplayLength(s6); + Assert.assertEquals(10,length1); + Assert.assertEquals(14,length2); + Assert.assertEquals(15,length3); + Assert.assertEquals(34,length4); + Assert.assertEquals(72,length5); + Assert.assertEquals(26,length6); + } + + @Test + public void isLetterTest(){ + char c1 = 'A'; + char c2 = '中'; + char c3 = ','; + char c4 = ','; + char c5 = 'デ'; + char c6 = ' '; + Assert.assertTrue(DisplayUtils.isLetter(c1)); + Assert.assertFalse(DisplayUtils.isLetter(c2)); + Assert.assertTrue(DisplayUtils.isLetter(c3)); + Assert.assertFalse(DisplayUtils.isLetter(c4)); + Assert.assertFalse(DisplayUtils.isLetter(c5)); + Assert.assertTrue(DisplayUtils.isLetter(c6)); + } +} \ No newline at end of file