Browse Source

REPORT-2773 mac中复制快捷键的修复

master
hzzz 8 years ago
parent
commit
ff84369039
  1. 3
      designer/src/com/fr/design/report/UnitFieldPane.java
  2. 23
      designer_base/src/com/fr/common/inputevent/InputEventBaseOnOS.java
  3. 3
      designer_base/src/com/fr/design/gui/frpane/UITextPane.java
  4. 24
      designer_base/src/com/fr/design/gui/itextarea/UITextArea.java
  5. 16
      designer_base/src/com/fr/design/gui/itextfield/UINumberField.java
  6. 27
      designer_base/src/com/fr/design/gui/itextfield/UITextField.java

3
designer/src/com/fr/design/report/UnitFieldPane.java

@ -6,6 +6,8 @@ package com.fr.design.report;
import java.awt.Dimension; import java.awt.Dimension;
import javax.swing.JFormattedTextField; import javax.swing.JFormattedTextField;
import com.fr.common.inputevent.InputEventBaseOnOS;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JSpinner; 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)); valueSpinner = new UIBasicSpinner(new SpinnerNumberModel(0.0, 0.0, Double.MAX_VALUE, 1.0));
textField = ((JSpinner.DefaultEditor) valueSpinner.getEditor()).getTextField(); textField = ((JSpinner.DefaultEditor) valueSpinner.getEditor()).getTextField();
textField.setColumns(4); textField.setColumns(4);
InputEventBaseOnOS.addBasicEditInputMap(textField);
this.add(valueSpinner); this.add(valueSpinner);
unitLable = new UnitLabel(unitType, valueSpinner.getPreferredSize().height); unitLable = new UnitLabel(unitType, valueSpinner.getPreferredSize().height);
this.add(unitLable); this.add(unitLable);

23
designer_base/src/com/fr/common/inputevent/InputEventBaseOnOS.java

@ -2,9 +2,13 @@ package com.fr.common.inputevent;
import com.fr.stable.OperatingSystem; import com.fr.stable.OperatingSystem;
import javax.swing.*;
import javax.swing.text.DefaultEditorKit;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER;
/** /**
* Created by hzzz on 2017/5/26. * Created by hzzz on 2017/5/26.
*/ */
@ -18,4 +22,23 @@ public class InputEventBaseOnOS {
public static boolean isControlDown(KeyEvent e) { public static boolean isControlDown(KeyEvent e) {
return IS_MACOS ? e.isMetaDown() : e.isControlDown(); 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);
}
}
} }

3
designer_base/src/com/fr/design/gui/frpane/UITextPane.java

@ -1,5 +1,6 @@
package com.fr.design.gui.frpane; package com.fr.design.gui.frpane;
import com.fr.common.inputevent.InputEventBaseOnOS;
import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserver;
import com.fr.design.event.UIObserverListener; import com.fr.design.event.UIObserverListener;
@ -22,11 +23,13 @@ public class UITextPane extends JTextPane implements UIObserver {
public UITextPane() { public UITextPane() {
super(); super();
InputEventBaseOnOS.addBasicEditInputMap(this);
iniListener(); iniListener();
} }
public UITextPane(StyledDocument doc) { public UITextPane(StyledDocument doc) {
super(doc); super(doc);
InputEventBaseOnOS.addBasicEditInputMap(this);
iniListener(); iniListener();
} }

24
designer_base/src/com/fr/design/gui/itextarea/UITextArea.java

@ -1,5 +1,6 @@
package com.fr.design.gui.itextarea; package com.fr.design.gui.itextarea;
import com.fr.common.inputevent.InputEventBaseOnOS;
import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserver;
import com.fr.design.event.UIObserverListener; import com.fr.design.event.UIObserverListener;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
@ -7,33 +8,14 @@ import com.fr.design.utils.gui.GUICoreUtils;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
import javax.swing.text.DefaultEditorKit;
import java.awt.*; 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 { public class UITextArea extends JTextArea implements UIObserver {
private UIObserverListener uiObserverListener; private UIObserverListener uiObserverListener;
public UITextArea(int i, int j) { public UITextArea(int i, int j) {
super(i, j); super(i, j);
InputMap inputMap = this.getInputMap(); InputEventBaseOnOS.addBasicEditInputMap(this);
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);
}
initComponents(); initComponents();
} }
@ -44,11 +26,13 @@ public class UITextArea extends JTextArea implements UIObserver {
public UITextArea() { public UITextArea() {
super(); super();
InputEventBaseOnOS.addBasicEditInputMap(this);
initComponents(); initComponents();
} }
public UITextArea(String s) { public UITextArea(String s) {
super(s); super(s);
InputEventBaseOnOS.addBasicEditInputMap(this);
initComponents(); initComponents();
} }

16
designer_base/src/com/fr/design/gui/itextfield/UINumberField.java

@ -1,20 +1,17 @@
package com.fr.design.gui.itextfield; 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.base.Utils;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.general.ComparatorUtils; import com.fr.general.ComparatorUtils;
import com.fr.stable.CoreConstants; import com.fr.stable.CoreConstants;
import com.fr.stable.StringUtils; 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. * Number Field.
*/ */
@ -54,7 +51,6 @@ public class UINumberField extends UITextField {
this.maxDecimalLength = maxDecimalLength; this.maxDecimalLength = maxDecimalLength;
this.minValue = minValue; this.minValue = minValue;
this.maxValue = maxValue; this.maxValue = maxValue;
setFieldDocument(); setFieldDocument();
} }

27
designer_base/src/com/fr/design/gui/itextfield/UITextField.java

@ -1,5 +1,6 @@
package com.fr.design.gui.itextfield; package com.fr.design.gui.itextfield;
import com.fr.common.inputevent.InputEventBaseOnOS;
import com.fr.design.event.GlobalNameListener; import com.fr.design.event.GlobalNameListener;
import com.fr.design.event.GlobalNameObserver; import com.fr.design.event.GlobalNameObserver;
import com.fr.design.event.UIObserver; import com.fr.design.event.UIObserver;
@ -10,12 +11,8 @@ import com.fr.stable.Constants;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener; import javax.swing.event.DocumentListener;
import javax.swing.text.DefaultEditorKit;
import javax.swing.text.Document; import javax.swing.text.Document;
import java.awt.*; import java.awt.*;
import java.awt.event.KeyEvent;
import static com.fr.design.gui.syntax.ui.rtextarea.RTADefaultInputMap.DEFAULT_MODIFIER;
/** /**
* @author Jerry * @author Jerry
@ -31,42 +28,32 @@ public class UITextField extends JTextField implements UIObserver, GlobalNameObs
public UITextField() { public UITextField() {
super(); super();
InputMap inputMap = this.getInputMap(); InputEventBaseOnOS.addBasicEditInputMap(this);
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);
}
initListener(); initListener();
} }
public UITextField(int columns) { public UITextField(int columns) {
super(columns); super(columns);
InputEventBaseOnOS.addBasicEditInputMap(this);
initListener(); initListener();
} }
public UITextField(String text, int columns) { public UITextField(String text, int columns) {
super(text, columns); super(text, columns);
InputEventBaseOnOS.addBasicEditInputMap(this);
initListener(); initListener();
} }
public UITextField(String text) { public UITextField(String text) {
super(text); super(text);
InputEventBaseOnOS.addBasicEditInputMap(this);
initListener(); initListener();
} }
public UITextField(Document doc, String text, int columns) { public UITextField(Document doc, String text, int columns) {
super(doc, text, columns); super(doc, text, columns);
InputEventBaseOnOS.addBasicEditInputMap(this);
initListener(); initListener();
} }

Loading…
Cancel
Save