Author: kono
Date: 2012-06-28 17:12:14 -0700 (Thu, 28 Jun 2012)
New Revision: 29723
Modified:
core3/api/trunk/swing-util-api/src/main/java/org/cytoscape/util/swing/CheckBoxJList.java
Log:
fixes #1037 Users can uncheck for the current selected item.
Modified:
core3/api/trunk/swing-util-api/src/main/java/org/cytoscape/util/swing/CheckBoxJList.java
===================================================================
---
core3/api/trunk/swing-util-api/src/main/java/org/cytoscape/util/swing/CheckBoxJList.java
2012-06-28 23:59:05 UTC (rev 29722)
+++
core3/api/trunk/swing-util-api/src/main/java/org/cytoscape/util/swing/CheckBoxJList.java
2012-06-29 00:12:14 UTC (rev 29723)
@@ -38,6 +38,8 @@
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -65,7 +67,7 @@
* Customized by Keiichiro Ono
* </p>
*/
-public class CheckBoxJList extends JList implements ListSelectionListener {
+public class CheckBoxJList extends JList implements ListSelectionListener
{
private final static long serialVersionUID = 120233987581935L;
@@ -81,6 +83,9 @@
* has been updated.
*/
public static final String LIST_UPDATED = "LIST_UPDATED";
+
+ private int lastIndex = 0;
+ private int firstIndex = 0;
static {
UIDefaults uid = UIManager.getLookAndFeel().getDefaults();
@@ -97,8 +102,19 @@
selectionCache = new HashSet<Integer>();
setCellRenderer(new CheckBoxListCellRenderer());
addListSelectionListener(this);
+ this.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mousePressed(MouseEvent e) {
+ processClick();
+ }
+ });
}
+ protected void processClick() {
+ if(selectionCache.size() == 1 && (this.getSelectedIndex() ==
firstIndex || this.getSelectedIndex() == lastIndex))
+ fireSelectionValueChanged(0, 0, false);
+ }
+
/**
* Sets the specified items as selected.
* @param selected the items to be selected.
@@ -130,6 +146,9 @@
public void valueChanged(ListSelectionEvent lse) {
if (!lse.getValueIsAdjusting()) {
+ firstIndex = lse.getFirstIndex();
+ lastIndex = lse.getLastIndex();
+
removeListSelectionListener(this);
// remember everything selected as a result of this
action
--
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en.