Browse Source

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

master
hzzz 8 years ago
parent
commit
419dfc1423
  1. 395
      designer/src/com/fr/grid/GridKeyListener.java
  2. 2
      designer_base/src/com/fr/design/actions/help/AboutPane.java

395
designer/src/com/fr/grid/GridKeyListener.java

@ -1,212 +1,215 @@
package com.fr.grid; package com.fr.grid;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import com.fr.design.mainframe.ElementCasePane; import com.fr.design.mainframe.ElementCasePane;
import com.fr.grid.selection.CellSelection; import com.fr.grid.selection.CellSelection;
import com.fr.grid.selection.FloatSelection; import com.fr.grid.selection.FloatSelection;
import com.fr.grid.selection.Selection; import com.fr.grid.selection.Selection;
import com.fr.report.elementcase.ElementCase; import com.fr.report.elementcase.ElementCase;
import com.fr.stable.OperatingSystem;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
/** /**
*
* @editor zhou * @editor zhou
* @since 2012-3-23上午10:55:36 * @since 2012-3-23上午10:55:36
*/ */
public class GridKeyListener implements KeyListener { public class GridKeyListener implements KeyListener {
private Grid grid; private Grid grid;
// Keypressed last time // Keypressed last time
private long keyPressedLastTime = 0; private long keyPressedLastTime = 0;
private boolean isKeyPressedContentChanged = false; private boolean isKeyPressedContentChanged = false;
public GridKeyListener(Grid grid) { public GridKeyListener(Grid grid) {
this.grid = grid; this.grid = grid;
} }
public void keyPressed(KeyEvent evt) { public void keyPressed(KeyEvent evt) {
if (!grid.isEnabled() || evt.isConsumed()) {// 如果用户在自己的KyeListener里面consume了.就不执行下面的代码了. if (!grid.isEnabled() || evt.isConsumed()) {// 如果用户在自己的KyeListener里面consume了.就不执行下面的代码了.
return; return;
} }
KeyEvent newEvt = KeyEventWork.processKeyEvent(evt); KeyEvent newEvt = KeyEventWork.processKeyEvent(evt);
if (newEvt == null) { if (newEvt == null) {
return; return;
} }
long systemCurrentTime = System.currentTimeMillis(); long systemCurrentTime = System.currentTimeMillis();
int code = evt.getKeyCode(); int code = evt.getKeyCode();
boolean isNeedRepaint = false; boolean isNeedRepaint = false;
ElementCasePane reportPane = grid.getElementCasePane(); ElementCasePane reportPane = grid.getElementCasePane();
ElementCase report = reportPane.getEditingElementCase(); ElementCase report = reportPane.getEditingElementCase();
if (reportPane.getSelection() instanceof FloatSelection) { if (reportPane.getSelection() instanceof FloatSelection) {
if (systemCurrentTime - keyPressedLastTime <= 2) { if (systemCurrentTime - keyPressedLastTime <= 2) {
return; return;
} else { } else {
keyPressedLastTime = systemCurrentTime; keyPressedLastTime = systemCurrentTime;
} }
dealWithFloatSelection(reportPane, code); dealWithFloatSelection(reportPane, code);
} else { } else {
if (systemCurrentTime - keyPressedLastTime <= 32) { if (systemCurrentTime - keyPressedLastTime <= 32) {
return; return;
} else { } else {
keyPressedLastTime = systemCurrentTime; keyPressedLastTime = systemCurrentTime;
} }
dealWithCellSelection(evt, code); dealWithCellSelection(evt, code);
} }
switch (code) { switch (code) {
case KeyEvent.VK_PAGE_UP: {// page up case KeyEvent.VK_PAGE_UP: {// page up
reportPane.getVerticalScrollBar().setValue(Math.max(0, grid.getVerticalValue() - grid.getVerticalExtent())); reportPane.getVerticalScrollBar().setValue(Math.max(0, grid.getVerticalValue() - grid.getVerticalExtent()));
isNeedRepaint = true; isNeedRepaint = true;
break; break;
} }
case KeyEvent.VK_PAGE_DOWN: {// page down case KeyEvent.VK_PAGE_DOWN: {// page down
reportPane.getVerticalScrollBar().setValue(grid.getVerticalValue() + grid.getVerticalExtent()); reportPane.getVerticalScrollBar().setValue(grid.getVerticalValue() + grid.getVerticalExtent());
isNeedRepaint = true; isNeedRepaint = true;
break; break;
} }
// Richie:Ctrl + A全选单元格 // Richie:Ctrl + A全选单元格
case KeyEvent.VK_A: case KeyEvent.VK_A:
if (code == KeyEvent.VK_A && evt.isControlDown()) { if ((OperatingSystem.isWindows() && evt.isControlDown())
reportPane.setSelection(new CellSelection(0, 0, report.getColumnCount(), report.getRowCount())); || OperatingSystem.isMacOS() && evt.isMetaDown()) {
isNeedRepaint = true; reportPane.setSelection(new CellSelection(0, 0, report.getColumnCount(), report.getRowCount()));
} isNeedRepaint = true;
isNeedRepaint = true; }
break; isNeedRepaint = true;
} break;
}
if (isNeedRepaint) {
reportPane.repaint(); if (isNeedRepaint) {
} reportPane.repaint();
} }
}
/**
* 单选中悬浮元素时只处理4个方向键 /**
* * 单选中悬浮元素时只处理4个方向键
* @param reportPane *
* @param code * @param reportPane
*/ * @param code
private void dealWithFloatSelection(ElementCasePane reportPane, int code) { */
boolean isContentChanged = false; private void dealWithFloatSelection(ElementCasePane reportPane, int code) {
FloatSelection floatselection = (FloatSelection)reportPane.getSelection(); boolean isContentChanged = false;
FloatSelection floatselection = (FloatSelection) reportPane.getSelection();
switch (code) {
case KeyEvent.VK_LEFT: {// left switch (code) {
floatselection.moveLeft(reportPane); case KeyEvent.VK_LEFT: {// left
isContentChanged = true; floatselection.moveLeft(reportPane);
break; isContentChanged = true;
} break;
case KeyEvent.VK_RIGHT: {// right }
floatselection.moveRight(reportPane); case KeyEvent.VK_RIGHT: {// right
isContentChanged = true; floatselection.moveRight(reportPane);
break; isContentChanged = true;
} break;
case KeyEvent.VK_UP: {// up }
floatselection.moveUp(reportPane); case KeyEvent.VK_UP: {// up
isContentChanged = true; floatselection.moveUp(reportPane);
break; isContentChanged = true;
} break;
case KeyEvent.VK_DOWN: {// down }
floatselection.moveDown(reportPane); case KeyEvent.VK_DOWN: {// down
isContentChanged = true; floatselection.moveDown(reportPane);
break; isContentChanged = true;
} break;
} }
}
if (isContentChanged) {
grid.getElementCasePane().repaint(); if (isContentChanged) {
this.isKeyPressedContentChanged = true; grid.getElementCasePane().repaint();
} this.isKeyPressedContentChanged = true;
} }
}
private void dealWithCellSelection(KeyEvent evt, int code) {
switch (code) { private void dealWithCellSelection(KeyEvent evt, int code) {
case KeyEvent.VK_ESCAPE: { switch (code) {
if (grid.isCellEditing()) { case KeyEvent.VK_ESCAPE: {
grid.cancelEditing(); if (grid.isCellEditing()) {
} grid.cancelEditing();
break; }
} break;
case KeyEvent.VK_F2: { }
if (!grid.isCellEditing()) { case KeyEvent.VK_F2: {
grid.startEditing(); if (!grid.isCellEditing()) {
} grid.startEditing();
}
break;
} break;
} }
}
// 支持小键盘
if (IS_NUM_PAD_KEY(code)) { // 支持小键盘
keyTyped(evt); if (IS_NUM_PAD_KEY(code)) {
} keyTyped(evt);
} }
}
public void keyReleased(KeyEvent evt) {
if (!grid.isEnabled() || evt.isConsumed()) { public void keyReleased(KeyEvent evt) {
return; if (!grid.isEnabled() || evt.isConsumed()) {
} return;
KeyEvent newEvt = KeyEventWork.processKeyEvent(evt); }
if (newEvt == null) { KeyEvent newEvt = KeyEventWork.processKeyEvent(evt);
return; if (newEvt == null) {
} return;
}
if (this.isKeyPressedContentChanged) {
grid.getElementCasePane().fireTargetModified(); if (this.isKeyPressedContentChanged) {
grid.getElementCasePane().fireTargetModified();
this.isKeyPressedContentChanged = false;
} this.isKeyPressedContentChanged = false;
} }
}
public void keyTyped(KeyEvent evt) {
if (!grid.isEnabled() || evt.isConsumed()) { public void keyTyped(KeyEvent evt) {
return; if (!grid.isEnabled() || evt.isConsumed()) {
} return;
KeyEvent newEvt = KeyEventWork.processKeyEvent(evt); }
if (newEvt == null || evt.isControlDown()) {// uneditable. KeyEvent newEvt = KeyEventWork.processKeyEvent(evt);
return; if (newEvt == null || evt.isControlDown()) {// uneditable.
} return;
char ch = evt.getKeyChar(); }
if (ch == KeyEvent.VK_TAB) {// 禁止Tab键. char ch = evt.getKeyChar();
return; if (ch == KeyEvent.VK_TAB) {// 禁止Tab键.
} return;
int code = evt.getKeyCode(); }
if (Character.isDefined(ch)) {// VK_SUBTRACT小键盘的减号 int code = evt.getKeyCode();
Selection s = grid.getElementCasePane().getSelection(); if (Character.isDefined(ch)) {// VK_SUBTRACT小键盘的减号
if (s instanceof CellSelection) { Selection s = grid.getElementCasePane().getSelection();
if (!grid.getElementCasePane().isSelectedOneCell()) { if (s instanceof CellSelection) {
Toolkit.getDefaultToolkit().beep(); if (!grid.getElementCasePane().isSelectedOneCell()) {
return; Toolkit.getDefaultToolkit().beep();
} return;
if (!grid.isCellEditing()) { }
grid.startEditing(true); if (!grid.isCellEditing()) {
} grid.startEditing(true);
}
if (grid.getCellEditor() != null && grid.editorComponent != null) {
if (IS_NUM_PAD_KEY(code)) { if (grid.getCellEditor() != null && grid.editorComponent != null) {
// 103 - 55 = 48, 小键盘和大键盘数字的差值 48 if (IS_NUM_PAD_KEY(code)) {
KeyEvent ke = new KeyEvent(grid, KeyEvent.KEY_PRESSED, 0, 0, code - 48, ch); // 103 - 55 = 48, 小键盘和大键盘数字的差值 48
grid.editorComponent.dispatchEvent(ke); KeyEvent ke = new KeyEvent(grid, KeyEvent.KEY_PRESSED, 0, 0, code - 48, ch);
ke.consume(); grid.editorComponent.dispatchEvent(ke);
} else { ke.consume();
if (!evt.isConsumed()) { } else {
grid.editorComponent.dispatchEvent(evt); if (!evt.isConsumed()) {
} grid.editorComponent.dispatchEvent(evt);
} }
} }
} }
} }
} }
/** }
* 小键盘
* @param code /**
* @return * 小键盘
*/ *
private static boolean IS_NUM_PAD_KEY(int code){ * @param code
return code == KeyEvent.VK_NUMPAD0 || code == KeyEvent.VK_NUMPAD1 * @return
*/
private static boolean IS_NUM_PAD_KEY(int code) {
return code == KeyEvent.VK_NUMPAD0 || code == KeyEvent.VK_NUMPAD1
|| code == KeyEvent.VK_NUMPAD2 || code == KeyEvent.VK_NUMPAD2
|| code == KeyEvent.VK_NUMPAD3 || code == KeyEvent.VK_NUMPAD3
|| code == KeyEvent.VK_NUMPAD4 || code == KeyEvent.VK_NUMPAD4
@ -220,5 +223,5 @@ public class GridKeyListener implements KeyListener {
|| code == KeyEvent.VK_SUBTRACT || code == KeyEvent.VK_SUBTRACT
|| code == KeyEvent.VK_DECIMAL || code == KeyEvent.VK_DECIMAL
|| code == KeyEvent.VK_DIVIDE; || code == KeyEvent.VK_DIVIDE;
} }
} }

2
designer_base/src/com/fr/design/actions/help/AboutPane.java

@ -47,7 +47,7 @@ public class AboutPane extends JPanel {
BoxCenterAlignmentCopyablePane buildCopyPane = new BoxCenterAlignmentCopyablePane( BoxCenterAlignmentCopyablePane buildCopyPane = new BoxCenterAlignmentCopyablePane(
getBuildTitle(), getBuildTitle(),
GeneralUtils.readFullBuildNO(), GeneralUtils.readBuildNO(),
new String[]{ new String[]{
Inter.getLocText("FR-Designer-Basic_Copy_Build_NO"), Inter.getLocText("FR-Designer-Basic_Copy_Build_NO"),
Inter.getLocText("FR-Designer-Basic_Copy_Build_NO_OK") Inter.getLocText("FR-Designer-Basic_Copy_Build_NO_OK")

Loading…
Cancel
Save