Revision 6576

View differences:

trunk/libraries/libUI/src-test/org/gvsig/gui/beans/comboBoxItemsSeeker/TestJComboBoxItemsSeekerDynamic.java
147 147
				jCBSD.addItem(new Item("extJDBC"));
148 148
				jCBSD.addItem(new Item("extCAD"));
149 149
				jCBSD.addItem(new Item("appgvSig"));
150
			//	jCBSD.setSelectedItem(jCBSD.getItemAt(3)); //Test setSelectedItem
150 151
				jCBSD.addItem(new Item("extNomenclatorIGN"));
151
	//			jCBSD.addItem(new Item("extWMS"));
152
			//	jCBSD.setSelectedIndex(1); //Test setSelectedIndex
153
				jCBSD.addItem(new Item("extWMS"));
152 154
	//			jCBSD.addItem(new Item("libCorePlugin"));
153 155
	//			jCBSD.addItem(new Item("libCq CMS for java"));
154 156
	//			jCBSD.addItem(new Item("libDriverManager"));
trunk/libraries/libUI/src/org/gvsig/gui/beans/comboBoxItemsSeeker/JComboBoxItemsSeekerDynamic.java
102 102
*      -> only_One_Color -> The text on the textField only will be showed on black color (if true); false -> if the text on the textField doesn't match with any current item of this component -> the text
103 103
*            will be showed on red color
104 104
*  +   	 * @param boolean (completeMatchedItem (explicar))
105
*  + @param boolean (useBeep (explicar))
105 106
* 
106 107
* Default Values of the Flags:
107 108
*  -> maintainPositionItems -> true
......
137 138
	// CONFIGURATION FLAGS
138 139
	private boolean onlyOneColor;
139 140
	private boolean completeMatchedItem;
141
	private boolean useBeep;
140 142
	// END FLAGS
141 143
	
142 144
	// PUEDE QUE TB. sOBren
......
185 187
		this.initialize();
186 188
		
187 189
		// Set the default values of the flags
188
		onlyOneColor = false;
189
		completeMatchedItem = false; //true;
190
		this.onlyOneColor = false;
191
		this.completeMatchedItem = false; //true;
192
		this.useBeep = false; //true;
190 193
		
191 194
		// Other configuration tasks
192 195
		this.createDefaultListeners();
......
215 218
		this.model.setAlphanumericSortedSearches(alphanumeric_Sorted_Searches);
216 219
		this.model.setKeySensitive(key_Sensitive);
217 220
		this.model.setShowAllItems(false);
218
		onlyOneColor = false;
219
		completeMatchedItem = true;
221
		this.onlyOneColor = false;
222
		this.completeMatchedItem = true;
223
		this.useBeep = false; //true;
220 224
		
221 225
		if (!testFlagsConfigurationOK())
222 226
			JOptionPane.showMessageDialog(this, PluginServices.getText(this, "error_message_JComboBoxSearcheableDynamic"), PluginServices.getText(this, "exportJOP2Title"), JOptionPane.ERROR_MESSAGE);
......
235 239
	 *                           will be showed on red color)
236 240
  	 * @param boolean (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)
237 241
  	 * @param boolean (completeMatchedItem (explicar))
242
  	 * @param boolean (useBeep (explicar))
238 243
	 */
