From ab8cd90400495febd2bb56567441dbfde8923321 Mon Sep 17 00:00:00 2001 From: hades Date: Wed, 12 Aug 2020 11:37:48 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-27497=20=E7=BC=96=E8=BE=91=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=A0=BC=E8=BE=93=E5=85=A5=E9=9F=A9=E6=96=87=E6=97=B6?= =?UTF-8?q?=E5=AD=97=E4=BC=9A=E7=BC=BA=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/com/fr/grid/Grid.java | 10 +++++- .../java/com/fr/grid/GridKeyListener.java | 5 +++ .../com/fr/grid/action/GridInputAction.java | 31 +++++++++++++++++ .../java/com/fr/grid/help/GridHelper.java | 24 +++++++++++++ .../java/com/fr/grid/help/GridHelperTest.java | 34 +++++++++++++++++++ 5 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 designer-realize/src/main/java/com/fr/grid/action/GridInputAction.java create mode 100644 designer-realize/src/main/java/com/fr/grid/help/GridHelper.java create mode 100644 designer-realize/src/test/java/com/fr/grid/help/GridHelperTest.java diff --git a/designer-realize/src/main/java/com/fr/grid/Grid.java b/designer-realize/src/main/java/com/fr/grid/Grid.java index 19e68a913..a16d64ead 100644 --- a/designer-realize/src/main/java/com/fr/grid/Grid.java +++ b/designer-realize/src/main/java/com/fr/grid/Grid.java @@ -130,6 +130,8 @@ public class Grid extends BaseGridComponent { private boolean notShowingTableSelectPane = true; private GridMouseAdapter gridMouseAdapter; + private boolean needRequestFocus = true; + public Grid(int resolution) { this.resolution = resolution; // 能触发processEvent,不管是否给component增加listener @@ -259,6 +261,10 @@ public class Grid extends BaseGridComponent { this.getElementCasePane().repaint(); } + public void setNeedRequestFocus(boolean needRequestFocus) { + this.needRequestFocus = needRequestFocus; + } + /** * Gets vertical frozen line color. */ @@ -908,7 +914,9 @@ public class Grid extends BaseGridComponent { this.validate(); // 需要重新绘制界面 this.repaint(10); - this.editorComponent.requestFocus(); + if (this.needRequestFocus) { + this.editorComponent.requestFocus(); + } } /** diff --git a/designer-realize/src/main/java/com/fr/grid/GridKeyListener.java b/designer-realize/src/main/java/com/fr/grid/GridKeyListener.java index d72165d7f..8cfa7bbf2 100644 --- a/designer-realize/src/main/java/com/fr/grid/GridKeyListener.java +++ b/designer-realize/src/main/java/com/fr/grid/GridKeyListener.java @@ -2,10 +2,12 @@ package com.fr.grid; import com.fr.common.inputevent.InputEventBaseOnOS; import com.fr.design.mainframe.ElementCasePane; +import com.fr.grid.action.GridInputAction; import com.fr.grid.selection.CellSelection; import com.fr.grid.selection.FloatSelection; import com.fr.grid.selection.Selection; import com.fr.report.elementcase.ElementCase; +import com.fr.stable.os.support.OSSupportCenter; import java.awt.*; import java.awt.event.KeyEvent; @@ -177,6 +179,9 @@ public class GridKeyListener implements KeyListener { return; } if (!grid.isCellEditing()) { + GridInputAction action = OSSupportCenter.getAction(GridInputAction.class); + action.register(grid, ch); + action.execute(); grid.startEditing(true); } diff --git a/designer-realize/src/main/java/com/fr/grid/action/GridInputAction.java b/designer-realize/src/main/java/com/fr/grid/action/GridInputAction.java new file mode 100644 index 000000000..3eb26a74e --- /dev/null +++ b/designer-realize/src/main/java/com/fr/grid/action/GridInputAction.java @@ -0,0 +1,31 @@ +package com.fr.grid.action; + +import com.fr.design.os.impl.SupportOSImpl; +import com.fr.grid.Grid; +import com.fr.grid.help.GridHelper; +import com.fr.stable.os.support.OSBasedAction; + +/** + * @author hades + * @version 10.0 + * Created by hades on 2020/8/12 + */ +public class GridInputAction implements OSBasedAction { + + private Grid grid; + private char ch; + + @Override + public void execute(Object... objects) { + // win下韩语输入法与其他输入法不一样 在输入第二个字符时 就开始触发keyType 而其中grid的焦点转移会导致输入失效 + boolean accept = SupportOSImpl.KOREAN_INPUT.support() && grid != null; + if (accept) { + grid.setNeedRequestFocus(!GridHelper.isKoreanCharacter(ch)); + } + } + + public void register(Grid grid, char ch) { + this.grid = grid; + this.ch = ch; + } +} diff --git a/designer-realize/src/main/java/com/fr/grid/help/GridHelper.java b/designer-realize/src/main/java/com/fr/grid/help/GridHelper.java new file mode 100644 index 000000000..bba218463 --- /dev/null +++ b/designer-realize/src/main/java/com/fr/grid/help/GridHelper.java @@ -0,0 +1,24 @@ +package com.fr.grid.help; + +/** + * @author hades + * @version 10.0 + * Created by hades on 2020/8/7 + */ +public class GridHelper { + + private static final char X_AC00 = 0xAC00; + private static final char X_D7A3 = 0xD7A3; + private static final char X_3130 = 0x3130; + private static final char X_318F = 0x318F; + private static final char X_1100 = 0x1100; + private static final char X_11FF = 0x11FF; + private static final char X_20A9 = 0x20A9; + + public static boolean isKoreanCharacter(char value) { + return value >= X_AC00 && value <= X_D7A3 + || value > X_3130 && value < X_318F + || value > X_1100 && value < X_11FF + || value == X_20A9; + } +} diff --git a/designer-realize/src/test/java/com/fr/grid/help/GridHelperTest.java b/designer-realize/src/test/java/com/fr/grid/help/GridHelperTest.java new file mode 100644 index 000000000..dc5c2b843 --- /dev/null +++ b/designer-realize/src/test/java/com/fr/grid/help/GridHelperTest.java @@ -0,0 +1,34 @@ +package com.fr.grid.help; + +import junit.framework.TestCase; +import org.junit.Assert; + +/** + * @author hades + * @version 10.0 + * Created by hades on 2020/8/7 + */ +public class GridHelperTest extends TestCase { + + /** + * 为空 + */ + private char ch; + + public void testIsKoreanCharacter() { + Assert.assertFalse(GridHelper.isKoreanCharacter('1')); + Assert.assertFalse(GridHelper.isKoreanCharacter('A')); + Assert.assertFalse(GridHelper.isKoreanCharacter('z')); + Assert.assertFalse(GridHelper.isKoreanCharacter('测')); + Assert.assertFalse(GridHelper.isKoreanCharacter('測')); + Assert.assertFalse(GridHelper.isKoreanCharacter('鐪')); + Assert.assertFalse(GridHelper.isKoreanCharacter('&')); + Assert.assertFalse(GridHelper.isKoreanCharacter(' ')); + Assert.assertFalse(GridHelper.isKoreanCharacter(ch)); + Assert.assertFalse(GridHelper.isKoreanCharacter('は')); + Assert.assertTrue(GridHelper.isKoreanCharacter('먀')); + Assert.assertTrue(GridHelper.isKoreanCharacter('이')); + } + + +} From e372a89f8760655606a152d6182ba64b3fce694e Mon Sep 17 00:00:00 2001 From: hades Date: Wed, 12 Aug 2020 15:10:44 +0800 Subject: [PATCH 2/2] =?UTF-8?q?REPORT-27497=20=E7=BC=96=E8=BE=91=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=A0=BC=E8=BE=93=E5=85=A5=E9=9F=A9=E6=96=87=E6=97=B6?= =?UTF-8?q?=E5=AD=97=E4=BC=9A=E7=BC=BA=E5=A4=B1=20=E4=BD=BF=E7=94=A8java?= =?UTF-8?q?=E8=87=AA=E5=B8=A6=E6=96=B9=E5=BC=8F=E5=88=A4=E6=96=AD=20+=20?= =?UTF-8?q?=E6=BC=8F=E4=BC=A0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/os/impl/SupportOSImpl.java | 7 +++ .../java/com/fr/grid/help/GridHelper.java | 53 ++++++++++++++----- .../java/com/fr/grid/help/GridHelperTest.java | 13 +++++ 3 files changed, 61 insertions(+), 12 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/os/impl/SupportOSImpl.java b/designer-base/src/main/java/com/fr/design/os/impl/SupportOSImpl.java index 366e7d565..88fe2a275 100644 --- a/designer-base/src/main/java/com/fr/design/os/impl/SupportOSImpl.java +++ b/designer-base/src/main/java/com/fr/design/os/impl/SupportOSImpl.java @@ -117,6 +117,13 @@ public enum SupportOSImpl implements SupportOS { public boolean support() { return OperatingSystem.isWindows(); } + }, + + KOREAN_INPUT { + @Override + public boolean support() { + return OperatingSystem.isWindows(); + } } } diff --git a/designer-realize/src/main/java/com/fr/grid/help/GridHelper.java b/designer-realize/src/main/java/com/fr/grid/help/GridHelper.java index bba218463..5eebe9325 100644 --- a/designer-realize/src/main/java/com/fr/grid/help/GridHelper.java +++ b/designer-realize/src/main/java/com/fr/grid/help/GridHelper.java @@ -1,24 +1,53 @@ package com.fr.grid.help; /** + * 韩文unicode编码范围 + * http://www.ch2ko.com/hanguoyu/hanwen-unicode/ + * + * 韩文音节:AC00-D7AF + * Character.UnicodeBlock.HANGUL_SYLLABLES + * https://www.unicode.org/charts/PDF/UAC00.pdf + * + * + * 韩文兼容字母:3130-318F + * Character.UnicodeBlock.HANGUL_COMPATIBILITY_JAMO + * https://www.unicode.org/charts/PDF/U3130.pdf + * + * + * 韩文字母:1100-11FF + * Character.UnicodeBlock.HANGUL_JAMO + * https://www.unicode.org/charts/PDF/U1100.pdf + * + * + * 韩文字母扩展A + * Character.UnicodeBlock.HANGUL_JAMO_EXTENDED_A + * https://www.unicode.org/charts/PDF/UA960.pdf + * + * + * 韩文字母扩展B + * haracter.UnicodeBlock.HANGUL_JAMO_EXTENDED_B + * https://www.unicode.org/charts/PDF/UD7B0.pdf + * + * + * 使用java内部的韩文unicode集判断 + * * @author hades * @version 10.0 * Created by hades on 2020/8/7 */ public class GridHelper { - - private static final char X_AC00 = 0xAC00; - private static final char X_D7A3 = 0xD7A3; - private static final char X_3130 = 0x3130; - private static final char X_318F = 0x318F; - private static final char X_1100 = 0x1100; - private static final char X_11FF = 0x11FF; - private static final char X_20A9 = 0x20A9; + /** + * 韩国货币符号 + */ + private static final char HEX_20A9 = 0x20A9; public static boolean isKoreanCharacter(char value) { - return value >= X_AC00 && value <= X_D7A3 - || value > X_3130 && value < X_318F - || value > X_1100 && value < X_11FF - || value == X_20A9; + Character.UnicodeBlock unicodeBlock = Character.UnicodeBlock.of(value); + return unicodeBlock == Character.UnicodeBlock.HANGUL_JAMO + || unicodeBlock == Character.UnicodeBlock.HANGUL_COMPATIBILITY_JAMO + || unicodeBlock == Character.UnicodeBlock.HANGUL_SYLLABLES + || unicodeBlock == Character.UnicodeBlock.HANGUL_JAMO_EXTENDED_A + || unicodeBlock == Character.UnicodeBlock.HANGUL_JAMO_EXTENDED_B + || value == HEX_20A9; } } diff --git a/designer-realize/src/test/java/com/fr/grid/help/GridHelperTest.java b/designer-realize/src/test/java/com/fr/grid/help/GridHelperTest.java index dc5c2b843..412ee3826 100644 --- a/designer-realize/src/test/java/com/fr/grid/help/GridHelperTest.java +++ b/designer-realize/src/test/java/com/fr/grid/help/GridHelperTest.java @@ -28,6 +28,19 @@ public class GridHelperTest extends TestCase { Assert.assertFalse(GridHelper.isKoreanCharacter('は')); Assert.assertTrue(GridHelper.isKoreanCharacter('먀')); Assert.assertTrue(GridHelper.isKoreanCharacter('이')); + Assert.assertTrue(GridHelper.isKoreanCharacter('한')); + // 韩文音节 + Assert.assertTrue(GridHelper.isKoreanCharacter('휖')); + // 韩文兼容字母 + Assert.assertTrue(GridHelper.isKoreanCharacter('ㆋ')); + // 韩文字母 + Assert.assertTrue(GridHelper.isKoreanCharacter('ᇪ')); + // 韩文字母扩展A + Assert.assertTrue(GridHelper.isKoreanCharacter('ꥵ')); + // 韩文字母扩展B + Assert.assertTrue(GridHelper.isKoreanCharacter('ퟂ')); + // 韩文货币符号 + Assert.assertTrue(GridHelper.isKoreanCharacter('₩')); }