Revision 6793

View differences:

trunk/libraries/libUI/src/org/gvsig/gui/beans/comboBoxItemsSeeker/JComboBoxItemsSeekerConfigurable.java
1 1
package org.gvsig.gui.beans.comboBoxItemsSeeker;
2 2

  
3 3
import java.awt.Color;
4
import java.awt.Point;
4 5
import java.awt.event.ActionEvent;
6
import java.awt.event.ActionListener;
5 7
import java.awt.event.FocusAdapter;
6 8
import java.awt.event.FocusEvent;
7 9
import java.awt.event.FocusListener;
8 10
import java.awt.event.KeyAdapter;
9 11
import java.awt.event.KeyEvent;
10 12
import java.awt.event.KeyListener;
13
import java.awt.event.MouseAdapter;
14
import java.awt.event.MouseEvent;
15
import java.awt.event.MouseListener;
11 16
import java.beans.PropertyChangeEvent;
12 17
import java.beans.PropertyChangeListener;
13 18

  
14 19
import javax.swing.ComboBoxEditor;
15 20
import javax.swing.ComboBoxModel;
21
import javax.swing.JButton;
16 22
import javax.swing.JComboBox;
17 23
import javax.swing.JOptionPane;
24
import javax.swing.event.AncestorEvent;
25
import javax.swing.event.AncestorListener;
18 26
import javax.swing.event.DocumentEvent;
19 27
import javax.swing.event.DocumentListener;
20 28
import javax.swing.event.ListDataEvent;
21 29
import javax.swing.event.ListDataListener;
22 30
import javax.swing.event.PopupMenuEvent;
23 31
import javax.swing.event.PopupMenuListener;
32
import javax.swing.event.UndoableEditEvent;
33
import javax.swing.event.UndoableEditListener;
24 34
import javax.swing.text.AttributeSet;
25 35
import javax.swing.text.BadLocationException;
26 36
import javax.swing.text.JTextComponent;
27 37
import javax.swing.text.PlainDocument;
38
import javax.swing.undo.UndoManager;
28 39

  
29 40
import org.apache.log4j.Logger;
30 41

  
......
123 134
public class JComboBoxItemsSeekerConfigurable extends JComboBox implements java.io.Serializable {
124 135
	//private static final long serialVersionUID = -1853812970336818959L;
125 136
	// PONER SERIALIZACI?N
126

  
137
	
127 138
	// eSTAS HAY QUE BORRARLAS!
128 139
/*	private Vector defaultItems;
129 140
	private Set notRemovedItems;
......
162 173
	
163 174
	// Some listeners for the Control between the View and de Model
164 175
	private KeyListener editorKeyListener;
176
	private MouseAdapter editorMouseListener;
165 177
	private FocusListener editorFocusListener;
166 178
	private DocumentListener documentListener;
167 179
	private ListDataListener modelListDataListener;
168 180
	private PopupMenuListener popupMenuListener;
181
	private PropertyChangeListener editionMenuListener;
169 182
	
183
	
170 184
	// Reference to the document of the Editor of this component for optimize the seeks
171 185
	private PlainDocumentSeeker document;
172 186
	
......
178 192
	private boolean lastWasTheBeginningState;
179 193
	private boolean lastWasPressedAKeyModifier;
180 194
	private boolean popupWillBeVisible;
195
	private boolean optionsEditorWasVisible;
181 196
//	private boolean keyPressed;
182 197
//	private boolean updatePopUp;
183 198
//	private boolean upOrDownKeyPressed;
......
191 206
	private boolean hitBackspaceOnSelection;
192 207
	private boolean allowedRepeatedItems;
193 208
	
194
	// TRAZA - DEBUG
209
	// TRACE - DEBUG
195 210
	private Logger logger = Logger.getLogger(JComboBoxItemsSeekerConfigurable.class.getClass());
196

  
211
	// END TRACE - DEBUG
197 212
	
213
//	OptionsEditionByMouse optionsEditionByMouse = new OptionsEditionByMouse();
214
	OptionsEditionByMouse optionsEditionByMouse;
215
//	OptionsEditionByMouseV2 pme = new OptionsEditionByMouseV2();
216
	
217
	// UNDO-REDO
218
//	protected UndoManager undo = new UndoManager();
219
	// END UNDO-REDO	
220
	
198 221
	/**
199 222
	 * Default Constructor
200 223
	 */
......
214 237
		this.createDefaultListeners();
215 238
		this.configure();
216 239
		//this.configure();
240
		
241

  
217 242
	}
218 243
	
