Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libUI / src / org / gvsig / gui / beans / comboBoxItemsSeeker / ComboBoxItemsSeekerDynamicModel.java @ 6716

History | View | Annotate | Download (40 KB)

1
package org.gvsig.gui.beans.comboBoxItemsSeeker;
2

    
3
import java.util.Arrays;
4
import java.util.Collections;
5
import java.util.List;
6
import java.util.TreeSet;
7
import java.util.Vector;
8

    
9
import javax.swing.DefaultComboBoxModel;
10

    
11

    
12
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
13
 *
14
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
15
 *
16
 * This program is free software; you can redistribute it and/or
17
 * modify it under the terms of the GNU General Public License
18
 * as published by the Free Software Foundation; either version 2
19
 * of the License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU General Public License
27
 * along with this program; if not, write to the Free Software
28
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
29
 *
30
 * For more information, contact:
31
 *
32
 *  Generalitat Valenciana
33
 *   Conselleria d'Infraestructures i Transport
34
 *   Av. Blasco Ib??ez, 50
35
 *   46010 VALENCIA
36
 *   SPAIN
37
 *
38
 *      +34 963862235
39
 *   gvsig@gva.es
40
 *      www.gvsig.gva.es
41
 *
42
 *    or
43
 *
44
 *   IVER T.I. S.A
45
 *   Salamanca 50
46
 *   46005 Valencia
47
 *   Spain
48
 *
49
 *   +34 963163400
50
 *   dac@iver.es
51
 */
52

    
53
/** VERSI?N EN DESARROLLO
54
 *  COMENTAR Y REVISAR
55
 * Se consideran los datos que contiene DefaultComboBoxModel como los que se tomar?n para devolver datos a no ser que sea para actualizar la lista
56
 *    de la vista, que en cuyo caso se tendr? en cuenta la configuraci?n del comportamiento y atributos internos.
57
 * 
58
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
59
 */
