svn-gvsig-desktop / trunk / libraries / libUI / src / org / gvsig / gui / beans / comboBoxItemsSeeker / JComboBoxItemsSeekerConfigurable.java @ 6799
History | View | Annotate | Download (83.1 KB)
1 |
package org.gvsig.gui.beans.comboBoxItemsSeeker; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Point; |
5 |
import java.awt.event.ActionEvent; |
6 |
import java.awt.event.ActionListener; |
7 |
import java.awt.event.FocusAdapter; |
8 |
import java.awt.event.FocusEvent; |
9 |
import java.awt.event.FocusListener; |
10 |
import java.awt.event.KeyAdapter; |
11 |
import java.awt.event.KeyEvent; |
12 |
import java.awt.event.KeyListener; |
13 |
import java.awt.event.MouseAdapter; |
14 |
import java.awt.event.MouseEvent; |
15 |
import java.awt.event.MouseListener; |
16 |
import java.beans.PropertyChangeEvent; |
17 |
import java.beans.PropertyChangeListener; |
18 |
|
19 |
import javax.swing.ComboBoxEditor; |
20 |
import javax.swing.ComboBoxModel; |
21 |
import javax.swing.JButton; |
22 |
import javax.swing.JComboBox; |
23 |
import javax.swing.JOptionPane; |
24 |
import javax.swing.event.AncestorEvent; |
25 |
import javax.swing.event.AncestorListener; |
26 |
import javax.swing.event.DocumentEvent; |
27 |
import javax.swing.event.DocumentListener; |
28 |
import javax.swing.event.ListDataEvent; |
29 |
import javax.swing.event.ListDataListener; |
30 |
import javax.swing.event.PopupMenuEvent; |
31 |
import javax.swing.event.PopupMenuListener; |
32 |
import javax.swing.event.UndoableEditEvent; |
33 |
import javax.swing.event.UndoableEditListener; |
34 |
import javax.swing.text.AttributeSet; |
35 |
import javax.swing.text.BadLocationException; |
36 |
import javax.swing.text.JTextComponent; |
37 |
import javax.swing.text.PlainDocument; |
38 |
import javax.swing.undo.UndoManager; |
39 |
|
40 |
import org.apache.log4j.Logger; |
41 |
|
42 |
|
43 |
import com.iver.andami.PluginServices; |
44 |
|
45 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
46 |
*
|
47 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
48 |
*
|
49 |
* This program is free software; you can redistribute it and/or
|
50 |
* modify it under the terms of the GNU General Public License
|
51 |
* as published by the Free Software Foundation; either version 2
|
52 |
* of the License, or (at your option) any later version.
|
53 |
*
|
54 |
* This program is distributed in the hope that it will be useful,
|
55 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
56 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
57 |
* GNU General Public License for more details.
|
58 |
*
|
59 |
* You should have received a copy of the GNU General Public License
|
60 |
* along with this program; if not, write to the Free Software
|
61 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
62 |
*
|
63 |
* For more information, contact:
|
64 |
*
|
65 |
* Generalitat Valenciana
|
66 |
* Conselleria d'Infraestructures i Transport
|
67 |
* Av. Blasco Ib??ez, 50
|
68 |
* 46010 VALENCIA
|
69 |
* SPAIN
|
70 |
*
|
71 |
* +34 963862235
|
72 |
* gvsig@gva.es
|
73 |
* www.gvsig.gva.es
|
74 |
*
|
75 |
* or
|
76 |
*
|
77 |
* IVER T.I. S.A
|
78 |
* Salamanca 50
|
79 |
* 46005 Valencia
|
80 |
* Spain
|
81 |
*
|
82 |
* +34 963163400
|
83 |
* dac@iver.es
|
84 |
*/
|
85 |
|
86 |
/** VERSI?N EN DESARROLLO
|
87 |
* REVISAR COMENTARIOS Y C?DIGO QUE PUEDA SOBRAR
|
88 |
*
|
89 |
* POR DEFECTO USA UN MODELO QUE NO FUNCIONA BIEN SI HAY ITEMS REPETIDOS
|
90 |
*
|
91 |
* This class allows users to insert a chain of characters and show all the sentences of the JComboBox that match its first ones characters with it.
|
92 |
* This class is also a Java Bean, and is made according the MVC (Model - View - Controller) pattern.
|
93 |
* This class has the View, the Control and can access to the Model.
|
94 |
* The behavior of this componet can be configurated by 7 flags: (Esto lo cambio!!!!!)
|
95 |
* + The appearence of the items showed at the beginning and when the user presses the ESCAPE key: (This is configured with 2 flags -> 3 different states are possible)
|
96 |
* -> maintainPositionItems -> When we see the list of all items, this are showed in the ordenation as they have been introduced (if true); (if false) each new item
|
97 |
* when we write on the TextField of this Component will be showed at the end (esto ?ltimo creo q. no -> revisarlo)
|
98 |
* -> all_Alphanumeric_Sorted -> All items we can see in this Component will be showed in alphanumeric ordenation (if true)
|
99 |
* + The list of the items showed when the user makes a search writting or pressing the BACK-SPACE key (This is configured with 1 flag -> 2 different states are possible)
|
100 |
* -> alphanumericSortedSearches -> When we write on the TextField of this Component all results (items) are showed in alphanumeric ordenation (if true)
|
101 |
* + case Sensitive or not when the user writes
|
102 |
* -> case_Sensitive -> When we write on the TextField it can discriminate upper cases from down cases (if true) or not (if false) (This is configured with 1 flag -> 2 different states are possible)
|
103 |
* + Show all items always
|
104 |
* -> showAllItems -> If true -> this component shows all items always; if false -> this component only shows items that their first characters match with the string written by the user
|
105 |
* + Use one color (black) or 2 colors (black by default and red if the string written doesn't match with the beginning of all items)
|
106 |
* -> 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
|
107 |
* will be showed on red color
|
108 |
* + * @param boolean (completeMatchedItem (explicar))
|
109 |
* + @param boolean (useBeep (explicar))
|
110 |
*
|
111 |
* Default Values of the Flags:
|
112 |
* -> maintainPositionItems -> true
|
113 |
* -> all_Alphanumeric_Sorted -> true
|
114 |
* -> alphanumericSortedSearches -> false
|
115 |
* -> case_Sensitive -> false
|
116 |
* -> showAllItems -> false
|
117 |
* -> only_One_Color -> false
|
118 |
*
|
119 |
* The flags are distributed in two classes:
|
120 |
* -> ComboBoxSearcheableDynamicModel -> maintainPositionItems, all_Alphanumeric_Sorted, alphanumericSortedSearches, case_Sensitive, showAllItems
|
121 |
* -> JComboBoxSearcheableDynamic -> only_One_Color
|
122 |
*
|
123 |
* Combinations of flags not allowed:
|
124 |
* -> maintainPositionItems == allAlphanumericSorted == true
|
125 |
* -> ((maintain_Position_Items == false) && (all_Alphanumeric_Sorted == true) && (alphanumeric_Sorted_Searches == false))
|
126 |
* -> showAllItems == true && maintainPositionItems == false (Creo que esta mal)
|
127 |
*
|
128 |
* Limitations:
|
129 |
* -> When we add more than one item with the same name (string value) -> the behavior of this component only considers one item in most of the cases when it does a search
|
130 |
* -> If this component has Hundreds,Thousands or even Million/s of items is probably that had quite delay to respond the evens of the user; this also depends of the machine where it's executed and other factors
|
131 |
*
|
132 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
|
133 |
*/
|
134 |
public class JComboBoxItemsSeekerConfigurable extends JComboBox implements java.io.Serializable { |
135 |
//private static final long serialVersionUID = -1853812970336818959L;
|
136 |
// PONER SERIALIZACI?N
|
137 |
|
138 |
// eSTAS HAY QUE BORRARLAS!
|
139 |
/* private Vector defaultItems;
|
140 |
private Set notRemovedItems;
|
141 |
private Set removedItems;*/
|
142 |
|
143 |
private final int BEGINNING_VIEW_STATE = 0; |
144 |
private final int START_VIEW_STATE = 1; |
145 |
private final int SEARCH_VIEW_STATE = 2; |
146 |
private int currentShowState; // 0 -> at the beginning; 1 -> when is showing the start list of items; 2 -> when is showing a search list of items |
147 |
|
148 |
|
149 |
// CONFIGURATION FLAGS
|
150 |
private boolean onlyOneColor; |
151 |
private boolean completeMatchedItem; |
152 |
private boolean beepEnabled; |
153 |
// END FLAGS
|
154 |
|
155 |
// PUEDE QUE TB. sOBren
|
156 |
// private boolean allItemsAreSorted;
|
157 |
|
158 |
// Last selected item
|
159 |
private Object selectedItem; |
160 |
private Object lastSelectedItem; // This is used for only update (refresh) de popup when a different item is selected |
161 |
private String lastDocumentText; |
162 |
|
163 |
// pueDE QUE TB. SOBRE
|
164 |
private int num = 0; |
165 |
// private JTextField txtField;
|
166 |
|
167 |
private final int POPUP_LIST_ITEMS_HEIGHT = 8; |
168 |
// Reference to the ui
|
169 |
//private MetalComboBoxItemsSeekerUI ui;
|
170 |
|
171 |
// Reference to the model
|
172 |
private AbstractDefaultComboBoxItemsSeekerConfigurableModel model;
|
173 |
|
174 |
// Some listeners for the Control between the View and de Model
|
175 |
private KeyListener editorKeyListener; |
176 |
private MouseAdapter editorMouseListener; |
177 |
private FocusListener editorFocusListener; |
178 |
private DocumentListener documentListener; |
179 |
private ListDataListener modelListDataListener; |
180 |
private PopupMenuListener popupMenuListener; |
181 |
private PropertyChangeListener editionMenuListener; |
182 |
|
183 |
|
184 |
// Reference to the document of the Editor of this component for optimize the seeks
|
185 |
private PlainDocumentSeeker document;
|
186 |
|
187 |
// private String writtenString;
|
188 |
|
189 |
private boolean continueOnStartViewState; |
190 |
// private boolean specialKeys; // ESC and TAB keys
|
191 |
private boolean textKeyPressed; |
192 |
private boolean lastWasTheBeginningState; |
193 |
private boolean lastWasPressedAKeyModifier; |
194 |
private boolean popupWillBeVisible; |
195 |
private boolean optionsEditorWasVisible; |
196 |
// private boolean keyPressed;
|
197 |
// private boolean updatePopUp;
|
198 |
// private boolean upOrDownKeyPressed;
|
199 |
// private boolean deleteKeyPressed;
|
200 |
// private boolean escapeKeyPressed;
|
201 |
|
202 |
// OTRAS FLAGS que puede que sobren alguNAS
|
203 |
private boolean selecting=false; |
204 |
private boolean hidePopupOnFocusLoss; |
205 |
private boolean hitBackspace; |
206 |
private boolean hitBackspaceOnSelection; |
207 |
private boolean allowedRepeatedItems; |
208 |
|
209 |
// TRACE - DEBUG
|
210 |
private Logger logger = Logger.getLogger(JComboBoxItemsSeekerConfigurable.class.getClass()); |
211 |
// END TRACE - DEBUG
|
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 |
|
221 |
/**
|
222 |
* Default Constructor
|
223 |
*/
|
224 |
public JComboBoxItemsSeekerConfigurable() {
|
225 |
// Invokes to the parent class constructor
|
226 |
super();
|
227 |
|
228 |
// Create attributes and set initial values
|
229 |
this.initialize();
|
230 |
|
231 |
// Set the default values of the flags
|
232 |
this.onlyOneColor = false; |
233 |
this.completeMatchedItem = false; //true; |
234 |
this.beepEnabled = false; //true; |
235 |
|
236 |
// Other configuration tasks
|
237 |
this.createDefaultListeners();
|
238 |
this.configure();
|
239 |
//this.configure();
|
240 |
|
241 |
|
242 |
} |
243 |
|
244 |
/**
|
245 |
* Default Constructor with four parameters: configure the 4 flags
|
246 |
*
|
247 |
* @param boolean (true -> maintains the position of the items; false -> don't maintains the position of the items)
|
248 |
* @param boolean (true -> all items showed when we write on the textfield will be showed in alphanumeric ordenation; false -> they don't have to be in alphanumeric ordenation)
|
249 |
* @param boolean (true -> all items showed will be in alphanumeric ordenation; false -> they don't have to be in alphanumeric ordenation)
|
250 |
* @param boolean (true -> discriminates capital letters from small letters; false -> don't discriminates capital letters from small letters)
|
251 |
*/
|
252 |
public JComboBoxItemsSeekerConfigurable(int start_Behavior, int search_Behavior, boolean case_Sensitive) { |
253 |
// Invokes to the parent class constructor
|
254 |
super();
|
255 |
|
256 |
// Create attributes and set initial values
|
257 |
this.initialize();
|
258 |
|
259 |
// Sets the options selected by the user
|
260 |
// this.model.setMaintainPositionItems(maintain_Position_Items);
|
261 |
// this.model.setAllAlphanumericSorted(all_Alphanumeric_Sorted);
|
262 |
// this.model.setAlphanumericSortedSearches(alphanumeric_Sorted_Searches);
|
263 |
this.model.setStartBehavior(start_Behavior);
|
264 |
this.model.setStartBehavior(search_Behavior);
|
265 |
this.model.setCaseSensitive(case_Sensitive);
|
266 |
// this.model.setShowAllItems(false);
|
267 |
this.onlyOneColor = false; |
268 |
this.completeMatchedItem = false; //true; |
269 |
this.beepEnabled = true; |
270 |
|
271 |
if (!testFlagsConfigurationOK())
|
272 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "errorMessageJComboBoxItemsSeekerConfigurable"), PluginServices.getText(this, "exportJOP2Title"), JOptionPane.ERROR_MESSAGE); |
273 |
else
|
274 |
this.configure();
|
275 |
} |
276 |
|
277 |
/**
|
278 |
* Default Constructor with six parameters: configure the 6 flags
|
279 |
*
|
280 |
* @param boolean (true -> maintains the position of the items; false -> don't maintains the position of the items)
|
281 |
* @param boolean (true -> all items showed when we write on the textfield will be showed in alphanumeric ordenation; false -> they don't have to be in alphanumeric ordenation)
|
282 |
* @param boolean (true -> all items showed will be in alphanumeric ordenation; false -> they don't have to be in alphanumeric ordenation)
|
283 |
* @param boolean (true -> discriminates capital letters from small letters; false -> don't discriminates capital letters from small letters)
|
284 |
* @param boolean (true -> 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
|
285 |
* will be showed on red color)
|
286 |
* @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)
|
287 |
* @param boolean (completeMatchedItem (explicar))
|
288 |
* @param boolean (beepEnabled (explicar))
|
289 |
* @param boolean (allowedRepeatedItems (explicar))
|
290 |
*/
|
291 |
public JComboBoxItemsSeekerConfigurable(int start_Behavior, int search_Behavior, boolean case_Sensitive, boolean only_One_Color, boolean show_All_Items, boolean complete_Matched_Item, boolean use_Beep, boolean allowed_Repeated_Items) { |
292 |
// Invokes to the parent class constructor
|
293 |
super();
|
294 |
|
295 |
// Create attributes and set initial values
|
296 |
this.initialize();
|
297 |
|
298 |
// Sets the options selected by the user
|
299 |
// this.model.setMaintainPositionItems(maintain_Position_Items);
|
300 |
// this.model.setAllAlphanumericSorted(all_Alphanumeric_Sorted);
|
301 |
// this.model.setAlphanumericSortedSearches(alphanumeric_Sorted_Searches);
|
302 |
this.model.setStartBehavior(start_Behavior);
|
303 |
this.model.setStartBehavior(search_Behavior);
|
304 |
this.model.setCaseSensitive(case_Sensitive);
|
305 |
// this.model.setShowAllItems(show_All_Items);
|
306 |
this.onlyOneColor = only_One_Color;
|
307 |
this.completeMatchedItem = complete_Matched_Item;
|
308 |
this.beepEnabled = use_Beep;
|
309 |
this.allowedRepeatedItems = allowed_Repeated_Items;
|
310 |
|
311 |
if (!testFlagsConfigurationOK())
|
312 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "errorMessageJComboBoxItemsSeekerConfigurable"), PluginServices.getText(this, "exportJOP2Title"), JOptionPane.ERROR_MESSAGE); |
313 |
else
|
314 |
this.configure();
|
315 |
} |
316 |
|
317 |
|
318 |
/**
|
319 |
*
|
320 |
*/
|
321 |
private void initialize() { |
322 |
// // Creates the ui for this component and gets it reference
|
323 |
// super.setUI(new MetalComboBoxItemsSeekerUI());
|
324 |
// this.ui = (MetalComboBoxItemsSeekerUI) super.getUI();
|
325 |
// super.setUI(new MetalComboBoxItemsSeekerUI());
|
326 |
|
327 |
// Creates the model for this component and gets it reference
|
328 |
if (this.isAllowedRepeatedItems()) |
329 |
{ |
330 |
super.setModel(new ComboBoxItemsSeekerConfigurableModel()); |
331 |
this.model = (ComboBoxItemsSeekerConfigurableModel) super.getModel(); |
332 |
} |
333 |
else
|
334 |
{ |
335 |
super.setModel(new ComboBoxSingularItemsSeekerConfigurableModel()); |
336 |
this.model = (ComboBoxSingularItemsSeekerConfigurableModel) super.getModel(); |
337 |
} |
338 |
|
339 |
// Allows user to edit on the combobox
|
340 |
super.setEditable(true); |
341 |
|
342 |
// By default the last state of showign items was showing all the items (at the beginning of this component)
|
343 |
currentShowState = BEGINNING_VIEW_STATE; |
344 |
|
345 |
// Set the last selected item -> if there isn't any item -> -1; else -> this will be 0
|
346 |
super.setSelectedIndex(-1); |
347 |
this.selectedItem = null; |
348 |
// logger.debug("selectedItem: " + this.getSelectedIndex());
|
349 |
|
350 |
// By default the keys Up and Down aren't pressed
|
351 |
// this.upOrDownKeyPressed = false;
|
352 |
|
353 |
// By default the keys Delete aren't pressed
|
354 |
// this.escapeKeyPressed = false;
|
355 |
|
356 |
// By default any text key has been pressed
|
357 |
textKeyPressed = false;
|
358 |
|
359 |
allowedRepeatedItems = false;
|
360 |
|
361 |
lastWasPressedAKeyModifier = false;
|
362 |
|
363 |
// By default popup won't be visible when gained the focus the editor associated
|
364 |
popupWillBeVisible = false;
|
365 |
|
366 |
|
367 |
|
368 |
hitBackspace=false;
|
369 |
|
370 |
optionsEditionByMouse = new OptionsEditionByMouse();
|
371 |
optionsEditorWasVisible = false;
|
372 |
|
373 |
// // By default any key has been pressed
|
374 |
// keyPressed = false;
|
375 |
|
376 |
// specialKeys = false;
|
377 |
// updatePopUp = false;
|
378 |
|
379 |
// Remove the default mouse listener
|
380 |
// super.removeMouseListener(super.getMouseListeners()[0]);
|
381 |
|
382 |
|
383 |
} |
384 |
|
385 |
/**
|
386 |
*
|
387 |
*/
|
388 |
private void createDefaultListeners() { |
389 |
// TODO Auto-generated method stub
|
390 |
|
391 |
this.defineEditionMenuPropertyChangeListener(this); |
392 |
|
393 |
// Define the key listener for the editor of this component
|
394 |
this.defineEditorKeyListener(this); |
395 |
|
396 |
// Define the focus listener for the editor of this component
|
397 |
this.defineEditorFocusListener(this); |
398 |
|
399 |
this.defineEditorMouseListener(this); |
400 |
|
401 |
// Define a document listener for changes of text
|
402 |
this.defineDocumentListener();
|
403 |
|
404 |
// Define the list data listener for the model of this component
|
405 |
this.defineModelListDataListener();
|
406 |
|
407 |
// Define a popup menu listener for the popup of this component
|
408 |
this.definePopUpMenuListener(this); |
409 |
} |
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 |
|
462 |
/**
|
463 |
* Define a document listener for changes of text
|
464 |
*/
|
465 |
private void defineDocumentListener() { |
466 |
// TODO Auto-generated method stub
|
467 |
documentListener = new DocumentListener() { |
468 |
|
469 |
public void changedUpdate(DocumentEvent arg0) { |
470 |
// TODO Auto-generated method stub
|
471 |
} |
472 |
|
473 |
public void insertUpdate(DocumentEvent arg0) { |
474 |
// TODO Auto-generated method stub
|
475 |
|
476 |
|
477 |
logger.debug("NUM: " + num + " DocumentListener->insertUpdate"); |
478 |
try {
|
479 |
// lastDocumentText = document.getText(0, document.getLength())
|
480 |
logger.debug("Texto insertado: ->" + document.getText(0, document.getLength()) + "<-"); |
481 |
|
482 |
} catch (BadLocationException e) { |
483 |
// TODO Auto-generated catch block
|
484 |
e.printStackTrace(); |
485 |
} |
486 |
num++; |
487 |
|
488 |
// Indicate to the model that now is disabled the start view
|
489 |
// This is used for the first text inserted to the document when the component is loaded and it does setSelectedIndex(0), to avoid use a search view
|
490 |
if (currentShowState == BEGINNING_VIEW_STATE)
|
491 |
{ |
492 |
currentShowState = START_VIEW_STATE; |
493 |
lastWasTheBeginningState = true;
|
494 |
continueOnStartViewState = true;
|
495 |
logger.debug("Pasa al estado 1 (de vista inicial)");
|
496 |
} |
497 |
} |
498 |
|
499 |
public void removeUpdate(DocumentEvent arg0) { |
500 |
// TODO Auto-generated method stub
|
501 |
logger.debug("NUM: " + num + " DocumentListener->removeUpdate"); |
502 |
num++; |
503 |
} |
504 |
}; |
505 |
} |
506 |
|
507 |
private void updateLastSelectionItem() { |
508 |
setSelectedItem(selectedItem); |
509 |
} |
510 |
|
511 |
/**
|
512 |
*
|
513 |
*/
|
514 |
private void configure() { |
515 |
// TODO Auto-generated method stub
|
516 |
|
517 |
// Configure the document of the editor of this component
|
518 |
this.configureDocument();
|
519 |
|
520 |
// Configure the editor (ComboBoxEditor) of this component
|
521 |
this.configureEditor(this.getEditor()); |
522 |
|
523 |
// Configure the model of this component
|
524 |
this.configureModel();
|
525 |
|
526 |
// Configure the popup of this component
|
527 |
this.configurePopUp();
|
528 |
|
529 |
this.configureOptionsEditionByMouse();
|
530 |
|
531 |
} |
532 |
|
533 |
private void configureOptionsEditionByMouse() { |
534 |
this.optionsEditionByMouse.addPropertyChangeListener(editionMenuListener);
|
535 |
// optionsEditionByMouse.addPropertyChangeListener(OptionsEditionByMouse.PROPERTYNAME, editionMenuListener);
|
536 |
} |
537 |
|
538 |
/**
|
539 |
*
|
540 |
*
|
541 |
*/
|
542 |
private void configurePopUp() { |
543 |
// TODO Auto-generated method stub
|
544 |
this.addPopupMenuListener(this.popupMenuListener); |
545 |
} |
546 |
|
547 |
// /**
|
548 |
// *
|
549 |
// */
|
550 |
// private void uninstallDefaultListeners() {
|
551 |
//
|
552 |
//
|
553 |
// }
|
554 |
|
555 |
/**
|
556 |
*
|
557 |
*/
|
558 |
private void configureModel() { |
559 |
// TODO Auto-generated method stub
|
560 |
this.model.addListDataListener(this.modelListDataListener); |
561 |
} |
562 |
|
563 |
/**
|
564 |
*
|
565 |
*/
|
566 |
private void configureDocument() { |
567 |
// TODO Auto-generated method stub
|
568 |
|
569 |
// Creates the document of the editor of this component
|
570 |
document = new PlainDocumentSeeker();
|
571 |
document.setJComboBoxItemsSeekerDynamicReference(this);
|
572 |
|
573 |
// Set the written String
|
574 |
// writtenString = "";
|
575 |
|
576 |
// Remove all Previous document Listeners
|
577 |
// DocumentListener documentListener[] = document.getDocumentListeners();
|
578 |
// for (int i=0; i < documentListener.length; i++)
|
579 |
// document.removeDocumentListener(documentListener[i]);
|
580 |
|
581 |
// Defines and add a Document listener for changes on the document of the editor of this component
|
582 |
document.addDocumentListener(this.documentListener);
|
583 |
} |
584 |
|
585 |
|
586 |
/**
|
587 |
* Define the list data listener for the model of this component
|
588 |
*/
|
589 |
public void defineModelListDataListener() { |
590 |
|
591 |
this.modelListDataListener = new ListDataListener() { |
592 |
|
593 |
public void contentsChanged(ListDataEvent e) { |
594 |
// TODO Auto-generated method stub
|
595 |
// logger.debug("ContentsChanged");
|
596 |
|
597 |
// This flag indicates to the 'insertString' and 'remove' methods of the PlainDocumentSeeker that the text of the item selected or written by the user
|
598 |
// hasn't been written on the TextEditor of ths component
|
599 |
selecting = false;
|
600 |
} |
601 |
|
602 |
public void intervalAdded(ListDataEvent e) { |
603 |
// TODO Auto-generated method stub
|
604 |
// logger.debug("intervalAdded");
|
605 |
} |
606 |
|
607 |
public void intervalRemoved(ListDataEvent e) { |
608 |
// TODO Auto-generated method stub
|
609 |
// logger.debug("intervalRemoved");
|
610 |
} |
611 |
|
612 |
}; |
613 |
|
614 |
} |
615 |
|
616 |
/**
|
617 |
* ?Sobra? Contiene c?digo interesante
|
618 |
*/
|
619 |
private void defineAndAddPropertyChangeListener() { |
620 |
// Define and add a Listener for changes on the editor or the model of the JComboBox
|
621 |
super.addPropertyChangeListener(new PropertyChangeListener() { |
622 |
public void propertyChange(PropertyChangeEvent ev) { |
623 |
if (ev.getPropertyName().equals("editor")) |
624 |
configureEditor((ComboBoxEditor) ev.getNewValue());
|
625 |
if (ev.getPropertyName().equals("model")) |
626 |
{ |
627 |
if (isAllowedRepeatedItems())
|
628 |
model = (ComboBoxItemsSeekerConfigurableModel) ev.getNewValue(); |
629 |
else
|
630 |
model = (ComboBoxSingularItemsSeekerConfigurableModel) ev.getNewValue(); |
631 |
} |
632 |
} |
633 |
}); |
634 |
} |
635 |
|
636 |
/**
|
637 |
* (S? SE EST? USANDO)
|
638 |
*/
|
639 |
private void defineEditorFocusListener(JComboBoxItemsSeekerConfigurable combo_Box) { |
640 |
final JComboBoxItemsSeekerConfigurable comboBoxReference = combo_Box;
|
641 |
|
642 |
// Bug 5100422 on Java 1.5: Editable JComboBox won't hide popup when tabbing out
|
643 |
hidePopupOnFocusLoss=System.getProperty("java.version").startsWith("1.5"); |
644 |
|
645 |
// TODO Auto-generated method stub
|
646 |
// Highlight whole text when gaining focus
|
647 |
editorFocusListener = new FocusAdapter() { |
648 |
public void focusGained(FocusEvent e) { |
649 |
if (!optionsEditorWasVisible)
|
650 |
{ |
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 |
} |
662 |
} |
663 |
} |
664 |
|
665 |
public void focusLost(FocusEvent e) { |
666 |
logger.debug("EDITOR FOCUS LOST");
|
667 |
|
668 |
if (isPopupVisible())
|
669 |
popupWillBeVisible = true;
|
670 |
else
|
671 |
popupWillBeVisible = false;
|
672 |
|
673 |
// Workaround for Bug 5100422 - Hide Popup on focus loss
|
674 |
if (hidePopupOnFocusLoss) comboBoxReference.setPopupVisible(false); |
675 |
} |
676 |
}; |
677 |
} |
678 |
|
679 |
private void defineEditorMouseListener(JComboBoxItemsSeekerConfigurable combo_Box) { |
680 |
final JComboBoxItemsSeekerConfigurable comboBoxReference = combo_Box;
|
681 |
editorMouseListener = new MouseAdapter() { |
682 |
|
683 |
// public void mousePressed(MouseEvent e) {
|
684 |
//
|
685 |
// if (e.isPopupTrigger()) {
|
686 |
// logger.debug("MousePopupTrigered");
|
687 |
// }
|
688 |
// }
|
689 |
//
|
690 |
// public void mouseReleased(MouseEvent e) {
|
691 |
|
692 |
// Deber?a ser mouseRelease, pero en linux s?lo deja mousePressed
|
693 |
public void mousePressed(MouseEvent e) { |
694 |
logger.debug("MOUSE-LISTENER : MOUSE-PRESSED!" + e.getButton());
|
695 |
logger.debug("MOUSE-LISTENER : MOUSE-PRESSED!" +e.isPopupTrigger());
|
696 |
|
697 |
|
698 |
if (e.isPopupTrigger()) {
|
699 |
JTextComponent editor = (JTextComponent) comboBoxReference.getEditor().getEditorComponent(); |
700 |
|
701 |
// editor.selectAll();
|
702 |
|
703 |
// By default disable all options
|
704 |
optionsEditionByMouse.setEnabledAllOptions(false);
|
705 |
|
706 |
// Habilitar las opciones disponibles (HACER!!)
|
707 |
|
708 |
|
709 |
//Habilitar "eliminar" si hay texto seleccionado
|
710 |
if (editor.getCaretPosition() != editor.getCaret().getMark())
|
711 |
optionsEditionByMouse.setEnabledDeleteOption(true);
|
712 |
|
713 |
// Enable the "Select-All" option (by default it's always enabled)
|
714 |
optionsEditionByMouse.setEnabledSelectAllOption(true);
|
715 |
|
716 |
optionsEditionByMouse.setLocation((int)comboBoxReference.getLocationOnScreen().getX() + e.getX(), (int)comboBoxReference.getLocationOnScreen().getY() + e.getY()); |
717 |
optionsEditionByMouse.setInvoker(comboBoxReference); |
718 |
optionsEditionByMouse.setVisible(true);
|
719 |
// optionsEditorWasVisible = true;
|
720 |
} |
721 |
} |
722 |
}; |
723 |
} |
724 |
|
725 |
/**
|
726 |
*
|
727 |
*/
|
728 |
private void defineEditorKeyListener(JComboBoxItemsSeekerConfigurable combo_Box) { |
729 |
final JComboBoxItemsSeekerConfigurable comboBoxReference = combo_Box;
|
730 |
|
731 |
// keyPressed = true;
|
732 |
|
733 |
|
734 |
// This flag indicates to the 'insertString' and 'remove' methods of the PlainDocumentSeeker that the text of the item selected or written by the user
|
735 |
// hasn't been written on the TextEditor of ths component
|
736 |
|
737 |
// TODO Auto-generated method stub
|
738 |
editorKeyListener = new KeyAdapter() |
739 |
{ |
740 |
// public void keyTyped(KeyEvent ke) {
|
741 |
// logger.debug("Tecla tecleada: ->" + ke.getKeyChar() + "<- ; Su keyCode es: " + ke.getKeyCode());
|
742 |
// }
|
743 |
|
744 |
public void keyPressed(KeyEvent ke) // Executed on the Start view state or Search view state |
745 |
{ |
746 |
// DISTINGUIR SI: s?lo tienen keyChar ? s?lo keyCode ? ambas!!!
|
747 |
|
748 |
logger.debug("Tecla apretada: ->" + ke.getKeyChar() + "<- ; Su keyCode es: " + ke.getKeyCode() + " TIPO: " + Character.getType(ke.getKeyChar())); |
749 |
|
750 |
if (model.getParentSize() == 0) |
751 |
{ |
752 |
if (beepEnabled)
|
753 |
comboBoxReference.getToolkit().beep(); // when available use: UIManager.getLookAndFeel().provideErrorFeedback(comboBox);
|
754 |
} |
755 |
else
|
756 |
{ |
757 |
// This flag indicates to the 'insertString' and 'remove' methods of the PlainDocumentSeeker that the text of the item selected or written by the user
|
758 |
// hasn't been written on the TextEditor of ths component
|
759 |
selecting = false;
|
760 |
|
761 |
// This resolves the bug when the popup wasn't seen any time and the uses press a key that updates the view of the popup (the bug is that popup has the items but
|
762 |
// aren't seen
|
763 |
if (lastWasTheBeginningState)
|
764 |
{ |
765 |
// This maintains visible the popup
|
766 |
if (comboBoxReference.isDisplayable())
|
767 |
comboBoxReference.setPopupVisible(true);
|
768 |
lastWasTheBeginningState = false;
|
769 |
} |
770 |
|
771 |
if (Character.isLetterOrDigit(ke.getKeyChar())) { |
772 |
logger.debug("IS LETTER OR DIGIT");
|
773 |
} |
774 |
else
|
775 |
logger.debug("ISN'T LETTER OR DIGIT");
|
776 |
|
777 |
|
778 |
// hitBackspace=false;
|
779 |
JTextComponent editor = (JTextComponent) comboBoxReference.getEditor().getEditorComponent(); |
780 |
|
781 |
// if (ke.getKeyCode() == 0)
|
782 |
// {
|
783 |
// logger.debug("CASO -> KEYCHAR");
|
784 |
//
|
785 |
// switch (ke.getKeyChar())
|
786 |
// {
|
787 |
//
|
788 |
// }
|
789 |
// }
|
790 |
// else
|
791 |
// {
|
792 |
// logger.debug("CASO -> KEYCODE");
|
793 |
|
794 |
|
795 |
|
796 |
|
797 |
switch (ke.getKeyCode())
|
798 |
{ |
799 |
// determine if the pressed key is backspace (needed by the remove method)
|
800 |
case KeyEvent.VK_BACK_SPACE : |
801 |
hitBackspace=true;
|
802 |
hitBackspaceOnSelection=editor.getSelectionStart()!=editor.getSelectionEnd(); |
803 |
|
804 |
break;
|
805 |
// ignore delete key
|
806 |
case KeyEvent.VK_DELETE : // supr key in spanish keyboard |
807 |
// specialKeys = true;
|
808 |
// This avoids that popup listener could report about it detected item (Este no va)
|
809 |
// textKeyPressed = true;
|
810 |
|
811 |
|
812 |
|
813 |
deleteTextLogic(editor); |
814 |
|
815 |
// // Remove selected text:
|
816 |
// logger.debug("GETMARK: " + editor.getCaret().getMark() + "GETCARETPOSITION" + editor.getCaretPosition());
|
817 |
//
|
818 |
// try {
|
819 |
// // If no characters are selected
|
820 |
// if (editor.getCaret().getMark() == editor.getCaretPosition())
|
821 |
// {
|
822 |
// // Remove the character which is on the right of the caret position
|
823 |
// if (editor.getCaretPosition() < document.getLength())
|
824 |
// document.remove(editor.getCaretPosition(), 1);
|
825 |
// }
|
826 |
// else // If there are characters selected
|
827 |
// {
|
828 |
// // Remove the characters which are selected
|
829 |
// // int documentLength = document.getLength();
|
830 |
// int length = Math.abs(editor.getCaret().getMark() - editor.getCaretPosition());
|
831 |
//
|
832 |
// // Remove the characters which are selected
|
833 |
// document.remove(Math.min(editor.getCaret().getMark(), editor.getCaretPosition()), length);
|
834 |
// }
|
835 |
// } catch (BadLocationException e) {
|
836 |
// // TODO Auto-generated catch block
|
837 |
// e.printStackTrace();
|
838 |
// }
|
839 |
//
|
840 |
// switch(currentShowState)
|
841 |
// {
|
842 |
// case START_VIEW_STATE :
|
843 |
// if (document.getLength() > 0)
|
844 |
// {
|
845 |
// // If dynamic searches:
|
846 |
// try {
|
847 |
// // If the search will be dynamic:
|
848 |
// if (isDynamicSearchConfiguration())
|
849 |
// {
|
850 |
// model.setWrittenText(document.getText(0, document.getLength()));
|
851 |
// logger.debug("Texto que se le env?a al modelo desde SUPR: ->" + document.getText(0, document.getLength()) + "<-");
|
852 |
// }
|
853 |
// } catch (BadLocationException e) {
|
854 |
// // TODO Auto-generated catch block
|
855 |
// e.printStackTrace();
|
856 |
// }
|
857 |
//
|
858 |
// // Indicate to the model that now is disabled the start view
|
859 |
// if (currentShowState == START_VIEW_STATE)
|
860 |
// {
|
861 |
// model.setStartViewFlag(false);
|
862 |
// currentShowState = SEARCH_VIEW_STATE;
|
863 |
// // updateLastSelectionItem();
|
864 |
// }
|
865 |
// }
|
866 |
// break;
|
867 |
// case SEARCH_VIEW_STATE :
|
868 |
// // If there isn't characters
|
869 |
// if (document.getLength() == 0)
|
870 |
// {
|
871 |
// // This instruction avoids popup could failure when got invisible
|
872 |
// hidePopup();
|
873 |
//
|
874 |
// // If it's a dynamic search
|
875 |
// if (isDynamicSearchConfiguration())
|
876 |
// {
|
877 |
// model.setWrittenText("");
|
878 |
// logger.debug("Texto que se le env?a al modelo desde SUPR: ->\"\"<-");
|
879 |
// }
|
880 |
//
|
881 |
// // Return to the start view state
|
882 |
// model.setStartViewFlag(true);
|
883 |
// currentShowState = START_VIEW_STATE;
|
884 |
//
|
885 |
// // Select the first Item
|
886 |
// setSelectedIndex(0);
|
887 |
//
|
888 |
// highlightCompletedText(0);
|
889 |
// }
|
890 |
// else
|
891 |
// {
|
892 |
// // If dynamic searches:
|
893 |
// try {
|
894 |
// // If the search will be dynamic:
|
895 |
// if (isDynamicSearchConfiguration())
|
896 |
// {
|
897 |
// model.setWrittenText(document.getText(0, document.getLength()));
|
898 |
// logger.debug("Texto que se le env?a al modelo desde SUPR: ->" + document.getText(0, document.getLength()) + "<-");
|
899 |
// }
|
900 |
// } catch (BadLocationException e) {
|
901 |
// // TODO Auto-generated catch block
|
902 |
// e.printStackTrace();
|
903 |
// }
|
904 |
// }
|
905 |
// break;
|
906 |
// }
|
907 |
//
|
908 |
// updatePopUpView();
|
909 |
|
910 |
break;
|
911 |
case KeyEvent.VK_ENTER : |
912 |
// try {
|
913 |
// specialKeys = true;
|
914 |
logger.debug("ENTRA EN EL C?DIGO DE ENTER");
|
915 |
|
916 |
// Reports about the written text to the model
|
917 |
try {
|
918 |
// Reports about the written text to the model
|
919 |
if (model.isDynamicSearch())
|
920 |
model.setWrittenText(document.getText(0, document.getLength()));
|
921 |
} catch (BadLocationException e1) { |
922 |
// TODO Auto-generated catch block
|
923 |
e1.printStackTrace(); |
924 |
} |
925 |
|
926 |
// Indicate to the model that now is disabled the start view
|
927 |
if (currentShowState == START_VIEW_STATE)
|
928 |
{ |
929 |
model.setStartViewFlag(false);
|
930 |
currentShowState = SEARCH_VIEW_STATE; |
931 |
// updateLastSelectionItem();
|
932 |
} |
933 |
|
934 |
|
935 |
// String text = document.getText(0, document.getLength());
|
936 |
// document.remove(0, document.getLength());
|
937 |
// document.insertString(0, text, null);
|
938 |
//
|
939 |
//
|
940 |
//
|
941 |
//// // If the text doesn't completely match with the selectedItem.toString() -> if allow 2 colors -> set foreground color to red
|
942 |
//// if (!onlyOneColor)
|
943 |
//// {
|
944 |
//// if (model.isCaseSensitive())
|
945 |
//// {
|
946 |
//// if (text.compareTo(getSelectedItem().toString()) != 0)
|
947 |
//// editor.setForeground(Color.RED);
|
948 |
//// }
|
949 |
//// else
|
950 |
//// {
|
951 |
//// if (text.toUpperCase().compareTo(getSelectedItem().toString().toUpperCase()) != 0)
|
952 |
//// editor.setForeground(Color.RED);
|
953 |
//// }
|
954 |
//// }
|
955 |
// } catch (BadLocationException e1) {
|
956 |
// // TODO Auto-generated catch block
|
957 |
// e1.printStackTrace();
|
958 |
// }
|
959 |
hidePopup(); |
960 |
break;
|
961 |
case KeyEvent.VK_DOWN : |
962 |
// 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
|
963 |
// ke.consume();
|
964 |
// selecting = true; // For indicate to the 'insertString' of the 'PlainDocumentSeeker' class that an item has been selected
|
965 |
// upOrDownKeyPressed = true;
|
966 |
// continueOnStartViewState = true;
|
967 |
|
968 |
// This allows user press the key DOWN for select another item of the start view list
|
969 |
// if ((model.isStartViewFlag()) && (lastWasStartShow))
|
970 |
// lastWasStartShow = true;
|
971 |
|
972 |
// // Reports about the written text to the model
|
973 |
// try {
|
974 |
// if (model.isDynamicSearch())
|
975 |
// model.setWrittenText(document.getText(0, document.getLength()));
|
976 |
// } catch (BadLocationException e2) {
|
977 |
// // TODO Auto-generated catch block
|
978 |
// e2.printStackTrace();
|
979 |
// }
|
980 |
|
981 |
// If items are disordered -> get the index of the selected item
|
982 |
if (model.nowItemsAreDisordered())
|
983 |
updateLastSelectionItem(); |
984 |
|
985 |
if (getItemCount() > 0) |
986 |
{ |
987 |
if (getSelectedIndex() == (getItemCount()-1)) |
988 |
((JComboBox)comboBoxReference).setSelectedIndex(0); |
989 |
else
|
990 |
((JComboBox)comboBoxReference).setSelectedIndex(getSelectedIndex()+1); |
991 |
} |
992 |
|
993 |
// model.setCurrentString(getSelectedItem().toString());
|
994 |
|
995 |
// lastSelectedIndex = getSelectedIndex();
|
996 |
selectedItem = getSelectedItem(); |
997 |
showPopup(); |
998 |
|
999 |
break;
|
1000 |
case KeyEvent.VK_UP : |
1001 |
// 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
|
1002 |
// ke.consume();
|
1003 |
// selecting = true; // For indicate to the 'insertString' of the 'PlainDocumentSeeker' class that an item has been selected
|
1004 |
// upOrDownKeyPressed = true;
|
1005 |
// continueOnStartViewState = true;
|
1006 |
|
1007 |
// This allows user press the key UP for select another item of the start view list
|
1008 |
// if ((model.isStartViewFlag()) && (lastWasStartShow))
|
1009 |
// lastWasStartShow = true;
|
1010 |
|
1011 |
// // Reports about the written text to the model
|
1012 |
// try {
|
1013 |
// if (model.isDynamicSearch())
|
1014 |
// model.setWrittenText(document.getText(0, document.getLength()));
|
1015 |
// } catch (BadLocationException e2) {
|
1016 |
// // TODO Auto-generated catch block
|
1017 |
// e2.printStackTrace();
|
1018 |
// }
|
1019 |
|
1020 |
// If items are disordered -> get the index of the selected item
|
1021 |
if (model.nowItemsAreDisordered())
|
1022 |
updateLastSelectionItem(); |
1023 |
|
1024 |
switch(getSelectedIndex())
|
1025 |
{ |
1026 |
case -1: case 0: |
1027 |
((JComboBox)comboBoxReference).setSelectedIndex(getItemCount()-1); |
1028 |
break;
|
1029 |
default:
|
1030 |
((JComboBox)comboBoxReference).setSelectedIndex(getSelectedIndex()-1); |
1031 |
} |
1032 |
|
1033 |
// model.setCurrentString(getSelectedItem().toString());
|
1034 |
selectedItem = getSelectedItem(); |
1035 |
// lastSelectedIndex = getSelectedIndex();
|
1036 |
showPopup(); |
1037 |
break;
|
1038 |
case KeyEvent.VK_LEFT : |
1039 |
// Move the caret to left
|
1040 |
if (editor.getCaretPosition() > 0) |
1041 |
editor.setCaretPosition(editor.getCaretPosition() - 1);
|
1042 |
else
|
1043 |
{ |
1044 |
// User hit backspace with the cursor positioned on the start => beep
|
1045 |
if (beepEnabled)
|
1046 |
getToolkit().beep(); // when available use: UIManager.getLookAndFeel().provideErrorFeedback(comboBox);
|
1047 |
} |
1048 |
//ke.consume();
|
1049 |
break;
|
1050 |
case KeyEvent.VK_RIGHT : |
1051 |
// Move the caret to right
|
1052 |
try {
|
1053 |
if (editor.getCaretPosition() < (document.getText(0, document.getLength())).length()) |
1054 |
editor.setCaretPosition(editor.getCaretPosition() + 1);
|
1055 |
else
|
1056 |
{ |
1057 |
// User hit backspace with the cursor positioned on the start => beep
|
1058 |
if (beepEnabled)
|
1059 |
getToolkit().beep(); // when available use: UIManager.getLookAndFeel().provideErrorFeedback(comboBox);
|
1060 |
} |
1061 |
} catch (BadLocationException e) { |
1062 |
// TODO Auto-generated catch block
|
1063 |
e.printStackTrace(); |
1064 |
} |
1065 |
//ke.consume();
|
1066 |
break;
|
1067 |
case KeyEvent.VK_PAGE_DOWN : |
1068 |
if (getItemCount() > 0) |
1069 |
// if (getSelectedIndex() != -1)
|
1070 |
{ |
1071 |
// // Reports about the written text to the model
|
1072 |
// try {
|
1073 |
// if (model.isDynamicSearch())
|
1074 |
// model.setWrittenText(document.getText(0, document.getLength()));
|
1075 |
// } catch (BadLocationException e2) {
|
1076 |
// // TODO Auto-generated catch block
|
1077 |
// e2.printStackTrace();
|
1078 |
// }
|
1079 |
|
1080 |
int index;
|
1081 |
|
1082 |
if (getSelectedIndex() == -1) |
1083 |
index = 0;
|
1084 |
else
|
1085 |
index = getSelectedIndex() + POPUP_LIST_ITEMS_HEIGHT; |
1086 |
|
1087 |
if (index < getItemCount())
|
1088 |
setSelectedIndex(index); |
1089 |
else
|
1090 |
setSelectedIndex(getItemCount()-1);
|
1091 |
|
1092 |
selectedItem = getSelectedItem(); |
1093 |
} |
1094 |
|
1095 |
// ke.consume();
|
1096 |
break;
|
1097 |
case KeyEvent.VK_PAGE_UP : |
1098 |
if (getItemCount() > 0) |
1099 |
// if (getSelectedIndex() != -1)
|
1100 |
{ |
1101 |
// // Reports about the written text to the model
|
1102 |
// try {
|
1103 |
// if (model.isDynamicSearch())
|
1104 |
// model.setWrittenText(document.getText(0, document.getLength()));
|
1105 |
// } catch (BadLocationException e2) {
|
1106 |
// // TODO Auto-generated catch block
|
1107 |
// e2.printStackTrace();
|
1108 |
// }
|
1109 |
|
1110 |
int index;
|
1111 |
|
1112 |
if (getSelectedIndex() == -1) |
1113 |
index = getItemCount() - 1;
|
1114 |
else
|
1115 |
index = getSelectedIndex() - POPUP_LIST_ITEMS_HEIGHT; |
1116 |
|
1117 |
if (index > -1) |
1118 |
setSelectedIndex(index); |
1119 |
else
|
1120 |
setSelectedIndex(0);
|
1121 |
|
1122 |
selectedItem = getSelectedItem(); |
1123 |
} |
1124 |
|
1125 |
// ke.consume();
|
1126 |
break;
|
1127 |
case KeyEvent.VK_HOME : // 'Inicio' key on the spanish keyboard |
1128 |
editor.setCaretPosition(0);
|
1129 |
break;
|
1130 |
case KeyEvent.VK_END : // 'Fin' key on the spanish keyboard |
1131 |
editor.setCaretPosition(document.getLength()); |
1132 |
break;
|
1133 |
case KeyEvent.VK_TAB : |
1134 |
// specialKeys = true;
|
1135 |
|
1136 |
// This avoids that popup listener could report about it detected item
|
1137 |
textKeyPressed = true;
|
1138 |
|
1139 |
if (model.getSize() > 0) |
1140 |
{ |
1141 |
// logger.debug("SelectedIndex: " + getSelectedIndex());
|
1142 |
// boolean update = false;
|
1143 |
|
1144 |
if (((JComboBox)comboBoxReference).getSelectedIndex() == -1) |
1145 |
{ |
1146 |
// lastSelectedIndex = 0;
|
1147 |
// ((JComboBox)comboBoxReference).setSelectedIndex(0);
|
1148 |
//updatePopUp = true; // Indicate to the document.insertString that has update the popup after insert
|
1149 |
// updatePopUpView();
|
1150 |
// comboBoxReference.setSelectedIndex(0);
|
1151 |
selectedItem = comboBoxReference.getItemAt(0); //.getSelectedItem(); |
1152 |
} |
1153 |
else
|
1154 |
{ |
1155 |
// lastSelectedIndex = getSelectedIndex();
|
1156 |
// updatePopUp = true; // Indicate to the document.insertString that has update the popup after insert
|
1157 |
// updatePopUpView();
|
1158 |
selectedItem = comboBoxReference.getSelectedItem(); |
1159 |
|
1160 |
// setSelectedIndex()); // Complete the item string value in the document of the editor
|
1161 |
// update = true;
|
1162 |
} |
1163 |
|
1164 |
document.setText(selectedItem.toString()); |
1165 |
|
1166 |
// Reports about the written text to the model
|
1167 |
// try {
|
1168 |
if (model.isDynamicSearch()) {
|
1169 |
model.setWrittenText(selectedItem.toString()); |
1170 |
logger.debug("Texto que se le env?a al modelo: ->" + selectedItem.toString() + "<-"); |
1171 |
} |
1172 |
|
1173 |
// } catch (BadLocationException e2) {
|
1174 |
// // TODO Auto-generated catch block
|
1175 |
// e2.printStackTrace();
|
1176 |
// }
|
1177 |
//
|
1178 |
if (currentShowState == START_VIEW_STATE)
|
1179 |
{ |
1180 |
model.setStartViewFlag(false);
|
1181 |
currentShowState = SEARCH_VIEW_STATE; |
1182 |
// updatePopUpView(); // Update to the new popup view
|
1183 |
} |
1184 |
|
1185 |
|
1186 |
// It's supposed that the text on the document is equal as the string value of the selected item -> then text must be on black color
|
1187 |
comboBoxReference.getEditor().getEditorComponent().setForeground(Color.BLACK);
|
1188 |
|
1189 |
updatePopUpView(); |
1190 |
|
1191 |
|
1192 |
// document.setText(selectedItem.toString());
|
1193 |
|
1194 |
// continueOnStartViewState = false;
|
1195 |
|
1196 |
// HidePopUp + ShowPopUp to force update the popup list of items
|
1197 |
// hidePopup();
|
1198 |
// showPopup();
|
1199 |
//// hidePopup();
|
1200 |
} |
1201 |
break;
|
1202 |
case KeyEvent.VK_ESCAPE : |
1203 |
// Reset to the Start View State
|
1204 |
// model.setStartViewFlag(true);
|
1205 |
|
1206 |
// Force update the popup
|
1207 |
if (isPopupVisible())
|
1208 |
hidePopup(); |
1209 |
|
1210 |
model.setWrittenText("");
|
1211 |
selectedItem = null;
|
1212 |
|
1213 |
// currentShowState = START_VIEW_STATE;
|
1214 |
if (currentShowState == SEARCH_VIEW_STATE)
|
1215 |
{ |
1216 |
try {
|
1217 |
document.remove(0, document.getLength());
|
1218 |
} catch (BadLocationException e) { |
1219 |
// TODO Auto-generated catch block
|
1220 |
e.printStackTrace(); |
1221 |
} |
1222 |
|
1223 |
// setSelectedItem(selectedItem);
|
1224 |
// setSelectedIndex(model.getIndexOf(selectedItem));
|
1225 |
|
1226 |
// Return to the start view state
|
1227 |
model.setStartViewFlag(true);
|
1228 |
currentShowState = START_VIEW_STATE; |
1229 |
// escapeKeyPressed = true;
|
1230 |
// continueOnStartViewState = true;
|
1231 |
|
1232 |
// If items are disordered -> get the index of the selected item
|
1233 |
// if (model.nowItemsAreDisordered())
|
1234 |
// updateLastSelectionItem();
|
1235 |
|
1236 |
// Select the first Item
|
1237 |
setSelectedIndex(0);
|
1238 |
// selectFirstItemAddedToModel();
|
1239 |
|
1240 |
// updatePopUp = true;
|
1241 |
// updatePopUpView();
|
1242 |
|
1243 |
//updateLastSelectionItem();
|
1244 |
// setSelectedIndex(lastSelectedIndex);
|
1245 |
highlightCompletedText(0);
|
1246 |
// HidePopUp + ShowPopUp to force update the popup list of items
|
1247 |
// hidePopup();
|
1248 |
// showPopup();
|
1249 |
} |
1250 |
else
|
1251 |
{ |
1252 |
// Select the first Item
|
1253 |
setSelectedIndex(0);
|
1254 |
// selectFirstItemAddedToModel();
|
1255 |
|
1256 |
highlightCompletedText(0);
|
1257 |
} |
1258 |
updatePopUpView(); |
1259 |
break;
|
1260 |
case KeyEvent.VK_SHIFT : // Do nothing |
1261 |
break;
|
1262 |
case KeyEvent.VK_ALT_GRAPH : // Do nothing |
1263 |
break;
|
1264 |
case KeyEvent.VK_ALT : // Do nothing |
1265 |
break;
|
1266 |
case KeyEvent.VK_CONTROL : // Do nothing |
1267 |
break;
|
1268 |
case KeyEvent.VK_NUM_LOCK : // Do nothing |
1269 |
break;
|
1270 |
case KeyEvent.VK_CAPS_LOCK : // Do nothing |
1271 |
break;
|
1272 |
default:
|
1273 |
logger.debug("Actualiza view flag a false");
|
1274 |
|
1275 |
logger.debug("LASTITEM1 :" + lastSelectedItem);
|
1276 |
|
1277 |
logger.debug("GETMARK: " + editor.getCaret().getMark() + "GETCARETPOSITION" + editor.getCaretPosition()); |
1278 |
|
1279 |
// If it has been pressed a modifier key (Examples: ^ ` ? ?), not consume the key pressed
|
1280 |
if ((Character.getType(ke.getKeyChar()) == Character.MODIFIER_LETTER) || (Character.getType(ke.getKeyChar()) == Character.MODIFIER_SYMBOL)) |
1281 |
{ |
1282 |
logger.debug("CAR?CTER MODIFICADOR");
|
1283 |
lastWasPressedAKeyModifier = true;
|
1284 |
} |
1285 |
else
|
1286 |
{ |
1287 |
logger.debug("CAR?CTER NO MODIFICADOR");
|
1288 |
|
1289 |
if (lastWasPressedAKeyModifier)
|
1290 |
{ |
1291 |
logger.debug("PRESSED: " + editor.getText().substring(0)); |
1292 |
lastWasPressedAKeyModifier = false;
|
1293 |
} |
1294 |
|
1295 |
// if (!isOnlyOneColor())
|
1296 |
// comboBoxReference.getEditor().getEditorComponent().setForeground(Color.RED);
|
1297 |
//
|
1298 |
if (model.isDynamicSearch())
|
1299 |
{ |
1300 |
// Force update the popup
|
1301 |
|
1302 |
String text;
|
1303 |
if (editor.getCaretPosition() == editor.getCaret().getMark())
|
1304 |
text = editor.getText().substring(0, editor.getCaretPosition()) + ke.getKeyChar() + editor.getText().substring(editor.getCaretPosition(), editor.getText().length());
|
1305 |
else
|
1306 |
{ |
1307 |
text = "" + editor.getText().substring(0, (int) Math.min(editor.getCaretPosition(), editor.getCaret().getMark())) + ke.getKeyChar(); |
1308 |
text += editor.getText().substring((int) Math.max(editor.getCaretPosition(), editor.getCaret().getMark()), editor.getText().length()); |
1309 |
} |
1310 |
|
1311 |
// Reports about the written text to the model
|
1312 |
logger.debug("Texto que se le env?a KEY al modelo: ->" + text + "<-"); |
1313 |
model.setWrittenText(text); |
1314 |
|
1315 |
// Indicate to the model that now is disabled the start view
|
1316 |
if (currentShowState == START_VIEW_STATE)
|
1317 |
{ |
1318 |
model.setStartViewFlag(false);
|
1319 |
currentShowState = SEARCH_VIEW_STATE; |
1320 |
// updateLastSelectionItem();
|
1321 |
} |
1322 |
|
1323 |
|
1324 |
// textKeyPressed = false;
|
1325 |
} |
1326 |
|
1327 |
updatePopUpView(); |
1328 |
textKeyPressed = true;
|
1329 |
|
1330 |
|
1331 |
logger.debug("Key Pressed:" + ke.getKeyCode());
|
1332 |
} |
1333 |
} |
1334 |
|
1335 |
// Consume the key event for not to use the handler of the keyboard of other components
|
1336 |
// Only if it has been pressed a modifier key, not consume the key pressed
|
1337 |
if (!lastWasPressedAKeyModifier)
|
1338 |
{ |
1339 |
ke.consume(); |
1340 |
} |
1341 |
} |
1342 |
} |
1343 |
// }
|
1344 |
}; |
1345 |
|
1346 |
// keyPressed = false;
|
1347 |
} |
1348 |
|
1349 |
private void deleteTextLogic(JTextComponent editor) { |
1350 |
|
1351 |
// Remove selected text:
|
1352 |
logger.debug("GETMARK: " + editor.getCaret().getMark() + "GETCARETPOSITION" + editor.getCaretPosition()); |
1353 |
|
1354 |
try {
|
1355 |
// If no characters are selected
|
1356 |
if (editor.getCaret().getMark() == editor.getCaretPosition())
|
1357 |
{ |
1358 |
// Remove the character which is on the right of the caret position
|
1359 |
if (editor.getCaretPosition() < document.getLength())
|
1360 |
document.remove(editor.getCaretPosition(), 1);
|
1361 |
} |
1362 |
else // If there are characters selected |
1363 |
{ |
1364 |
// Remove the characters which are selected
|
1365 |
// int documentLength = document.getLength();
|
1366 |
int length = Math.abs(editor.getCaret().getMark() - editor.getCaretPosition()); |
1367 |
|
1368 |
// Remove the characters which are selected
|
1369 |
document.remove(Math.min(editor.getCaret().getMark(), editor.getCaretPosition()), length);
|
1370 |
} |
1371 |
} catch (BadLocationException e) { |
1372 |
// TODO Auto-generated catch block
|
1373 |
e.printStackTrace(); |
1374 |
} |
1375 |
|
1376 |
|
1377 |
switch(currentShowState)
|
1378 |
{ |
1379 |
case START_VIEW_STATE :
|
1380 |
if (document.getLength() > 0) |
1381 |
{ |
1382 |
// If dynamic searches:
|
1383 |
try {
|
1384 |
// If the search will be dynamic:
|
1385 |
if (isDynamicSearchConfiguration())
|
1386 |
{ |
1387 |
model.setWrittenText(document.getText(0, document.getLength()));
|
1388 |
logger.debug("Texto que se le env?a al modelo desde SUPR: ->" + document.getText(0, document.getLength()) + "<-"); |
1389 |
} |
1390 |
} catch (BadLocationException e) { |
1391 |
// TODO Auto-generated catch block
|
1392 |
e.printStackTrace(); |
1393 |
} |
1394 |
|
1395 |
// Indicate to the model that now is disabled the start view
|
1396 |
if (currentShowState == START_VIEW_STATE)
|
1397 |
{ |
1398 |
model.setStartViewFlag(false);
|
1399 |
currentShowState = SEARCH_VIEW_STATE; |
1400 |
// updateLastSelectionItem();
|
1401 |
} |
1402 |
} |
1403 |
break;
|
1404 |
case SEARCH_VIEW_STATE :
|
1405 |
// If there isn't characters
|
1406 |
if (document.getLength() == 0) |
1407 |
{ |
1408 |
// This instruction avoids popup could failure when got invisible
|
1409 |
hidePopup(); |
1410 |
|
1411 |
// If it's a dynamic search
|
1412 |
if (isDynamicSearchConfiguration())
|
1413 |
{ |
1414 |
model.setWrittenText("");
|
1415 |
logger.debug("Texto que se le env?a al modelo desde SUPR: ->\"\"<-");
|
1416 |
} |
1417 |
|
1418 |
// Return to the start view state
|
1419 |
model.setStartViewFlag(true);
|
1420 |
currentShowState = START_VIEW_STATE; |
1421 |
|
1422 |
// Select the first Item
|
1423 |
setSelectedIndex(0);
|
1424 |
|
1425 |
highlightCompletedText(0);
|
1426 |
} |
1427 |
else
|
1428 |
{ |
1429 |
// If dynamic searches:
|
1430 |
try {
|
1431 |
// If the search will be dynamic:
|
1432 |
if (isDynamicSearchConfiguration())
|
1433 |
{ |
1434 |
model.setWrittenText(document.getText(0, document.getLength()));
|
1435 |
logger.debug("Texto que se le env?a al modelo desde SUPR: ->" + document.getText(0, document.getLength()) + "<-"); |
1436 |
} |
1437 |
} catch (BadLocationException e) { |
1438 |
// TODO Auto-generated catch block
|
1439 |
e.printStackTrace(); |
1440 |
} |
1441 |
} |
1442 |
break;
|
1443 |
} |
1444 |
|
1445 |
updatePopUpView(); |
1446 |
|
1447 |
} |
1448 |
|
1449 |
/**
|
1450 |
*
|
1451 |
*/
|
1452 |
private void definePopUpMenuListener(JComboBoxItemsSeekerConfigurable combo_Box) { |
1453 |
final JComboBoxItemsSeekerConfigurable comboBoxReference = combo_Box;
|
1454 |
|
1455 |
this.popupMenuListener = new PopupMenuListener() { |
1456 |
|
1457 |
/*
|
1458 |
* (non-Javadoc)
|
1459 |
* @see javax.swing.event.PopupMenuListener#popupMenuCanceled(javax.swing.event.PopupMenuEvent)
|
1460 |
*/
|
1461 |
public void popupMenuCanceled(PopupMenuEvent e) { |
1462 |
// TODO Auto-generated method stub
|
1463 |
logger.debug("MenuCANCELED");
|
1464 |
|
1465 |
// // This is used when the component has lost the focus, the popup whas in show state and is restored the focus -> update the popup
|
1466 |
// if (isPopupVisible())
|
1467 |
// popupVisible = true;
|
1468 |
// else
|
1469 |
// popupVisible = false;
|
1470 |
} |
1471 |
|
1472 |
/*
|
1473 |
* (non-Javadoc)
|
1474 |
* @see javax.swing.event.PopupMenuListener#popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent)
|
1475 |
*/
|
1476 |
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { |
1477 |
// TODO Auto-generated method stub
|
1478 |
logger.debug("MenuBECOMEINVISIBLE");
|
1479 |
// popupVisible = false;
|
1480 |
|
1481 |
|
1482 |
// if ((!textKeyPressed) && (!optionsEditorWasVisible))
|
1483 |
if (!textKeyPressed)
|
1484 |
{ |
1485 |
if (lastSelectedItem != null) |
1486 |
{ |
1487 |
// If the user has select a different item with the mouse, and this is in the Start View State -> change to the Search View State
|
1488 |
if (!getSelectedItem().equals(lastSelectedItem))
|
1489 |
{ |
1490 |
logger.debug("POPUP: NO SON IGUALES");
|
1491 |
|
1492 |
// Reports about the written text to the model
|
1493 |
if (model.isDynamicSearch())
|
1494 |
{ |
1495 |
model.setWrittenText(getSelectedItem().toString()); |
1496 |
logger.debug("Texto que le envia POPUP al modelo: ->" + getSelectedItem().toString() + "<-"); |
1497 |
} |
1498 |
|
1499 |
if (currentShowState == START_VIEW_STATE)
|
1500 |
{ |
1501 |
model.setStartViewFlag(false);
|
1502 |
currentShowState = SEARCH_VIEW_STATE; |
1503 |
// updateLastSelectionItem();
|
1504 |
} |
1505 |
logger.debug("Selected index of item: " + lastSelectedItem.toString() + " is " + getSelectedIndex()); |
1506 |
// updatePopUpView();
|
1507 |
// setSelectedIndex(1);
|
1508 |
} |
1509 |
else
|
1510 |
logger.debug("POPUP: SON IGUALES");
|
1511 |
} |
1512 |
} |
1513 |
} |
1514 |
|
1515 |
/*
|
1516 |
* (non-Javadoc)
|
1517 |
* @see javax.swing.event.PopupMenuListener#popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent)
|
1518 |
*/
|
1519 |
public void popupMenuWillBecomeVisible(PopupMenuEvent e) { |
1520 |
// TODO Auto-generated method stub
|
1521 |
logger.debug("MenuBECOMEVISIBLE");
|
1522 |
// popupVisible = true;
|
1523 |
lastSelectedItem = selectedItem; // This object is used for know if the user has select a different item with the mouse
|
1524 |
} |
1525 |
}; |
1526 |
} |
1527 |
|
1528 |
|
1529 |
/**
|
1530 |
* Returns true if the model has a dynamic search configuration
|
1531 |
*
|
1532 |
* @return
|
1533 |
*/
|
1534 |
private boolean isDynamicSearchConfiguration() { |
1535 |
switch(model.getSearchBehavior())
|
1536 |
{ |
1537 |
case AbstractDefaultComboBoxItemsSeekerConfigurableModel.MAINTAIN_ORIGINAL_POSITION_DYNAMIC_SEARCH :
|
1538 |
case AbstractDefaultComboBoxItemsSeekerConfigurableModel.ORDERED_DYNAMIC_SEARCH :
|
1539 |
case AbstractDefaultComboBoxItemsSeekerConfigurableModel.DISORDERED_DYNAMIC_SEARCH :
|
1540 |
return true; |
1541 |
} |
1542 |
|
1543 |
return false; |
1544 |
} |
1545 |
|
1546 |
|
1547 |
// comboBoxReference.getUI().
|
1548 |
// for (int i=0; i<comboBoxReference.getComponentCount(); i++) {
|
1549 |
// logger.debug("Componente: " + comboBoxReference.getComponent(i).getName());
|
1550 |
// comboBoxReference.getComponent(i).addMouseListener(editorMouseListener);
|
1551 |
//
|
1552 |
// }
|
1553 |
// this.addMouseListener(editorMouseListener);
|
1554 |
// }
|
1555 |
|
1556 |
/**
|
1557 |
* Selects the first item added to the model
|
1558 |
*/
|
1559 |
public void selectFirstItemAddedToModel() { |
1560 |
// Select the first Item added
|
1561 |
Object item = model.getFirstItemAdded();
|
1562 |
if (item != null) |
1563 |
setSelectedItem(item); |
1564 |
} |
1565 |
|
1566 |
private void configureEditor(ComboBoxEditor newEditor) { |
1567 |
JTextComponent editor = (JTextComponent) this.getEditor().getEditorComponent(); |
1568 |
|
1569 |
// If there isn't any change on the editor
|
1570 |
if (editor == newEditor)
|
1571 |
return;
|
1572 |
|
1573 |
// Remove the default or last keyListener and FocusListener of the editor of this component
|
1574 |
if (editor != null) { |
1575 |
editor.removeKeyListener(this.editorKeyListener);
|
1576 |
editor.removeMouseListener(this.editorMouseListener);
|
1577 |
editor.removeFocusListener(this.editorFocusListener);
|
1578 |
} |
1579 |
|
1580 |
// Add the new keyListener and FocusListener for this editor and sets
|
1581 |
// it document as a PlainDocument to optimize the searches of items
|
1582 |
// when user writes on this editor
|
1583 |
if (newEditor != null) { |
1584 |
editor = (JTextComponent) newEditor.getEditorComponent();
|
1585 |
editor.addKeyListener(this.editorKeyListener);
|
1586 |
editor.addMouseListener(this.editorMouseListener);
|
1587 |
editor.addFocusListener(this.editorFocusListener);
|
1588 |
editor.setDocument(this.document);
|
1589 |
|
1590 |
// Disable the focus transversal keys (Example: CTRL+TAB) for enable the TAB key
|
1591 |
editor.setFocusTraversalKeysEnabled(false);
|
1592 |
} |
1593 |
|
1594 |
// editor.add(optionsEditionByMouse);
|
1595 |
// ((JButton)this.getComponent(0)).add(optionsEditionByMouse);
|
1596 |
} |
1597 |
|
1598 |
/**
|
1599 |
* Marks text since 'start' position to its end on a grey color
|
1600 |
*
|
1601 |
* @param start Start position for mark the text
|
1602 |
*/
|
1603 |
private void highlightCompletedText(int start) { |
1604 |
JTextComponent editor = (JTextComponent) this.getEditor().getEditorComponent(); |
1605 |
|
1606 |
editor.setCaretPosition(document.getLength()); |
1607 |
editor.moveCaretPosition(start); |
1608 |
} |
1609 |
|
1610 |
/**
|
1611 |
*
|
1612 |
*/
|
1613 |
private void updatePopUpView() { |
1614 |
// HidePopUp + ShowPopUp to force update the popup list of items
|
1615 |
hidePopup(); |
1616 |
showPopup(); |
1617 |
this.setVisible(true); |
1618 |
} |
1619 |
|
1620 |
////// REDEFINITION OF SOME METHODS OF JCOMBOBOX //////
|
1621 |
|
1622 |
|
1623 |
/*
|
1624 |
* (non-Javadoc)
|
1625 |
* @see javax.swing.JComboBox#actionPerformed(java.awt.event.ActionEvent)
|
1626 |
*/
|
1627 |
public void actionPerformed(ActionEvent e) |
1628 |
{ |
1629 |
super.actionPerformed(e);
|
1630 |
// logger.debug("Action-Performed");
|
1631 |
|
1632 |
// This flag indicates to the 'insertString' method of the PlainDocumentSeeker that the text of the item selected or written by the user
|
1633 |
// hasn't been written on the TextEditor of ths component
|
1634 |
selecting = false;
|
1635 |
} |
1636 |
|
1637 |
|
1638 |
/*
|
1639 |
* (non-Javadoc)
|
1640 |
* @see javax.swing.JComboBox#addItem(java.lang.Object)
|
1641 |
*/
|
1642 |
public void addItem(Object anObject) { |
1643 |
// Adds the item to this component
|
1644 |
model.addElement(anObject); |
1645 |
|
1646 |
// logger.debug("LastSelectedIndexWas: " + this.lastSelectedIndex);
|
1647 |
|
1648 |
// Set the last selected item -> by default select the first item:
|
1649 |
// This is used to show the first item that model returns when we add a new item. This also
|
1650 |
// corrects the 'mistake' produced by 'ComboBoxModel' when is added a new item and there wasn't
|
1651 |
// any selected -> that the 'ComboBoxModel' selects by default the first added (that in our case
|
1652 |
// might not be the same as the first item seen in the popup list)
|
1653 |
if (this.getSelectedIndex() != 0) |
1654 |
{ |
1655 |
this.setSelectedIndex(0); |
1656 |
this.selectedItem = this.getSelectedItem(); |
1657 |
} |
1658 |
} |
1659 |
|
1660 |
/*
|
1661 |
* (non-Javadoc)
|
1662 |
* @see javax.swing.JComboBox#removeAllItems()
|
1663 |
*/
|
1664 |
public void removeAllItems() { |
1665 |
// Removes all items from the model
|
1666 |
model.removeAllElements(); |
1667 |
|
1668 |
currentShowState = BEGINNING_VIEW_STATE; |
1669 |
} |
1670 |
|
1671 |
/*
|
1672 |
* (non-Javadoc)
|
1673 |
* @see javax.swing.JComboBox#removeItem(java.lang.Object)
|
1674 |
*/
|
1675 |
public void removeItem(Object anObject) { |
1676 |
// Removes an object from the model
|
1677 |
model.removeElement(anObject); |
1678 |
|
1679 |
if (model.getSize() == 0) |
1680 |
currentShowState = BEGINNING_VIEW_STATE; |
1681 |
} |
1682 |
|
1683 |
/*
|
1684 |
* (non-Javadoc)
|
1685 |
* @see javax.swing.JComboBox#removeItemAt(int)
|
1686 |
*/
|
1687 |
public void removeItemAt(int anIndex) { |
1688 |
// Removes an object, which is in a determinated position (index), from the model
|
1689 |
model.removeElementAt(anIndex); |
1690 |
|
1691 |
if (model.getSize() == 0) |
1692 |
currentShowState = BEGINNING_VIEW_STATE; |
1693 |
} |
1694 |
|
1695 |
// /*
|
1696 |
// * (non-Javadoc)
|
1697 |
// * @see javax.swing.JComboBox#getSelectedIndex()
|
1698 |
// */
|
1699 |
// public int getSelectedIndex() {
|
1700 |
// // ??Modificarlo??
|
1701 |
// return super.getSelectedIndex();
|
1702 |
// }
|
1703 |
|
1704 |
/*
|
1705 |
* (non-Javadoc)
|
1706 |
* @see javax.swing.JComboBox#getItemCount()
|
1707 |
*/
|
1708 |
public int getItemCount() { |
1709 |
return model.getSize();
|
1710 |
} |
1711 |
|
1712 |
/*
|
1713 |
* (non-Javadoc)
|
1714 |
* @see javax.swing.JComboBox#getItemAt(int)
|
1715 |
*/
|
1716 |
public Object getItemAt(int index) { |
1717 |
return model.getElementAt(index);
|
1718 |
} |
1719 |
|
1720 |
/*
|
1721 |
* (non-Javadoc)
|
1722 |
* @see javax.swing.JComboBox#setModel(javax.swing.ComboBoxModel)
|
1723 |
*/
|
1724 |
public void setModel(ComboBoxModel aModel) { //PROBLEMA |
1725 |
|
1726 |
// Depending on the type of class of the current object, this object will execute different code
|
1727 |
if ( (aModel instanceof ComboBoxSingularItemsSeekerConfigurableModel) || (aModel instanceof ComboBoxItemsSeekerConfigurableModel) ) |
1728 |
{ |
1729 |
// logger.debug("A");
|
1730 |
//super.setModel(aModel);
|
1731 |
super.setModel(aModel);
|
1732 |
|
1733 |
if (aModel instanceof ComboBoxSingularItemsSeekerConfigurableModel) |
1734 |
model = (ComboBoxSingularItemsSeekerConfigurableModel)super.getModel();
|
1735 |
else
|
1736 |
model = (ComboBoxItemsSeekerConfigurableModel)super.getModel();
|
1737 |
|
1738 |
// If we insert a model with items -> select by default the first
|
1739 |
if (aModel.getSize() > 0) |
1740 |
{ |
1741 |
this.setSelectedIndex(0); |
1742 |
this.selectedItem = this.getSelectedItem(); |
1743 |
// model.setCurrentString(this.getSelectedItem().toString());
|
1744 |
} |
1745 |
else
|
1746 |
{ |
1747 |
// Else -> set the default index (-1) and current showed string ("")
|
1748 |
this.selectedItem = null; |
1749 |
this.setSelectedIndex(-1); |
1750 |
// model.setCurrentString("");
|
1751 |
} |
1752 |
|
1753 |
this.configureModel();
|
1754 |
} |
1755 |
else
|
1756 |
{ |
1757 |
// If it's an instance of DefaultComboBoxModel:
|
1758 |
|
1759 |
// logger.debug("B");
|
1760 |
super.setModel(aModel);
|
1761 |
} |
1762 |
} |
1763 |
|
1764 |
/*
|
1765 |
* (non-Javadoc)
|
1766 |
* @see javax.swing.JComboBox#setSelectedIndex(int)
|
1767 |
*/
|
1768 |
public void setSelectedIndex(int anIndex) { |
1769 |
super.setSelectedIndex(anIndex);
|
1770 |
this.selectedItem = super.getSelectedItem(); |
1771 |
|
1772 |
// this.lastSelectedIndex = anIndex;
|
1773 |
|
1774 |
try {
|
1775 |
document.remove(0, document.getLength());
|
1776 |
if (getSelectedIndex() > -1) |
1777 |
document.insertString(0, getSelectedItem().toString(), null); |
1778 |
// else
|
1779 |
// this.lastSelectedIndex = -1;
|
1780 |
|
1781 |
} catch (BadLocationException e) { |
1782 |
// TODO Auto-generated catch block
|
1783 |
e.printStackTrace(); |
1784 |
} |
1785 |
} |
1786 |
|
1787 |
/*
|
1788 |
* (non-Javadoc)
|
1789 |
* @see javax.swing.JComboBox#getSelectedIndex()
|
1790 |
*/
|
1791 |
public int getSelectedIndex() { |
1792 |
Object item = this.getSelectedItem(); |
1793 |
|
1794 |
if (item == null) |
1795 |
return -1; |
1796 |
else
|
1797 |
return model.getIndexOf(item);
|
1798 |
} |
1799 |
|
1800 |
/*
|
1801 |
* (non-Javadoc)
|
1802 |
* @see javax.swing.JComboBox#setSelectedItem(java.lang.Object)
|
1803 |
*/
|
1804 |
public void setSelectedItem(Object anObject) { |
1805 |
super.setSelectedItem(anObject);
|
1806 |
this.selectedItem = super.getSelectedItem(); |
1807 |
// this.lastSelectedIndex = model.getIndexOf(anObject);
|
1808 |
// logger.debug("Posici?n: " + this.lastSelectedIndex);
|
1809 |
|
1810 |
//super.setSelectedIndex(this.lastSelectedIndex);
|
1811 |
|
1812 |
// try {
|
1813 |
// document.remove(0, document.getLength());
|
1814 |
// if (getSelectedIndex() > -1)
|
1815 |
// document.insertString(0, getSelectedItem().toString(), null);
|
1816 |
// else
|
1817 |
// this.lastSelectedIndex = -1;
|
1818 |
//
|
1819 |
// } catch (BadLocationException e) {
|
1820 |
// // TODO Auto-generated catch block
|
1821 |
// e.printStackTrace();
|
1822 |
// }
|
1823 |
} |
1824 |
|
1825 |
//
|
1826 |
////// END REDEFINITION OF SOME METHODS OF JCOMBOBOX //////
|
1827 |
|
1828 |
|
1829 |
|
1830 |
|
1831 |
|
1832 |
////// METHODS FOR THE BEHAVIOR FLAGS //////
|
1833 |
|
1834 |
/**
|
1835 |
* This method tests the configuration of the flags and returns true or false if its ok or not with the
|
1836 |
* logical behavior of this component
|
1837 |
*
|
1838 |
* @return boolean True if the configuration of the flags is oks, false if not
|
1839 |
*/
|
1840 |
public boolean testFlagsConfigurationOK() { |
1841 |
return this.model.testFlagsConfigurationOK(); |
1842 |
} |
1843 |
|
1844 |
public int getStartBehavior() { |
1845 |
return this.model.getStartBehavior(); |
1846 |
} |
1847 |
|
1848 |
public void setStartBehavior(int start_Behavior) { |
1849 |
this.model.setStartBehavior(start_Behavior);
|
1850 |
|
1851 |
if (!this.model.testFlagsConfigurationOK()) |
1852 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "errorMessageJComboBoxItemsSeekerConfigurable"), PluginServices.getText(this, "exportJOP2Title"), JOptionPane.ERROR_MESSAGE); |
1853 |
else
|
1854 |
updateLastSelectionItem(); |
1855 |
} |
1856 |
|
1857 |
public int getSearchBehavior() { |
1858 |
return this.model.getSearchBehavior(); |
1859 |
} |
1860 |
|
1861 |
public void setSearchBehavior(int search_Behavior) { |
1862 |
this.model.setSearchBehavior(search_Behavior);
|
1863 |
|
1864 |
if (!this.model.testFlagsConfigurationOK()) |
1865 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "errorMessageJComboBoxItemsSeekerConfigurable"), PluginServices.getText(this, "exportJOP2Title"), JOptionPane.ERROR_MESSAGE); |
1866 |
else
|
1867 |
updateLastSelectionItem(); |
1868 |
} |
1869 |
|
1870 |
|
1871 |
/**
|
1872 |
* Gets the flag of the configuration of the caseSensitive flag of this component
|
1873 |
* (true -> discriminates capital letters from small letters ,false -> don't discriminates capital letters from small letters)
|
1874 |
*
|
1875 |
* @return boolean The value of the flag
|
1876 |
*/
|
1877 |
public boolean isCaseSensitive() { |
1878 |
return this.model.isCaseSensitive(); |
1879 |
} |
1880 |
|
1881 |
/**
|
1882 |
* Sets the flag of the configuration of the caseSensitive flag of this component
|
1883 |
* (true -> discriminates capital letters from small letters ,false -> don't discriminates capital letters from small letters)
|
1884 |
*
|
1885 |
* @param boolean The value of the flag
|
1886 |
*/
|
1887 |
public void setCaseSensitive(boolean case_Sensitive) { |
1888 |
this.model.setCaseSensitive(case_Sensitive);
|
1889 |
|
1890 |
if (!this.model.testFlagsConfigurationOK()) |
1891 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "errorMessageJComboBoxItemsSeekerConfigurable"), PluginServices.getText(this, "exportJOP2Title"), JOptionPane.ERROR_MESSAGE); |
1892 |
} |
1893 |
|
1894 |
/**
|
1895 |
* Gets the flag of the configuration of the onlyOneColor flag of this component
|
1896 |
* (true -> The text on the textField only will be showed on black color; false -> if the text on the textField doesn't match with any current item of this
|
1897 |
* component -> the text will be showed on red color)
|
1898 |
*
|
1899 |
* @return boolean The value of the flag
|
1900 |
*/
|
1901 |
public boolean isOnlyOneColor() { |
1902 |
return onlyOneColor;
|
1903 |
} |
1904 |
|
1905 |
|
1906 |
/**
|
1907 |
* Sets the flag of the configuration of the onlyOneColor flag of this component
|
1908 |
* (true -> discriminates capital letters from small letters ,false -> don't discriminates capital letters from small letters)
|
1909 |
*
|
1910 |
* @param boolean The value of the flag
|
1911 |
*/
|
1912 |
public void setOnlyOneColor(boolean only_One_Color) { |
1913 |
this.onlyOneColor = only_One_Color;
|
1914 |
|
1915 |
if (!this.model.testFlagsConfigurationOK()) |
1916 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this, "errorMessageJComboBoxItemsSeekerConfigurable"), PluginServices.getText(this, "exportJOP2Title"), JOptionPane.ERROR_MESSAGE); |
1917 |
} |
1918 |
|
1919 |
|
1920 |
public boolean isBeepEnabled() { |
1921 |
return this.beepEnabled; |
1922 |
} |
1923 |
|
1924 |
public void setBeepEnabled(boolean beep_Enabled) { |
1925 |
this.beepEnabled = beep_Enabled;
|
1926 |
} |
1927 |
|
1928 |
public boolean isCompleteMatchedItem() { |
1929 |
return this.completeMatchedItem; |
1930 |
} |
1931 |
|
1932 |
public void setCompleteMatchedItem(boolean Complete_Matched_Item) { |
1933 |
this.completeMatchedItem = Complete_Matched_Item;
|
1934 |
} |
1935 |
|
1936 |
public boolean isAllowedRepeatedItems() { |
1937 |
return this.allowedRepeatedItems; |
1938 |
} |
1939 |
|
1940 |
public void setAllowedRepeatedItems(boolean allowed_Repeated_Items) { |
1941 |
this.allowedRepeatedItems = allowed_Repeated_Items;
|
1942 |
|
1943 |
try {
|
1944 |
AbstractDefaultComboBoxItemsSeekerConfigurableModel model_temp; |
1945 |
// if (model.getSize() > 0)
|
1946 |
// {
|
1947 |
// Add the items to the new model
|
1948 |
if (allowed_Repeated_Items)
|
1949 |
model_temp = new ComboBoxItemsSeekerConfigurableModel(model.getParentAllData());
|
1950 |
else
|
1951 |
model_temp = new ComboBoxSingularItemsSeekerConfigurableModel(model.getParentAllData());
|
1952 |
|
1953 |
// Copy the behavior of the model
|
1954 |
model_temp.setStartBehavior(this.getStartBehavior());
|
1955 |
model_temp.setSearchBehavior(this.getSearchBehavior());
|
1956 |
model_temp.setCaseSensitive(this.isCaseSensitive());
|
1957 |
|
1958 |
// Set the new model
|
1959 |
this.setModel(model_temp);
|
1960 |
// }
|
1961 |
} |
1962 |
catch(Exception e) |
1963 |
{ |
1964 |
e.printStackTrace(); |
1965 |
} |
1966 |
} |
1967 |
|
1968 |
|
1969 |
|
1970 |
////// END METHODS FOR THE BEHAVIOR FLAGS //////
|
1971 |
|
1972 |
////// IMPLEMENTATION OF THE METHODS OF THE INTERFACE 'PropertyChangeListener' //////
|
1973 |
/* (non-Javadoc)
|
1974 |
* @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
|
1975 |
*/
|
1976 |
// public void propertyChange(PropertyChangeEvent arg0) {
|
1977 |
// // TODO Auto-generated method stub
|
1978 |
// logger.debug("AAAAAAAAA");
|
1979 |
//
|
1980 |
// if (arg0.getPropertyName().equals(OptionsEditionByMouse.PROPERTYNAME)) {
|
1981 |
// JTextComponent editor = (JTextComponent) getEditor().getEditorComponent();
|
1982 |
//
|
1983 |
// logger.debug("PropertyChanged: " + arg0.getNewValue().toString());
|
1984 |
//
|
1985 |
// switch(Integer.parseInt(arg0.getNewValue().toString()))
|
1986 |
// {//HACER!!
|
1987 |
// case OptionsEditionByMouse.UNDO:
|
1988 |
// break;
|
1989 |
// case OptionsEditionByMouse.REDO:
|
1990 |
// break;
|
1991 |
// case OptionsEditionByMouse.CUT:
|
1992 |
// break;
|
1993 |
// case OptionsEditionByMouse.COPY:
|
1994 |
// break;
|
1995 |
// case OptionsEditionByMouse.PASTE:
|
1996 |
// break;
|
1997 |
// case OptionsEditionByMouse.DELETE:
|
1998 |
// try {
|
1999 |
// document.remove(0, document.getLength());
|
2000 |
// } catch (BadLocationException e) {
|
2001 |
// // TODO Auto-generated catch block
|
2002 |
// e.printStackTrace();
|
2003 |
// }
|
2004 |
// break;
|
2005 |
// case OptionsEditionByMouse.SELECT_ALL:
|
2006 |
// break;
|
2007 |
// default: // do anything
|
2008 |
// }
|
2009 |
// }
|
2010 |
//
|
2011 |
// }
|
2012 |
|
2013 |
////// END IMPLEMENTATION OF THE METHODS OF THE INTERFACE 'PropertyChangeListener' //////
|
2014 |
|
2015 |
/** REVISAR COMENTARIOS Y C?DIGO
|
2016 |
* Inner class for optimize the seek of items
|
2017 |
*
|
2018 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
|
2019 |
*
|
2020 |
*/
|
2021 |
private class PlainDocumentSeeker extends PlainDocument{ |
2022 |
private JComboBoxItemsSeekerConfigurable comboBox;
|
2023 |
|
2024 |
|
2025 |
/**
|
2026 |
* Default Constructor
|
2027 |
*/
|
2028 |
public PlainDocumentSeeker() {
|
2029 |
super();
|
2030 |
|
2031 |
// // Add an Undo - Redo Listener
|
2032 |
// this.addUndoableEditListener(new MyUndoableEditListener());
|
2033 |
} |
2034 |
|
2035 |
/**
|
2036 |
* Sets a reference of the combo_Box
|
2037 |
*
|
2038 |
* @param combo_Box
|
2039 |
*/
|
2040 |
public void setJComboBoxItemsSeekerDynamicReference(JComboBoxItemsSeekerConfigurable combo_Box) { |
2041 |
comboBox = combo_Box; |
2042 |
} |
2043 |
|
2044 |
/* REVISAR
|
2045 |
* (non-Javadoc)
|
2046 |
* @see javax.swing.text.Document#remove(int, int)
|
2047 |
*/
|
2048 |
public void remove(int offs, int len) throws BadLocationException { |
2049 |
// return immediately when selecting an item
|
2050 |
if (selecting) return; |
2051 |
|
2052 |
if (hitBackspace)
|
2053 |
{ |
2054 |
// user hit backspace => move the selection backwards
|
2055 |
// old item keeps being selected
|
2056 |
if (offs>0) |
2057 |
{ |
2058 |
if (hitBackspaceOnSelection)
|
2059 |
offs--; |
2060 |
} |
2061 |
else
|
2062 |
{ |
2063 |
// User hit backspace with the cursor positioned on the start => beep
|
2064 |
if (beepEnabled)
|
2065 |
comboBox.getToolkit().beep(); // when available use: UIManager.getLookAndFeel().provideErrorFeedback(comboBox);
|
2066 |
} |
2067 |
|
2068 |
highlightCompletedText(offs); |
2069 |
hitBackspace=false;
|
2070 |
} |
2071 |
else
|
2072 |
{ |
2073 |
super.remove(offs, len);
|
2074 |
} |
2075 |
|
2076 |
lookupItem(document.getText(0, document.getLength()));
|
2077 |
|
2078 |
|
2079 |
// if ((!isOnlyOneColor()) && (selectedItem == null))
|
2080 |
// comboBox.getEditor().getEditorComponent().setForeground(Color.RED);
|
2081 |
|
2082 |
//
|
2083 |
// if (updatePopUp)
|
2084 |
// {
|
2085 |
// updatePopUpView();
|
2086 |
// updatePopUp = false;
|
2087 |
// }
|
2088 |
|
2089 |
} |
2090 |
|
2091 |
/*VERSI?N NUEVA
|
2092 |
* (non-Javadoc)
|
2093 |
* @see javax.swing.text.Document#insertString(int, java.lang.String, javax.swing.text.AttributeSet)
|
2094 |
*/
|
2095 |
public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { |
2096 |
// super.insertString(offs, str, a);
|
2097 |
logger.debug("INSERTSTRING: " + str);
|
2098 |
// model.setCurrentString(str);
|
2099 |
|
2100 |
if (model.getParentSize() > 0) |
2101 |
{ |
2102 |
// Insert the string into the document
|
2103 |
|
2104 |
// If we aren't in the particular case of show all items at the beginning and is enabled the flag for complete the matched item:
|
2105 |
// this is for not insert two strings to the document of the editor of this component
|
2106 |
if (!((completeMatchedItem) && (model.isStartViewFlag())))
|
2107 |
// if (!completeMatchedItem)
|
2108 |
{ |
2109 |
super.insertString(offs, str, a);
|
2110 |
logger.debug("INSERT STRING DE PLAINDOCUMENTSEEKER A?ADE : " + str);
|
2111 |
} |
2112 |
|
2113 |
String text = getText(0, getLength()); |
2114 |
// Lookup and select a matching item
|
2115 |
Object item = lookupItem(text);
|
2116 |
|
2117 |
if (item != null) |
2118 |
{ |
2119 |
logger.debug("ITEM NOT NULL");
|
2120 |
|
2121 |
setSelectedItem(item); |
2122 |
|
2123 |
if (!completeMatchedItem)
|
2124 |
|
2125 |
|
2126 |
// Set the complete item value matched
|
2127 |
if (completeMatchedItem)
|
2128 |
setText(item.toString()); |
2129 |
else
|
2130 |
{ |
2131 |
editor.getEditorComponent().setForeground(Color.BLACK);
|
2132 |
setText(text); |
2133 |
} |
2134 |
|
2135 |
// Imitate no insert (later on offs will be incremented by str.length(): selection won't move forward)
|
2136 |
offs+=str.length(); |
2137 |
} |
2138 |
else
|
2139 |
{ |
2140 |
logger.debug("ITEM NULL");
|
2141 |
|
2142 |
// If no item matches -> default selection (no item selection)
|
2143 |
selectedItem = null;
|
2144 |
setSelectedIndex(-1);
|
2145 |
super.insertString(0, text, null); |
2146 |
|
2147 |
// Provide feedback to the user that his input has been received but can not be accepted
|
2148 |
if (beepEnabled)
|
2149 |
comboBox.getToolkit().beep(); // when available use: UIManager.getLookAndFeel().provideErrorFeedback(comboBox);
|
2150 |
|
2151 |
// Update the popup view for not see any item selected
|
2152 |
updatePopUpView(); |
2153 |
} |
2154 |
|
2155 |
// Select the completed part
|
2156 |
highlightCompletedText(offs); |
2157 |
|
2158 |
if (textKeyPressed)
|
2159 |
{ |
2160 |
// updatePopUpView();
|
2161 |
|
2162 |
textKeyPressed = false;
|
2163 |
} |
2164 |
} |
2165 |
} |
2166 |
|
2167 |
|
2168 |
// /*VERSI?N ANTIGUA
|
2169 |
// * (non-Javadoc)
|
2170 |
// * @see javax.swing.text.Document#insertString(int, java.lang.String, javax.swing.text.AttributeSet)
|
2171 |
// */
|
2172 |
// public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
|
2173 |
//// super.insertString(offs, str, a);
|
2174 |
// logger.debug("INSERTSTRING: " + str);
|
2175 |
//// model.setCurrentString(str);
|
2176 |
//
|
2177 |
// if (model.getParentSize() > 0)
|
2178 |
// {
|
2179 |
// // Insert the string into the document
|
2180 |
//
|
2181 |
// // If we aren't in the particular case of show al items at the beginning and is enabled the flag for complete the matched item:
|
2182 |
// // this is for not insert two strings to the document of the editor of this component
|
2183 |
// if (!((completeMatchedItem) && (model.isStartViewFlag())))
|
2184 |
// // if (!completeMatchedItem)
|
2185 |
// {
|
2186 |
// super.insertString(offs, str, a);
|
2187 |
// logger.debug("INSERT STRING DE PLAINDOCUMENTSEEKER A?ADE : " + str);
|
2188 |
// }
|
2189 |
//
|
2190 |
// // Lookup and select a matching item
|
2191 |
// Object item = lookupItem(getText(0, getLength()));
|
2192 |
//
|
2193 |
// if (item != null)
|
2194 |
// {
|
2195 |
// logger.debug("ITEM NOT NULL");
|
2196 |
// if ((completeMatchedItem) || (getSearchBehavior() == AbstractDefaultComboBoxItemsSeekerConfigurableModel.MAINTAIN_ORIGINAL_POSITION_ALL_ITEMS_SEARCH))
|
2197 |
// setSelectedItem(item);
|
2198 |
//
|
2199 |
//
|
2200 |
// // model.setCurrentString(getSelectedItem().toString());
|
2201 |
// // lastSelectedIndex = getSelectedIndex();
|
2202 |
// }
|
2203 |
// else
|
2204 |
// {
|
2205 |
// logger.debug("ITEM NULL");
|
2206 |
// // Keep old item selected if there is no match
|
2207 |
// item = comboBox.getSelectedItem();
|
2208 |
// logger.debug("ITEM QUE SELECCIONA CUANDO NULL: ->" + item.toString() + "<-");
|
2209 |
//
|
2210 |
// // Imitate no insert (later on offs will be incremented by str.length(): selection won't move forward)
|
2211 |
// offs = offs-str.length();
|
2212 |
//
|
2213 |
// // Provide feedback to the user that his input has been received but can not be accepted
|
2214 |
// if (beepEnabled)
|
2215 |
// comboBox.getToolkit().beep(); // when available use: UIManager.getLookAndFeel().provideErrorFeedback(comboBox);
|
2216 |
// }
|
2217 |
//
|
2218 |
// // Set the complete item value matched
|
2219 |
// if (completeMatchedItem)
|
2220 |
// setText(item.toString());
|
2221 |
//
|
2222 |
// // Select the completed part
|
2223 |
// highlightCompletedText(offs+str.length());
|
2224 |
//
|
2225 |
// if (textKeyPressed)
|
2226 |
// {
|
2227 |
//// updatePopUpView();
|
2228 |
//
|
2229 |
// textKeyPressed = false;
|
2230 |
// }
|
2231 |
// }
|
2232 |
// }
|
2233 |
|
2234 |
/** ?Sobra?
|
2235 |
* This method sets the string value of the item to the PlainDocument removing the previous value of the PlainDocument
|
2236 |
*
|
2237 |
* @param text The string value of the item
|
2238 |
*/
|
2239 |
private void setText(String text) { |
2240 |
try
|
2241 |
{ |
2242 |
// remove all text and insert the completed string
|
2243 |
super.remove(0, super.getLength()); |
2244 |
super.insertString(0, text, null); |
2245 |
logger.debug("SET TEXT DE PLAINDOCUMENTSEEKER A?ADE : " + text);
|
2246 |
} |
2247 |
catch (BadLocationException e) |
2248 |
{ |
2249 |
throw new RuntimeException(e.toString()); |
2250 |
} |
2251 |
} |
2252 |
|
2253 |
/** ANTIGUO
|
2254 |
* Only in red color if is allowed by the configuration and any item starts with this pattern
|
2255 |
*/
|
2256 |
private Object lookupItem(String pattern) { |
2257 |
logger.debug("LOOKUP -> patr?n ->" + pattern + "<-"); |
2258 |
// Reset the color to the default
|
2259 |
// editor.getEditorComponent().setForeground(Color.BLACK);
|
2260 |
|
2261 |
// If no item starts with the pattern => return null and set the text written on red color if it's allowed
|
2262 |
|
2263 |
Object selectedItem = model.getSelectedItem();
|
2264 |
|
2265 |
// if (selectedItem.toString().length() >= pattern.length())
|
2266 |
// {
|
2267 |
// only search for a different item if the currently selected does not match
|
2268 |
if ((selectedItem != null) && (str1StartsWithStr2(selectedItem.toString(), pattern))) |
2269 |
{ |
2270 |
editor.getEditorComponent().setForeground(Color.BLACK);
|
2271 |
|
2272 |
this.setRedColorToTextIfDoesntMatch(selectedItem.toString(), pattern);
|
2273 |
|
2274 |
return selectedItem;
|
2275 |
} |
2276 |
else
|
2277 |
{ |
2278 |
// iterate over all items
|
2279 |
for (int i=0, n=model.getSize(); i < n; i++) |
2280 |
{ |
2281 |
Object currentItem = model.getElementAt(i);
|
2282 |
|
2283 |
// current item starts with the pattern?
|
2284 |
if ((currentItem != null) && (str1StartsWithStr2(currentItem.toString(), pattern))) |
2285 |
{ |
2286 |
editor.getEditorComponent().setForeground(Color.BLACK);
|
2287 |
|
2288 |
this.setRedColorToTextIfDoesntMatch(currentItem.toString(), pattern);
|
2289 |
|
2290 |
return currentItem;
|
2291 |
} |
2292 |
} |
2293 |
} |
2294 |
|
2295 |
if (!comboBox.isOnlyOneColor()){
|
2296 |
editor.getEditorComponent().setForeground(Color.RED);
|
2297 |
logger.debug("Pone a Rojo Lookup");
|
2298 |
} |
2299 |
|
2300 |
return null; |
2301 |
} |
2302 |
|
2303 |
// /** NUEVO
|
2304 |
// * Only in red color if is allowed by the configuration and any item starts with this pattern
|
2305 |
// */
|
2306 |
// private Object lookupItem(String pattern) {
|
2307 |
// logger.debug("LOOKUP -> patr?n ->" + pattern + "<-");
|
2308 |
// // Reset the color to the default
|
2309 |
//// editor.getEditorComponent().setForeground(Color.BLACK);
|
2310 |
//
|
2311 |
// // If no item starts with the pattern => return null and set the text written on red color if it's allowed
|
2312 |
//
|
2313 |
// Object selectedItem = model.getSelectedItem();
|
2314 |
//
|
2315 |
// if (isCaseSensitive())
|
2316 |
// {
|
2317 |
// // only search for a different item if the currently selected does not match
|
2318 |
// if ((selectedItem != null) && (startsWith(selectedItem.toString(), pattern)))
|
2319 |
// {
|
2320 |
// editor.getEditorComponent().setForeground(Color.BLACK);
|
2321 |
//
|
2322 |
// if (!isOnlyOneColor()){
|
2323 |
// editor.getEditorComponent().setForeground(Color.RED);
|
2324 |
// logger.debug("Pone a Rojo Lookup");
|
2325 |
// }
|
2326 |
// return selectedItem;
|
2327 |
// }
|
2328 |
// else
|
2329 |
// {
|
2330 |
// // iterate over all items
|
2331 |
// for (int i=0, n=model.getSize(); i < n; i++)
|
2332 |
// {
|
2333 |
// Object currentItem = model.getElementAt(i);
|
2334 |
//
|
2335 |
// // current item starts with the pattern?
|
2336 |
// if ((currentItem != null) && (startsWith(currentItem.toString(), pattern)))
|
2337 |
// {
|
2338 |
// editor.getEditorComponent().setForeground(Color.BLACK);
|
2339 |
//
|
2340 |
// if (!isOnlyOneColor()){
|
2341 |
// editor.getEditorComponent().setForeground(Color.RED);
|
2342 |
// logger.debug("Pone a Rojo Lookup");
|
2343 |
// }
|
2344 |
// return currentItem;
|
2345 |
// }
|
2346 |
// }
|
2347 |
// }
|
2348 |
// }
|
2349 |
// else
|
2350 |
// {
|
2351 |
// // only search for a different item if the currently selected does not match
|
2352 |
// if ((selectedItem != null) && (startsWithIgnoreCase(selectedItem.toString(), pattern)))
|
2353 |
// {
|
2354 |
// editor.getEditorComponent().setForeground(Color.BLACK);
|
2355 |
//
|
2356 |
// if (!isOnlyOneColor()){
|
2357 |
// editor.getEditorComponent().setForeground(Color.RED);
|
2358 |
// logger.debug("Pone a Rojo Lookup");
|
2359 |
// }
|
2360 |
// return selectedItem;
|
2361 |
// }
|
2362 |
// else
|
2363 |
// {
|
2364 |
// // iterate over all items
|
2365 |
// for (int i=0, n=model.getSize(); i < n; i++)
|
2366 |
// {
|
2367 |
// Object currentItem = model.getElementAt(i);
|
2368 |
//
|
2369 |
// // current item starts with the pattern?
|
2370 |
// if ((currentItem != null) && (startsWithIgnoreCase(currentItem.toString(), pattern)))
|
2371 |
// {
|
2372 |
// editor.getEditorComponent().setForeground(Color.BLACK);
|
2373 |
//
|
2374 |
// if (!isOnlyOneColor()){
|
2375 |
// editor.getEditorComponent().setForeground(Color.RED);
|
2376 |
// logger.debug("Pone a Rojo Lookup");
|
2377 |
// }
|
2378 |
// return currentItem;
|
2379 |
// }
|
2380 |
// }
|
2381 |
// }
|
2382 |
// }
|
2383 |
//
|
2384 |
// if (!isOnlyOneColor()){
|
2385 |
// editor.getEditorComponent().setForeground(Color.RED);
|
2386 |
// logger.debug("Pone a Rojo Lookup");
|
2387 |
// }
|
2388 |
//
|
2389 |
// return null;
|
2390 |
// }
|
2391 |
|
2392 |
|
2393 |
private void setRedColorToTextIfDoesntMatch(String str1, String str2) { |
2394 |
if (!isOnlyOneColor()){
|
2395 |
if (comboBox.isCaseSensitive())
|
2396 |
{ |
2397 |
if (str1.compareTo(str2) != 0) |
2398 |
{ |
2399 |
editor.getEditorComponent().setForeground(Color.RED);
|
2400 |
logger.debug("Pone a Rojo Lookup");
|
2401 |
} |
2402 |
} |
2403 |
else
|
2404 |
{ |
2405 |
if (str1.compareToIgnoreCase(str2) != 0) |
2406 |
{ |
2407 |
editor.getEditorComponent().setForeground(Color.RED);
|
2408 |
logger.debug("Pone a Rojo Lookup");
|
2409 |
} |
2410 |
} |
2411 |
} |
2412 |
} |
2413 |
|
2414 |
|
2415 |
/**
|
2416 |
* Checks if the starts of two strings agrees
|
2417 |
*/
|
2418 |
private boolean str1StartsWithStr2(String str1, String str2) { |
2419 |
if (comboBox.isCaseSensitive())
|
2420 |
return str1.startsWith(str2);
|
2421 |
else
|
2422 |
return str1.toUpperCase().startsWith(str2.toUpperCase());
|
2423 |
} |
2424 |
} |
2425 |
|
2426 |
|
2427 |
|
2428 |
|
2429 |
|
2430 |
// // UNDO - REDO
|
2431 |
// protected class MyUndoableEditListener implements UndoableEditListener {
|
2432 |
// /* (non-Javadoc)
|
2433 |
// * @see javax.swing.event.UndoableEditListener#undoableEditHappened(javax.swing.event.UndoableEditEvent)
|
2434 |
// */
|
2435 |
// public void undoableEditHappened(UndoableEditEvent arg0) {
|
2436 |
// // TODO Auto-generated method stub
|
2437 |
// logger.debug("UNDO-REDO: " + arg0.toString());
|
2438 |
//// Recuerda la edici?n y actualiza los men?s
|
2439 |
//// undo.addEdit(arg0.getEdit());
|
2440 |
//// undoAction.update();
|
2441 |
//// redoAction.update();
|
2442 |
// }
|
2443 |
// }
|
2444 |
} |