219 244
	/**
......
339 364
		popupWillBeVisible = false;
340 365
		
341 366
		
367
		
342 368
		hitBackspace=false;
343 369
		
370
		optionsEditionByMouse = new OptionsEditionByMouse();
371
		optionsEditorWasVisible = false;
372
		
344 373
//		// By default any key has been pressed
345 374
//		keyPressed = false;
346 375
		
......
349 378
		
350 379
		// Remove the default mouse listener
351 380
//		super.removeMouseListener(super.getMouseListeners()[0]);
381
		
382
		
352 383
	}
353 384
	
354 385
	/**
......
357 388
	private void createDefaultListeners() {
358 389
		// TODO Auto-generated method stub		
359 390
		
391
		this.defineEditionMenuPropertyChangeListener(this);
392
		
360 393
        // Define the key listener for the editor of this component
361 394
        this.defineEditorKeyListener(this);
362 395
         
363 396
        // Define the focus listener for the editor of this component
364 397
        this.defineEditorFocusListener(this);
365 398
        
399
        this.defineEditorMouseListener(this);
400
        
366 401
        // Define a document listener for changes of text
367 402
        this.defineDocumentListener();
368 403
         
......
373 408
        this.definePopUpMenuListener(this);
374 409
	}
375 410
	
411
	private void defineEditionMenuPropertyChangeListener(JComboBoxItemsSeekerConfigurable combo_Box) {
412
		final JComboBoxItemsSeekerConfigurable comboBoxReference = combo_Box;
413
		editionMenuListener = new PropertyChangeListener() {
414

  
415
			public void propertyChange(PropertyChangeEvent arg0) {
416
				// TODO Auto-generated method stub
417

  
418
				if (arg0.getPropertyName().equals(OptionsEditionByMouse.SELECTEDOPTION)) {
419
	            	JTextComponent editor = (JTextComponent) comboBoxReference.getEditor().getEditorComponent();
420
		
421
	            	logger.debug("PropertyChanged: " + arg0.getNewValue().toString());
422
					
423
			          switch(Integer.parseInt(arg0.getNewValue().toString()))
424
			          {//HACER!!
425
				          case OptionsEditionByMouse.UNDO:
426
				        	  break;
427
				          case OptionsEditionByMouse.REDO:
428
				        	  break;
429
				          case OptionsEditionByMouse.CUT:
430
				        	  break;
431
				          case OptionsEditionByMouse.COPY:
432
				        	  break;
433
				          case OptionsEditionByMouse.PASTE:
434
				        	  break;
435
				          case OptionsEditionByMouse.DELETE:				        	 
436
				        	  deleteTextLogic(editor);
437
				        	  break;
438
				          case OptionsEditionByMouse.SELECT_ALL:
439
				        	  editor.selectAll();
440
				        	  break;
441
				          default: // do anything
442
			          }
443
				}
444
				else
445
				{
446
					if (arg0.getPropertyName().equals(OptionsEditionByMouse.VISIBILITYCHANGED))
447
					{
448
						logger.debug("PropertyChanged: " + arg0.getNewValue().toString());
449
						
450
						// First True, after False (when false -> optionsEditorWasVisible = true)
451
						if (!optionsEditionByMouse.isVisible())
452
							optionsEditorWasVisible = true;
453
						else
454
							optionsEditorWasVisible = false;
455
					}
456
				}
457
			}			
458
		};
459
	}
460
	
461
	
376 462
	/**
377 463
	 *  Define a document listener for changes of text
378 464
	 */
......
440 526
		// Configure the popup of this component
441 527
		this.configurePopUp();
442 528
		
529
		this.configureOptionsEditionByMouse();		
530
		
443 531
	}
444 532
	
533
	private void configureOptionsEditionByMouse() {
534
		this.optionsEditionByMouse.addPropertyChangeListener(editionMenuListener);
535
//		optionsEditionByMouse.addPropertyChangeListener(OptionsEditionByMouse.PROPERTYNAME, editionMenuListener);
536
	}
537
	
445 538
	/**
446 539
	 * 
447 540
	 *
......
553 646
		// Highlight whole text when gaining focus
554 647
		editorFocusListener = new FocusAdapter() {
555 648
			public void focusGained(FocusEvent e) {
556
				highlightCompletedText(0);
557
				logger.debug("currentShowState: " + currentShowState);
558
				logger.debug("EDITOR FOCUS GAINED");
559
				
560
				// This is used when the component has lost the focus, the popup whas in show state and is restored the focus -> update the popup
561
				//if (() && (currentShowState != BEGINNING_VIEW_STATE))
562
				if (popupWillBeVisible)
649
				if (!optionsEditorWasVisible)
563 650
				{
564
					logger.debug("UPDATE POPUP DESDE EL FOCUSGAINED");
565
					comboBoxReference.updatePopUpView();
651
					highlightCompletedText(0);
652
					logger.debug("currentShowState: " + currentShowState);
653
					logger.debug("EDITOR FOCUS GAINED");
654
					
655
					// This is used when the component has lost the focus, the popup whas in show state and is restored the focus -> update the popup
656
					//if (() && (currentShowState != BEGINNING_VIEW_STATE))
657
					if (popupWillBeVisible)
658
					{
659
						logger.debug("UPDATE POPUP DESDE EL FOCUSGAINED");
660
						comboBoxReference.updatePopUpView();
661
					}
566 662
				}
567 663
			}
568 664
			
......
579 675
			}
580 676
		};
581 677
	}
678
	
679
	private void defineEditorMouseListener(JComboBoxItemsSeekerConfigurable combo_Box) {
680
		final JComboBoxItemsSeekerConfigurable comboBoxReference = combo_Box;
681
		editorMouseListener = new MouseAdapter() {
682
		
683
			public void mouseReleased(MouseEvent e) {
684
				logger.debug("MOUSE-LISTENER : MOUSE-PRESSED!" + e.getButton());
582 685

  
686
				
687
	            if (e.isPopupTrigger()) {
688
	            	JTextComponent editor = (JTextComponent) comboBoxReference.getEditor().getEditorComponent();
689

  
690
//	            	editor.selectAll();
691
	            	
692
	            	// By default disable all options
693
	            	optionsEditionByMouse.setEnabledAllOptions(false);
694
	            	
695
	            	// Habilitar las opciones disponibles (HACER!!)            	
696
	            	
697
	            	
698
	            	//Habilitar "eliminar" si hay texto seleccionado
699
	            	if (editor.getCaretPosition() != editor.getCaret().getMark())
700
	            		optionsEditionByMouse.setEnabledDeleteOption(true);
701
	            	
702
	            	// Enable the "Select-All" option (by default it's always enabled)
703
	            	optionsEditionByMouse.setEnabledSelectAllOption(true);
704
	            	
705
					optionsEditionByMouse.setLocation((int)comboBoxReference.getLocationOnScreen().getX() + e.getX(), (int)comboBoxReference.getLocationOnScreen().getY() + e.getY());
706
	            	optionsEditionByMouse.setInvoker(comboBoxReference);
707
	            	optionsEditionByMouse.setVisible(true);
708
//	            	optionsEditorWasVisible = true;
709
	            }
710
	        }
711
		};
712
	}
713

  
583 714
	/**
584 715
	 * 
585 716
	 */
