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