Revision 6716 trunk/libraries/libUI/src/org/gvsig/gui/beans/comboBoxItemsSeeker/ComboBoxItemsSeekerDynamicModel.java

View differences:

ComboBoxItemsSeekerDynamicModel.java
713 713
	private void seekDynamicItems() {
714 714
		int lowIndex;
715 715
		int hightIndex;
716
		int lowIndexSubSet2;
717
		int hightIndexSubSet2;
718
//		int lastIndex;
719
		List aux;
720 716
		
721 717
		// If doesn't have to seek items -> finish
722 718
		if (this.writtenText.compareTo("") == 0)
......
740 736
			// Get the items
741 737
			switch(this.getSearchBehavior())
742 738
			{
743
				case MAINTAIN_ORIGINAL_POSITION_DYNAMIC_SEARCH: // If maintain original position // REVISAR y HACER
739
				case MAINTAIN_ORIGINAL_POSITION_DYNAMIC_SEARCH: // If maintain original position // REVISAR y HACER					
744 740
					int numberOfItems = hightIndex - lowIndex;
745 741
					
742
					this.getDynamicItemsSearch(search, lowIndex, hightIndex);
743
					
746 744
					if (numberOfItems > 0)
747
					{
745
					{						
748 746
						int positions[] = new int[numberOfItems];
749 747
						
750 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
751 754
						for (int i = lowIndex; i < hightIndex; i++)
752 755
						{
753 756
							positions[positionArrayIndex] = super.getIndexOf(this.itemsSearchesShow[i]);
......
757 760
						
758 761
						this.itemsSearchesShow = new Object[numberOfItems]; // Remove the array
759 762
		
763
						// Get the items at the original position
760 764
						for (int i = 0; i < numberOfItems; i++)
761 765
							this.itemsSearchesShow[i] = super.getElementAt(positions[i]);	
762 766
					}
763 767
					break;
764 768
				case ORDERED_DYNAMIC_SEARCH: // If ordered			
765
//					lenght = hightIndex - lowIndex + 1;
766
//					System.out.println("CURRENT LENGHT: " + lenght);
767
//					lastIndex = (itemsSearchesShow.length - 1);
768 769
					
769
					if (isKeySensitive())
770
					{
771
						if (lowIndex <= hightIndex)
772
						{
773
							if (hightIndex == (itemsSearchesShow.length - 1))
774
							{
775
								aux = new Vector(hightIndex - lowIndex + 1 , 1); // Parameters: Initial Capacity and 1 -> capacity increment
776
								aux.addAll(Arrays.asList((this.itemsShowed.subSet(this.itemsSearchesShow[lowIndex], this.itemsSearchesShow[hightIndex])).toArray()));
777
								aux.add(this.itemsSearchesShow[hightIndex]);
778
								this.itemsSearchesShow = aux.toArray();
779
							}
780
							else
781
								this.itemsSearchesShow = (this.itemsShowed.subSet(this.itemsSearchesShow[lowIndex], this.itemsSearchesShow[hightIndex+1])).toArray();
782
						}
783
						else // Any items match their start with the written text
784
							this.itemsSearchesShow = new Object[0];
785
					}
786
					else
787
					{
788
						lowIndexSubSet2 = search.getLowIndexSecondSubSet();
789
						hightIndexSubSet2 = search.getHightIndexSecondSubSet();
790
						
791
						// If any element has been found
792
						if ((lowIndex > hightIndex) && (lowIndexSubSet2 > hightIndexSubSet2))
793
						{
794
							this.itemsSearchesShow = new Object[0];
795
							return;
796
						}
797
						
798
						aux = new Vector();
799
						
800
						if (lowIndex <= hightIndex)
801
						{
802
							aux.addAll(Arrays.asList((this.itemsShowed.subSet(this.itemsSearchesShow[lowIndex], this.itemsSearchesShow[hightIndex])).toArray()));
803
							aux.add(this.itemsSearchesShow[hightIndex]);
804
						}
805
						
806
						if (lowIndexSubSet2 <= hightIndexSubSet2)
807
						{
808
							if ((lowIndex != lowIndexSubSet2) && (hightIndex != hightIndexSubSet2))
809
							{
810
								aux.addAll(Arrays.asList((this.itemsShowed.subSet(this.itemsSearchesShow[lowIndexSubSet2], this.itemsSearchesShow[hightIndexSubSet2])).toArray()));
811
								aux.add(this.itemsSearchesShow[hightIndexSubSet2]);
812
							}
813
						}
814
						
815
						
816
						this.itemsSearchesShow = aux.toArray();
817
						
818
//							lenght += hightIndex - lowIndex + 1;
819
//						
820
//						if (lowIndexSubSet2 <= hightIndexSubSet2)
821
//							lenght += hightIndexSubSet2 - lowIndexSubSet2 + 1;
822
//						
823
//						aux = new Vector(lenght);
824
//
825
//						if
826
//						
827
//						
828
//						// The first subset
829
//						if (lowIndex <= hightIndex)
830
//						{
831
//							if (hightIndex == (itemsSearchesShow.length - 1))
832
//							{
833
//								aux = new Vector(hightIndex - lowIndex + 1 , 1); // Parameters: Initial Capacity and 1 -> capacity increment
834
//								aux.addAll(Arrays.asList((this.itemsShowed.subSet(this.itemsSearchesShow[lowIndex], this.itemsSearchesShow[hightIndex])).toArray()));
835
//								aux.add(this.itemsSearchesShow[hightIndex]);
836
//								this.itemsSearchesShow = aux.toArray();
837
//							}
838
//							else
839
//								this.itemsSearchesShow = (this.itemsShowed.subSet(this.itemsSearchesShow[lowIndex], this.itemsSearchesShow[hightIndex+1])).toArray();
840
//						}
841
//						else // Any items match their start with the written text
842
//							this.itemsSearchesShow = new Object[0];
843
//this.itemsSearchesShow = new Object[0];						
844
					}
845
					break;
846
				case DISORDERED_DYNAMIC_SEARCH: // If disordered //HACER
847
					this.disorderItemsCopy();
848
//					this.itemsSearchesShow = (this.itemsShowed.subSet(this.itemsSearchesShow[lowIndex], this.itemsSearchesShow[hightIndex])).toArray();
849
//					
850
//					if (hightIndex == (itemsSearchesShow.length - 1))
851

  
852
//					lenght = hightIndex - lowIndex + 1;
853
//					lastIndex = ;
770
					this.getDynamicItemsSearch(search, lowIndex, hightIndex);
854 771
					
855
					if (lowIndex <= hightIndex)
856
					{
857
						if (hightIndex == (itemsSearchesShow.length - 1))
858
						{
859
							aux = new Vector(hightIndex - lowIndex + 1 , 1); // Parameters: Initial Capacity and 1 -> capacity increment
860
							aux.addAll(Arrays.asList((this.itemsShowed.subSet(this.itemsSearchesShow[lowIndex], this.itemsSearchesShow[hightIndex])).toArray()));
861
							aux.add(this.itemsSearchesShow[hightIndex]);
862
							this.itemsSearchesShow = aux.toArray();
863
						}
864
						else
865
							this.itemsSearchesShow = (this.itemsShowed.subSet(this.itemsSearchesShow[lowIndex], this.itemsSearchesShow[hightIndex+1])).toArray();
866
					}
867
					else // Any items match their start with the written text
868
						this.itemsSearchesShow = new Object[0];
869
					
870 772
					break;
773
				case DISORDERED_DYNAMIC_SEARCH: // If disordered //HACER				
774

  
775
					this.getDynamicItemsSearch(search, lowIndex, hightIndex);
776
					this.disorderItemsCopy();
871 777
			}			
872 778
		}
873 779
	}	
......
887 793
		return false;
888 794
	}