......
667 798
	//							textKeyPressed = true; 
668 799
				
669 800
															
670
								// Remove selected text:
671
								logger.debug("GETMARK: " + editor.getCaret().getMark() + "GETCARETPOSITION" + editor.getCaretPosition());
672
	
673
								try {
674
									// If no characters are selected
675
									if (editor.getCaret().getMark() == editor.getCaretPosition())
676
									{
677
										// Remove the character which is on the right of the caret position
678
										if (editor.getCaretPosition() < document.getLength())									
679
											document.remove(editor.getCaretPosition(), 1);										
680
									}
681
									else // If there are characters selected
682
									{
683
										// Remove the characters which are selected
684
		//								int documentLength = document.getLength();
685
										int length = Math.abs(editor.getCaret().getMark() - editor.getCaretPosition());
686 801
										
687
										// Remove the characters which are selected
688
										document.remove(Math.min(editor.getCaret().getMark(), editor.getCaretPosition()), length);
689
									}
690
								} catch (BadLocationException e) {
691
									// TODO Auto-generated catch block
692
									e.printStackTrace();
693
								}
694
															
695
								switch(currentShowState)
696
								{
697
									case START_VIEW_STATE :
698
										if (document.getLength() > 0)
699
										{										
700
											// If dynamic searches:
701
											try {
702
												// If the search will be dynamic:
703
												if (isDynamicSearchConfiguration())
704
												{
705
													model.setWrittenText(document.getText(0, document.getLength()));
706
													logger.debug("Texto que se le env?a al modelo desde SUPR: ->" + document.getText(0, document.getLength()) + "<-");						
707
												}
708
											} catch (BadLocationException e) {
709
												// TODO Auto-generated catch block
710
												e.printStackTrace();
711
											}									
712
										
713
											// Indicate to the model that now is disabled the start view
714
											if (currentShowState == START_VIEW_STATE)
715
											{
716
												model.setStartViewFlag(false);
717
												currentShowState = SEARCH_VIEW_STATE;
718
				//								updateLastSelectionItem();
719
											}
720
										}
721
										break;
722
									case SEARCH_VIEW_STATE :
723
										 // If there isn't characters
724
										if (document.getLength() == 0)
725
										{
726
											// This instruction avoids popup could failure when got invisible
727
											hidePopup();
728
											
729
											// If it's a dynamic search
730
											if (isDynamicSearchConfiguration())
731
											{
732
												model.setWrittenText("");
733
												logger.debug("Texto que se le env?a al modelo desde SUPR: ->\"\"<-");
734
											}
735
											
736
											// Return to the start view state
737
											model.setStartViewFlag(true);
738
											currentShowState = START_VIEW_STATE;
739
	
740
											// Select the first Item 
741
											setSelectedIndex(0);
742
	
743
											highlightCompletedText(0);
744
										}
745
										else
746
										{
747
											// If dynamic searches:
748
											try {
749
												// If the search will be dynamic:
750
												if (isDynamicSearchConfiguration())
751
												{
752
													model.setWrittenText(document.getText(0, document.getLength()));
753
													logger.debug("Texto que se le env?a al modelo desde SUPR: ->" + document.getText(0, document.getLength()) + "<-");						
754
												}
755
											} catch (BadLocationException e) {
756
												// TODO Auto-generated catch block
757
												e.printStackTrace();
758
											}
759
										}									
760
										break;									
761
								}
802
								deleteTextLogic(editor);
762 803
								
763
//								// Update the selected item
804
//								// Remove selected text:
805
//								logger.debug("GETMARK: " + editor.getCaret().getMark() + "GETCARETPOSITION" + editor.getCaretPosition());
806
//	
764 807
//								try {
765
//									document.insertString(0, document.getText(0, document.getLength()), null);
766
//								} catch (BadLocationException e3) {
767
//									// TODO Auto-generated catch block
768
//									e3.printStackTrace();
769
//								}
770
								
