Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / swing / jComboBoxItemsSeeker / DefaultComboBoxItemsSeekerConfigurableModel.java @ 13191

History | View | Annotate | Download (21.5 KB)

1
package org.gvsig.gui.beans.swing.jComboBoxItemsSeeker;
2
/* DefaultComboBoxModel.java --
3
   Copyright (C) 2002, 2004, 2005, 2006, Free Software Foundation, Inc.
4

5
This file is part of GNU Classpath.
6

7
GNU Classpath is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2, or (at your option)
10
any later version.
11

12
GNU Classpath is distributed in the hope that it will be useful, but
13
WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
General Public License for more details.
16

17
You should have received a copy of the GNU General Public License
18
along with GNU Classpath; see the file COPYING.  If not, write to the
19
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20
02110-1301 USA.
21

22
Linking this library statically or dynamically with other modules is
23
making a combined work based on this library.  Thus, the terms and
24
conditions of the GNU General Public License cover the whole
25
combination.
26

27
As a special exception, the copyright holders of this library give you
28
permission to link this library with independent modules to produce an
29
executable, regardless of the license terms of these independent
30
modules, and to copy and distribute the resulting executable under
31
terms of your choice, provided that you also meet, for each linked
32
independent module, the terms and conditions of the license of that
33
module.  An independent module is a module which is not derived from
34
or based on this library.  If you modify this library, you may extend
35
this exception to your version of the library, but you are not
36
obligated to do so.  If you do not wish to do so, delete this
37
exception statement from your version. */
38

    
39
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
40
 *
41
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
42
 *
43
 * This program is free software; you can redistribute it and/or
44
 * modify it under the terms of the GNU General Public License
45
 * as published by the Free Software Foundation; either version 2
46
 * of the License, or (at your option) any later version.
47
 *
48
 * This program is distributed in the hope that it will be useful,
49
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
50
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
51
 * GNU General Public License for more details.
52
 *
53
 * You should have received a copy of the GNU General Public License
54
 * along with this program; if not, write to the Free Software
55
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
56
 *
57
 * For more information, contact:
58
 *
59
 *  Generalitat Valenciana
60
 *   Conselleria d'Infraestructures i Transport
61
 *   Av. Blasco Ib??ez, 50
62
 *   46010 VALENCIA
63
 *   SPAIN
64
 *
65
 *      +34 963862235
66
 *   gvsig@gva.es
67
 *      www.gvsig.gva.es
68
 *
69
 *    or
70
 *
71
 *   IVER T.I. S.A
72
 *   Salamanca 50
73
 *   46005 Valencia
74
 *   Spain
75
 *
76
 *   +34 963163400
77
 *   dac@iver.es
78
 */
79

    
80
import java.io.Serializable;
81
import java.text.Collator;
82
import java.util.ArrayList;
83
import java.util.Arrays;
84
import java.util.Collections;
85
import java.util.List;
86
import java.util.Locale;
87
import java.util.Vector;
88

    
89
import javax.swing.AbstractListModel;
90
import javax.swing.DefaultComboBoxModel;
91
import javax.swing.MutableComboBoxModel;
92

    
93
/**
94
 * Reimplementation of {@link DefaultComboBoxModel} adapted for the behavior needed for seek items which start with a text. This model also has behaviour configurable using flags.<br>
95
 * Represents the model used by {@link org.gvsig.gui.beans.swing.jComboBoxItemsSeeker.JComboBoxItemsSeekerConfigurable}, according the MVC (Model-View-Controller) pattern.
96
 * <ul>
97
 *  <li><b>ItemsOrder:</b> order in which items will be showed: maintain position (according the items were introduced); alphabetical order (according the local rules); or disordered.<br>
98
 *   * <b><i>MAINTAIN_POSITION</i></b>: in the same position as they are stored.<br>
99
 *   * <b><i>ALPHABETICAL_ORDERED</i></b>: in alphabetical order (according a local language rules).<br>
100
 *   * <b><i>DISORDERED</i></b>: disordered.
101
 *  </li>   
102
 *  <li><b>ShowAllItemsInListBox:</b> show all items in list box always, or only items that their start match with the text written.<br>
103
 *   * <b><i>SHOW_ALL_ITEMS</i></b>: shows all items of the model always.<br>
104
 *   * <b><i>SHOW_ONLY_MATCHES</i></b>: shows only the items that start with text written.
105
 *  </li>
106
 *  <li><b>LanguageRules:</b> language rules (es_ES, en_US, fr_FR, ...)</li>  
107
 *  <li><b>CaseSensitive:</b> consider or ignore the case sensitive seeking the items that start with the text written.<br>
108
 *   * <b><i>CASE_SENSITIVE</i></b>: discriminates between lower and upper cases.<br>
109
 *   * <b><i>CASE_INSENSITIVE</i></b>: doesn't discriminate between lower and upper cases.
110
 *  </li>  
111
 * </ul>
112
 * 
113
 * @see javax.swing.DefaultComboBoxModel
114
 *  
115
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
116
 */
