Browse Source

Merge pull request #903 in BA/design from ~HZZZ/design:fix-REPORT-2773 to dev

* commit 'ac5976346ac2ce30299cf629d062c78ed029e458':
  PMD
  PMD
  PMD
  PMD
  REPORT-2773 mac中复制快捷键的修复
  PMD
  PMD
  REPORT-2773 mac中复制快捷键的修复
  REPORT-2773 mac中复制快捷键的修复
master
superman 8 years ago
parent
commit
d30d8bfc7b
  1. 366
      designer/src/com/fr/design/mainframe/AuthorityToolBarPane.java
  2. 392
      designer/src/com/fr/grid/GridKeyListener.java
  3. 1605
      designer/src/com/fr/grid/GridMouseAdapter.java
  4. 21
      designer_base/src/com/fr/common/inputevent/InputEventBaseOnOS.java
  5. 4
      designer_base/src/com/fr/design/gui/icombobox/ExtendedComboBox.java
  6. 3
      designer_base/src/com/fr/design/gui/icombobox/UIComboBoxUI.java
  7. 585
      designer_base/src/com/fr/design/gui/ilist/CheckBoxList.java
  8. 20
      designer_base/src/com/fr/design/gui/itable/TableSorter.java
  9. 3
      designer_base/src/com/fr/design/gui/itree/refreshabletree/UserObjectRefreshJTree.java
  10. 3
      designer_base/src/com/fr/design/roleAuthority/UIRoleTreeUI.java
  11. 5
      designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java

366
designer/src/com/fr/design/mainframe/AuthorityToolBarPane.java

File diff suppressed because one or more lines are too long

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

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

1605
designer/src/com/fr/grid/GridMouseAdapter.java

File diff suppressed because it is too large Load Diff

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

@ -0,0 +1,21 @@
package com.fr.common.inputevent;
import com.fr.stable.OperatingSystem;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
/**
* Created by hzzz on 2017/5/26.
*/
public class InputEventBaseOnOS {
private static final boolean IS_MACOS = OperatingSystem.isMacOS();
public static boolean isControlDown(MouseEvent e) {
return IS_MACOS ? e.isMetaDown() : e.isControlDown();
}
public static boolean isControlDown(KeyEvent e) {
return IS_MACOS ? e.isMetaDown() : e.isControlDown();
}
}

4
designer_base/src/com/fr/design/gui/icombobox/ExtendedComboBox.java