771
//	//							 If we remove characters by default if we use two color -> set color red ; and if the item would match in the lookUp algorithm of the PlainDocumentSeeker
772
//								//    text will be on black color
773
//						        if (!isOnlyOneColor())
774
//						        {
775
//									if (isCaseSensitive())
808
//									// If no characters are selected
809
//									if (editor.getCaret().getMark() == editor.getCaretPosition())
776 810
//									{
777
////										try {
778
////											if (document.getText(0, document.getLength()).compareTo(getSelectedItem().toString()) == 0)
779
//											if (getSelectedIndex() != -1)
780
//												comboBoxReference.getEditor().getEditorComponent().setForeground(Color.BLACK);
781
//											else
782
//												comboBoxReference.getEditor().getEditorComponent().setForeground(Color.RED);
783
////										} catch (BadLocationException e2) {
784
////											// TODO Auto-generated catch block
785
////											e2.printStackTrace();
786
////										}
811
//										// Remove the character which is on the right of the caret position
812
//										if (editor.getCaretPosition() < document.getLength())									
813
//											document.remove(editor.getCaretPosition(), 1);										
787 814
//									}
788
//									else
815
//									else // If there are characters selected
789 816
//									{
790
////										try {
791
////											if (document.getText(0, document.getLength()).compareToIgnoreCase(getSelectedItem().toString()) == 0)
792
//											if (getSelectedIndex() != -1)
793
//											  	comboBoxReference.getEditor().getEditorComponent().setForeground(Color.BLACK);
794
//											else
795
//												comboBoxReference.getEditor().getEditorComponent().setForeground(Color.RED);
796
////										} catch (BadLocationException e2) {
797
////											// TODO Auto-generated catch block
798
////											e2.printStackTrace();
799
////										}
817
//										// Remove the characters which are selected
818
//		//								int documentLength = document.getLength();
819
//										int length = Math.abs(editor.getCaret().getMark() - editor.getCaretPosition());
820
//										
821
//										// Remove the characters which are selected
822
//										document.remove(Math.min(editor.getCaret().getMark(), editor.getCaretPosition()), length);
800 823
//									}
801
//						        }
824
//								} catch (BadLocationException e) {
825
//									// TODO Auto-generated catch block
826
//									e.printStackTrace();
827
//								}
828
//								
829
//								switch(currentShowState)
830
//								{
831
//									case START_VIEW_STATE :
832
//										if (document.getLength() > 0)
833
//										{										
834
//											// If dynamic searches:
835
//											try {
836
//												// If the search will be dynamic:
837
//												if (isDynamicSearchConfiguration())
838
//												{
839
//													model.setWrittenText(document.getText(0, document.getLength()));
840
//													logger.debug("Texto que se le env?a al modelo desde SUPR: ->" + document.getText(0, document.getLength()) + "<-");						
841
//												}
842
//											} catch (BadLocationException e) {
843
//												// TODO Auto-generated catch block
844
//												e.printStackTrace();
845
//											}									
846
//										
847
//											// Indicate to the model that now is disabled the start view
848
//											if (currentShowState == START_VIEW_STATE)
849
//											{
850
//												model.setStartViewFlag(false);
851
//												currentShowState = SEARCH_VIEW_STATE;
852
//				//								updateLastSelectionItem();
853
//											}
854
//										}
855
//										break;
856
//									case SEARCH_VIEW_STATE :
857
//										 // If there isn't characters
858
//										if (document.getLength() == 0)
859
//										{
860
//											// This instruction avoids popup could failure when got invisible
861
//											hidePopup();
862
//											
863
//											// If it's a dynamic search
864
//											if (isDynamicSearchConfiguration())
865
//											{
866
//												model.setWrittenText("");
867
//												logger.debug("Texto que se le env?a al modelo desde SUPR: ->\"\"<-");
868
//											}
869
//											
870
//											// Return to the start view state
871
//											model.setStartViewFlag(true);
872
//											currentShowState = START_VIEW_STATE;
873
//	
874
//											// Select the first Item 
875
//											setSelectedIndex(0);
876
//	
877
//											highlightCompletedText(0);
878
//										}
879
//										else
880
//										{
881
//											// If dynamic searches:
882
//											try {
883
//												// If the search will be dynamic:
884
//												if (isDynamicSearchConfiguration())
885
//												{
886
//													model.setWrittenText(document.getText(0, document.getLength()));
887
//													logger.debug("Texto que se le env?a al modelo desde SUPR: ->" + document.getText(0, document.getLength()) + "<-");						
888
//												}
889
//											} catch (BadLocationException e) {
890
//												// TODO Auto-generated catch block
891
//												e.printStackTrace();
892
//											}
893
//										}									
894
//										break;									
895
//								}
896
//								
897
//								updatePopUpView();
802 898
								
803
								updatePopUpView();
804
								
805 899
								break;
806 900
							case KeyEvent.VK_ENTER :
807 901
		//						try {
......
890 984
		//						lastSelectedIndex = getSelectedIndex();
891 985
								selectedItem = getSelectedItem();
892 986
								showPopup();
987
								
893 988
								break;
894 989
							case KeyEvent.VK_UP :
895 990
							    // If the key (typed, pressed and) released has been the Up Key -> when there isn't any text (item of the list) selected, select the last
......
1155 1250
								break;
1156 1251
							case KeyEvent.VK_ALT_GRAPH : // Do nothing
1157 1252
								break;
1158
							case KeyEvent.VK_ALT : // Do nothing
1253
							case KeyEvent.VK_ALT : // Do nothing			
1159 1254
								break;
1160 1255
							case KeyEvent.VK_CONTROL : // Do nothing
1161 1256
								break;
......
1240 1335
//		keyPressed = false;
1241 1336
	}
1242 1337
	
