1 14 package org.wings; 15 16 import javax.swing.*; 17 import javax.swing.event.ListSelectionEvent ; 18 import javax.swing.event.ListSelectionListener ; 19 import java.util.ArrayList ; 20 import java.util.Iterator ; 21 22 23 30 public class SDefaultListSelectionModel 31 extends DefaultListSelectionModel 32 implements SListSelectionModel { 33 34 40 private boolean noSelection = false; 41 42 46 private boolean delayEvents = false; 47 48 53 private boolean fireAdjustingEvents = false; 54 55 58 protected final ArrayList delayedEvents = new ArrayList (5); 59 60 public int getMinSelectionIndex() { 61 if (noSelection) { 62 return -1; 63 } else { 64 return super.getMinSelectionIndex(); 65 } 66 } 67 68 public int getMaxSelectionIndex() { 69 if (noSelection) { 70 return -1; 71 } else { 72 return super.getMaxSelectionIndex(); 73 } 74 } 75 76 public boolean isSelectedIndex(int index) { 77 if (noSelection) { 78 return false; 79 } else { 80 return super.isSelectedIndex(index); 81 } 82 } 83 84 public int getAnchorSelectionIndex() { 85 if (noSelection) { 86 return -1; 87 } else { 88 return super.getAnchorSelectionIndex(); 89 } 90 } 91 92 public int getLeadSelectionIndex() { 93 if (noSelection) { 94 return -1; 95 } else { 96 return super.getLeadSelectionIndex(); 97 } 98 } 99 100 public boolean isSelectionEmpty() { 101 if (noSelection) { 102 return true; 103 } else { 104 return super.isSelectionEmpty(); 105 } 106 } 107 108 public int getSelectionMode() { 109 if (noSelection) { 110 return NO_SELECTION; 111 } else { 112 return super.getSelectionMode(); 113 } 114 } 115 116 public void setSelectionMode(int selectionMode) { 117 if (selectionMode == NO_SELECTION) { 118 noSelection = true; 119 } else { 120 noSelection = false; 121 super.setSelectionMode(selectionMode); 122 } 123 } 124 125 protected void fireDelayedEvents(boolean onlyAdjusting) { 126 for (Iterator iter = delayedEvents.iterator(); iter.hasNext();) { 127 ListSelectionEvent e = (ListSelectionEvent ) iter.next(); 128 129 if (!onlyAdjusting || e.getValueIsAdjusting()) { 130 fireValueChanged(e.getFirstIndex(), e.getLastIndex(), 131 e.getValueIsAdjusting()); 132 } 133 iter.remove(); 134 } 135 } 136 137 public boolean getDelayEvents() { 138 return delayEvents; 139 } 140 141 public void setDelayEvents(boolean b) { 142 delayEvents = b; 143 } 144 145 public boolean getFireAdjustingEvents() { 146 return fireAdjustingEvents; 147 } 148 149 public void setFireAdjustingEvents(boolean b) { 150 fireAdjustingEvents = b; 151 } 152 153 156 public void fireDelayedIntermediateEvents() { 157 if (fireAdjustingEvents) { 158 fireDelayedEvents(true); 159 } 160 } 161 162 public void fireDelayedFinalEvents() { 163 if (!delayEvents) { 164 fireDelayedEvents(false); 165 delayedEvents.clear(); 166 } 167 } 168 169 protected void fireValueChanged(int firstIndex, int lastIndex, 170 boolean isAdjusting) { 171 if (!noSelection) { 172 173 if (delayEvents) { 174 if (!isAdjusting || fireAdjustingEvents) { 175 delayedEvents.add(new ListSelectionEvent (this, 176 firstIndex, lastIndex, 177 isAdjusting)); 178 } 179 } else { 180 super.fireValueChanged(firstIndex, lastIndex, isAdjusting); 181 } 182 } 183 } 184 185 191 public static final ListSelectionModel NO_SELECTION_LIST_SELECTION_MODEL = 192 new ListSelectionModel() { 193 194 public void setSelectionInterval(int index0, int index1) {} 195 196 public void addSelectionInterval(int index0, int index1) {} 197 198 public void removeSelectionInterval(int index0, int index1) {} 199 200 public int getMinSelectionIndex() { return -1;} 201 202 public int getMaxSelectionIndex() { return -1;} 203 204 public boolean isSelectedIndex(int index) { return false;} 205 206 public int getAnchorSelectionIndex() { return -1;} 207 208 public void setAnchorSelectionIndex(int index) {} 209 210 public int getLeadSelectionIndex() { return -1;} 211 212 public void setLeadSelectionIndex(int index) {} 213 214 public void clearSelection() {} 215 216 public boolean isSelectionEmpty() { return true;} 217 218 public void insertIndexInterval(int index, int length, 219 boolean before) {} 220 221 public void removeIndexInterval(int index0, int index1) {} 222 223 public void setValueIsAdjusting(boolean valueIsAdjusting) {} 224 225 public boolean getValueIsAdjusting() { return false;} 226 227 public void setSelectionMode(int selectionMode) {} 228 229 public int getSelectionMode() { return NO_SELECTION; } 230 231 public void addListSelectionListener(ListSelectionListener x) {} 232 233 public void removeListSelectionListener(ListSelectionListener x) {} 234 235 public boolean getDelayEvents() { return false;} 236 237 public void setDelayEvents(boolean b) {} 238 239 public void fireDelayedIntermediateEvents() {} 240 241 public void fireDelayedFinalEvents() {} 242 }; 243 244 } 245 246 247 | Popular Tags |