• Views
  • Iteration Report
  • My Iteration Report
  •  
OMERO.clients
  • Login
  • Help/Guide
  • About Trac
  • Preferences
  • Wiki
  • Timeline
  • Roadmap
  • Browse Source
  • View Tickets
  • Search

Context Navigation

  • ← Previous Change
  • Next Change →

Changeset 5533 for branches/ProtocolEditor/src/search/SearchController.java

Show
Ignore:
Timestamp:
07/09/08 16:41:38 (5 months ago)
Author:
will
Message:

Auto-complete on the search box, to help user pick a term that is already in the Lucene index.

Files:
1 modified

  • branches/ProtocolEditor/src/search/SearchController.java (modified) (6 diffs)

Legend:

Unmodified
Added
Removed
  • branches/ProtocolEditor/src/search/SearchController.java

    r5515 r5533  
    22 
    33import java.awt.BorderLayout; 
     4import java.awt.Rectangle; 
    45import java.awt.event.ActionEvent; 
    56import java.awt.event.ActionListener; 
     7import java.beans.PropertyChangeEvent; 
     8import java.beans.PropertyChangeListener; 
    69import java.io.File; 
    710import java.io.FileNotFoundException; 
    … …  
    1316import javax.swing.Icon; 
    1417import javax.swing.JButton; 
     18import javax.swing.JDialog; 
    1519import javax.swing.JPanel; 
    1620import javax.swing.JTextField; 
     21import javax.swing.event.DocumentEvent; 
     22import javax.swing.event.DocumentListener; 
    1723import javax.swing.text.JTextComponent; 
    1824 
     25import org.openmicroscopy.shoola.util.ui.HistoryDialog; 
    1926import org.xml.sax.SAXParseException; 
    2027 
    … …  
    6572public class SearchController  
    6673        extends AbstractComponent 
    67         implements ActionListener { 
     74        implements ActionListener, 
     75        DocumentListener, PropertyChangeListener { 
    6876         
    6977        /** 
    … …  
    115123         */ 
    116124        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; 
    117132         
    118133        /** 
    … …  
    133148        public void setSearchTermSource(JTextComponent searchTermSource) { 
    134149                this.searchTermSource = searchTermSource; 
     150                searchTermSource.getDocument().addDocumentListener(this); 
    135151        } 
    136152         
    … …  
    312328                else return null; 
    313329        } 
     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        } 
    314367 
    315368} 

Download in other formats:

  • Unified Diff
  • Zip Archive

Trac Powered

Powered by Trac 0.11
By Edgewall Software.

Visit the Trac open source project at
http://trac.edgewall.org/