1338
	private void deleteTextLogic(JTextComponent editor) {
1339
		
1340
		// Remove selected text:
1341
		logger.debug("GETMARK: " + editor.getCaret().getMark() + "GETCARETPOSITION" + editor.getCaretPosition());
1342

  
1343
		try {
1344
			// If no characters are selected
1345
			if (editor.getCaret().getMark() == editor.getCaretPosition())
1346
			{
1347
				// Remove the character which is on the right of the caret position
1348
				if (editor.getCaretPosition() < document.getLength())									
1349
					document.remove(editor.getCaretPosition(), 1);										
1350
			}
1351
			else // If there are characters selected
1352
			{
1353
				// Remove the characters which are selected
1354
//								int documentLength = document.getLength();
1355
				int length = Math.abs(editor.getCaret().getMark() - editor.getCaretPosition());
1356
				
1357
				// Remove the characters which are selected
1358
				document.remove(Math.min(editor.getCaret().getMark(), editor.getCaretPosition()), length);
1359
			}
1360
		} catch (BadLocationException e) {
1361
			// TODO Auto-generated catch block
1362
			e.printStackTrace();
1363
		}
1364

  
1365
		
1366
		switch(currentShowState)
1367
		{
1368
			case START_VIEW_STATE :
1369
				if (document.getLength() > 0)
1370
				{										
1371
					// If dynamic searches:
1372
					try {
1373
						// If the search will be dynamic:
1374
						if (isDynamicSearchConfiguration())
1375
						{
1376
							model.setWrittenText(document.getText(0, document.getLength()));
1377
							logger.debug("Texto que se le env?a al modelo desde SUPR: ->" + document.getText(0, document.getLength()) + "<-");						
1378
						}
1379
					} catch (BadLocationException e) {
1380
						// TODO Auto-generated catch block
1381
						e.printStackTrace();
1382
					}									
1383
				
1384
					// Indicate to the model that now is disabled the start view
1385
					if (currentShowState == START_VIEW_STATE)
1386
					{
1387
						model.setStartViewFlag(false);
1388
						currentShowState = SEARCH_VIEW_STATE;
1389
//								updateLastSelectionItem();
1390
					}
1391
				}
1392
				break;
1393
			case SEARCH_VIEW_STATE :
1394
				 // If there isn't characters
1395
				if (document.getLength() == 0)
1396
				{
1397
					// This instruction avoids popup could failure when got invisible
1398
					hidePopup();
1399
					
1400
					// If it's a dynamic search
1401
					if (isDynamicSearchConfiguration())
1402
					{
1403
						model.setWrittenText("");
1404
						logger.debug("Texto que se le env?a al modelo desde SUPR: ->\"\"<-");
1405
					}
1406
					
1407
					// Return to the start view state
1408
					model.setStartViewFlag(true);
1409
					currentShowState = START_VIEW_STATE;
1410

  
1411
					// Select the first Item 
1412
					setSelectedIndex(0);
1413

  
1414
					highlightCompletedText(0);
1415
				}
1416
				else
1417
				{
1418
					// If dynamic searches:
1419
					try {
1420
						// If the search will be dynamic:
1421
						if (isDynamicSearchConfiguration())
1422
						{
1423
							model.setWrittenText(document.getText(0, document.getLength()));
1424
							logger.debug("Texto que se le env?a al modelo desde SUPR: ->" + document.getText(0, document.getLength()) + "<-");						
1425
						}
1426
					} catch (BadLocationException e) {
1427
						// TODO Auto-generated catch block
1428
						e.printStackTrace();
1429
					}
1430
				}									
1431
				break;									
1432
		}
1433
		
1434
		updatePopUpView();
1435
		
1436
	}
1437
	
1243 1438
	/**
1244 1439
	 * 
1245 1440
	 */
......
1272 1467
				logger.debug("MenuBECOMEINVISIBLE");
1273 1468
//				popupVisible = false;
1274 1469
				
1470
			
1471
//				if ((!textKeyPressed) && (!optionsEditorWasVisible))
1275 1472
				if (!textKeyPressed)
1276 1473
				{
1277 1474
					if (lastSelectedItem != null)
......
1365 1562
		// Remove the default or last keyListener and FocusListener of the editor of this component
1366 1563
        if (editor != null) {
1367 1564
            editor.removeKeyListener(this.editorKeyListener);
1368
//            editor.removeMouseListener(this.editorMouseListener);
1565
            editor.removeMouseListener(this.editorMouseListener);
1369 1566
            editor.removeFocusListener(this.editorFocusListener);            
1370 1567
        }
1371 1568
        
......
1375 1572
        if (newEditor != null) {
1376 1573
            editor = (JTextComponent) newEditor.getEditorComponent();
1377 1574
            editor.addKeyListener(this.editorKeyListener);
1378
//            editor.addMouseListener(this.editorMouseListener);
1575
            editor.addMouseListener(this.editorMouseListener);
1379 1576
            editor.addFocusListener(this.editorFocusListener);
1380 1577
            editor.setDocument(this.document);
1381 1578
            
1382 1579
    		// Disable the focus transversal keys (Example: CTRL+TAB) for enable the TAB key
1383 1580
    		editor.setFocusTraversalKeysEnabled(false);
1384 1581
        }
1582
        
1583
//        editor.add(optionsEditionByMouse);
1584
//        ((JButton)this.getComponent(0)).add(optionsEditionByMouse);
1385 1585
	}
1386 1586
	
1387 1587
	/**
......
1758 1958
	
1759 1959
	////// END METHODS FOR THE BEHAVIOR FLAGS  //////
1760 1960
	
1961
	////// IMPLEMENTATION OF THE METHODS OF THE INTERFACE 'PropertyChangeListener' //////
1962
	/* (non-Javadoc)
1963
	 * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
1964
	 */
