Statistics
| Revision:

root / trunk / libraries / libUIComponent / src / org / gvsig / gui / beans / swing / jComboBoxItemsSeeker / DefaultComboBoxItemsSeekerConfigurableModel.java @ 13136

History | View | Annotate | Download (21.6 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.MutableComboBoxModel;
90
import javax.swing.AbstractListModel;
91

    
92
import org.gvsig.gui.beans.swing.jComboBoxItemsSeeker.ISearchUsingFirstCharacters;
93
import org.gvsig.gui.beans.swing.jComboBoxItemsSeeker.StringComparator;
94

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

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

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

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

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

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

    
313
                if (size > 0)
314
                {
315
                        vector.clear();
316
                        alphabeticallyOrdered.clear();
317

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

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

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

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

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

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

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

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

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

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

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

    
669
        ///// END REIMPLEMENTATION OF METHODS OF THE INTERFACE ISearchUsingFirstCharacters /////
670
}