changeset 4870:dfa991721457

7125456: [macosx] Programmatically selecting List item triggers an ItemEvent Reviewed-by: serb, anthony
author alexp
date Wed, 18 Jan 2012 20:49:02 +0400
parents dbd828ae28db
children d2494547f2d7
files src/macosx/classes/sun/lwawt/LWListPeer.java
diffstat 1 files changed, 15 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/lwawt/LWListPeer.java	Wed Jan 18 16:23:17 2012 +0000
+++ b/src/macosx/classes/sun/lwawt/LWListPeer.java	Wed Jan 18 20:49:02 2012 +0400
@@ -50,7 +50,9 @@
         setMultipleMode(getTarget().isMultipleMode());
         final int[] selectedIndices = getTarget().getSelectedIndexes();
         synchronized (getDelegateLock()) {
+            getDelegate().setSkipStateChangedEvent(true);
             getDelegate().getView().setSelectedIndices(selectedIndices);
+            getDelegate().setSkipStateChangedEvent(false);
         }
     }
 
@@ -94,7 +96,9 @@
     @Override
     public void select(final int index) {
         synchronized (getDelegateLock()) {
+            getDelegate().setSkipStateChangedEvent(true);
             getDelegate().getView().setSelectedIndex(index);
+            getDelegate().setSkipStateChangedEvent(false);
         }
     }
 
@@ -145,6 +149,8 @@
 
     final class ScrollableJList extends JScrollPane implements ListSelectionListener {
 
+        private boolean skipStateChangedEvent;
+
         private DefaultListModel<Object> model =
                 new DefaultListModel<Object>() {
                     @Override
@@ -173,9 +179,17 @@
             }
         }
 
+        public boolean isSkipStateChangedEvent() {
+            return skipStateChangedEvent;
+        }
+
+        public void setSkipStateChangedEvent(boolean skipStateChangedEvent) {
+            this.skipStateChangedEvent = skipStateChangedEvent;
+        }
+
         @Override
         public void valueChanged(final ListSelectionEvent e) {
-            if (!e.getValueIsAdjusting()) {
+            if (!e.getValueIsAdjusting() && !isSkipStateChangedEvent()) {
                 final JList source = (JList) e.getSource();
                 for(int i = 0 ; i < source.getModel().getSize(); i++) {