diff options
author | Anthony Balkissoon <abalkiss@redhat.com> | 2005-06-30 18:16:57 +0000 |
---|---|---|
committer | Anthony Balkissoon <abalkiss@redhat.com> | 2005-06-30 18:16:57 +0000 |
commit | fa1d4587505a1d707171afc0c27ab8e91eafc04e (patch) | |
tree | 3e73c0af88080e5278fa81bb0239ab1d5929bd13 | |
parent | 35e2b1db037e9522de92d2f97cc4f18f44aa475b (diff) | |
download | classpath-fa1d4587505a1d707171afc0c27ab8e91eafc04e.tar.gz |
2005-06-30 Anthony Balkissoon <abalkiss@redhat.com>
* javax/swing/DefaultListSelectionModel.java:
(addSelectionInterval): Don't clear the selection state if JList's
selection mode is SINGLE_SELECTION_INTERVAL and index0 and index1
correspond to an interval adjacent to an already selected interval.
(removeSelectionInterval): Added check for a middle interval being
removed when selection mode is SINGLE_SELECTION_INTERVAL.
* javax/swing/plaf/basic/BasicListUI.java:
(KeyHandler.keyPressed): Added check for scrolling past bottom of list.
(MouseHandler.mouseClicked): Added check for shift key being
pressed.
-rw-r--r-- | ChangeLog | 13 | ||||
-rw-r--r-- | javax/swing/DefaultListSelectionModel.java | 52 | ||||
-rw-r--r-- | javax/swing/plaf/basic/BasicListUI.java | 39 |
3 files changed, 83 insertions, 21 deletions
@@ -1,3 +1,16 @@ +2005-06-30 Anthony Balkissoon <abalkiss@redhat.com> + + * javax/swing/DefaultListSelectionModel.java: + (addSelectionInterval): Don't clear the selection state if JList's + selection mode is SINGLE_SELECTION_INTERVAL and index0 and index1 + correspond to an interval adjacent to an already selected interval. + (removeSelectionInterval): Added check for a middle interval being + removed when selection mode is SINGLE_SELECTION_INTERVAL. + * javax/swing/plaf/basic/BasicListUI.java: + (KeyHandler.keyPressed): Added check for scrolling past bottom of list. + (MouseHandler.mouseClicked): Added check for shift key being + pressed. + 2005-06-30 Keith Seitz <keiths@redhat.com> * gnu/classpath/jdwp/transport/JdwpPacket.java (write): New method. diff --git a/javax/swing/DefaultListSelectionModel.java b/javax/swing/DefaultListSelectionModel.java index 0f93da0d6..71bf90538 100644 --- a/javax/swing/DefaultListSelectionModel.java +++ b/javax/swing/DefaultListSelectionModel.java @@ -393,10 +393,14 @@ public class DefaultListSelectionModel implements Cloneable, /** * If the {@link #selectionMode} property is equal to - * <code>SINGLE_SELECTION</code> or - * <code>SINGLE_INTERVAL_SELECTION</code>, equivalent to calling - * <code>setSelectionInterval(index1, index2)</code>; otherwise adds the - * range <code>[index0, index1]</code> to the selection interval set. + * <code>SINGLE_SELECTION</code> equivalent to calling + * <code>setSelectionInterval(index1, index2)</code>; + * If the {@link #selectionMode} property is equal to + * <code>SINGLE_INTERVAL_SELECTION</code> and the interval being + * added is not adjacent to an already selected interval, + * equivalent to <code>setSelectionInterval(index1, index2)</code>. + * Otherwise adds the range <code>[index0, index1]</code> + * to the selection interval set. * * @param index0 The beginning of the range of indices to select * @param index1 The end of the range of indices to select @@ -406,30 +410,40 @@ public class DefaultListSelectionModel implements Cloneable, */ public void addSelectionInterval(int index0, int index1) { + int lo = Math.min(index0, index1); + int hi = Math.max(index0, index1); oldSel = sel.clone(); - if (selectionMode == SINGLE_SELECTION - || selectionMode == SINGLE_INTERVAL_SELECTION) + + if (selectionMode == SINGLE_SELECTION) sel.clear(); + + // COMPAT: Like Sun (but not like IBM), we allow calls to + // addSelectionInterval when selectionMode is + // SINGLE_SELECTION_INTERVAL iff the interval being added + // is adjacent to an already selected interval + if (selectionMode == SINGLE_INTERVAL_SELECTION) + if (!(isSelectedIndex(index0) || + isSelectedIndex(index1) || + isSelectedIndex(Math.max(lo-1,0)) || + isSelectedIndex(Math.min(hi+1,sel.size())))) + sel.clear(); if (selectionMode == SINGLE_SELECTION) index0 = index1; - int lo = Math.min(index0, index1); - int hi = Math.max(index0, index1); - - /* We have to update the anchorSelectionIndex and leadSelectionIndex - variables */ + // We have to update the anchorSelectionIndex and leadSelectionIndex + // variables - /* The next if statements breaks down to "if this selection is adjacent - to the previous selection and going in the same direction" */ + // The next if statements breaks down to "if this selection is adjacent + // to the previous selection and going in the same direction" if (((index0 - 1 == leadSelectionIndex && (index1 >= index0) && (leadSelectionIndex >= anchorSelectionIndex)) || (index0 + 1 == leadSelectionIndex && (index1 <= index0) && (leadSelectionIndex <= anchorSelectionIndex))) && (anchorSelectionIndex != -1 || leadSelectionIndex != -1)) { - /* setting setLeadCalledFromAdd to true tells setLeadSelectionIndex - not to update oldSel */ + // setting setLeadCalledFromAdd to true tells setLeadSelectionIndex + // not to update oldSel setLeadCalledFromAdd = true; setLeadSelectionIndex(index1); setLeadCalledFromAdd = false; @@ -461,6 +475,14 @@ public class DefaultListSelectionModel implements Cloneable, oldSel = sel.clone(); int lo = Math.min(index0, index1); int hi = Math.max(index0, index1); + + // if selectionMode is SINGLE_INTERVAL_SELECTION and removing the interval + // (index0,index1) would leave two disjoint selection intervals, remove all + // selected indices from lo to the last selected index + if (getMinSelectionIndex() > 0 && getMinSelectionIndex() < lo && + selectionMode == SINGLE_INTERVAL_SELECTION) + hi = sel.size() - 1; + sel.clear(lo, hi+1); //update anchorSelectionIndex and leadSelectionIndex variables //TODO: will probably need MouseDragged to test properly and know if this works diff --git a/javax/swing/plaf/basic/BasicListUI.java b/javax/swing/plaf/basic/BasicListUI.java index a70f27a12..c6d75842d 100644 --- a/javax/swing/plaf/basic/BasicListUI.java +++ b/javax/swing/plaf/basic/BasicListUI.java @@ -200,14 +200,16 @@ public class BasicListUI extends ListUI if (evt.getKeyCode() == KeyEvent.VK_DOWN) { int lead = BasicListUI.this.list.getLeadSelectionIndex(); + int max = BasicListUI.this.list.getModel().getSize() - 1; if (!evt.isShiftDown()) { BasicListUI.this.list.clearSelection(); - BasicListUI.this.list.setSelectedIndex(lead+1); + BasicListUI.this.list.setSelectedIndex(Math.min(lead+1,max)); } else { - BasicListUI.this.list.getSelectionModel().setLeadSelectionIndex(lead+1); + BasicListUI.this.list.getSelectionModel(). + setLeadSelectionIndex(Math.min(lead+1,max)); } } else if (evt.getKeyCode() == KeyEvent.VK_UP) @@ -220,7 +222,8 @@ public class BasicListUI extends ListUI } else { - BasicListUI.this.list.getSelectionModel().setLeadSelectionIndex(Math.max(lead-1,0)); + BasicListUI.this.list.getSelectionModel(). + setLeadSelectionIndex(Math.max(lead-1,0)); } } } @@ -244,16 +247,40 @@ public class BasicListUI extends ListUI int index = BasicListUI.this.locationToIndex(list, click); if (index == -1) return; - boolean controlPressed = event.isControlDown(); - if (controlPressed) + if (event.isControlDown()) { - if (BasicListUI.this.list.getSelectionMode() == ListSelectionModel.SINGLE_SELECTION) + if (BasicListUI.this.list.getSelectionMode() == + ListSelectionModel.SINGLE_SELECTION) BasicListUI.this.list.setSelectedIndex(index); else if (BasicListUI.this.list.isSelectedIndex(index)) BasicListUI.this.list.removeSelectionInterval(index,index); else BasicListUI.this.list.addSelectionInterval(index,index); } + else if (event.isShiftDown()) + { + if (BasicListUI.this.list.getSelectionMode() == + ListSelectionModel.SINGLE_SELECTION) + BasicListUI.this.list.setSelectedIndex(index); + else if (BasicListUI.this.list.getSelectionMode() == + ListSelectionModel.SINGLE_INTERVAL_SELECTION) + // COMPAT: the IBM VM is compatible with the following line of code. + // However, compliance with Sun's VM would correspond to replacing + // getAnchorSelectionIndex() with getLeadSelectionIndex().This is + // both unnatural and contradictory to the way they handle other + // similar UI interactions. + BasicListUI.this.list.setSelectionInterval + (BasicListUI.this.list.getAnchorSelectionIndex(), index); + else + // COMPAT: both Sun and IBM are compatible instead with: + // BasicListUI.this.list.setSelectionInterval + // (BasicListUI.this.list.getLeadSelectionIndex(),index); + // Note that for IBM this is contradictory to what they did in + // the above situation for SINGLE_INTERVAL_SELECTION. + // The most natural thing to do is the following: + BasicListUI.this.list.getSelectionModel(). + setLeadSelectionIndex(index); + } else BasicListUI.this.list.setSelectedIndex(index); } |