239
	public JComboBoxItemsSeekerDynamic(boolean maintain_Position_Items, boolean alphanumeric_Sorted_Searches, boolean all_Alphanumeric_Sorted, boolean key_Sensitive, boolean only_One_Color, boolean show_All_Items, boolean complete_Matched_Item) {
244
	public JComboBoxItemsSeekerDynamic(boolean maintain_Position_Items, boolean alphanumeric_Sorted_Searches, boolean all_Alphanumeric_Sorted, boolean key_Sensitive, boolean only_One_Color, boolean show_All_Items, boolean complete_Matched_Item, boolean use_Beep) {
240 245
		// Invokes to the parent class constructor		
241 246
		super();	
242 247

  
......
249 254
		this.model.setAlphanumericSortedSearches(alphanumeric_Sorted_Searches);
250 255
		this.model.setKeySensitive(key_Sensitive);
251 256
		this.model.setShowAllItems(show_All_Items);
252
		onlyOneColor = only_One_Color;
253
		completeMatchedItem = complete_Matched_Item;
257
		this.onlyOneColor = only_One_Color;
258
		this.completeMatchedItem = complete_Matched_Item;
259
		this.useBeep = use_Beep;
254 260
		
255 261
		if (!testFlagsConfigurationOK())
256 262
			JOptionPane.showMessageDialog(this, PluginServices.getText(this, "error_message_JComboBoxSearcheableDynamic"), PluginServices.getText(this, "exportJOP2Title"), JOptionPane.ERROR_MESSAGE);
......
275 281
		super.setEditable(true);
276 282
		
277 283
		// Set the last selected item -> if there isn't any item -> -1; else -> this will be 0
278
		lastSelectedIndex = -1;
279
		this.setSelectedIndex(lastSelectedIndex);
284
		this.lastSelectedIndex = -1;
285
		super.setSelectedIndex(lastSelectedIndex);
280 286
//		System.out.println("lastselecteditem: " + this.getSelectedIndex());
281 287
		
282 288
		// By default the keys Up and Down aren't pressed
283
		upOrDownKeyPressed = false;
289
		this.upOrDownKeyPressed = false;
284 290
	}
285 291
	
286 292
	/**
......
496 502
						hitBackspaceOnSelection=editor.getSelectionStart()!=editor.getSelectionEnd();
497 503
						break;
498 504
					// ignore delete key
499
					case KeyEvent.VK_DELETE :
500
						ke.consume();
501
						comboBoxReference.getToolkit().beep();
505
					case KeyEvent.VK_DELETE : // supr key in spanish keyboard
506
						// Do nothing -> use the default behavior
507
						//ke.consume();
502 508
						break;
503 509
					case KeyEvent.VK_DOWN :
504 510
					    // If the key (typed, pressed and) released has been the Down Key -> when there isn't any text (item of the list) selected, select the first
......
539 545
						showPopup();
540 546
						break;
541 547
					case KeyEvent.VK_LEFT :
542
						// Do nothing
548
						// Do nothing -> use the default behavior
543 549
						//ke.consume();
544 550
						break;
545 551
					case  KeyEvent.VK_RIGHT :
546
						// Do nothing
552
						// Do nothing -> use the default behavior
547 553
						//ke.consume();
548 554
						break;
549 555
					case  KeyEvent.VK_PAGE_DOWN :
550
						// Do nothing
556
						// Do nothing -> use the default behavior
551 557
					//	ke.consume();
552 558
						break;
553 559
					case KeyEvent.VK_PAGE_UP :
554
						// Do nothing
560
						// Do nothing -> use the default behavior
555 561
					//	ke.consume();
556
						break;
562
						break;					
557 563
					case KeyEvent.VK_TAB :
558 564
						if (model.getSize() > 0)
559 565
						{
......
566 572
							else
567 573
							{
568 574
								lastSelectedIndex = getSelectedIndex();
569
								try {
570
									document.remove(0, document.getLength());
571
									document.insertString(0, getSelectedItem().toString(), null);
572
								} catch (BadLocationException e) {
573
									// TODO Auto-generated catch block
574
									e.printStackTrace();
575
								}
575
								setSelectedIndex(lastSelectedIndex);	// Complete the item string value in the document of the editor							
576 576
							}
577 577
							
578 578
							hidePopup();
579 579
						}
580 580
						break;
581
					case KeyEvent.VK_ESCAPE :
582
						// Reset to the beginning behavior
583
						setSelectedIndex(0);
584
						highlightCompletedText(0);
585
						break;
586

  
581 587
					default:
588
						//System.out.println("Key Pressed:" + ke.getKeyCode());
582 589
						 if (editor.getText().trim().equalsIgnoreCase("")) {
583 590
							// If the current string in the JTextField of the Editor is an empty string -> hide the popup list and the reset the index
584 591
							lastSelectedIndex = -1;
......
724 731
		// Add the item to this component		
725 732
		model.addElement(anObject);
726 733
		
734
//		System.out.println("LastSelectedIndexWas: " + this.lastSelectedIndex);
727 735
		// Set the last selected item -> by default select the first item
728 736
		if (this.lastSelectedIndex == -1)
729 737
		{
......
804 812
     */
805 813
    public void setSelectedIndex(int anIndex) {
806 814
    	super.setSelectedIndex(anIndex);
815
    	
807 816
    	this.lastSelectedIndex = anIndex;
817
    	
818
    	try {
819
			document.remove(0, document.getLength());
820
			if (getSelectedIndex() > -1)
821
				document.insertString(0, getSelectedItem().toString(), null);
822
			else
823
				this.lastSelectedIndex = -1;
824
			
825
		} catch (BadLocationException e) {
826
			// TODO Auto-generated catch block
827
			e.printStackTrace();
828
		}		
808 829
    }
809 830
    
810 831
    /*
811
     * (non-Javadoc)
812
     * @see javax.swing.JComboBox#setSelectedIndex(int)
832
     *  (non-Javadoc)
833
     * @see javax.swing.JComboBox#setSelectedItem(java.lang.Object)
813 834
     */
814
//    public void setSelectedIndex(int index) {
815
//    	
816
//    }
835
    public void setSelectedItem(Object anObject) {
836
    	super.setSelectedItem(anObject);
837
    	this.lastSelectedIndex = model.getIndexOf(anObject);
838
//    	System.out.println("Posici?n: " + this.lastSelectedIndex);
839
    	
840
    	//super.setSelectedIndex(this.lastSelectedIndex);
841
    	
842
//    	try {
843
//			document.remove(0, document.getLength());
844
//			if (getSelectedIndex() > -1)
845
//				document.insertString(0, getSelectedItem().toString(), null);
846
//			else
847
//				this.lastSelectedIndex = -1;
848
//			
849
//		} catch (BadLocationException e) {
850
//			// TODO Auto-generated catch block
851
//			e.printStackTrace();
852
//		}		
853
    }
854
    
817 855
//    
818 856
    ////// END REDEFINITION OF SOME METHODS OF JCOMBOBOX //////
819 857
	
......
1034 1072
	            else
1035 1073
	            {
1036 1074
	                // User hit backspace with the cursor positioned on the start => beep
1037
	                comboBox.getToolkit().beep(); // when available use: UIManager.getLookAndFeel().provideErrorFeedback(comboBox);
1075
	            	if (useBeep)
1076
	            		comboBox.getToolkit().beep(); // when available use: UIManager.getLookAndFeel().provideErrorFeedback(comboBox);
1038 1077
	            }
1039 1078
	            
1040 1079
	            highlightCompletedText(offs);
......
1082 1121
		            offs = offs-str.length();
1083 1122
		            
1084 1123
		            // Provide feedback to the user that his input has been received but can not be accepted
1085
		            comboBox.getToolkit().beep(); // when available use: UIManager.getLookAndFeel().provideErrorFeedback(comboBox);
1124
		            if (useBeep)
1125
		            	comboBox.getToolkit().beep(); // when available use: UIManager.getLookAndFeel().provideErrorFeedback(comboBox);
1086 1126
		        }
1087 1127
		        
1088 1128
		        // Set the complete item value matched

Also available in: Unified diff