Revision 18600

View differences:

trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/comboboxitemsseeker/JComboBoxItemsSeekerConfigurable.java
125 125
	 * Has an item of the popup been selected or not by the user
126 126
	 */
127 127
	private boolean popupItemSelected;
128
	
129
	/**
130
	 * Determines if an arrow key (meanwhile down or up) has been pressed.
131
	 */
132
	private boolean arrowKeyPressed;
128 133
	// END NEW ATTRIBUTES
129 134
	
130 135
	// LISTENERS
......
226 231
		// By default user hasn't selected an item of the popup
227 232
		popupItemSelected = false;
228 233
		
234
		// By default no arrow key has been pressed
235
		arrowKeyPressed = false;
236
		
229 237
		// By default no item has been selected
230 238
		previousSelected = null;
231 239
		
......
357 365
				switch (ke.getKeyCode())
358 366
				{
359 367
					case KeyEvent.VK_ENTER :
360
						// Don't allow execute the default instructions because they have a bug (first time we remove some characteres, no item will be displayed in the popup)
368
						// Don't allow execute the default instructions because they have a bug (first time we remove some characters, no item will be displayed in the popup)
361 369
						ke.consume();
362 370

  
363 371
						// Sets the caret position of the text in the document to the end:
......
370 378
								// Select now the first item or the previous selected
371 379
								if (c_model.getSelectedItem() == null) {
372 380
									if (c_model.getData().size() > 0) {
373
										previousSelected = c_model.getDataAccordingItemsOrderFlag().elementAt(0);
381
										if (previousSelected == null)
382
											previousSelected = c_model.getDataAccordingItemsOrderFlag().elementAt(0);
383
										else {
384
											((JTextComponent) comboBoxReference.getEditor().getEditorComponent()).setText(previousSelected.toString());
385
											return;
386
										}
374 387
									}
375 388
									else {
376 389
										previousSelected = "";
......
399 412
										((JTextComponent) comboBoxReference.getEditor().getEditorComponent()).setText(previousSelected.toString());
400 413
										break;
401 414
									default:
402
										previousSelected = comboBoxReference.getItemAt(0); // Select the first
403
										comboBoxReference.setSelectedIndex(0);
415
										if (previousSelected == null) {
416
											previousSelected = comboBoxReference.getItemAt(0); // Select the first
417
											comboBoxReference.setSelectedIndex(0);
418
										}
419
										else
420
											((JTextComponent) comboBoxReference.getEditor().getEditorComponent()).setText(previousSelected.toString());
404 421
								}
405 422
							}
406 423
						}						
......
412 429
					case KeyEvent.VK_UP: case KeyEvent.VK_DOWN:
413 430
						// User selects an item of the popup using the mouse
414 431
						popupItemSelected = true;
432
						arrowKeyPressed = true;
415 433
						break;
416 434
				}
417 435
			}
......
440 458
				((JTextComponent) comboBoxReference.getEditor().getEditorComponent()).setCaretPosition(document.getLength());
441 459

  
442 460
				final DefaultComboBoxItemsSeekerConfigurableModel c_model = (DefaultComboBoxItemsSeekerConfigurableModel)comboBoxReference.getModel();
443
				
461

  
444 462
				if (toForceSelectAnItem) {
445 463
					if (c_model.isShowAllItemsInListBox()) {
446 464
						// Select now the first item or the previous selected
447 465
						if (c_model.getSelectedItem() == null) {
448 466
							if (c_model.getData().size() > 0) {
449
								previousSelected = c_model.getDataAccordingItemsOrderFlag().elementAt(0);
467
								if (previousSelected == null)
468
									previousSelected = c_model.getDataAccordingItemsOrderFlag().elementAt(0);
469
								else {
470
									((JTextComponent) comboBoxReference.getEditor().getEditorComponent()).setText(previousSelected.toString());
471
									return;
472
								}
450 473
							}
451 474
							else {
452 475
								previousSelected = "";
......
475 498
								((JTextComponent) comboBoxReference.getEditor().getEditorComponent()).setText(previousSelected.toString());
476 499
								break;
477 500
							default:
478
								previousSelected = comboBoxReference.getItemAt(0); // Select the first
479
								comboBoxReference.setSelectedIndex(0);
501
								if (previousSelected == null) {
502
									previousSelected = comboBoxReference.getItemAt(0); // Select the first
503
									comboBoxReference.setSelectedIndex(0);
504
								}
505
								else
506
									((JTextComponent) comboBoxReference.getEditor().getEditorComponent()).setText(previousSelected.toString());
480 507
						}
481 508
					}
482 509
				}
......
710 737
	    	}
