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 |
}
|