@ -1,5 +1,7 @@
package com.fr.design.gui.icombobox;
import com.fr.common.inputevent.InputEventBaseOnOS;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Point;
@ -76,7 +78,7 @@ public class ExtendedComboBox extends UIComboBox {
protected JList createList() {
return new JList(comboBox.getModel()) {
public void processMouseEvent(MouseEvent e) {
if (e.isControlDown()) {
if (InputEventBaseOnOS.isControlDown(e)) {
// Fix for 4234053. Filter out the Control
// Key from the list.
// ie., don't allow CTRL key deselection.

3
designer_base/src/com/fr/design/gui/icombobox/UIComboBoxUI.java

@ -16,6 +16,7 @@ import javax.swing.plaf.basic.BasicComboBoxUI;
import javax.swing.plaf.basic.BasicComboPopup;
import javax.swing.plaf.basic.ComboPopup;
import com.fr.common.inputevent.InputEventBaseOnOS;
import com.fr.design.constants.UIConstants;
import sun.swing.DefaultLookup;
@ -209,7 +210,7 @@ public class UIComboBoxUI extends BasicComboBoxUI implements MouseListener {
@Override
public void processMouseEvent(MouseEvent e) {
if (e.isControlDown()) {
if (InputEventBaseOnOS.isControlDown(e)) {
e = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiers() ^ DEFAULT_MODIFIER, e.getX(), e.getY(), e.getClickCount(),
e.isPopupTrigger());
}

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

@ -1,311 +1,300 @@
package com.fr.design.gui.ilist;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.stable.StringUtils;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EventListener;
import java.util.List;
import javax.swing.JComponent;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import com.fr.design.gui.icheckbox.UICheckBox;
import com.fr.stable.StringUtils;
/**
* CheckBoxs + JList.
*/
public class CheckBoxList extends JComponent {
/**
* 选择状态----全选和全不选
*
* @editor zhou
* @since 2012-4-1下午2:39:10
*/
public static enum SelectedState {
ALL, NONE
}
private boolean[] selects;
private JList jlist;
private UICheckBox chooseAll;
public CheckBoxList(Object[] items) {
this(items, SelectedState.NONE, StringUtils.EMPTY);
}
public CheckBoxList(Object[] items, String name) {
this(items, SelectedState.NONE, name);
}
/**
* Class constructor.
*
* @param items
* Items with which to populate the list.
* @param default_state
* default state, true or false
*/
public CheckBoxList(Object[] items, SelectedState state, String name) {
jlist = new BOXLIST(items);
jlist.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
this.selects = new boolean[items.length];
boolean default_state = (state == SelectedState.ALL);
Arrays.fill(this.selects, default_state);
jlist.setCellRenderer(new CheckListCellRenderer());
jlist.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
doCheck();
}
public void mouseReleased(MouseEvent e) {
doCheck();
}
});
jlist.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
if (e.getKeyChar() == ' ') {
doCheck();
}
}
});
this.setLayout(new BorderLayout());
chooseAll = new UICheckBox(name, default_state);
chooseAll.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (chooseAll.isSelected()) {
setSelected(true);
} else {
setSelected(false);
}
}
});
this.add(chooseAll, BorderLayout.NORTH);
this.add(jlist, BorderLayout.CENTER);
}
/*
* 用于CellRenderer显示value为text
*/
protected String value2Text(Object value) {
return value != null ? value.toString() : StringUtils.EMPTY;
}
public void setItems(Object[] os) {
if (os == null) {
this.setSelected(false);
} else {
for (int i = 0, len = os.length; i < len; i++) {
Object o = os[i];
for (int j = 0, jen = jlist.getModel().getSize(); j < jen; j++) {
if (o.equals(jlist.getModel().getElementAt(j))) {
this.setSelected(j, true);
}
}
}
}
this.repaint();
}
/**
* Is selected
*/
public boolean isSelected(int index) {
if (selects == null || index >= selects.length) {
return false;
}
return selects[index];
}
public void setSelected(int index, boolean isSelected) {
if (selects == null || index >= selects.length) {
return;
}
selects[index] = isSelected;
this.repaint(this.getBounds());
this.fireCheckBoxListSelectionChangeListener();
}
private void setSelected(boolean isSelected) {
if (selects == null) {
return;
}
for (int i = 0; i < selects.length; i++) {
selects[i] = isSelected;
}
this.repaint(this.getBounds());
this.fireCheckBoxListSelectionChangeListener();
}
/**
* Returns an array of the objects that have been selected. Overrides the
* JList method.
*/
public Object[] getSelectedValues() {
return this.jlist.getSelectedValues();
}
private class BOXLIST extends JList {
public BOXLIST(Object[] items) {
super(items);
}
@Override
protected void processMouseEvent(MouseEvent e) {
if (e.getX() < 20) {
if (e.isControlDown() || e.isAltDown() || e.isShiftDown() || e.isMetaDown()) {
int[] indices = getSelectedIndices();
if (indices.length == 0) {
super.processMouseEvent(e);
}
} else {
super.processMouseEvent(e);
}
} else {
super.processMouseEvent(e);
}
int id = e.getID();
switch (id) {
case MouseEvent.MOUSE_PRESSED:
break;
case MouseEvent.MOUSE_RELEASED:
break;
case MouseEvent.MOUSE_CLICKED:
doCheck();
break;
case MouseEvent.MOUSE_EXITED:
break;
case MouseEvent.MOUSE_ENTERED:
break;
}
}
@Override
protected void processMouseMotionEvent(MouseEvent e) {
if (e.getX() < 20) {
return;
}
super.processMouseEvent(e);
}
@Override
public Object[] getSelectedValues() {
List<Object> list = new ArrayList<Object>(selects.length);
for (int i = 0; i < selects.length; i++) {
if (selects[i]) {
list.add(this.getModel().getElementAt(i));
}
}
return list.toArray();
}
}
private void doCheck() {
// p:这里必须改变所有选择checkbox.
int index = jlist.getSelectedIndex();
boolean sValue = !selects[index];
// p:开始设置所有选择的checkbox.
int[] indices = jlist.getSelectedIndices();
for (int i = 0; i < indices.length; i++) {
setSelected(indices[i], sValue);
}
for (boolean selected : selects) {
if (!selected) {
chooseAll.setSelected(false);
return;
}
}
chooseAll.setSelected(true);
repaint();
}
private static final Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
private class CheckListCellRenderer extends UICheckBox implements ListCellRenderer {
public CheckListCellRenderer() {
this.setOpaque(true);
this.setBorder(noFocusBorder);
}
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
this.setText(value2Text(value));
this.setSelected(selects[index]);
this.setFont(list.getFont());
if (isSelected) {
this.setBackground(list.getSelectionBackground());
this.setForeground(list.getSelectionForeground());
} else {
this.setBackground(list.getBackground());
this.setForeground(list.getForeground());
}
if (cellHasFocus) {
this.setBorder(UIManager.getBorder("List.focusCellHighlightBorder"));
} else {
this.setBorder(noFocusBorder);
}
return this;
}
}
public void addCheckBoxListSelectionChangeListener(CheckBoxListSelectionChangeListener l) {
this.listenerList.add(CheckBoxListSelectionChangeListener.class, l);
}
public void removeCheckBoxListSelectionChangeListener(CheckBoxListSelectionChangeListener l) {
this.listenerList.remove(CheckBoxListSelectionChangeListener.class, l);
}
public void fireCheckBoxListSelectionChangeListener() {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == CheckBoxListSelectionChangeListener.class) {
((CheckBoxListSelectionChangeListener)listeners[i + 1]).selectionChanged(this);
}
}
}
public static interface CheckBoxListSelectionChangeListener extends EventListener {
public void selectionChanged(CheckBoxList target);
}
public ListModel getModel() {
return jlist.getModel();
}
private final static int X_COORDINATE = 20;
/**
* 选择状态----全选和全不选
*
* @editor zhou
* @since 2012-4-1下午2:39:10
*/
public static enum SelectedState {
ALL, NONE
}
private boolean[] selects;
private JList jlist;
private UICheckBox chooseAll;
public CheckBoxList(Object[] items) {
this(items, SelectedState.NONE, StringUtils.EMPTY);
}
public CheckBoxList(Object[] items, String name) {
this(items, SelectedState.NONE, name);
}
/**
* Class constructor.
*
* @param items Items with which to populate the list.
* @param state default state, true or false
*/
public CheckBoxList(Object[] items, SelectedState state, String name) {
jlist = new BOXLIST(items);
jlist.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
this.selects = new boolean[items.length];
boolean default_state = (state == SelectedState.ALL);
Arrays.fill(this.selects, default_state);
jlist.setCellRenderer(new CheckListCellRenderer());
jlist.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
doCheck();
}
public void mouseReleased(MouseEvent e) {
doCheck();
}
});
jlist.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
if (e.getKeyChar() == ' ') {
doCheck();
}
}
});
this.setLayout(new BorderLayout());
chooseAll = new UICheckBox(name, default_state);
chooseAll.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (chooseAll.isSelected()) {
setSelected(true);
} else {
setSelected(false);
}
}
});
this.add(chooseAll, BorderLayout.NORTH);
this.add(jlist, BorderLayout.CENTER);
}
/*
* 用于CellRenderer显示value为text
*/
protected String value2Text(Object value) {
return value != null ? value.toString() : StringUtils.EMPTY;
}
public void setItems(Object[] os) {
if (os == null) {
this.setSelected(false);
} else {
for (int i = 0, len = os.length; i < len; i++) {
Object o = os[i];
for (int j = 0, jen = jlist.getModel().getSize(); j < jen; j++) {
if (o.equals(jlist.getModel().getElementAt(j))) {
this.setSelected(j, true);
}
}
}
}
this.repaint();
}
/**
* Is selected
*/
public boolean isSelected(int index) {
if (selects == null || index >= selects.length) {
return false;
}
return selects[index];
}
public void setSelected(int index, boolean isSelected) {
if (selects == null || index >= selects.length) {
return;
}
selects[index] = isSelected;
this.repaint(this.getBounds());
this.fireCheckBoxListSelectionChangeListener();
}
private void setSelected(boolean isSelected) {
if (selects == null) {
return;
}
for (int i = 0; i < selects.length; i++) {
selects[i] = isSelected;
}
this.repaint(this.getBounds());
this.fireCheckBoxListSelectionChangeListener();
}
/**
* Returns an array of the objects that have been selected. Overrides the
* JList method.
*/
public Object[] getSelectedValues() {
return this.jlist.getSelectedValues();
}
private class BOXLIST extends JList {
public BOXLIST(Object[] items) {
super(items);
}
@Override
protected void processMouseEvent(MouseEvent e) {
if (e.getX() < X_COORDINATE) {
boolean anyMaskDown = e.isControlDown() || e.isAltDown() || e.isShiftDown() || e.isMetaDown();
if (anyMaskDown) {
int[] indices = getSelectedIndices();
if (indices.length == 0) {
super.processMouseEvent(e);
}
} else {
super.processMouseEvent(e);
}
} else {
super.processMouseEvent(e);
}
int id = e.getID();
switch (id) {
case MouseEvent.MOUSE_PRESSED:
break;
case MouseEvent.MOUSE_RELEASED:
break;
case MouseEvent.MOUSE_CLICKED:
doCheck();
break;
case MouseEvent.MOUSE_EXITED:
break;
case MouseEvent.MOUSE_ENTERED:
break;
}
}
@Override
protected void processMouseMotionEvent(MouseEvent e) {
if (e.getX() < X_COORDINATE) {
return;
}
super.processMouseEvent(e);
}
@Override
public Object[] getSelectedValues() {
List<Object> list = new ArrayList<Object>(selects.length);
for (int i = 0; i < selects.length; i++) {
if (selects[i]) {
list.add(this.getModel().getElementAt(i));
}
}
return list.toArray();
}
}
private void doCheck() {
// p:这里必须改变所有选择checkbox.
int index = jlist.getSelectedIndex();
boolean sValue = !selects[index];
// p:开始设置所有选择的checkbox.
int[] indices = jlist.getSelectedIndices();
for (int i = 0; i < indices.length; i++) {
setSelected(indices[i], sValue);
}
for (boolean selected : selects) {
if (!selected) {
chooseAll.setSelected(false);
return;
}
}
chooseAll.setSelected(true);
repaint();
}
private static final Border NO_FOCUS_BORDER = new EmptyBorder(1, 1, 1, 1);
private class CheckListCellRenderer extends UICheckBox implements ListCellRenderer {
public CheckListCellRenderer() {
this.setOpaque(true);
this.setBorder(NO_FOCUS_BORDER);
}
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
this.setText(value2Text(value));
this.setSelected(selects[index]);
this.setFont(list.getFont());
if (isSelected) {
this.setBackground(list.getSelectionBackground());
this.setForeground(list.getSelectionForeground());
} else {
this.setBackground(list.getBackground());
this.setForeground(list.getForeground());
}
if (cellHasFocus) {
this.setBorder(UIManager.getBorder("List.focusCellHighlightBorder"));
} else {
this.setBorder(NO_FOCUS_BORDER);
}
return this;
}
}
public void addCheckBoxListSelectionChangeListener(CheckBoxListSelectionChangeListener l) {
this.listenerList.add(CheckBoxListSelectionChangeListener.class, l);
}
public void removeCheckBoxListSelectionChangeListener(CheckBoxListSelectionChangeListener l) {
this.listenerList.remove(CheckBoxListSelectionChangeListener.class, l);
}
public void fireCheckBoxListSelectionChangeListener() {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == CheckBoxListSelectionChangeListener.class) {
((CheckBoxListSelectionChangeListener) listeners[i + 1]).selectionChanged(this);
}
}
}
public static interface CheckBoxListSelectionChangeListener extends EventListener {
public void selectionChanged(CheckBoxList target);
}
public ListModel getModel() {
return jlist.getModel();
}
}

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

