|
|
|
@ -1,34 +1,24 @@
|
|
|
|
|
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 { |
|
|
|
|
private final static int X_COORDINATE = 20; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 选择状态----全选和全不选 |
|
|
|
|
* |
|
|
|
@ -54,10 +44,8 @@ public class CheckBoxList extends JComponent {
|
|
|
|
|
/** |
|
|
|
|
* Class constructor. |
|
|
|
|
* |
|
|
|
|
* @param items |
|
|
|
|
* Items with which to populate the list. |
|
|
|
|
* @param default_state |
|
|
|
|
* default state, true or false |
|
|
|
|
* @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); |
|
|
|
@ -175,8 +163,9 @@ public class CheckBoxList extends JComponent {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void processMouseEvent(MouseEvent e) { |
|
|
|
|
if (e.getX() < 20) { |
|
|
|
|
if (e.isControlDown() || e.isAltDown() || e.isShiftDown() || e.isMetaDown()) { |
|
|
|
|
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); |
|
|
|
@ -205,7 +194,7 @@ public class CheckBoxList extends JComponent {
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
protected void processMouseMotionEvent(MouseEvent e) { |
|
|
|
|
if (e.getX() < 20) { |
|
|
|
|
if (e.getX() < X_COORDINATE) { |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -246,13 +235,13 @@ public class CheckBoxList extends JComponent {
|
|
|
|
|
repaint(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static final Border noFocusBorder = new EmptyBorder(1, 1, 1, 1); |
|
|
|
|
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(noFocusBorder); |
|
|
|
|
this.setBorder(NO_FOCUS_BORDER); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
|
|
|
@ -271,7 +260,7 @@ public class CheckBoxList extends JComponent {
|
|
|
|
|
if (cellHasFocus) { |
|
|
|
|
this.setBorder(UIManager.getBorder("List.focusCellHighlightBorder")); |
|
|
|
|
} else { |
|
|
|
|
this.setBorder(noFocusBorder); |
|
|
|
|
this.setBorder(NO_FOCUS_BORDER); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return this; |
|
|
|
@ -294,7 +283,7 @@ public class CheckBoxList extends JComponent {
|
|
|
|
|
// 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); |
|
|
|
|
((CheckBoxListSelectionChangeListener) listeners[i + 1]).selectionChanged(this); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|