hzzz 7 years ago
parent
commit
082987e03c
  1. 16
      designer/src/com/fr/grid/GridKeyListener.java
  2. 6
      designer_base/src/com/fr/common/inputevent/InputEventBaseOnOS.java
  3. 29
      designer_base/src/com/fr/design/gui/ilist/CheckBoxList.java
  4. 16
      designer_base/src/com/fr/design/gui/itable/TableSorter.java

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

@ -6,7 +6,6 @@ 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.*;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
@ -18,6 +17,7 @@ import java.awt.event.KeyListener;
*/ */
public class GridKeyListener implements KeyListener { public class GridKeyListener implements KeyListener {
private static final int DIFF = 48; // 103 - 55 = 48, 小键盘和大键盘数字的差值 48 private static final int DIFF = 48; // 103 - 55 = 48, 小键盘和大键盘数字的差值 48
private static final int DELAY = 32;
private Grid grid; private Grid grid;
// Keypressed last time // Keypressed last time
private long keyPressedLastTime = 0; private long keyPressedLastTime = 0;
@ -31,8 +31,7 @@ public class GridKeyListener implements KeyListener {
if (!grid.isEnabled() || evt.isConsumed()) {// 如果用户在自己的KyeListener里面consume了.就不执行下面的代码了. if (!grid.isEnabled() || evt.isConsumed()) {// 如果用户在自己的KyeListener里面consume了.就不执行下面的代码了.
return; return;
} }
KeyEvent newEvt = KeyEventWork.processKeyEvent(evt); if (KeyEventWork.processKeyEvent(evt) == null) {
if (newEvt == null) {
return; return;
} }
long systemCurrentTime = System.currentTimeMillis(); long systemCurrentTime = System.currentTimeMillis();
@ -47,17 +46,14 @@ public class GridKeyListener implements KeyListener {
keyPressedLastTime = systemCurrentTime; keyPressedLastTime = systemCurrentTime;
} }
dealWithFloatSelection(reportPane, code); dealWithFloatSelection(reportPane, code);
} else { } else {
if (systemCurrentTime - keyPressedLastTime <= 32) { if (systemCurrentTime - keyPressedLastTime <= DELAY) {
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()));
@ -71,16 +67,12 @@ public class GridKeyListener implements KeyListener {
} }
// Richie:Ctrl + A全选单元格 // Richie:Ctrl + A全选单元格
case KeyEvent.VK_A: case KeyEvent.VK_A:
boolean macOS = OperatingSystem.isMacOS() && evt.isMetaDown(); if (InputEventBaseOnOS.isControlDown(evt)) {
boolean windows = OperatingSystem.isWindows() && InputEventBaseOnOS.isControlDown(evt);
if (macOS || windows) {
reportPane.setSelection(new CellSelection(0, 0, report.getColumnCount(), report.getRowCount())); reportPane.setSelection(new CellSelection(0, 0, report.getColumnCount(), report.getRowCount()));
isNeedRepaint = true;
} }
isNeedRepaint = true; isNeedRepaint = true;
break; break;
} }
if (isNeedRepaint) { if (isNeedRepaint) {
reportPane.repaint(); reportPane.repaint();
} }

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

@ -9,13 +9,13 @@ import java.awt.event.MouseEvent;
* Created by hzzz on 2017/5/26. * Created by hzzz on 2017/5/26.
*/ */
public class InputEventBaseOnOS { public class InputEventBaseOnOS {
private static final boolean isMacOS = OperatingSystem.isMacOS(); private static final boolean IS_MACOS = OperatingSystem.isMacOS();
public static boolean isControlDown(MouseEvent e) { public static boolean isControlDown(MouseEvent e) {
return isMacOS ? e.isMetaDown() : e.isControlDown(); return IS_MACOS ? e.isMetaDown() : e.isControlDown();
} }
public static boolean isControlDown(KeyEvent e) { public static boolean isControlDown(KeyEvent e) {
return isMacOS ? e.isMetaDown() : e.isControlDown(); return IS_MACOS ? e.isMetaDown() : e.isControlDown();
} }
} }

29
designer_base/src/com/fr/design/gui/ilist/CheckBoxList.java

