|
|
@ -1,34 +1,24 @@ |
|
|
|
package com.fr.design.gui.ilist; |
|
|
|
package com.fr.design.gui.ilist; |
|
|
|
|
|
|
|
|
|
|
|
import java.awt.BorderLayout; |
|
|
|
import com.fr.design.gui.icheckbox.UICheckBox; |
|
|
|
import java.awt.Component; |
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
|
|
|
|
import java.awt.event.ActionListener; |
|
|
|
import javax.swing.*; |
|
|
|
import java.awt.event.KeyAdapter; |
|
|
|
import javax.swing.border.Border; |
|
|
|
import java.awt.event.KeyEvent; |
|
|
|
import javax.swing.border.EmptyBorder; |
|
|
|
import java.awt.event.MouseAdapter; |
|
|
|
import java.awt.*; |
|
|
|
import java.awt.event.MouseEvent; |
|
|
|
import java.awt.event.*; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.Arrays; |
|
|
|
import java.util.EventListener; |
|
|
|
import java.util.EventListener; |
|
|
|
import java.util.List; |
|
|
|
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. |
|
|
|
* CheckBoxs + JList. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class CheckBoxList extends JComponent { |
|
|
|
public class CheckBoxList extends JComponent { |
|
|
|
|
|
|
|
private final static int X_COORDINATE = 20; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 选择状态----全选和全不选 |
|
|
|
* 选择状态----全选和全不选 |
|
|
|
* |
|
|
|
* |
|
|
@ -54,10 +44,8 @@ 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 state default state, true or false |
|
|
|
* @param default_state |
|
|
|
|
|
|
|
* default state, true or false |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public CheckBoxList(Object[] items, SelectedState state, String name) { |
|
|
|
public CheckBoxList(Object[] items, SelectedState state, String name) { |
|
|
|
jlist = new BOXLIST(items); |
|
|
|
jlist = new BOXLIST(items); |
|
|
@ -175,8 +163,9 @@ public class CheckBoxList extends JComponent { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void processMouseEvent(MouseEvent e) { |
|
|
|
protected void processMouseEvent(MouseEvent e) { |
|
|
|
if (e.getX() < 20) { |
|
|
|
if (e.getX() < X_COORDINATE) { |
|
|
|
if (e.isControlDown() || e.isAltDown() || e.isShiftDown() || e.isMetaDown()) { |
|
|
|
boolean anyMaskDown = e.isControlDown() || e.isAltDown() || e.isShiftDown() || e.isMetaDown(); |
|
|
|
|
|
|
|
if (anyMaskDown) { |
|
|
|
int[] indices = getSelectedIndices(); |
|
|
|
int[] indices = getSelectedIndices(); |
|
|
|
if (indices.length == 0) { |
|
|
|
if (indices.length == 0) { |
|
|
|
super.processMouseEvent(e); |
|
|
|
super.processMouseEvent(e); |
|
|
@ -205,7 +194,7 @@ public class CheckBoxList extends JComponent { |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected void processMouseMotionEvent(MouseEvent e) { |
|
|
|
protected void processMouseMotionEvent(MouseEvent e) { |
|
|
|
if (e.getX() < 20) { |
|
|
|
if (e.getX() < X_COORDINATE) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -246,13 +235,13 @@ public class CheckBoxList extends JComponent { |
|
|
|
repaint(); |
|
|
|
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 { |
|
|
|
private class CheckListCellRenderer extends UICheckBox implements ListCellRenderer { |
|
|
|
|
|
|
|
|
|
|
|
public CheckListCellRenderer() { |
|
|
|
public CheckListCellRenderer() { |
|
|
|
this.setOpaque(true); |
|
|
|
this.setOpaque(true); |
|
|
|
this.setBorder(noFocusBorder); |
|
|
|
this.setBorder(NO_FOCUS_BORDER); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
|
|
|
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
|
|
@ -271,7 +260,7 @@ public class CheckBoxList extends JComponent { |
|
|
|
if (cellHasFocus) { |
|
|
|
if (cellHasFocus) { |
|
|
|
this.setBorder(UIManager.getBorder("List.focusCellHighlightBorder")); |
|
|
|
this.setBorder(UIManager.getBorder("List.focusCellHighlightBorder")); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
this.setBorder(noFocusBorder); |
|
|
|
this.setBorder(NO_FOCUS_BORDER); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return this; |
|
|
|
return this; |
|
|
@ -294,7 +283,7 @@ public class CheckBoxList extends JComponent { |
|
|
|
// those that are interested in this event
|
|
|
|
// those that are interested in this event
|
|
|
|
for (int i = listeners.length - 2; i >= 0; i -= 2) { |
|
|
|
for (int i = listeners.length - 2; i >= 0; i -= 2) { |
|
|
|
if (listeners[i] == CheckBoxListSelectionChangeListener.class) { |
|
|
|
if (listeners[i] == CheckBoxListSelectionChangeListener.class) { |
|
|
|
((CheckBoxListSelectionChangeListener)listeners[i + 1]).selectionChanged(this); |
|
|
|
((CheckBoxListSelectionChangeListener) listeners[i + 1]).selectionChanged(this); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|