1965
//	public void propertyChange(PropertyChangeEvent arg0) {
1966
//		// TODO Auto-generated method stub
1967
//    	logger.debug("AAAAAAAAA");
1968
//
1969
//		if (arg0.getPropertyName().equals(OptionsEditionByMouse.PROPERTYNAME)) {
1970
//        	JTextComponent editor = (JTextComponent) getEditor().getEditorComponent();
1971
//
1972
//        	logger.debug("PropertyChanged: " + arg0.getNewValue().toString());
1973
//			
1974
//	          switch(Integer.parseInt(arg0.getNewValue().toString()))
1975
//	          {//HACER!!
1976
//		          case OptionsEditionByMouse.UNDO:
1977
//		        	  break;
1978
//		          case OptionsEditionByMouse.REDO:
1979
//		        	  break;
1980
//		          case OptionsEditionByMouse.CUT:
1981
//		        	  break;
1982
//		          case OptionsEditionByMouse.COPY:
1983
//		        	  break;
1984
//		          case OptionsEditionByMouse.PASTE:
1985
//		        	  break;
1986
//		          case OptionsEditionByMouse.DELETE:
1987
//		        	  try {
1988
//						document.remove(0, document.getLength());
1989
//					} catch (BadLocationException e) {
1990
//						// TODO Auto-generated catch block
1991
//						e.printStackTrace();
1992
//					}
1993
//		        	  break;
1994
//		          case OptionsEditionByMouse.SELECT_ALL:
1995
//		        	  break;
1996
//		          default: // do anything
1997
//	          }
1998
//		}
1999
//
2000
//	}
2001

  
2002
	////// END IMPLEMENTATION OF THE METHODS OF THE INTERFACE 'PropertyChangeListener' //////
1761 2003
	
1762 2004
	/** REVISAR COMENTARIOS Y C?DIGO
1763 2005
	 * Inner class for optimize the seek of items
......
1768 2010
	private class PlainDocumentSeeker extends PlainDocument{
1769 2011
		private JComboBoxItemsSeekerConfigurable comboBox;
1770 2012

  
2013

  
1771 2014
		/**
1772 2015
		 * Default Constructor
1773 2016
		 */
1774 2017
		public PlainDocumentSeeker() {
1775 2018
			super();
2019
			
2020
//			// Add an Undo - Redo Listener
2021
//			this.addUndoableEditListener(new MyUndoableEditListener());
1776 2022
		}
1777 2023
		
1778 2024
		/**
......
2165 2411
	    		return str1.toUpperCase().startsWith(str2.toUpperCase());
2166 2412
	    }
2167 2413
	}
2414

  
2415

  
2416

  
2417

  
2418
	
2419
//	// UNDO - REDO
2420
//	protected class MyUndoableEditListener implements UndoableEditListener {
2421
//		/* (non-Javadoc)
2422
//		 * @see javax.swing.event.UndoableEditListener#undoableEditHappened(javax.swing.event.UndoableEditEvent)
2423
//		 */
2424
//		public void undoableEditHappened(UndoableEditEvent arg0) {
2425
//			// TODO Auto-generated method stub
2426
//			logger.debug("UNDO-REDO: " + arg0.toString());
2427
////			Recuerda la edici?n y actualiza los men?s
2428
////	        undo.addEdit(arg0.getEdit());
2429
////	        undoAction.update();
2430
////	        redoAction.update();
2431
//		}
2432
//	}  
2168 2433
}
trunk/libraries/libUI/src/org/gvsig/gui/beans/comboBoxItemsSeeker/OptionsEditionByMouse.java
1
package org.gvsig.gui.beans.comboBoxItemsSeeker;
2

  
3
import java.awt.event.ActionEvent;
4
import java.awt.event.ActionListener;
5
import java.beans.PropertyChangeListener;
6
import java.beans.PropertyChangeSupport;
7
import java.util.HashMap;
8

  
9
import com.iver.andami.PluginServices;
10

  
11
import javax.swing.ImageIcon;
12
import javax.swing.JMenuItem;
13
import javax.swing.JPopupMenu;
14
import javax.swing.border.BevelBorder;
15

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

  
57

  
58
/** EN DESARROLLO
59
 * 
60
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
61
 *
62
 * The icons used are from the opensource 'Tango Icon Library' project (http://tango.freedesktop.org/Tango_Icon_Library)
63
 */