711 738
	    	
712 739
	    	model.setTextWritten(textWritten);
713
	    	
740

  
714 741
	    	super.insertString(offs, str, a);
715 742

  
716 743
	    	// Update the color of the text
......
726 753
	    			showPopup();	
727 754
	    		}
728 755
	    	}
729

  
756
	    	
730 757
	    	if (caretToEnd) {
731 758
		    	// Update the caret position -> at the same place it was or at the end
732 759
		    	updateCaretPosition(textWritten.length());
......
742 769
	     * @see javax.swing.text.AbstractDocument#replace(int, int, java.lang.String, javax.swing.text.AttributeSet)
743 770
	     */
744 771
	    public void replace(int offset, int length, String text, AttributeSet attrs) throws BadLocationException {
772
			String old_textWritten;
773

  
774
    		if (arrowKeyPressed) {
775
				if (!model.isShowAllItemsInListBox())
776
					insertString(0, "", null);
777

  
778
				previousSelected = text;
779
	    		arrowKeyPressed = false;
780

  
781
	    		return;
782
	    	}
783

  
745 784
	    	// Avoid two replaces for the same operation
746 785
	    	if ((text.compareTo("") == 0) && (length == textWritten.length()))
747 786
	    		return;
748 787
	    	
749 788
	    	// Only remove if there is text to be replaced (text selected)
750 789
	    	if (length > 0) {
790

  
751 791
	    		textOfReplacement = text;
752 792
	    		remove(offset, length);
753 793
	    	}
754 794
	    	else {
755 795
	    		if ((offset > 0) && (offset != textWritten.length())) {
756 796
	    			// Must replace the model for update the data in the popup correctly
757
	    			String old_textWritten;
758 797
	    	    	
759 798
	    	    	// There is a bug that when text has been removed, the elements in the popup aren seen.
760 799
	    	    	// The solution to this bug is add them as a new model
......
815 854
	    		}
816 855
	    		else {
817 856
		    		// Default replacement
818
		    		super.replace(offset, length, text, attrs);
857
	        		super.replace(offset, length, text, attrs);
819 858
	    		}
820 859
	    	}
821 860
	    }
......
834 873
	    	updatedModel = true;
835 874

  
836 875
	    	old_textWritten = textWritten;
876
//	    	old_textWritten = ((JTextComponent) comboBoxReference.getEditor()).getText();
877
	    	
878
	    	
837 879
	    	old_caretPosition = Math.min(((JTextComponent) comboBoxReference.getEditor().getEditorComponent()).getCaretPosition(), offs);
838 880
		    
839 881
	    	textWritten = "";
trunk/libraries/libUIComponent/src/org/gvsig/gui/beans/comboboxitemsseeker/DefaultComboBoxItemsSeekerConfigurableModel.java
650 650
			return BinarySearchUsingFirstCharacters.doSearchIgnoringCaseSensitive(textWritten, alphabeticallyOrdered, stringComparator);
651 651
		}
652 652
	}
653
	
653

  
654 654
	///// END NEW METHODS /////
655
	
655

  
656 656
	///// REIMPLEMENTATION OF METHODS OF THE INTERFACE ISearchUsingFirstCharacters /////
657 657

  
658 658
	/*

Also available in: Unified diff