117
public class DefaultComboBoxItemsSeekerConfigurableModel extends AbstractListModel
118
    implements MutableComboBoxModel, Serializable, ISearchUsingFirstCharacters
119
    {
120
                private static final long serialVersionUID = 9200879660096233842L;
121

    
122
                /**
123
             * Storage for the elements in the model's vector. <br>
124
             * 
125
             * All items will be stored according they are introduced.
126
             */
127
            private Vector vector;
128
            
129
            /**
130
             * Stores the elements of 'vector' in alphabetical order. <br>
131
             * 
132
             * This attribute will be used in the searches.
133
             */
134
            private Vector alphabeticallyOrdered;
135
          
136
            /**
137
             * The selected item (<code>null</code> indicates no selection).
138
             */
139
            private Object selectedItem = null;
140
            
141
            ///// NEW ATTRIBUTES /////
142
                /**
143
                 * Object that allows compare strings
144
                 */
145
                private StringComparator stringComparator;
146
        
147
                /**
148
                 * Items that will be visible (displayed)
149
                 */
150
                private List visibleList;
151
                
152
                /**
153
                 * Text written
154
                 */
155
                private String textWritten;
156
                
157
            ///// END NEW ATTRIBUTES /////
158
                
159
                // CONSTANTS FOR CONFIGURE THE BEHAVIOR
160
                public static final int MAINTAIN_POSITION = 0;
161
                public static final int ALPHABETICAL_ORDERED = 1;
162
                public static final int DISORDERED = 2;
163
                public static final boolean SHOW_ALL_ITEMS = true;
164
                public static final boolean SHOW_ONLY_MATCHES = false;
165
                public static final boolean CASE_SENSITIVE = true;
166
                public static final boolean CASE_INSENSITIVE = false;
167
                
168
                public static final int DEFAULT_ITEMS_ORDER_CONFIGURATION = ALPHABETICAL_ORDERED;
169
                public static final boolean DEFAULT_SHOW_ALL_ITEMS_IN_LIST_BOX_CONFIGURATION = SHOW_ONLY_MATCHES;
170
                
171
                public static final String DEFAULT_LANGUAGE_RULES_CONFIGURATION = "es_ES";
172
                public static final boolean DEFAULT_CASE_SENSITIVE_CONFIGURATION = CASE_SENSITIVE;
173
                // END CONSTANTS FOR CONFIGURE THE BEHAVIOR
174
                
175
                // CONFIGURATION FLAGS
176
                /**
177
                 * Flag: order in which items will be showed: maintain position (according the items were introduced); alphabetical order (according the local rules); or disordered
178
                 */
179
                private int itemsOrder_Flag;
180
                
181
                /**
182
                 * Flag: show all items in list box always, or only items that their start match with the text written
183
                 */
184
                private boolean showAllItemsInListBox_Flag;
185
                
186
                /**
187
                 * Flag: language rules (es_ES, en_US, fr_FR, ...)
188
                 */
189
                private String languageRules_Flag;
190
                
191
                /**
192
                 * Flag: consider or ignore the case sensitive seeking the items that start with the text written.
193
                 */
194
                private boolean caseSensitive_Flag;
195
                // END FLAGS
196
        
197
                ///// REIMPLEMENTATION OF METHODS /////
198
            /**
199
             * @see javax.swing.DefaultComboBoxModel#DefaultComboBoxModel()
200
             */
201
            public DefaultComboBoxItemsSeekerConfigurableModel()
202
            {
203
                    vector = new Vector();
204
              
205
                    initialize();
206
            }
207
  
208
            /**
209
             * @see javax.swing.DefaultComboBoxModel#DefaultComboBoxModel(java.lang.Object[])
210
             */
211
            public DefaultComboBoxItemsSeekerConfigurableModel(Object[] items)
212
            {
213
                    vector = new Vector(Arrays.asList(items));
214

    
215
                    initialize();
216
            }
217
  
218
            /**
219
             * @see javax.swing.DefaultComboBoxModel#DefaultComboBoxModel(java.util.Vector)
220
             */
221
            public DefaultComboBoxItemsSeekerConfigurableModel(Vector vector)
222
            {
223
                    this.vector = new Vector(vector);
224
     
225
                    initialize();
226
            }
227
 
228
            /**
229
             * @see javax.swing.DefaultComboBoxModel#addElement(java.lang.Object)
230
             */
231
        public void addElement(Object object)
232
        {
233
                vector.addElement(object);
234
                VectorUtilities.addAlphabeticallyOrdered(alphabeticallyOrdered, object, stringComparator);
235
     
236
                int index = vector.size() - 1;
237
                fireIntervalAdded(this, index, index);
238
                
239
                updateVisibleList();
240
                
241
                 if ((itemsOrder_Flag == DISORDERED) && (visibleList != null))
242
                         Collections.shuffle(visibleList);
243
         }
244
 
245
        /**
246
         * @see javax.swing.DefaultComboBoxModel#removeElementAt(int)
247
         */
248
        public void removeElementAt(int index)
249
        {
250
                int selected = getIndexOf(selectedItem);
251
                if (selected == index) // choose a new selected item
252
                {
253
                        if (selected > 0)
254
                                setSelectedItem(getElementAt(selected - 1));
255
                        else 
256
                                setSelectedItem(getElementAt(selected + 1));
257
                }
258
                
259
                Object obj = vector.get(index);
260
                
261
                alphabeticallyOrdered.remove(obj);
262
                vector.removeElementAt(index);
263

    
264
                fireIntervalRemoved(this, index, index);
265
                
266
                updateVisibleList();
267
                
268
                 if ((itemsOrder_Flag == DISORDERED) && (visibleList != null))
269
                         Collections.shuffle(visibleList);
270
        }
271
 
272
        /**
273
         * @see javax.swing.DefaultComboBoxModel#insertElementAt(java.lang.Object, int)
274
         */                
275

    
276
        public void insertElementAt(Object object, int index)
277
        {
278
                vector.insertElementAt(object, index);
279
                VectorUtilities.addAlphabeticallyOrdered(alphabeticallyOrdered, object, stringComparator);
280

    
281
                fireIntervalAdded(this, index, index);
282
                
283
                updateVisibleList();
284
                
285
                 if ((itemsOrder_Flag == DISORDERED) && (visibleList != null))
286
                         Collections.shuffle(visibleList);
287
        }
288
 
289
        /**
290
         * @see javax.swing.DefaultComboBoxModel#removeElement(java.lang.Object)
291
         */
292
        public void removeElement(Object object)
293
        {
294
                int index = getIndexOf(object);
295
                
296
                if (index != -1) {
297
                        removeElementAt(index);
298
                }
299
        }
300
 
301
        /**
302
         * @see javax.swing.DefaultComboBoxModel#removeAllElements()
303
         */
304
        public void removeAllElements()
305
        {
306
                selectedItem = null;
307
                //int size = getSize();
308
                int size = vector.size();
309
                System.out.println("SIZE: " + size);
310

    
311
                if (size > 0)
312
                {
313
                        vector.clear();
314
                        alphabeticallyOrdered.clear();
315

    
316
                        fireIntervalRemoved(this, 0, size - 1);
317
                        
318
                        updateVisibleList();
319
                        
320
                         if ((itemsOrder_Flag == DISORDERED) && (visibleList != null))
321
                                 Collections.shuffle(visibleList);
322
                }
323
        }
324

    
325
        /**
326
         * @see javax.swing.DefaultComboBoxModel#getSize()
327
         */
328
        public int getSize()
329
        {
330
                if (visibleList == null)
331
                        return 0;
332
                else
333
                        return visibleList.size();
334
        }
335
   
336
        /**
337
         * @see javax.swing.DefaultComboBoxModel#setSelectedItem(java.lang.Object)
338
         */
339
        public void setSelectedItem(Object object)
340
        {
341
                // No item is selected and object is null, so no change required.
342
                if (selectedItem == null && object == null)
343
                        return;
344
 
345
                // object is already selected so no change required.
346
                if (selectedItem != null && selectedItem.equals(object))
347
                        return;
348
 
349
                // Simply return if object is not in the vector.
350
                if (object != null && getIndexOf(object) == -1)
351
                        return;
352
 
353
                // Here we know that object is either an item in the vector or null.
354
 
355
                // Handle the three change cases: selectedItem is null, object is
356
                // non-null; selectedItem is non-null, object is null;
357
                // selectedItem is non-null, object is non-null and they're not
358
                // equal.
359
                selectedItem = object;
360
                
361
                textWritten = object.toString();
362
                
363
                fireContentsChanged(this, -1, -1);
364
                
365
                updateVisibleList();
366
        }
367
 
368
        /**
369
         * @see javax.swing.DefaultComboBoxModel#getSelectedItem()
370
         */
371
        public Object getSelectedItem()
372
        {
373
                return selectedItem;
374
        }
375
 
376
        /**
377
         * @see javax.swing.DefaultComboBoxModel#getElementAt(int)
378
         */
379
        public Object getElementAt(int index)
380
        {
381
                if (index < 0 || index >= visibleList.size())
382
                        return null;
383
                return visibleList.get(index);
384
        }
385
        
386
        /**
387
         * @see javax.swing.DefaultComboBoxModel#getIndexOf(java.lang.Object)
388
         */
389
        public int getIndexOf(Object object)
390
        {
391
                if (visibleList == null)
392
                        return -1;
393
            
394
                return visibleList.indexOf(object);
395
        }
396

    
397
        ///// END REIMPLEMENTATION OF METHODS /////    
398
    
399
        ///// METHODS FOR THE BEHAVIOR FLAGS  /////
400
        /**
401
         * Returns the 'itemsOrder_Flag' configuration value of this component. Configuration values are: <br>
402
         *   + MAINTAIN_POSITION: all items will be shown in the order programmer did. <br>
403
         *   + ALPHABETICAL_ORDERED: all items will be shown in alphabetical order. <br>
404
         *   + DISORDERED: all items will be shown disordered.
405
         * 
406
         * @return 'itemsOrder_Flag' configuration
407
         */
408
        public int getItemsOrder_Flag() {
409
                return itemsOrder_Flag;
410
        }
411

    
412
        /**
413
         * Sets the 'itemsOrder_Flag' configuration value for this component. Configuration values are: <br>
414
         *   + MAINTAIN_POSITION: all items will be shown in the order programmer did. <br>
415
         *   + ALPHABETICAL_ORDERED: all items will be shown in alphabetical order. <br>
416
         *   + DISORDERED: all items will be shown disordered.
417
         * 
418
         * @param An int value for 'itemsOrder_Flag' configuration flag
419
         */
420
        public void setItemsOrder_Flag(int itemsOrder) {
421
                this.itemsOrder_Flag = itemsOrder;
422
        }
423
        
424
        /**
425
         * Returns the 'showAllItemsInListBox_Flag' configuration value of this component. Configuration values are: <br>
426
         *   + SHOW_ALL_ITEMS: shows all items in the list box. <br>
427
         *   + SHOW_ONLY_MATCHES: shows only the items that match with the text written.
428
         * 
429
         * @return 'showAllItemsInListBox_Flag' configuration
430
         */
431
        public boolean isShowAllItemsInListBox_Flag() {
432
                return showAllItemsInListBox_Flag;
433
        }
434
        
435
        /**
436
         * Sets the 'showAllItemsInListBox_Flag' configuration value for this component. Configuration values are: <br>
437
         *   + SHOW_ALL_ITEMS: shows all items in the list box. <br>
438
         *   + SHOW_ONLY_MATCHES: shows only the items that match with the text written.
439
         * 
440
         * @param A boolean value for 'showAllItemsInListBox_Flag' configuration flag
441
         */
442
        public void setShowAllItemsInListBox_Flag(boolean itemsShownInListBox) {
443
                this.showAllItemsInListBox_Flag = itemsShownInListBox;
444
        }
445
        
446
        /**
447
         * Returns the 'languageRules_Flag' configuration value of this component. The language code values could be consulted at: <br>
448
         * <i>http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt </i><br>
449
         * <i>http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html </i><br>
450
         * 
451
         * @see {@Locale}
452
         * 
453
         * @return 'languageRules_Flag' configuration
454
         */
455
        public String getLanguageRules_Flag() {
456
                return languageRules_Flag;
457
        }
458
        
459
        /**
460
         * Sets the 'languageRules_Flag' configuration value for this component. Configuration values are: <br>
461
         * <i>http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt </i><br>
462
         * <i>http://www.chemie.fu-berlin.de/diverse/doc/ISO_3166.html </i><br>
463
         * 
464
         * @see {@Locale}
465
         * 
466
         * @param An String value for 'languageRules_Flag' configuration flag
467
         */
468
        public void setLanguageRules_Flag(String languageRules) {
469
                this.languageRules_Flag = languageRules;
470
                
471
                stringComparator.setLocaleRules(stringComparator.new LocaleRules(true, Collator.getInstance(new Locale(this.languageRules_Flag))));
472
                Collections.sort(alphabeticallyOrdered.subList(0, alphabeticallyOrdered.size()), stringComparator); 
473
                
474
                updateVisibleList();
475
        }
476
        
477
        /**
478
         * Returns the 'caseSensitive_Flag' configuration value of this component. Configuration values are: <br>
479
         *    + CASE_SENSITIVE: discriminates between small letters and capital letters. <br>
480
         *    + CASE_INSENSITIVE: doesn't discriminates between small letters and capital letters.
481
         * 
482
         * @return 'caseSensitive_Flag' configuration
483
         */
484
        public boolean isCaseSensitive_Flag() {
485
                return caseSensitive_Flag;
486
        }
487
        
488
        /**
489
         * Sets the 'caseSensitive_Flag' configuration value for this component. Configuration values are: <br>
490
         *    + CASE_SENSITIVE: discriminates between small letters and capital letters. <br>
491
         *    + CASE_INSENSITIVE: doesn't discriminates between small letters and capital letters.
492
         * 
493
         * @param A boolean value for 'caseSensitive_Flag' configuration flag
494
         */
495
        public void setCaseSensitive_Flag(boolean caseSensitive) {
496
                this.caseSensitive_Flag = caseSensitive;
497

    
498
                stringComparator.setCaseSensitive(this.caseSensitive_Flag);
499
                Collections.sort(alphabeticallyOrdered.subList(0, alphabeticallyOrdered.size()), stringComparator); 
500

    
501
                updateVisibleList();
502
        }
503
        ///// END METHODS FOR THE BEHAVIOR FLAGS  /////
504
    
505
   ///// NEW METHODS /////
506
   
507
        /**
508
         * Initializes some attributes of this class
509
         */
510
        private void initialize() {
511
                textWritten = "";
512
                
513
                // Set default flags configuration
514
                this.setDefaultBehaviorFlagsConfiguration();
515
                
516
                // Initialize the StringComparator -> use spanish alphabetical rules, and case sensitive
517
                stringComparator = new StringComparator();
518
                stringComparator.setCaseSensitive(DEFAULT_CASE_SENSITIVE_CONFIGURATION);
519
                stringComparator.setLocaleRules(stringComparator.new LocaleRules(true, Collator.getInstance(new Locale(DEFAULT_LANGUAGE_RULES_CONFIGURATION))));
520
                
521
                alphabeticallyOrdered = new Vector(vector.subList(0, vector.size()));
522
                Collections.sort(alphabeticallyOrdered.subList(0, alphabeticallyOrdered.size()), stringComparator); // Use an algorithm of comparision which implements the rules of the language.
523
                
524
                visibleList = new ArrayList();
525
        }
526
        
527
        /**
528
         *  Sets the default values of the flags
529
         */
530
        private void setDefaultBehaviorFlagsConfiguration() {
531
                this.itemsOrder_Flag = DEFAULT_ITEMS_ORDER_CONFIGURATION;
532
                this.showAllItemsInListBox_Flag = DEFAULT_SHOW_ALL_ITEMS_IN_LIST_BOX_CONFIGURATION;
533
                this.languageRules_Flag = DEFAULT_LANGUAGE_RULES_CONFIGURATION;
534
                this.caseSensitive_Flag = DEFAULT_CASE_SENSITIVE_CONFIGURATION;
535
        }
536

    
537
        /**
538
         * This method is necessary to fix a bug
539
         * 
540
         * @return Data stored in this model. Elements will be alphabetical sort ordered.
541
         */
542
        public Vector getData() {
543
                return vector;
544
        }
545

    
546
        /**
547
         * This method is necessary to fix a bug
548
         * 
549
         * @return Data stored in this model according the alphabetical order in the 'itemsOrder_Flag' flag. Elements will be alphabetical sort ordered.
550
         */
551
        public Vector getDataAccordingItemsOrderFlag() {
552
                switch(itemsOrder_Flag) {
553
                        case MAINTAIN_POSITION:
554
                                return vector;
555
                     case ALPHABETICAL_ORDERED:
556
                             // Do nothing because items are already alphabetically ordered
557
                             return alphabeticallyOrdered;
558
                     case DISORDERED:
559
                             updateVisibleList();                             
560
                             return new Vector(visibleList.subList(0, visibleList.size()));
561
                     default:
562
                             // Default case: ALPHABETICAL_ORDERED
563
                             // Do nothing because items are already alphabetically ordered
564
                             return alphabeticallyOrdered;
565
                }
566
        }
567
        
568
        /**
569
         * Updates the list with the results of the search of all items that thei first characters start with the text written.<br>
570
         * Updates its the configuration.
571
         */
572
        private void updateVisibleList() {
573
                if (vector.size() == 0) {
574
                        visibleList = alphabeticallyOrdered.subList(0, 0);
575
                        return;
576
                }
577
                
578
                if (showAllItemsInListBox_Flag) {
579
                        switch (itemsOrder_Flag) {
580
                                case MAINTAIN_POSITION:
581
                                        visibleList = vector.subList(0, vector.size());
582
                                     break;
583
                             case ALPHABETICAL_ORDERED:
584
                                     visibleList = alphabeticallyOrdered.subList(0, alphabeticallyOrdered.size());
585
                                 break;
586
                             case DISORDERED:
587
                                     visibleList = vector.subList(0, vector.size());
588
                                     break;
589
                             default:
590
                                     // Default case: ALPHABETICAL_ORDERED
591
                                     visibleList = alphabeticallyOrdered.subList(0, alphabeticallyOrdered.size());
592
                        }
593
                        
594
                        if ((visibleList.size() > 0) && (textWritten.compareTo("") != 0)) {
595
                                List list = binarySearch(); //BinarySearchUsingFirstCharacters.doSearchConsideringCaseSensitive(textWritten, alphabeticallyOrdered, stringComparator);
596

    
597
                                if ((list != null) && (list.size() > 0)) {
598
                                        selectedItem = list.get(0);
599
                                        textWritten = selectedItem.toString();
600
                                }
601
                                else {
602
                                        selectedItem = null;
603
                                }
604
                        }
605
                }
606
                else {
607
                        visibleList = binarySearch(); //BinarySearchUsingFirstCharacters.doSearchConsideringCaseSensitive(textWritten, alphabeticallyOrdered, stringComparator);
608
                        
609
                        switch (itemsOrder_Flag) {
610
                                case MAINTAIN_POSITION: case DISORDERED:
611
                                        if (visibleList != null) {
612
                                                Vector aux = new Vector(vector.subList(0, vector.size()));
613
                                                int size = aux.size();
614
                                                Object obj = new Object();
615

    
616
                                                for (int i = (size - 1); i >= 0; i--) {
617
                                                        obj = aux.get(i);
618
        
619
                                                        if (visibleList.contains(obj)) {
620
                                                                visibleList.remove(obj);
621
                                                        }
622
                                                        else {
623
                                                                aux.remove(i);
624
                                                        }
625
                                                }
626
        
627
                                                visibleList = aux.subList(0, aux.size());
628
                                        }
629
                                     break;
630
                             case ALPHABETICAL_ORDERED:
631
                                     // Do nothing because items are already alphabetically ordered
632
                                     break;
633
                             default:
634
                                     // Default case: ALPHABETICAL_ORDERED
635
                                     // Do nothing because items are already alphabetically ordered
636
                        }
637
                }
638
        }
639
        
640
        /**
641
         * Fetches a binary search with the text written, the items alphabetically ordered, and an string comparator.
642
         * 
643
         * @return java.util.List
644
         */
645
        private List binarySearch() {
646
                if (stringComparator.isCaseSensitive()) {
647
                        return BinarySearchUsingFirstCharacters.doSearchConsideringCaseSensitive(textWritten, alphabeticallyOrdered, stringComparator);
648
                }
649
                else  {
650
                        return BinarySearchUsingFirstCharacters.doSearchIgnoringCaseSensitive(textWritten, alphabeticallyOrdered, stringComparator);
651
                }
652
        }
653
        
654
        ///// END NEW METHODS /////
655
        
656
        ///// REIMPLEMENTATION OF METHODS OF THE INTERFACE ISearchUsingFirstCharacters /////
657

    
658
        /*
659
         *  (non-Javadoc)
660
         * @see org.gvsig.gui.beans.swing.jComboBoxItemsSeeker.ISearchUsingFirstCharacters#setWrittenText(java.lang.String)
661
         */
662
        public void setTextWritten(String text) {
663
                textWritten = text;
664
                updateVisibleList();
665
        }
666

    
667
        ///// END REIMPLEMENTATION OF METHODS OF THE INTERFACE ISearchUsingFirstCharacters /////
668
}