889 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
	
890 859
	/**
891 860
	 * This method sort the items of this component and store them on a array
892 861
	 */
......
1008 977
				// Elements are ordered in this order -> First UpperCases, Second Simbols, Third LowerCases (left -> right character priority)
1009 978
				
1010 979
				// Get The first SubSet
1011
				// Iterational version of a binary search of the first item that it start matches with a text
980
				// Iterational version of a binary search of the first item that its start matches with a text
1012 981
				while (continueInLoop)
1013 982
				{
1014 983
					// If can't continue searching (item hasn't been found) (With this condition we avoid infinites loops)
......
1031 1000
						else
1032 1001
						{
1033 1002
							// Reduce the rank of search
1034
							if (itemsSearchesShow[mediumIndex].toString().compareTo(writtenText) > 0) // da problemas
1003
							if (itemsSearchesShow[mediumIndex].toString().compareToIgnoreCase(writtenText) > 0) // da problemas
1035 1004
//							if (itemsSearchesShow[mediumIndex].toString().toLowerCase().compareTo(writtenText.toLowerCase()) > 0) // da problemas
1036 1005
//							if (itemsSearchesShow[mediumIndex].toString().toUpperCase().compareTo(writtenText.toUpperCase()) > 0) // da problemas
1037 1006
								this.hightIndex = mediumIndex - 1;							
......
1054 1023
			
1055 1024
				System.out.println("BINARY-SEARCH-FirstSubSet: Low-Index: " + this.lowIndex + "; Hight-Index: " + this.hightIndex);
1056 1025
				
1026
				
1027
				//		EL SEGUNDO SUBCONJUNTO DEBE BUSCAR S?LO LAS PALABRAS/ITEMS QUE EMPIECEN POR MAY?SCULAS!!
1057 1028
				// Get The second SubSet
1058 1029
				continueInLoop = true;
1059 1030
				currentIteration = 0;
1060 1031
				this.lowIndexSubSet2 = 0;
1061 1032
				this.hightIndexSubSet2 = itemsSearchesShow.length - 1;
1062 1033

  
1063
				// Iterational version of a binary search of the first item that it start matches with a text
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
1064 1036
				while (continueInLoop)
1065 1037
				{
1066 1038
					// If can't continue searching (item hasn't been found) (With this condition we avoid infinites loops)
......
1084 1056
						{
1085 1057
							// Reduce the rank of search
1086 1058
//							if (itemsSearchesShow[mediumIndex].toString().compareTo(writtenText) > 0) // da problemas
1087
							if (itemsSearchesShow[mediumIndex].toString().toLowerCase().compareTo(writtenText.toLowerCase()) > 0) // da problemas
1059
							if (itemsSearchesShow[mediumIndex].toString().compareTo(writtenText.toUpperCase()) > 0) // da problemas
1088 1060
	//						if (itemsSearchesShow[mediumIndex].toString().toUpperCase().compareTo(writtenText.toUpperCase()) > 0) // da problemas
1089 1061
								this.hightIndexSubSet2 = mediumIndex - 1;							
1090 1062
							else
......
1207 1179
			}
1208 1180
			System.out.println("Low-Index: " + this.lowIndex + "; Hight-Index: " + this.hightIndex);
1209 1181
			
1182
			
1183

  
1210 1184
			// This executed only for cases which isn't enabled key sensitive
1211 1185
			if (!isKeySensitive())
1212 1186
			{

Also available in: Unified diff