Changeset 5533
- Timestamp:
- 07/09/08 16:41:38 (3 months ago)
- Location:
- branches/ProtocolEditor/src/search
- Files:
-
- 1 added
- 1 modified
-
IndexTermFinder.java (added)
-
SearchController.java (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/ProtocolEditor/src/search/SearchController.java
r5515 r5533 2 2 3 3 import java.awt.BorderLayout; 4 import java.awt.Rectangle; 4 5 import java.awt.event.ActionEvent; 5 6 import java.awt.event.ActionListener; 7 import java.beans.PropertyChangeEvent; 8 import java.beans.PropertyChangeListener; 6 9 import java.io.File; 7 10 import java.io.FileNotFoundException; … … 13 16 import javax.swing.Icon; 14 17 import javax.swing.JButton; 18 import javax.swing.JDialog; 15 19 import javax.swing.JPanel; 16 20 import javax.swing.JTextField; 21 import javax.swing.event.DocumentEvent; 22 import javax.swing.event.DocumentListener; 17 23 import javax.swing.text.JTextComponent; 18 24 25 import org.openmicroscopy.shoola.util.ui.HistoryDialog; 19 26 import org.xml.sax.SAXParseException; 20 27 … … 65 72 public class SearchController 66 73 extends AbstractComponent 67 implements ActionListener { 74 implements ActionListener, 75 DocumentListener, PropertyChangeListener { 68 76 69 77 /** … … 115 123 */ 116 124 boolean displayControllerPanel = true; 125 126 /** 127 * A popup to display the terms from the lucene index that match what the 128 * user is typing into the searchTermSource, so as to provide an 129 * Auto-Complete functionality. 130 */ 131 HistoryDialog popup; 117 132 118 133 /** … … 133 148 public void setSearchTermSource(JTextComponent searchTermSource) { 134 149 this.searchTermSource = searchTermSource; 150 searchTermSource.getDocument().addDocumentListener(this); 135 151 } 136 152 … … 312 328 else return null; 313 329 } 330 331 public void autoComplete() { 332 Rectangle rect = searchTermSource.getBounds(); 333 String text = searchTermSource.getText(); 334 if (text.length() < 2) return; 335 336 String[] matchingTerms = IndexTermFinder.getMatchingTerms(text); 337 338 popup = new HistoryDialog(matchingTerms, rect.width); 339 popup.addPropertyChangeListener( 340 HistoryDialog.SELECTION_PROPERTY, this); 341 342 popup.show(searchTermSource, 0, rect.height); 343 344 searchTermSource.requestFocusInWindow(); 345 } 346 347 public void insertUpdate(DocumentEvent e) { 348 autoComplete(); 349 } 350 351 public void changedUpdate(DocumentEvent e) { 352 autoComplete(); 353 } 354 public void removeUpdate(DocumentEvent e) { 355 autoComplete(); 356 } 357 358 public void propertyChange(PropertyChangeEvent evt) { 359 if (HistoryDialog.SELECTION_PROPERTY.equals(evt.getPropertyName())) { 360 Object item = evt.getNewValue(); 361 searchTermSource.setText(item.toString()); 362 363 popup.setVisible(false); 364 365 } 366 } 314 367 315 368 }