@ -22,7 +22,6 @@ import javax.swing.UIManager;
import javax.swing.border.Border; import javax.swing.border.Border;
import javax.swing.border.EmptyBorder; import javax.swing.border.EmptyBorder;
import com.fr.common.inputevent.InputEventBaseOnOS;
import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
@ -32,7 +31,7 @@ import com.fr.stable.StringUtils;
public class CheckBoxList extends JComponent { public class CheckBoxList extends JComponent {
/** /**
* 选择状态----全选和全不选 * 选择状态----全选和全不选
* *
* @editor zhou * @editor zhou
* @since 2012-4-1下午2:39:10 * @since 2012-4-1下午2:39:10
*/ */
@ -54,7 +53,7 @@ public class CheckBoxList extends JComponent {
/** /**
* Class constructor. * Class constructor.
* *
* @param items * @param items
* Items with which to populate the list. * Items with which to populate the list.
* @param default_state * @param default_state
@ -177,7 +176,7 @@ public class CheckBoxList extends JComponent {
@Override @Override
protected void processMouseEvent(MouseEvent e) { protected void processMouseEvent(MouseEvent e) {
if (e.getX() < 20) { if (e.getX() < 20) {
if (InputEventBaseOnOS.isControlDown(e) || e.isAltDown() || e.isShiftDown() || e.isMetaDown()) { if (e.isControlDown() || e.isAltDown() || e.isShiftDown() || e.isMetaDown()) {
int[] indices = getSelectedIndices(); int[] indices = getSelectedIndices();
if (indices.length == 0) { if (indices.length == 0) {
super.processMouseEvent(e); super.processMouseEvent(e);
@ -190,17 +189,17 @@ public class CheckBoxList extends JComponent {
} }
int id = e.getID(); int id = e.getID();
switch (id) { switch (id) {
case MouseEvent.MOUSE_PRESSED: case MouseEvent.MOUSE_PRESSED:
break; break;
case MouseEvent.MOUSE_RELEASED: case MouseEvent.MOUSE_RELEASED:
break; break;
case MouseEvent.MOUSE_CLICKED: case MouseEvent.MOUSE_CLICKED:
doCheck(); doCheck();
break; break;
case MouseEvent.MOUSE_EXITED: case MouseEvent.MOUSE_EXITED:
break; break;
case MouseEvent.MOUSE_ENTERED: case MouseEvent.MOUSE_ENTERED:
break; break;
} }
} }

16
designer_base/src/com/fr/design/gui/itable/TableSorter.java

@ -81,7 +81,7 @@ import javax.swing.table.TableModel;
public class TableSorter extends AbstractTableModel { public class TableSorter extends AbstractTableModel {
protected TableModel tableModel; protected TableModel tableModel;
private static final int ADD = 4;
public static final int DESCENDING = -1; public static final int DESCENDING = -1;
public static final int NOT_SORTED = 0; public static final int NOT_SORTED = 0;
public static final int ASCENDING = 1; public static final int ASCENDING = 1;
@ -343,17 +343,14 @@ public class TableSorter extends AbstractTableModel {
fireTableChanged(e); fireTableChanged(e);
return; return;
} }
// If the table structure has changed, cancel the sorting; the
// If the table structure has changed, cancel the sorting; the // sorting columns may have been either moved or deleted from the model.
// sorting columns may have been either moved or deleted from
// the model.
if (e.getFirstRow() == TableModelEvent.HEADER_ROW) { if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
cancelSorting(); cancelSorting();
fireTableChanged(e); fireTableChanged(e);
return; return;
} }
// We can map a cell event through to the view without widening
// We can map a cell event through to the view without widening
// when the following conditions apply: // when the following conditions apply:
// //
// a) all the changes are on one row (e.getFirstRow() == e.getLastRow()) and, // a) all the changes are on one row (e.getFirstRow() == e.getLastRow()) and,
@ -382,8 +379,7 @@ public class TableSorter extends AbstractTableModel {
column, e.getType())); column, e.getType()));
return; return;
} }
// Something has happened to the data that may have invalidated the row order.
// Something has happened to the data that may have invalidated the row order.
clearSortingState(); clearSortingState();
fireTableDataChanged(); fireTableDataChanged();
return; return;
@ -404,7 +400,7 @@ public class TableSorter extends AbstractTableModel {
// Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or // Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
// {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed. // {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
status = status + (e.isShiftDown() ? -1 : 1); status = status + (e.isShiftDown() ? -1 : 1);
status = (status + 4) % 3 - 1; // signed mod, returning {-1, 0, 1} status = (status + ADD) % 3 - 1; // signed mod, returning {-1, 0, 1}
setSortingStatus(column, status); setSortingStatus(column, status);
} }
} }

Loading…
Cancel
Save