@ -15,6 +15,8 @@ import java.util.List;
import java.util.Map;
import javax.swing.Icon;
import com.fr.common.inputevent.InputEventBaseOnOS;
import com.fr.design.gui.ilable.UILabel;
import javax.swing.JTable;
import javax.swing.event.TableModelEvent;
@ -79,7 +81,7 @@ import javax.swing.table.TableModel;
public class TableSorter extends AbstractTableModel {
protected TableModel tableModel;
private static final int ADD = 4;
public static final int DESCENDING = -1;
public static final int NOT_SORTED = 0;
public static final int ASCENDING = 1;
@ -341,17 +343,14 @@ public class TableSorter extends AbstractTableModel {
fireTableChanged(e);
return;
}
// If the table structure has changed, cancel the sorting; the
// sorting columns may have been either moved or deleted from
// the model.
// If the table structure has changed, cancel the sorting; the
// sorting columns may have been either moved or deleted from the model.
if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
cancelSorting();
fireTableChanged(e);
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:
//
// a) all the changes are on one row (e.getFirstRow() == e.getLastRow()) and,
@ -380,8 +379,7 @@ public class TableSorter extends AbstractTableModel {
column, e.getType()));
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();
fireTableDataChanged();
return;
@ -396,13 +394,13 @@ public class TableSorter extends AbstractTableModel {
int column = columnModel.getColumn(viewColumn).getModelIndex();
if (column != -1) {
int status = getSortingStatus(column);
if (!e.isControlDown()) {
if (!InputEventBaseOnOS.isControlDown(e)) {
cancelSorting();
}
// Cycle the sorting states through {NOT_SORTED, ASCENDING, DESCENDING} or
// {NOT_SORTED, DESCENDING, ASCENDING} depending on whether shift is pressed.
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);
}
}

