From ff84369039240851e4f1f6fb3ba7f2ab585de2e1 Mon Sep 17 00:00:00 2001 From: hzzz Date: Tue, 6 Jun 2017 09:53:08 +0800 Subject: [PATCH 1/2] =?UTF-8?q?REPORT-2773=20mac=E4=B8=AD=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=E5=BF=AB=E6=8D=B7=E9=94=AE=E7=9A=84=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/report/UnitFieldPane.java | 3 +++ .../common/inputevent/InputEventBaseOnOS.java | 23 ++++++++++++++++ .../com/fr/design/gui/frpane/UITextPane.java | 3 +++ .../fr/design/gui/itextarea/UITextArea.java | 24 +++-------------- .../design/gui/itextfield/UINumberField.java | 16 +++++------ .../fr/design/gui/itextfield/UITextField.java | 27 +++++-------------- 6 files changed, 46 insertions(+), 50 deletions(-) diff --git a/designer/src/com/fr/design/report/UnitFieldPane.java b/designer/src/com/fr/design/report/UnitFieldPane.java index b091738d0..6e5717031 100644 --- a/designer/src/com/fr/design/report/UnitFieldPane.java +++ b/designer/src/com/fr/design/report/UnitFieldPane.java @@ -6,6 +6,8 @@ package com.fr.design.report; import java.awt.Dimension; import javax.swing.JFormattedTextField; + +import com.fr.common.inputevent.InputEventBaseOnOS; import com.fr.design.gui.ilable.UILabel; import javax.swing.JPanel; import javax.swing.JSpinner; @@ -67,6 +69,7 @@ public class UnitFieldPane extends JPanel { valueSpinner = new UIBasicSpinner(new SpinnerNumberModel(0.0, 0.0, Double.MAX_VALUE, 1.0)); textField = ((JSpinner.DefaultEditor) valueSpinner.getEditor()).getTextField(); textField.setColumns(4); + InputEventBaseOnOS.addBasicEditInputMap(textField); this.add(valueSpinner); unitLable = new UnitLabel(unitType, valueSpinner.getPreferredSize().height); this.add(unitLable); diff --git a/designer_base/src/com/fr/common/inputevent/InputEventBaseOnOS.java b/designer_base/src/com/fr/common/inputevent/InputEventBaseOnOS.java index 29b6b9ce3..c0e195ced 100644 --- a/designer_base/src/com/fr/common/inputevent/InputEventBaseOnOS.java +++ b/designer_base/src/com/fr/common/inputevent/InputEventBaseOnOS.java @@ -2,9 +2,13 @@ package com.fr.common.inputevent; import com.fr.stable.OperatingSystem; +import javax.swing.*; +import javax.swing.text.DefaultEditorKit; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; +import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER; + /** * Created by hzzz on 2017/5/26. */ @@ -18,4 +22,23 @@ public class InputEventBaseOnOS { public static boolean isControlDown(KeyEvent e) { return IS_MACOS ? e.isMetaDown() : e.isControlDown(); } + + public static void addBasicEditInputMap(JComponent jComponent) { + InputMap inputMap = jComponent.getInputMap(); + while (inputMap.getParent() != null) { + inputMap = inputMap.getParent(); + } + if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_A, DEFAULT_MODIFIER)) == null) { + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, DEFAULT_MODIFIER), DefaultEditorKit.selectAllAction); + } + if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_C, DEFAULT_MODIFIER)) == null) { + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, DEFAULT_MODIFIER), DefaultEditorKit.copyAction); + } + if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_V, DEFAULT_MODIFIER)) == null) { + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, DEFAULT_MODIFIER), DefaultEditorKit.pasteAction); + } + if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_X, DEFAULT_MODIFIER)) == null) { + inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, DEFAULT_MODIFIER), DefaultEditorKit.cutAction); + } + } } diff --git a/designer_base/src/com/fr/design/gui/frpane/UITextPane.java b/designer_base/src/com/fr/design/gui/frpane/UITextPane.java index ab7fed53a..16a35ce2f 100644 --- a/designer_base/src/com/fr/design/gui/frpane/UITextPane.java +++ b/designer_base/src/com/fr/design/gui/frpane/UITextPane.java @@ -1,5 +1,6 @@ package com.fr.design.gui.frpane; +import com.fr.common.inputevent.InputEventBaseOnOS; import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserverListener; @@ -22,11 +23,13 @@ public class UITextPane extends JTextPane implements UIObserver { public UITextPane() { super(); + InputEventBaseOnOS.addBasicEditInputMap(this); iniListener(); } public UITextPane(StyledDocument doc) { super(doc); + InputEventBaseOnOS.addBasicEditInputMap(this); iniListener(); } diff --git a/designer_base/src/com/fr/design/gui/itextarea/UITextArea.java b/designer_base/src/com/fr/design/gui/itextarea/UITextArea.java index 6e04eacb8..534be62ee 100644 --- a/designer_base/src/com/fr/design/gui/itextarea/UITextArea.java +++ b/designer_base/src/com/fr/design/gui/itextarea/UITextArea.java @@ -1,5 +1,6 @@ package com.fr.design.gui.itextarea; +import com.fr.common.inputevent.InputEventBaseOnOS; import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserverListener; import com.fr.design.utils.gui.GUICoreUtils; @@ -7,33 +8,14 @@ import com.fr.design.utils.gui.GUICoreUtils; import javax.swing.*; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; -import javax.swing.text.DefaultEditorKit; import java.awt.*; -import java.awt.event.KeyEvent; - -import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER; public class UITextArea extends JTextArea implements UIObserver { private UIObserverListener uiObserverListener; public UITextArea(int i, int j) { super(i, j); - InputMap inputMap = this.getInputMap(); - while (inputMap.getParent() != null) { - inputMap = inputMap.getParent(); - } - if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_A, DEFAULT_MODIFIER)) == null) { - inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, DEFAULT_MODIFIER), DefaultEditorKit.selectAllAction); - } - if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_C, DEFAULT_MODIFIER)) == null) { - inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, DEFAULT_MODIFIER), DefaultEditorKit.copyAction); - } - if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_V, DEFAULT_MODIFIER)) == null) { - inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, DEFAULT_MODIFIER), DefaultEditorKit.pasteAction); - } - if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_X, DEFAULT_MODIFIER)) == null) { - inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, DEFAULT_MODIFIER), DefaultEditorKit.cutAction); - } + InputEventBaseOnOS.addBasicEditInputMap(this); initComponents(); } @@ -44,11 +26,13 @@ public class UITextArea extends JTextArea implements UIObserver { public UITextArea() { super(); + InputEventBaseOnOS.addBasicEditInputMap(this); initComponents(); } public UITextArea(String s) { super(s); + InputEventBaseOnOS.addBasicEditInputMap(this); initComponents(); } diff --git a/designer_base/src/com/fr/design/gui/itextfield/UINumberField.java b/designer_base/src/com/fr/design/gui/itextfield/UINumberField.java index eb24fab9b..439e98d56 100644 --- a/designer_base/src/com/fr/design/gui/itextfield/UINumberField.java +++ b/designer_base/src/com/fr/design/gui/itextfield/UINumberField.java @@ -1,20 +1,17 @@ package com.fr.design.gui.itextfield; -import java.awt.Dimension; -import java.awt.GridLayout; -import java.awt.Toolkit; - -import javax.swing.JFrame; -import javax.swing.text.AttributeSet; -import javax.swing.text.BadLocationException; -import javax.swing.text.PlainDocument; - import com.fr.base.Utils; import com.fr.design.gui.ilable.UILabel; import com.fr.general.ComparatorUtils; import com.fr.stable.CoreConstants; import com.fr.stable.StringUtils; +import javax.swing.*; +import javax.swing.text.AttributeSet; +import javax.swing.text.BadLocationException; +import javax.swing.text.PlainDocument; +import java.awt.*; + /** * Number Field. */ @@ -54,7 +51,6 @@ public class UINumberField extends UITextField { this.maxDecimalLength = maxDecimalLength; this.minValue = minValue; this.maxValue = maxValue; - setFieldDocument(); } diff --git a/designer_base/src/com/fr/design/gui/itextfield/UITextField.java b/designer_base/src/com/fr/design/gui/itextfield/UITextField.java index 4f15b1f81..7df91335c 100644 --- a/designer_base/src/com/fr/design/gui/itextfield/UITextField.java +++ b/designer_base/src/com/fr/design/gui/itextfield/UITextField.java @@ -1,5 +1,6 @@ package com.fr.design.gui.itextfield; +import com.fr.common.inputevent.InputEventBaseOnOS; import com.fr.design.event.GlobalNameListener; import com.fr.design.event.GlobalNameObserver; import com.fr.design.event.UIObserver; @@ -10,12 +11,8 @@ import com.fr.stable.Constants; import javax.swing.*; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; -import javax.swing.text.DefaultEditorKit; import javax.swing.text.Document; import java.awt.*; -import java.awt.event.KeyEvent; - -import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER; /** * @author Jerry @@ -31,42 +28,32 @@ public class UITextField extends JTextField implements UIObserver, GlobalNameObs public UITextField() { super(); - InputMap inputMap = this.getInputMap(); - while (inputMap.getParent() != null) { - inputMap = inputMap.getParent(); - } - if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_A, DEFAULT_MODIFIER)) == null) { - inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_A, DEFAULT_MODIFIER), DefaultEditorKit.selectAllAction); - } - if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_C, DEFAULT_MODIFIER)) == null) { - inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_C, DEFAULT_MODIFIER), DefaultEditorKit.copyAction); - } - if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_V, DEFAULT_MODIFIER)) == null) { - inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_V, DEFAULT_MODIFIER), DefaultEditorKit.pasteAction); - } - if (inputMap.get(KeyStroke.getKeyStroke(KeyEvent.VK_X, DEFAULT_MODIFIER)) == null) { - inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_X, DEFAULT_MODIFIER), DefaultEditorKit.cutAction); - } + InputEventBaseOnOS.addBasicEditInputMap(this); initListener(); } public UITextField(int columns) { super(columns); + InputEventBaseOnOS.addBasicEditInputMap(this); initListener(); } public UITextField(String text, int columns) { super(text, columns); + InputEventBaseOnOS.addBasicEditInputMap(this); initListener(); } public UITextField(String text) { super(text); + InputEventBaseOnOS.addBasicEditInputMap(this); + initListener(); } public UITextField(Document doc, String text, int columns) { super(doc, text, columns); + InputEventBaseOnOS.addBasicEditInputMap(this); initListener(); } From 79b0c94c75ccd777da8ab05060d5c7c8d8099582 Mon Sep 17 00:00:00 2001 From: hzzz Date: Tue, 6 Jun 2017 11:01:32 +0800 Subject: [PATCH 2/2] PMD --- .../src/com/fr/design/report/UnitFieldPane.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/designer/src/com/fr/design/report/UnitFieldPane.java b/designer/src/com/fr/design/report/UnitFieldPane.java index 6e5717031..e74155a93 100644 --- a/designer/src/com/fr/design/report/UnitFieldPane.java +++ b/designer/src/com/fr/design/report/UnitFieldPane.java @@ -43,13 +43,13 @@ public class UnitFieldPane extends JPanel { } public void setUnitType(int unitType) { - if (unitType == Constants.UNIT_CM) { - this.setText(Inter.getLocText("Unit_CM")); - } else if (unitType == Constants.UNIT_INCH) { - this.setText(Inter.getLocText("PageSetup-inches")); - } else { - this.setText(Inter.getLocText("PageSetup-mm")); - } + if (unitType == Constants.UNIT_CM) { + this.setText(Inter.getLocText("FR-Designer_Unit_CM")); + } else if (unitType == Constants.UNIT_INCH) { + this.setText(Inter.getLocText("FR-Designer_Unit_INCH")); + } else { + this.setText(Inter.getLocText("FR-Designer_Unit_MM-mm")); + } //ajust the heigt of unitLabel. Dimension unitDimension = new Dimension(this.getPreferredSize().width,