60
public class ComboBoxItemsSeekerDynamicModel extends DefaultComboBoxModel implements java.io.Serializable {
61
        // INNER MODEL STRUCTURES
62
        //private Set itemsShowed;
63
        private TreeSet itemsShowed;
64
        //private Object itemsShowedSortedOrDisordered[];
65
        private Object itemsSearchesShow[];
66
//        private String writtenString = "";
67
        // END INNER MODEL STRUCTURES
68
//        Iterator iterator; // puede que sobre
69
        
70
        
71
        // CONTANTS FOR CONFIGURE THE BEHAVIOR
72
        public static final int MAINTAIN_ORIGINAL_POSITION_START = 0;
73
        public static final int ORDERED_START = 1;
74
        public static final int DISORDERED_START = 2;
75

    
76
        public static final int MAINTAIN_ORIGINAL_POSITION_ALL_ITEMS_SEARCH = 3;
77
        public static final int ORDERED_ALL_ITEMS_SEARCH = 4;
78
        public static final int DISORDERED_ALL_ITEMS_SEARCH = 5;
79
        public static final int MAINTAIN_ORIGINAL_POSITION_DYNAMIC_SEARCH = 6;
80
        public static final int ORDERED_DYNAMIC_SEARCH = 7;
81
        public static final int DISORDERED_DYNAMIC_SEARCH = 8;
82

    
83
        // END CONTANTS FOR CONFIGURE THE BEHAVIOR
84
        
85
        // CONFIGURATION FLAGS (Voy a Cambiar algunas!!!!)
86
//        private boolean maintainPositionItems;        
87
//        private boolean alphanumericSortedSearches;
88
//        private boolean allAlphanumericSorted;
89
        private int startBehavior;
90
        private int searchBehavior;
91
        private boolean keySensitive;
92
        private boolean showAllItems;
93
//        (With the default value)
94
//        private boolean maintainPositionItems = true;        
95
//        private boolean alphanumericSortedSearches = true;
96
//        private boolean allAlphanumericSorted  = true;
97
//        private boolean keySensitive = false;
98
//        private boolean showAllItems = true; //false;;
99
        // END FLAGS        //                this.maintainPositionItems = true;                
100
//        this.alphanumericSortedSearches = true;
101
//        this.allAlphanumericSorted = false;
102

    
103
        private int stateAllItems;
104
        private final int STATE_DEFAULT = 10;
105
        private final int STATE_ITEMS_ARE_ORDERED = 11;
106
        private final int STATE_ITEMS_ARE_DISORDERED = 12;
107
        
108
        
109
        // OTHER FLAGS
110
        private boolean startView;
111
//        private boolean allItemsAreSorted;
112
//        private boolean allItemsAreDisordered;
113
        private boolean thisIsAComboBoxItemsSeekerDynamicModelClass; // To distinguish the class which invokes some methods of this class
114
        private boolean dynamicSearches;
115
        private boolean dynamicStart;
116
        private boolean dynamicSearchDone;
117
        private boolean itemsInTheArray;
118
        // END OTHER FLAGS
119

    
120
        // ATTRIBUTES FOR DYNAMIC CASES
121
//        private int highIndex;
122
//        private int lowIndex;
123
//        private int lastDynamicIndexUsed;
124
        private String writtenText;
125
        // END ATTRIBUTES FOR DYNAMIC CASES
126
        
127
        /**
128
         * Default Constructor without parameters.
129
         * Constructs an empty ComboBoxItemsSeekerDynamicModel object.          
130
         */
131
        public ComboBoxItemsSeekerDynamicModel() {
132
                super();
133
                this.initialize();
134
        }
135
        
136
        /**
137
         * Default Constructor with an array of objects as parameter.
138
         * Constructs a ComboBoxItemsSeekerDynamicModel object initialized with an array of objects.
139
         * @throws Exception 
140
         */
141
        public ComboBoxItemsSeekerDynamicModel(Object[] items) throws Exception {                
142
                super(items);
143
                this.initialize();
144
                
145
                if (!this.itemsShowed.addAll(Arrays.asList(items)))
146
                        throw new Exception();
147
        }
148

    
149
        /**
150
         * Default Constructor with a vector as parameter.
151
         * Constructs a ComboBoxItemsSeekerDynamicModel object initialized with a vector.
152
         * @throws Exception 
153
         */
154
        public ComboBoxItemsSeekerDynamicModel(Vector objects) throws Exception {
155
                super(objects);
156
                this.initialize();
157
                
158
                if (!this.itemsShowed.addAll(objects))
159
                        throw new Exception();
160
        }
161
        
162
        /**
163
         * This method set the start values of inner attributes and creates the necessary inner objects
164
         */
165
        private void initialize() {
166
                thisIsAComboBoxItemsSeekerDynamicModelClass = true;
167
                
168
//                this.currentString = "";
169
                this.writtenText = "";
170
                this.setDefaultBehaviorFlagsConfiguration();
171
                this.startView = true;
172
//                this.allItemsAreSorted = false;
173
//                this.allItemsAreDisordered = false;
174
                this.stateAllItems = STATE_DEFAULT;
175
                this.dynamicSearches = false;
176
                this.dynamicStart = false;
177
                this.dynamicSearchDone = false; 
178
                this.itemsInTheArray = false;
179
        
180
                this.itemsShowed = new TreeSet();
181
        }
182
        
183
        /**
184
         * Method that sets the default values of the behavior flags
185
         */
186
        private void setDefaultBehaviorFlagsConfiguration() {
187
                // Set the default values of the flags
188
//                this.maintainPositionItems = true;                
189
//                this.alphanumericSortedSearches = true;
190
//                this.allAlphanumericSorted = false;
191
                this.startBehavior = MAINTAIN_ORIGINAL_POSITION_START;
192
                this.searchBehavior = ORDERED_ALL_ITEMS_SEARCH; //this.ORDERED_DYNAMIC_SEARCH;
193
                this.keySensitive = false;
194
                this.showAllItems = true; //false;        
195
        }
196
        
197
        /** A BORRAR
198
         * @param currentString The currentString to set.
199
         */
200
//        public void setCurrentString(String currentString) {
201
//                this.currentString = currentString;
202
//                Vector v = new Vector();                
203
//                
204
//                //Refrescar el modelo                
205
//                for (int i=0 ; i<allObjects.size() ; i++){
206
//                        String obj = allObjects.get(i).toString();
207
//                        if (currentString.equals("")){
208
//                                v.add(allObjects.get(i));
209
//                        }else if (obj.indexOf(currentString) == 0){
210
//                                v.add(allObjects.get(i));
211
//                        }
212
//                }
213
//                orderedObjects = v;
214
//        }
215
        
216
        
217
        ////// METHODS FOR THE BEHAVIOR FLAGS  //////
218
        
219
        /**
220
         * This method tests the configuration of the flags and returns true or false if its ok or not with the
221
         *   logical behavior of this component
222
         * 
223
         * @return boolean True if the configuration of the flags is oks, false if not
224
         */
225
        public boolean testFlagsConfigurationOK() {
226
//                if ((maintainPositionItems == allAlphanumericSorted) && (maintainPositionItems == true))
227
//                        return false;
228
//                
229
//                if ((maintainPositionItems == false) && (allAlphanumericSorted == true) && (alphanumericSortedSearches == false))
230
//                        return false;
231
                
232
                if ((this.startBehavior < 0) || (this.startBehavior > 2))
233
                        return false;
234
                
235
                if ((this.searchBehavior < 3) || (this.searchBehavior > 8))
236
                        return false;
237
                
238
//                if ((showAllItems == true) && (maintainPositionItems == false))
239
//                        return false;
240
                
241
                return true;
242
        }
243

    
244
        public int getStartBehavior() {
245
                return this.startBehavior;
246
        }
247
        
248
        public void setStartBehavior(int start_Behavior) {
249
                this.startBehavior = start_Behavior;                
250
        }
251

    
252
        public int getSearchBehavior() {
253
                return this.searchBehavior;
254
        }
255

    
256
        /**
257
         * 
258
         * @param search_Behavior
259
         */
260
        public void setSearchBehavior(int search_Behavior) {
261
                this.searchBehavior = search_Behavior;
262
                
263
                if ((this.searchBehavior > 5) && (this.searchBehavior < 9))
264
                        this.dynamicSearches = true;
265
                else
266
                        this.dynamicSearches = false;
267
        }
268

    
269
        /**
270
         * Gets the flag of the configuration of the keySensitive flag of this component 
271
         * (true -> discriminates capital letters from small letters ,false -> don't discriminates capital letters from small letters)
272
         * 
273
         * @return boolean The value of the flag
274
         */
275
        public boolean isKeySensitive() {
276
                return keySensitive;
277
        }
278
        
279
        /**
280
         * Sets the flag of the configuration of the keySensitive flag of this component 
281
         * (true -> discriminates capital letters from small letters ,false -> don't discriminates capital letters from small letters)
282
         * 
283
         * @param boolean The value of the flag
284
         */
285
        public void setKeySensitive(boolean key_Sensitive) {
286
                this.keySensitive = key_Sensitive;
287
        }
288

    
289
        /**
290
         * Gets the flag of the configuration of the showAllItems flag of this component
291
         * (true -> this component shows all items always; false -> this component only shows items that their first characters match with the string written by the user) 
292
         * 
293
         * @return boolean The value of the flag
294
         */
295
        public boolean isShowAllItems() {
296
                return showAllItems;
297
        }
298

    
299
        /**
300
         * Sets the flag of the configuration of the showAllItems flag of this component
301
         * (true -> this component shows all items always; false -> this component only shows items that their first characters match with the string written by the user)
302
         * 
303
         * @return boolean The value of the flag
304
         */
305
        public void setShowAllItems(boolean show_All_Items) {
306
                this.showAllItems = show_All_Items;
307
                
308
//                if (this.showAllItems == false)
309
//                        this.setModel(getCopyOfModel());
310
        }
311
        
312
        public Object getFirstItemAdded() {
313
                return super.getElementAt(0);
314
        }
315

    
316
        ////// END METHODS FOR THE BEHAVIOR FLAGS //////
317
        
318
        ////// REIMPLEMENTATION OF SOME METHODS OF "DefaultComboBoxModel" TO ADAPT THE BEHAVIOR OF THIS MODEL //////        
319
        
320
        /*
321
         *  (non-Javadoc)
322
         * @see javax.swing.DefaultComboBoxModel#getSize()
323
         */
324
        public int getSize() {
325
                if (thisIsAComboBoxItemsSeekerDynamicModelClass)
326
                {
327
                        if (this.startView)
328
                                return this.itemsShowed.size();                        
329
                        
330
                        switch(this.getSearchBehavior())
331
                        {
332
                                case MAINTAIN_ORIGINAL_POSITION_ALL_ITEMS_SEARCH: case ORDERED_ALL_ITEMS_SEARCH: case DISORDERED_ALL_ITEMS_SEARCH:
333
                                        return this.itemsShowed.size();
334
//                                        break;
335
                                case MAINTAIN_ORIGINAL_POSITION_DYNAMIC_SEARCH:
336
                                        if (!this.dynamicSearchDone)
337
                                                seekDynamicItems();
338

    
339
                                        return this.itemsSearchesShow.length;
340
//                                        break;
341
                                case ORDERED_DYNAMIC_SEARCH:
342
                                        if (!this.dynamicSearchDone)
343
                                                seekDynamicItems();
344

    
345
                                        return this.itemsSearchesShow.length;
346
//                                        break;
347
                                case DISORDERED_DYNAMIC_SEARCH:
348
                                        if (!this.dynamicSearchDone)
349
                                                seekDynamicItems();
350

    
351
                                        return this.itemsSearchesShow.length;
352
//                                        break;
353
                                default:
354
                                        // If error configuration -> it gives back 0 for not to produce more errors 
355
                                        return 0; // HACER
356
                        }
357
                }
358
                else
359
                        return super.getSize();
360
        }
361

    
362
        /*
363
         *  (non-Javadoc)
364
         * @see javax.swing.ListModel#getElementAt(int)
365
         */
366
        public Object getElementAt(int index) {
367
                
368
                if (this.startView) // At the beginning shows all items
369
                {                        
370
                        switch(this.getStartBehavior())
371
                        {
372
                                case MAINTAIN_ORIGINAL_POSITION_START :                                
373
                                        return super.getElementAt(index);
374
//                                        break;
375
                                case ORDERED_START :
376
                                        // If the items aren't sorted -> sort them!
377
//                                        if (!this.allItemsAreSorted)
378
//                                                this.sortItemsCopy();
379
                                        if ((!this.itemsInTheArray) || (this.stateAllItems != STATE_ITEMS_ARE_ORDERED))
380
                                                this.setItemsCopyToArray();
381
                                        
382
                                        // Return the item at that position
383
                                        return this.itemsSearchesShow[index];
384
//                                        return this.itemsShowedDisordered.[index];
385
//                                        break;
386
                                case DISORDERED_START :
387
                                        
388
                                        if (!this.itemsInTheArray)
389
                                                this.setItemsCopyToArray();
390
                                        
391
                                        // If the items aren't disordered -> sort them!
392
                                        if (this.stateAllItems != STATE_ITEMS_ARE_DISORDERED)
393
                                                this.disorderItemsCopy();
394

    
395
                                        // Return the item at that position
396
                                        return this.itemsSearchesShow[index];
397
//                                        return this.itemsShowedDisordered[index];
398
//                                        break;
399
                                default:
400
                                        // If error configuration -> it gives back an empty object for not to produce more errors 
401
                                        return new Object();
402
                        }
403
                }
404
                else
405
                {                        
406
                        switch(this.getSearchBehavior())
407
                        {
408
                                case MAINTAIN_ORIGINAL_POSITION_ALL_ITEMS_SEARCH :
409
                                        return super.getElementAt(index);
410
//                                                break;
411
                                case ORDERED_ALL_ITEMS_SEARCH :
412
                                        if ((!this.itemsInTheArray) || (this.stateAllItems != STATE_ITEMS_ARE_ORDERED))
413
                                                this.setItemsCopyToArray();
414

    
415
//                                                this.setItemsCopyToArray();
416

    
417
                                        // If the items aren't sorted -> sort them!
418
//                                        if (!this.allItemsAreSorted)
419
//                                                this.sortItemsCopy();
420
                                        
421
                                        // Return the item at that position
422
                                //        return this.iterator.next();        
423
                                        return this.itemsSearchesShow[index];
424
//                                        return this.itemsShowedDisordered[index];
425
//                                                break;
426
                                case DISORDERED_ALL_ITEMS_SEARCH :
427
                                        if (!this.itemsInTheArray)
428
                                                this.setItemsCopyToArray();
429

    
430
                                        // If the items aren't sorted -> sort them!
431
                                        if (this.stateAllItems != STATE_ITEMS_ARE_DISORDERED)
432
                                                this.disorderItemsCopy();
433

    
434
                                        // Return the item at that position
435
                                //        return this.iterator.next();
436
                                        return this.itemsSearchesShow[index];
437
//                                        return this.itemsShowedDisordered[index];
438
                                        
439
//                                                break;
440
                                case MAINTAIN_ORIGINAL_POSITION_DYNAMIC_SEARCH : case ORDERED_DYNAMIC_SEARCH : case DISORDERED_DYNAMIC_SEARCH :
441
                                        if (!this.itemsInTheArray)
442
                                                this.setItemsCopyToArray();
443

    
444
                                        if (!this.dynamicSearchDone)
445
                                                seekDynamicItems();
446
                                        
447
                                        return this.itemsSearchesShow[index];
448
//                                                break;
449
                                default:
450
                                        // If error configuration -> it gives back an empty object for not to produce more errors 
451
                                        return new Object();
452
                        }
453
                }                
454
        }
455

    
456

    
457
        /* HACER??
458
         *  (non-Javadoc)
459
         * @see javax.swing.DefaultComboBoxModel#getIndexOf(java.lang.Object)
460
         */
461
        public int getIndexOf(Object anObject) {
462
                if (!this.itemsInTheArray)
463
                {
464
                        if (this.startView) // At the beginning shows all items
465
                        {                        
466
                                switch(this.getStartBehavior())
467
                                {
468
                                        case MAINTAIN_ORIGINAL_POSITION_START : // Do nothing        
469
                                                break;
470
                                        case ORDERED_START :
471
                                                this.setItemsCopyToArray();
472
                                                break;
473
                                        case DISORDERED_START :
474
                                                if (!this.itemsInTheArray)
475
                                                        this.setItemsCopyToArray();
476
                                                
477
                                                // If the items aren't disordered -> sort them!
478
                                                if (this.stateAllItems != STATE_ITEMS_ARE_DISORDERED)
479
                                                        this.disorderItemsCopy();
480

    
481
                                                break;
482
                                        default:
483
                                                // If error configuration -> it gives back -1 for not to produce more errors 
484
                                                return -1;
485
                                }
486
                        }
487
                        else
488
                        {                        
489
                                switch(this.getSearchBehavior())
490
                                {
491
                                        case MAINTAIN_ORIGINAL_POSITION_ALL_ITEMS_SEARCH : // Do nothing        
492
                                                break;
493
                                        case ORDERED_ALL_ITEMS_SEARCH :
494
                                                if ((!this.itemsInTheArray) || (this.stateAllItems != STATE_ITEMS_ARE_ORDERED))
495
                                                        this.setItemsCopyToArray();
496
                                                break;
497
                                        case DISORDERED_ALL_ITEMS_SEARCH :
498
                                                if (!this.itemsInTheArray)
499
                                                        this.setItemsCopyToArray();
500

    
501
                                                // If the items aren't disordered -> sort them!
502
                                                if (this.stateAllItems != STATE_ITEMS_ARE_DISORDERED)
503
                                                        this.disorderItemsCopy();
504

    
505
                                                break;
506
                                        case MAINTAIN_ORIGINAL_POSITION_DYNAMIC_SEARCH : case ORDERED_DYNAMIC_SEARCH : case DISORDERED_DYNAMIC_SEARCH :
507
                                                if (!this.itemsInTheArray)
508
                                                        this.setItemsCopyToArray();
509

    
510
                                                if (!this.dynamicSearchDone)
511
                                                        seekDynamicItems();
512
                                                
513
                                                break;
514
                                        default:
515
                                                // If error configuration -> it gives back -1 for not to produce more errors 
516
                                                return -1;
517
                                }
518
                        }                
519
                        
520
                }
521
//                        this.setItemsCopyToArray();
522

    
523
                //if (this.alphanumericSortedSearches)
524
                        //return this.itemsShowedVector.indexOf(anObject);
525
                
526
                if (((this.startView) && (this.getStartBehavior() == MAINTAIN_ORIGINAL_POSITION_START)) || ((!this.startView) && (this.getSearchBehavior() == MAINTAIN_ORIGINAL_POSITION_ALL_ITEMS_SEARCH)))
527
                        return super.getIndexOf(anObject); //this.itemsShowed.indexOf(anObject);
528
                else
529
                        return (Arrays.asList(this.itemsSearchesShow)).indexOf(anObject);
530
        }
531
                
532
    /*
533
     *  (non-Javadoc)
534
     * @see javax.swing.ComboBoxModel#getSelectedItem()
535
     */
536
        public Object getSelectedItem() {
537
                return super.getSelectedItem();
538
        }
539
        
540
        /*
541
         *  (non-Javadoc)
542
         * @see javax.swing.MutableComboBoxModel#addElement(java.lang.Object)
543
         */
544
        public void addElement(Object anObject) {
545
                super.addElement(anObject); // this adds the element and selects by default the first item added
546
                
547
                // Add the item also in the inner attribute
548
                this.itemsShowed.add(anObject);
549

    
550
                this.reset();
551
//                // If this model has to return the elements sorted
552
////                if ((this.getStartBehavior() == this.ORDERED_START) || (this.getSearchBehavior() == this.ORDERED_ALL_ITEMS_SEARCH) || (this.getSearchBehavior() == this.ORDERED_DYNAMIC_SEARCH))
553
////                //if (this.alphanumericSortedSearches)
554
////                        this.allItemsAreSorted = false;
555
//                this.itemsInTheArray = false;
556
////                else
557
////                {
558
//                        // If elements have to be disordered
559
//                        if ((this.getStartBehavior() == DISORDERED_START) || (this.getSearchBehavior() == DISORDERED_ALL_ITEMS_SEARCH) || (this.getSearchBehavior() == DISORDERED_DYNAMIC_SEARCH))
560
//                                this.stateAllItems = STATE_DEFAULT;
561
//                        //if ((!this.maintainPositionItems) && (!this.alphanumericSortedSearches))
562
////                                this.allItemsAreDisordered = false;
563
////                }
564
         }
565
 
566
        /*
567
         *  (non-Javadoc)
568
         * @see javax.swing.MutableComboBoxModel#insertElementAt(java.lang.Object, int)
569
         */
570
        public void insertElementAt(Object anObject, int index) {
571
                super.insertElementAt(anObject, index);
572
                
573
                // Add the item also in the inner attribute
574
                this.itemsShowed.add(anObject);
575

    
576
                this.reset();                
577
//                // If this model has to return the elements sorted
578
////                if ((this.getStartBehavior() == this.ORDERED_START) || (this.getSearchBehavior() == this.ORDERED_ALL_ITEMS_SEARCH) || (this.getSearchBehavior() == this.ORDERED_DYNAMIC_SEARCH))
579
////                //if (this.alphanumericSortedSearches)
580
////                        this.allItemsAreSorted = false;
581
//                this.itemsInTheArray = false;
582
//                
583
//                // If elements have to be disordered
584
//                if ((this.getStartBehavior() == DISORDERED_START) || (this.getSearchBehavior() == DISORDERED_ALL_ITEMS_SEARCH) || (this.getSearchBehavior() == DISORDERED_DYNAMIC_SEARCH))
585
//                        this.stateAllItems = STATE_DEFAULT;
586
//                //if ((!this.maintainPositionItems) && (!this.alphanumericSortedSearches))
587
////                        this.allItemsAreDisordered = false;
588
        }
589
    
590
        /*
591
         *  (non-Javadoc)
592
         * @see javax.swing.DefaultComboBoxModel#removeAllElements()
593
         */
594
        public void removeAllElements() {
595
                super.removeAllElements();
596
                
597
                // Also empty the inner attribute
598
                itemsShowed.clear();                
599
                
600
                this.reset();                
601
//                // If this model has to return the elements sorted
602
////                if ((this.getStartBehavior() == this.ORDERED_START) || (this.getSearchBehavior() == this.ORDERED_ALL_ITEMS_SEARCH) || (this.getSearchBehavior() == this.ORDERED_DYNAMIC_SEARCH))
603
////                //if (this.alphanumericSortedSearches)
604
////                        this.allItemsAreSorted = false;
605
//                this.itemsInTheArray = false;
606
//                
607
//                // If elements have to be disordered
608
//                if ((this.getStartBehavior() == DISORDERED_START) || (this.getSearchBehavior() == DISORDERED_ALL_ITEMS_SEARCH) || (this.getSearchBehavior() == DISORDERED_DYNAMIC_SEARCH))
609
//                        this.stateAllItems = STATE_DEFAULT;
610
//                //if ((!this.maintainPositionItems) && (!this.alphanumericSortedSearches))
611
////                        this.allItemsAreDisordered = false;
612
        }
613
    
614
        /*
615
         *  (non-Javadoc)
616
         * @see javax.swing.MutableComboBoxModel#removeElement(java.lang.Object)
617
         */
618
        public void removeElement(Object anObject) {
619
                super.removeElement(anObject);
620
                
621
                // Remove the object also in the inner attribute
622
                itemsShowed.remove(anObject);
623
                
624
                this.reset();                
625
                // If this model has to return the elements sorted
626
//                if ((this.getStartBehavior() == this.ORDERED_START) || (this.getSearchBehavior() == this.ORDERED_ALL_ITEMS_SEARCH) || (this.getSearchBehavior() == this.ORDERED_DYNAMIC_SEARCH))
627
//                //if (this.alphanumericSortedSearches)
628
//                        this.allItemsAreSorted = false;
629
//                this.itemsInTheArray = false;
630
//                
631
//                // If elements have to be disordered
632
//                if ((this.getStartBehavior() == DISORDERED_START) || (this.getSearchBehavior() == DISORDERED_ALL_ITEMS_SEARCH) || (this.getSearchBehavior() == DISORDERED_DYNAMIC_SEARCH))
633
//                        this.stateAllItems = STATE_DEFAULT;
634
                //if ((!this.maintainPositionItems) && (!this.alphanumericSortedSearches))
635
//                        this.allItemsAreDisordered = false;
636
        }
637
    
638
        /*
639
         *  (non-Javadoc)
640
         * @see javax.swing.MutableComboBoxModel#removeElementAt(int)
641
         */
642
        public void removeElementAt(int index) {
643
                Object obj = new Object();
644
                
645
                obj = super.getElementAt(index);
646
                super.removeElementAt(index);
647
                
648
                // Remove the object also in the inner attribute
649
                itemsShowed.remove(obj);
650
                
651
                // If this model has to return the elements sorted
652
//                if ((this.getStartBehavior() == this.ORDERED_START) || (this.getSearchBehavior() == this.ORDERED_ALL_ITEMS_SEARCH) || (this.getSearchBehavior() == this.ORDERED_DYNAMIC_SEARCH))
653
//                //if (this.alphanumericSortedSearches)
654
//                        this.allItemsAreSorted = false;
655
                
656
                this.reset();
657
                
658
                // If elements have to be disordered
659
//                if ((this.getStartBehavior() == DISORDERED_START) || (this.getSearchBehavior() == DISORDERED_ALL_ITEMS_SEARCH) || (this.getSearchBehavior() == DISORDERED_DYNAMIC_SEARCH))
660
//                        this.stateAllItems = STATE_DEFAULT;
661
                //if ((!this.maintainPositionItems) && (!this.alphanumericSortedSearches))
662
//                        this.allItemsAreDisordered = false;
663
        }
664
    
665
//        public String getWrittenText() {
666
//                return this.writtenText;
667
//        }
668
        
669
        /**
670
         * Returns the size of the parent of this component: 'ComboBoxModel'
671
         * 
672
         * @return int The size of the parent
673
         */
674
        public int getParentSize() {
675
                return super.getSize();
676
        }
677
        
678
        
679
        /**
680
         * 
681
         */
682
        public void setWrittenText(String text) {
683
                this.writtenText = text;
684
                this.reset();
685
        }
686
        
687
        /**
688
         * 
689
         * @param flagValue
690
         */
691
        public void setStartViewFlag(boolean flagValue) {
692
                this.startView = flagValue;
693
                this.reset();
694
        }
695
        
696
        public boolean isStartViewFlag() {
697
                return this.startView;
698
        }
699
        
700
        private void reset() {
701
                if (this.stateAllItems != STATE_DEFAULT)
702
                {
703
                        this.stateAllItems = STATE_DEFAULT;
704
                        this.dynamicSearchDone = false; 
705
                        this.itemsInTheArray = false;
706
                }
707
        }
708
        
709
        public boolean isDynamicSearch() {
710
                return this.dynamicSearches;
711
        }
712
                
713
        private void seekDynamicItems() {
714
                int lowIndex;
715
                int hightIndex;
716
                
717
                // If doesn't have to seek items -> finish
718
                if (this.writtenText.compareTo("") == 0)
719
                        return;
720
                
721
                if (this.dynamicSearches) // Puede que sobre este if
722
                {                        
723
                        // Get a sorted copy of all items
724
                        this.itemsSearchesShow = this.itemsShowed.toArray();
725
                        
726
                        // Do the search of the rank
727
                        BinaryRankOfItemsSearch search = new BinaryRankOfItemsSearch();
728
                        search.binaryRankSearch();
729
                                                
730
                        // To obtain the range of items to showing
731
                        lowIndex = search.getLowIndex();
732
                        hightIndex = search.getHightIndex();                         
733
                        
734
                        this.dynamicSearchDone = true;
735
                        
736
                        // Get the items
737
                        switch(this.getSearchBehavior())
738
                        {
739
                                case MAINTAIN_ORIGINAL_POSITION_DYNAMIC_SEARCH: // If maintain original position // REVISAR y HACER                                        
740
                                        int numberOfItems = hightIndex - lowIndex;
741
                                        
742
                                        this.getDynamicItemsSearch(search, lowIndex, hightIndex);
743
                                        
744
                                        if (numberOfItems > 0)
745
                                        {                                                
746
                                                int positions[] = new int[numberOfItems];
747
                                                
748
                                                int positionArrayIndex = 0;
749
                                                
750
                                                // Gets the items ordered
751
                                                this.getDynamicItemsSearch(search, lowIndex, hightIndex);
752
                                                
753
                                                // Gets the position of the items in the original position
754
                                                for (int i = lowIndex; i < hightIndex; i++)
755
                                                {
756
                                                        positions[positionArrayIndex] = super.getIndexOf(this.itemsSearchesShow[i]);
757
                                                        positionArrayIndex ++;
758
                                                }
759
                                                Arrays.sort(positions);
760
                                                
761
                                                this.itemsSearchesShow = new Object[numberOfItems]; // Remove the array
762
                
763
                                                // Get the items at the original position
764
                                                for (int i = 0; i < numberOfItems; i++)
765
                                                        this.itemsSearchesShow[i] = super.getElementAt(positions[i]);        
766
                                        }
767
                                        break;
768
                                case ORDERED_DYNAMIC_SEARCH: // If ordered                        
769
                                        
770
                                        this.getDynamicItemsSearch(search, lowIndex, hightIndex);
771
                                        
772
                                        break;
773
                                case DISORDERED_DYNAMIC_SEARCH: // If disordered //HACER                                
774

    
775
                                        this.getDynamicItemsSearch(search, lowIndex, hightIndex);
776
                                        this.disorderItemsCopy();
777
                        }                        
778
                }
779
        }        
780
        
781
        public boolean nowItemsAreDisordered() {
782
                if (this.startView)
783
                {
784
                        if (getStartBehavior() == DISORDERED_START)
785
                                return true;
786
                }
787
                else
788
                {
789
                        if ((getSearchBehavior() == DISORDERED_DYNAMIC_SEARCH) || (getSearchBehavior() == DISORDERED_ALL_ITEMS_SEARCH))
790
                                return true;
791
                }
792
                
793
                return false;
794
        }
795
        
796
        
797
        private void getDynamicItemsSearch(BinaryRankOfItemsSearch search, int lowIndex, int hightIndex) {
798
                int lowIndexSubSet2;
799
                int hightIndexSubSet2;
800
//                int lastIndex;
801
                List aux;
802

    
803
                if (isKeySensitive())
804
                {
805
                        if (lowIndex <= hightIndex)
806
                        {
807
                                if (hightIndex == (itemsSearchesShow.length - 1))
808
                                {
809
                                        aux = new Vector(hightIndex - lowIndex + 1 , 1); // Parameters: Initial Capacity and 1 -> capacity increment
810
                                        aux.addAll(Arrays.asList((this.itemsShowed.subSet(this.itemsSearchesShow[lowIndex], this.itemsSearchesShow[hightIndex])).toArray()));
811
                                        aux.add(this.itemsSearchesShow[hightIndex]);
812
                                        this.itemsSearchesShow = aux.toArray();
813
                                }
814
                                else
815
                                        this.itemsSearchesShow = (this.itemsShowed.subSet(this.itemsSearchesShow[lowIndex], this.itemsSearchesShow[hightIndex+1])).toArray();
816
                        }
817
                        else // Any items match their start with the written text
818
                                this.itemsSearchesShow = new Object[0];
819
                }
820
                else
821
                {
822
                        lowIndexSubSet2 = search.getLowIndexSecondSubSet();
823
                        hightIndexSubSet2 = search.getHightIndexSecondSubSet();
824
                        
825
                        // If any element has been found
826
                        if ((lowIndex > hightIndex) && (lowIndexSubSet2 > hightIndexSubSet2))
827
                        {
828
                                this.itemsSearchesShow = new Object[0];
829
                                return;
830
                        }
831

    
832
                        aux = new Vector();
833
                        
834
                        // Second Subset (Uppercases are first)
835
                        if (lowIndexSubSet2 <= hightIndexSubSet2)
836
                        {
837
                                if ((lowIndex != lowIndexSubSet2) && (hightIndex != hightIndexSubSet2))
838
                                {
839
                                        aux.addAll(Arrays.asList((this.itemsShowed.subSet(this.itemsSearchesShow[lowIndexSubSet2], this.itemsSearchesShow[hightIndexSubSet2])).toArray()));
840
                                        aux.add(this.itemsSearchesShow[hightIndexSubSet2]);
841
                                }
842
                        }
843
        
844
                        // First Subset (Uppercases are first)
845
                        if (lowIndex <= hightIndex)
846
                        {
847
                                aux.addAll(Arrays.asList((this.itemsShowed.subSet(this.itemsSearchesShow[lowIndex], this.itemsSearchesShow[hightIndex])).toArray()));
848
                                aux.add(this.itemsSearchesShow[hightIndex]);
849
                        }
850
                        
851
                        this.itemsSearchesShow = aux.toArray();
852
                }                
853
        }
854
        
855
        
856
        
857
        
858
        
859
        /**
860
         * This method sort the items of this component and store them on a array
861
         */
862
//        private void sortItemsCopy() {
863
//                //if ((this.getStartBehavior() == this.ORDERED_START) || (this.getSearchBehavior() == this.ORDERED_SEARCH))
864
////                if (this.alphanumericSortedSearches)
865
////                {
866
//                        this.itemsShowedDisordered = this.itemsShowed.toArray();
867
//                        Arrays.sort(this.itemsShowedDisordered);
868
//                        this.allItemsAreSorted = true;
869
////                }
870
//        }
871
        
872
        private void setItemsCopyToArray() {
873
                this.itemsSearchesShow = null;
874
                this.itemsSearchesShow = this.itemsShowed.toArray();
875
                this.itemsInTheArray = true;
876
                this.stateAllItems = STATE_ITEMS_ARE_ORDERED;
877
        }
878
        
879
        /**
880
         * This method gets the items of this component disordered and store them on a array
881
         */
882
        private void disorderItemsCopy() {
883
                if (this.getSearchBehavior() == DISORDERED_DYNAMIC_SEARCH)
884
                        Collections.shuffle(Arrays.asList(this.itemsSearchesShow)); // Disorder the items to show
885
                else
886
                {
887
//                if ((!this.maintainPositionItems) && (!this.alphanumericSortedSearches))                        
888
//                {
889
                        this.itemsSearchesShow = this.itemsShowed.toArray();
890
                        Collections.shuffle(Arrays.asList(this.itemsSearchesShow)); // Disorder the items
891
                }
892
                
893
                this.stateAllItems = STATE_ITEMS_ARE_DISORDERED;
894
//                this.allItemsAreDisordered = true;
895
//                }
896
        }
897
        
898

    
899
        private class BinaryRankOfItemsSearch {
900
                private int lowIndex;
901
                private int hightIndex;
902
                private int lowIndexSubSet2; // Only used for not keySensitive case
903
                private int hightIndexSubSet2; // Only used for not keySensitive case
904
                
905
//                private String text;
906
        
907
                public BinaryRankOfItemsSearch () {
908
                        // By default -> no search has been made
909
                        this.lowIndex = -1;
910
                        this.hightIndex = -1;
911
                        this.lowIndexSubSet2 = -1;
912
                        this.hightIndexSubSet2 = -1;
913
//                        this.text = textStart;
914
                }
915
        
916
                public void binaryRankSearch() {
917
//                        boolean finish = false;
918
                        boolean continueInLoop = true;
919
                        int mediumIndex;
920
                        int maxNumberOfIterations = (int) MathExtensionReduced.log2(itemsSearchesShow.length);
921
                        System.out.println("Number of iterations: " + maxNumberOfIterations);
922
                        int currentIteration = 0;
923
                                
924
                        this.lowIndex = 0;
925
                        this.hightIndex = itemsSearchesShow.length - 1;
926
                        
927
                        // First -> Find the first item that match its start (This is an iterational version of the binarySearch algorithm)
928
                        if (isKeySensitive())
929
                        {
930
                                // Iterational version of a binary search of the first item that it start matches with a text
931
                                while (continueInLoop)
932
                                {
933
                                        // If can't continue searching (item hasn't been found) (With this condition we avoid infinites loops)
934
                                        if (currentIteration > maxNumberOfIterations)
935
                                        {
936
//                                                this.lowIndex = 0;
937
//                                                this.hightIndex = itemsSearchesShow.length -1;
938
                                                this.lowIndex = this.hightIndex + 1; // Force not show any item after
939
                                                continueInLoop = false;                                                        
940
                                        }
941
                                        else
942
                                        {
943
                                                mediumIndex = (int) Math.floor((this.lowIndex + this.hightIndex) / 2);
944
                                                                                        
945
                                                // If has find the first item that mathes its start
946
                                                if (itemsSearchesShow[mediumIndex].toString().startsWith(writtenText))
947
                                                {
948
                                                        this.lowIndex = this.hightIndex = mediumIndex;
949
                                                        continueInLoop = false;
950
                                                }
951
                                                else
952
                                                {
953
                                                        // Reduce the rank of search
954
                                                        if (itemsSearchesShow[mediumIndex].toString().compareTo(writtenText) > 0)
955
                                                                this.hightIndex = mediumIndex - 1;                                                        
956
                                                        else
957
                                                                this.lowIndex = mediumIndex + 1;
958
                                                        
959
//                                                         If can't continue searching (item hasn't been found)
960
                                                        if (this.lowIndex > this.hightIndex)
961
                                                        {
962
//                                                                this.lowIndex = 0;
963
//                                                                this.hightIndex = itemsSearchesShow.length -1;
964

    
965
                                                                continueInLoop = false;                                                        
966
                                                        }
967
                                                        else
968
                                                                currentIteration ++;
969
                                                }
970
                                        }
971
                                }
972
                                
973
                                System.out.println("BINARY-SEARCH: Low-Index: " + this.lowIndex + "; Hight-Index: " + this.hightIndex);
974
                        }
975
                        else
976
                        {        
977
                                // Elements are ordered in this order -> First UpperCases, Second Simbols, Third LowerCases (left -> right character priority)
978
                                
979
                                // Get The first SubSet
980
                                // Iterational version of a binary search of the first item that its start matches with a text
981
                                while (continueInLoop)
982
                                {
983
                                        // If can't continue searching (item hasn't been found) (With this condition we avoid infinites loops)
984
                                        if (currentIteration > maxNumberOfIterations)
985
                                        {
986
                                                this.lowIndex = this.hightIndex + 1; // Force not show any item after
987
                                                continueInLoop = false;                                                        
988
                                        }
989
                                        else
990
                                        {
991
                                                mediumIndex = (int) Math.floor((this.lowIndex + this.hightIndex) / 2);
992
                                                                                        
993
                                                // If has find the first item that mathes its start
994
                                                if (itemsSearchesShow[mediumIndex].toString().toUpperCase().startsWith(writtenText.toUpperCase()))
995
//                                                if (itemsSearchesShow[mediumIndex].toString().toLowerCase().startsWith(writtenText.toLowerCase()))
996
                                                {
997
                                                        this.lowIndex = this.hightIndex = mediumIndex;
998
                                                        continueInLoop = false;
999
                                                }
1000
                                                else
1001
                                                {
1002
                                                        // Reduce the rank of search
1003
                                                        if (itemsSearchesShow[mediumIndex].toString().compareToIgnoreCase(writtenText) > 0) // da problemas
1004
//                                                        if (itemsSearchesShow[mediumIndex].toString().toLowerCase().compareTo(writtenText.toLowerCase()) > 0) // da problemas
1005
//                                                        if (itemsSearchesShow[mediumIndex].toString().toUpperCase().compareTo(writtenText.toUpperCase()) > 0) // da problemas
1006
                                                                this.hightIndex = mediumIndex - 1;                                                        
1007
                                                        else
1008
                                                                this.lowIndex = mediumIndex + 1;
1009
                                                        
1010
//                                                         If can't continue searching (item hasn't been found)
1011
                                                        if (this.lowIndex > this.hightIndex)
1012
                                                        {
1013
//                                                                this.lowIndex = 0;
1014
//                                                                this.hightIndex = itemsSearchesShow.length -1;
1015

    
1016
                                                                continueInLoop = false;                                                        
1017
                                                        }
1018
                                                        else
1019
                                                                currentIteration ++;
1020
                                                }
1021
                                        }
1022
                                }
1023
                        
1024
                                System.out.println("BINARY-SEARCH-FirstSubSet: Low-Index: " + this.lowIndex + "; Hight-Index: " + this.hightIndex);
1025
                                
1026
                                
1027
                                //                EL SEGUNDO SUBCONJUNTO DEBE BUSCAR S?LO LAS PALABRAS/ITEMS QUE EMPIECEN POR MAY?SCULAS!!
1028
                                // Get The second SubSet
1029
                                continueInLoop = true;
1030
                                currentIteration = 0;
1031
                                this.lowIndexSubSet2 = 0;
1032
                                this.hightIndexSubSet2 = itemsSearchesShow.length - 1;
1033

    
1034
                                // Iterational version of a binary search of the first item that its start matches with a text
1035
                                // In this case tries to find a subset of items that ther string value start with uppercase
1036
                                while (continueInLoop)
1037
                                {
1038
                                        // If can't continue searching (item hasn't been found) (With this condition we avoid infinites loops)
1039
                                        if (currentIteration > maxNumberOfIterations)
1040
                                        {
1041
                                                this.lowIndexSubSet2 = this.hightIndexSubSet2 + 1; // Force not show any item after
1042
                                                continueInLoop = false;                                                        
1043
                                        }
1044
                                        else
1045
                                        {
1046
                                                mediumIndex = (int) Math.floor((this.lowIndexSubSet2 + this.hightIndexSubSet2) / 2);
1047
                                                                                        
1048
                                                // If has find the first item that mathes its start
1049
                                                if (itemsSearchesShow[mediumIndex].toString().toUpperCase().startsWith(writtenText.toUpperCase()))
1050
//                                                if (itemsSearchesShow[mediumIndex].toString().toLowerCase().startsWith(writtenText.toLowerCase()))
1051
                                                {
1052
                                                        this.lowIndexSubSet2 = this.hightIndexSubSet2 = mediumIndex;
1053
                                                        continueInLoop = false;
1054
                                                }
1055
                                                else
1056
                                                {
1057
                                                        // Reduce the rank of search
1058
//                                                        if (itemsSearchesShow[mediumIndex].toString().compareTo(writtenText) > 0) // da problemas
1059
                                                        if (itemsSearchesShow[mediumIndex].toString().compareTo(writtenText.toUpperCase()) > 0) // da problemas
1060
        //                                                if (itemsSearchesShow[mediumIndex].toString().toUpperCase().compareTo(writtenText.toUpperCase()) > 0) // da problemas
1061
                                                                this.hightIndexSubSet2 = mediumIndex - 1;                                                        
1062
                                                        else
1063
                                                                this.lowIndexSubSet2 = mediumIndex + 1;
1064
                                                        
1065
        //                                                 If can't continue searching (item hasn't been found)
1066
                                                        if (this.lowIndexSubSet2 > this.hightIndexSubSet2)
1067
                                                        {
1068
        //                                                        this.lowIndex = 0;
1069
        //                                                        this.hightIndex = itemsSearchesShow.length -1;
1070
        
1071
                                                                continueInLoop = false;                                                        
1072
                                                        }
1073
                                                        else
1074
                                                                currentIteration ++;
1075
                                                }
1076
                                        }
1077
                                }
1078
                                
1079
                                System.out.println("BINARY-SEARCH-SecondSubSet: Low-Index: " + this.lowIndexSubSet2 + "; Hight-Index: " + this.hightIndexSubSet2);
1080
                                
1081
                                // Force not do another search of rank of items
1082
                                if ((lowIndex == lowIndexSubSet2) && (hightIndex == hightIndexSubSet2))
1083
                                        lowIndexSubSet2 = hightIndexSubSet2 + 1;
1084
                        }
1085
                                        
1086
                        
1087
                        // Second -> if indexes are the same -> search the rank of items (items are ordered in the 'itemsSearchesShow' array
1088
                        if (this.lowIndex == this.hightIndex)
1089
                        {                                
1090
                                
1091
                                if (isKeySensitive())
1092
                                {
1093
                                        // Seek down
1094
                                        this.lowIndex --;
1095
                                        if (this.lowIndex > -1)
1096
                                                continueInLoop = true;
1097
                                        else
1098
                                                continueInLoop = false;
1099

    
1100
                                        while (continueInLoop)
1101
                                        {
1102
//                                                if (itemsSearchesShow[this.lowIndex].toString().compareTo(writtenText) < 0) // No s? si esta comparaci?n o la de startsWith
1103
                                                if (!itemsSearchesShow[this.lowIndex].toString().startsWith(writtenText))
1104
                                                        continueInLoop = false; // Because items are sorted in the array 'itemsSearchesShow'
1105
                                                else
1106
                                                {
1107
                                                        this.lowIndex --;
1108
                                                        if (this.lowIndex < 0) // Because the item at the 0 position has already been verified
1109
                                                                continueInLoop = false;
1110
                                                }
1111
                                        }
1112
                                        this.lowIndex++;
1113
                                        
1114
                                        // Seek up
1115
                                        this.hightIndex ++;
1116
                                        if (this.hightIndex < itemsSearchesShow.length)
1117
                                                continueInLoop = true;
1118
                                        else
1119
                                                continueInLoop = false;
1120
                                        
1121
                                        while (continueInLoop)
1122
                                        {
1123
//                                                if (itemsSearchesShow[this.hightIndex].toString().compareTo(writtenText) > 0) // No s? si esta comparaci?n o la de startsWith
1124
                                                if (!itemsSearchesShow[this.hightIndex].toString().startsWith(writtenText)) 
1125
                                                        continueInLoop = false; // Because items are sorted in the array 'itemsSearchesShow'
1126
                                                else
1127
                                                {
1128
                                                        this.hightIndex ++;
1129
                                                        if (this.hightIndex >= itemsSearchesShow.length) // Because the item at the 0 position has already been verified
1130
                                                                continueInLoop = false;
1131
                                                }
1132
                                        }
1133
                                        this.hightIndex --;                                
1134
                                }
1135
                                else
1136
                                {
1137
                                        // Seek down
1138
                                        this.lowIndex --;
1139
                                        if (this.lowIndex > -1)
1140
                                                continueInLoop = true;
1141
                                        else
1142
                                                continueInLoop = false;
1143

    
1144
                                        while (continueInLoop)
1145
                                        {
1146
                                                //if (itemsSearchesShow[this.lowIndex].toString().toUpperCase().compareTo(writtenText.toUpperCase()) > 0) // No s? si esta comparaci?n o la de startsWith
1147
                                                if (!itemsSearchesShow[this.lowIndex].toString().toUpperCase().startsWith(writtenText.toUpperCase()))
1148
                                                        continueInLoop = false; // Because items are sorted in the array 'itemsSearchesShow'
1149
                                                else
1150
                                                {
1151
                                                        this.lowIndex --;
1152
                                                        if (this.lowIndex < 0) // Because the item at the 0 position has already been verified
1153
                                                                continueInLoop = false;
1154
                                                }
1155
                                        }
1156
                                        this.lowIndex++;
1157
                                        
1158
                                        // Seek up
1159
                                        this.hightIndex ++;
1160
                                        if (this.hightIndex < itemsSearchesShow.length)
1161
                                                continueInLoop = true;
1162
                                        else
1163
                                                continueInLoop = false;
1164
                                        
1165
                                        while (continueInLoop)
1166
                                        {
1167
                                                //if (itemsSearchesShow[this.hightIndex].toString().toUpperCase().compareTo(writtenText.toUpperCase()) < 0) // No s? si esta comparaci?n o la de startsWith
1168
                                                if (!itemsSearchesShow[this.hightIndex].toString().toUpperCase().startsWith(writtenText.toUpperCase()))
1169
                                                        continueInLoop = false; // Because items are sorted in the array 'itemsSearchesShow'
1170
                                                else
1171
                                                {
1172
                                                        this.hightIndex ++;
1173
                                                        if (this.hightIndex >= itemsSearchesShow.length) // Because the item at the 0 position has already been verified
1174
                                                                continueInLoop = false;
1175
                                                }
1176
                                        }
1177
                                        this.hightIndex --;                                        
1178
                                }                                
1179
                        }
1180
                        System.out.println("Low-Index: " + this.lowIndex + "; Hight-Index: " + this.hightIndex);
1181
                        
1182
                        
1183

    
1184
                        // This executed only for cases which isn't enabled key sensitive
1185
                        if (!isKeySensitive())
1186
                        {
1187
                                // Second -> if indexes are the same -> search the rank of items (items are ordered in the 'itemsSearchesShow' array
1188
                                if (this.lowIndexSubSet2 == this.hightIndexSubSet2)
1189
                                {                                
1190

    
1191
                                        // Seek down
1192
                                        this.lowIndexSubSet2 --;
1193
                                        if (this.lowIndexSubSet2 > -1)
1194
                                                continueInLoop = true;
1195
                                        else
1196
                                                continueInLoop = false;
1197

    
1198
                                        while (continueInLoop)
1199
                                        {
1200
                                                //if (itemsSearchesShow[this.lowIndex].toString().toUpperCase().compareTo(writtenText.toUpperCase()) > 0) // No s? si esta comparaci?n o la de startsWith
1201
                                                if (!itemsSearchesShow[this.lowIndexSubSet2].toString().toUpperCase().startsWith(writtenText.toUpperCase()))
1202
                                                        continueInLoop = false; // Because items are sorted in the array 'itemsSearchesShow'
1203
                                                else
1204
                                                {
1205
                                                        this.lowIndexSubSet2 --;
1206
                                                        if (this.lowIndexSubSet2 < 0) // Because the item at the 0 position has already been verified
1207
                                                                continueInLoop = false;
1208
                                                }
1209
                                        }
1210
                                        this.lowIndexSubSet2++;
1211
                                        
1212
                                        // Seek up
1213
                                        this.hightIndexSubSet2 ++;
1214
                                        if (this.hightIndexSubSet2 < itemsSearchesShow.length)
1215
                                                continueInLoop = true;
1216
                                        else
1217
                                                continueInLoop = false;
1218
                                        
1219
                                        while (continueInLoop)
1220
                                        {
1221
                                                //if (itemsSearchesShow[this.hightIndex].toString().toUpperCase().compareTo(writtenText.toUpperCase()) < 0) // No s? si esta comparaci?n o la de startsWith
1222
                                                if (!itemsSearchesShow[this.hightIndexSubSet2].toString().toUpperCase().startsWith(writtenText.toUpperCase()))
1223
                                                        continueInLoop = false; // Because items are sorted in the array 'itemsSearchesShow'
1224
                                                else
1225
                                                {
1226
                                                        this.hightIndexSubSet2 ++;
1227
                                                        if (this.hightIndexSubSet2 >= itemsSearchesShow.length) // Because the item at the 0 position has already been verified
1228
                                                                continueInLoop = false;
1229
                                                }
1230
                                        }
1231
                                        this.hightIndexSubSet2 --;
1232
                                }                                
1233
                                
1234
                                System.out.println("Low-Index: " + this.lowIndexSubSet2 + "; Hight-Index: " + this.hightIndexSubSet2);
1235
                        }
1236
                }
1237
        
1238
                public int getLowIndex() {
1239
                        return this.lowIndex;
1240
                }
1241
                
1242
                public int getHightIndex() {
1243
                        return this.hightIndex;
1244
                }
1245

    
1246
                // Only for not keysetsitive cases
1247
                public int getLowIndexSecondSubSet() {
1248
                        return this.lowIndexSubSet2;
1249
                }
1250
                
1251
                // Only for not keysetsitive cases
1252
                public int getHightIndexSecondSubSet() {
1253
                        return this.hightIndexSubSet2;
1254
                }
1255
        }
1256
}