64
//public class OptionsEditionByMouse extends JPopUpMenu{ // No s? si JPopUpMenu o JPopupMenu
65
public class OptionsEditionByMouse extends JPopupMenu{
66
	// Hacer que sea serializable cuando est? acabado
67

  
68
	private JMenuItem jMenuItemUndo = null;
69
	private JMenuItem jMenuItemRedo = null;
70
	private JMenuItem jMenuItemCut = null;
71
	private JMenuItem jMenuItemCopy = null;
72
	private JMenuItem jMenuItemPaste = null;
73
	private JMenuItem jMenuItemDelete = null;
74
	private JMenuItem jMenuItemSelectAll = null;
75
	public static final int DEFAULT = 0;
76
	public static final int UNDO = 1;
77
	public static final int REDO = 2;
78
	public static final int CUT = 3;
79
	public static final int COPY = 4;
80
	public static final int PASTE = 5;
81
	public static final int DELETE = 6;
82
	public static final int SELECT_ALL = 7;
83
	public static final int VISIBILITY = 8;
84
	public static final String SELECTEDOPTION = "SelectedOption";
85
	public static final String VISIBILITYCHANGED = "Visibility";
86
	
87
	private HashMap map;
88

  
89
	private PropertyChangeSupport changes = new PropertyChangeSupport(this);
90

  
91
    public void addPropertyChangeListener(PropertyChangeListener l) {
92
      changes.addPropertyChangeListener(l);
93
    }
94
    public void removePropertyChangeListener(PropertyChangeListener l) {
95
      changes.removePropertyChangeListener(l);
96
    }
97

  
98

  
99
	
100
	/**
101
	 * This method initializes 
102
	 * 
103
	 */
104
	public OptionsEditionByMouse() {
105
		super();
106
		initialize();
107
	}
108

  
109
	/**
110
	 * This method initializes this
111
	 * 
112
	 */
113
	private void initialize() {
114
        map = new HashMap();
115
        this.add(getJMenuItemUndo());
116
        this.add(getJMenuItemRedo());
117
        this.addSeparator();
118
        this.add(getJMenuItemCut());
119
        this.add(getJMenuItemCopy());
120
        this.add(getJMenuItemPaste());
121
        this.add(getJMenuItemDelete());
122
        this.addSeparator();
123
        this.add(getJMenuItemSelectAll());
124
        this.setLabel("Edition");
125
        this.setBorder(new BevelBorder(BevelBorder.RAISED));
126
	}
127
	
128
	/**
129
	 * This method initializes jMenuItemUndo	
130
	 * 	
131
	 * @return javax.swing.JMenuItem	
132
	 */
133
	private JMenuItem getJMenuItemUndo() {
134
		if (jMenuItemUndo == null) {
135
			ImageIcon undoIcon = new ImageIcon("images/edit-undo.png", PluginServices.getText(null, "edit_undo"));
136
			jMenuItemUndo = new JMenuItem(PluginServices.getText(null, "edit_undo"), undoIcon);
137
			jMenuItemUndo.setHorizontalTextPosition(JMenuItem.RIGHT);
138
//			changes.firePropertyChange(this.PROPERTYNAME, this.DEFAULT, this.UNDO);
139
			jMenuItemUndo.addActionListener(menuListener);
140
			map.put(PluginServices.getText(null, "edit_undo"), new Integer(this.UNDO));
141
		}
142
		return jMenuItemUndo;
143
	}
144

  
145
	/**
146
	 * This method initializes jMenuItemRedo	
147
	 * 	
148
	 * @return javax.swing.JMenuItem	
149
	 */
150
	private JMenuItem getJMenuItemRedo() {
151
		if (jMenuItemRedo == null) {
152
			ImageIcon redoIcon = new ImageIcon("images/edit-redo.png", PluginServices.getText(null, "edit_redo"));
153
			jMenuItemRedo = new JMenuItem(PluginServices.getText(null, "edit_redo"), redoIcon);
154
			jMenuItemRedo.setHorizontalTextPosition(JMenuItem.RIGHT);
155
//			changes.firePropertyChange(this.PROPERTYNAME, this.DEFAULT, this.REDO);
156
			jMenuItemRedo.addActionListener(menuListener);
157
			map.put(PluginServices.getText(null, "edit_redo"), new Integer(this.REDO));
158
		}
159
		return jMenuItemRedo;
160
	}
161

  
162
	/**
163
	 * This method initializes jMenuItemCut	
164
	 * 	
165
	 * @return javax.swing.JMenuItem	
166
	 */
167
	private JMenuItem getJMenuItemCut() {
168
		if (jMenuItemCut == null) {
169
			ImageIcon cutIcon = new ImageIcon("images/edit-cut.png", PluginServices.getText(null, "edit_cut"));
170
			jMenuItemCut = new JMenuItem(PluginServices.getText(null, "edit_cut"), cutIcon);
171
			jMenuItemCut.setHorizontalTextPosition(JMenuItem.RIGHT);
172
//			changes.firePropertyChange(this.PROPERTYNAME, this.DEFAULT, this.CUT);
173
			jMenuItemCut.addActionListener(menuListener);
174
			map.put(PluginServices.getText(null, "edit_cut"), new Integer(this.CUT));
175
		}
176
		return jMenuItemCut;
177
	}
178
	
179
	/**
180
	 * This method initializes jMenuItemCopy	
181
	 * 	
182
	 * @return javax.swing.JMenuItem	
183
	 */
184
	private JMenuItem getJMenuItemCopy() {
185
		if (jMenuItemCopy == null) {
186
			ImageIcon copyIcon = new ImageIcon("images/edit-copy.png", PluginServices.getText(null, "edit_copy"));
187
			jMenuItemCopy = new JMenuItem(PluginServices.getText(null, "edit_copy"), copyIcon);
188
			jMenuItemCopy.setHorizontalTextPosition(JMenuItem.RIGHT);
189
//			changes.firePropertyChange(this.PROPERTYNAME, this.DEFAULT, this.COPY);
190
			jMenuItemCopy.addActionListener(menuListener);
191
			map.put(PluginServices.getText(null, "edit_copy"), new Integer(this.COPY));
192
		}
193
		return jMenuItemCopy;
194
	}
195

  
196
	/**
197
	 * This method initializes jMenuItemPaste	
198
	 * 	
199
	 * @return javax.swing.JMenuItem	
200
	 */
201
	private JMenuItem getJMenuItemPaste() {
202
		if (jMenuItemPaste == null) {
203
			ImageIcon pasteIcon = new ImageIcon("images/edit-paste.png", PluginServices.getText(null, "edit_paste"));
204
			jMenuItemPaste = new JMenuItem(PluginServices.getText(null, "edit_paste"), pasteIcon);
205
			jMenuItemPaste.setHorizontalTextPosition(JMenuItem.RIGHT);
206
//			changes.firePropertyChange(this.PROPERTYNAME, this.DEFAULT, this.PASTE);
207
			jMenuItemPaste.addActionListener(menuListener);
208
			map.put(PluginServices.getText(null, "edit_paste"), new Integer(this.PASTE));
209
		}
210
		return jMenuItemPaste;
211
	}
212

  
213
	/**
214
	 * This method initializes jMenuItemDelete	
215
	 * 	
216
	 * @return javax.swing.JMenuItem	
217
	 */
218
	private JMenuItem getJMenuItemDelete() {
219
		if (jMenuItemDelete == null) {
220
			ImageIcon deleteIcon = new ImageIcon("images/edit-delete.png", PluginServices.getText(null, "edit_delete"));
221
			jMenuItemDelete = new JMenuItem(PluginServices.getText(null, "edit_delete"), deleteIcon);
222
			jMenuItemDelete.setHorizontalTextPosition(JMenuItem.RIGHT);
223
//			changes.firePropertyChange(this.PROPERTYNAME, this.DEFAULT, this.DELETE);
224
			jMenuItemDelete.addActionListener(menuListener);
225
			map.put(PluginServices.getText(null, "edit_delete"), new Integer(this.DELETE));
226
		}
227
		return jMenuItemDelete;
228
	}
229
	
230

  
231
	/**
232
	 * This method initializes jMenuItemSelectAll	
233
	 * 	
234
	 * @return javax.swing.JMenuItem	
235
	 */
236
	private JMenuItem getJMenuItemSelectAll() {
237
		if (jMenuItemSelectAll == null) {
238
			ImageIcon selectAllIcon = new ImageIcon("images/edit-select-all.png", PluginServices.getText(null, "edit_select_all"));
239
			jMenuItemSelectAll = new JMenuItem(PluginServices.getText(null, "edit_select_all"), selectAllIcon);
240
			jMenuItemSelectAll.setHorizontalTextPosition(JMenuItem.RIGHT);
241
//			changes.firePropertyChange(this.PROPERTYNAME, this.DEFAULT, this.SELECT_ALL);
242
			jMenuItemSelectAll.addActionListener(menuListener);
243
			map.put(PluginServices.getText(null, "edit_select_all"), new Integer(this.SELECT_ALL));
244
		}
245
		return jMenuItemSelectAll;
246
	}
247

  
248
	public void setEnabledUndoOption(boolean b) {
249
		jMenuItemUndo.setEnabled(b);
250
	}
251
	
252
	public boolean isEnabledUndoOption() {
253
		return jMenuItemUndo.isEnabled();
254
	}
255
	
256
	public void setEnabledRedoOption(boolean b) {
257
		jMenuItemRedo.setEnabled(b);
258
	}
259
	
260
	public boolean isEnabledRedoOption() {
261
		return jMenuItemRedo.isEnabled();
262
	}
263
	
264
	public void setEnabledCutOption(boolean b) {
265
		jMenuItemCut.setEnabled(b);
266
	}
267
	
268
	public boolean isEnabledCutOption() {
269
		return jMenuItemCut.isEnabled();
270
	}
271
	
272
	public void setEnabledCopyOption(boolean b) {
273
		jMenuItemCopy.setEnabled(b);
274
	}
275
	
276
	public boolean isEnabledCopyOption() {
277
		return jMenuItemCopy.isEnabled();
278
	}
279
	
280
	public void setEnabledPasteOption(boolean b) {
281
		jMenuItemPaste.setEnabled(b);
282
	}
283
	
284
	public boolean isEnabledPasteOption() {
285
		return jMenuItemPaste.isEnabled();
286
	}
287
	
288
	public void setEnabledDeleteOption(boolean b) {
289
		jMenuItemDelete.setEnabled(b);
290
	}
291
	
292
	public boolean isEnabledDeleteOption() {
293
		return jMenuItemDelete.isEnabled();
294
	}
295
	
296
	public void setEnabledSelectAllOption(boolean b) {
297
		jMenuItemSelectAll.setEnabled(b);
298
	}
299
	
300
	public boolean isEnabledelectAllOption() {
301
		return jMenuItemSelectAll.isEnabled();
302
	}
303
	
304

  
305

  
306
	public void setEnabledAllOptions(boolean b) {
307
		this.setEnabledUndoOption(b);
308
		this.setEnabledRedoOption(b);
309
		this.setEnabledCutOption(b);
310
		this.setEnabledCopyOption(b);
311
		this.setEnabledPasteOption(b);
312
		this.setEnabledDeleteOption(b);
313
		this.setEnabledSelectAllOption(b);
314
	}
315
	
316
	
317
	/* (non-Javadoc)
318
	 * @see javax.swing.JPopupMenu#setVisible(boolean)
319
	 */
320
	public void setVisible(boolean b) {
321
//		 Notifica que ha cambiado la visibilidad de este componente (JPopupMenu)
322
		super.setVisible(b);
323
		menuListener.actionPerformed(new ActionEvent(this, this.VISIBILITY, this.VISIBILITYCHANGED));
324
	}
325
	
326
    ActionListener menuListener = new ActionListener() {
327
        public void actionPerformed(ActionEvent event) {
328
        	System.out.println("Popup menu item [" + map.get(event.getActionCommand()) + "] was pressed. ");
329
        	if (event.getActionCommand().equals(OptionsEditionByMouse.VISIBILITYCHANGED))
330
           		changes.firePropertyChange(OptionsEditionByMouse.VISIBILITYCHANGED, OptionsEditionByMouse.DEFAULT, OptionsEditionByMouse.VISIBILITY);
331
         	else
332
           		changes.firePropertyChange(OptionsEditionByMouse.SELECTEDOPTION, OptionsEditionByMouse.DEFAULT, ((Integer)map.get(event.getActionCommand())).intValue());
333
        	
334
      }
335
    };
336
    
337
}  //  @jve:decl-index=0:visual-constraint="10,10"
0 338

  

Also available in: Unified diff