View Javadoc

1   package nl.tudelft.goal.ut2004.visualizer.gui.widgets;
2   
3   import javax.swing.JComboBox;
4   import javax.swing.JPanel;
5   
6   /**
7    * Smart text field that displays a list of suggestions based on what the user
8    * types.
9    * 
10   * @author M.P. Korstanje
11   * 
12   */
13  public class SuggestionField extends JPanel {
14  
15  	private final JComboBox combobox;
16  	private final SuggestionModel model;
17  	private final SuggestionFieldEditor editor;
18  
19  	public SuggestionField(SuggestionModel model) {
20  		this.model = model;
21  		this.combobox = new JComboBox(model);
22  		this.editor = new SuggestionFieldEditor(combobox, model);
23  
24  		this.combobox.setEditor(editor);
25  		this.combobox.setEditable(true);
26  		this.combobox.setSelectedIndex(-1);
27  
28  		add(combobox);
29  	}
30  
31  	public void setSelectedItem(Object item) {
32  		combobox.setSelectedItem(item);
33  		editor.setItem(item);
34  		model.setSelectedItem(item);
35  	}
36  
37  	public Object getSelecteditem() {
38  		return combobox.getSelectedItem();
39  	}
40  
41  }