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