3
designer_base/src/com/fr/design/gui/itree/refreshabletree/UserObjectRefreshJTree.java

@ -1,5 +1,6 @@
package com.fr.design.gui.itree.refreshabletree;
import com.fr.common.inputevent.InputEventBaseOnOS;
import com.fr.general.NameObject;
import com.fr.design.gui.itree.refreshabletree.loader.ChildrenLoaderFactory;
import com.fr.general.ComparatorUtils;
@ -147,7 +148,7 @@ public abstract class UserObjectRefreshJTree<T extends UserObjectOP<?>> extends
}
}
// marks:鼠标在上次选中的paths上,则将上次的paths设为的树的路径,否则将鼠标所在的节点设为选中的节点
if (!(e.isShiftDown() || e.isControlDown())) {
if (!(e.isShiftDown() || InputEventBaseOnOS.isControlDown(e))) {
if (isFind) {
setSelectionPaths(oldPaths);
} else {

3
designer_base/src/com/fr/design/roleAuthority/UIRoleTreeUI.java

@ -1,5 +1,6 @@
package com.fr.design.roleAuthority;
import com.fr.common.inputevent.InputEventBaseOnOS;
import com.fr.design.gui.itree.UITreeUI;
import javax.swing.tree.TreePath;
@ -15,7 +16,7 @@ import java.awt.event.MouseEvent;
public class UIRoleTreeUI extends UITreeUI {
protected void selectPathForEvent(TreePath path, MouseEvent event) { /* Adjust from the anchor point. */
if (event.isControlDown() && tree.isPathSelected(path)) {
if (InputEventBaseOnOS.isControlDown(event) && tree.isPathSelected(path)) {
tree.removeSelectionPath(path);
} else if (event.isShiftDown()) {
tree.setAnchorSelectionPath(null);

5
designer_form/src/com/fr/design/designer/beans/models/SelectionModel.java

@ -1,5 +1,6 @@
package com.fr.design.designer.beans.models;
import com.fr.common.inputevent.InputEventBaseOnOS;
import com.fr.design.designer.beans.AdapterBus;
import com.fr.design.designer.beans.LayoutAdapter;
import com.fr.design.designer.beans.events.DesignerEvent;
@ -61,7 +62,7 @@ public class SelectionModel {
* @param e 鼠标事件
*/
public void selectACreatorAtMouseEvent(MouseEvent e) {
if (!e.isControlDown() && !e.isShiftDown()) {
if (!InputEventBaseOnOS.isControlDown(e) && !e.isShiftDown()) {
// 如果Ctrl或者Shift键盘没有按下,则清除已经选择的组件
selection.reset();
}
@ -372,7 +373,7 @@ public class SelectionModel {
public Direction getDirectionAt(MouseEvent e) {
Direction dir;
if (e.isControlDown() || e.isShiftDown()) {
if (InputEventBaseOnOS.isControlDown(e) || e.isShiftDown()) {
XCreator creator = designer.getComponentAt(e.getX(), e.getY(), selection.getSelectedCreators());
if (creator != designer.getRootComponent() && selection.addedable(creator)) {
return Location.add;

Loading…
Cancel
Save