source: josm/trunk/src/org/openstreetmap/josm/gui/widgets/HistoryComboBox.java@ 11921

Last change on this file since 11921 was 10179, checked in by Don-vip, 8 years ago

sonar - squid:AssignmentInSubExpressionCheck - Assignments should not be made from within sub-expressions

  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.widgets;
3
4import java.util.List;
5
6import javax.swing.text.JTextComponent;
7
8import org.openstreetmap.josm.Main;
9import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingComboBox;
10
11/**
12 * An {@link AutoCompletingComboBox} which keeps a history
13 */
14public class HistoryComboBox extends AutoCompletingComboBox {
15 private final ComboBoxHistory model;
16
17 public static final int DEFAULT_SEARCH_HISTORY_SIZE = 15;
18
19 /**
20 * Constructs a new {@code HistoryComboBox}.
21 */
22 public HistoryComboBox() {
23 int maxsize = Main.pref.getInteger("search.history-size", DEFAULT_SEARCH_HISTORY_SIZE);
24 model = new ComboBoxHistory(maxsize);
25 setModel(model);
26 setEditable(true);
27 }
28
29 /**
30 * Returns the text contained in this component
31 * @return the text
32 * @see JTextComponent#getText()
33 */
34 public String getText() {
35 return getEditorComponent().getText();
36 }
37
38 /**
39 * Sets the text of this component to the specified text
40 * @param value the text to set
41 * @see JTextComponent#setText(java.lang.String)
42 */
43 public void setText(String value) {
44 setAutocompleteEnabled(false);
45 getEditorComponent().setText(value);
46 setAutocompleteEnabled(true);
47 }
48
49 /**
50 * Adds or moves the current element to the top of the history
51 * @see ComboBoxHistory#addElement(java.lang.String)
52 */
53 public void addCurrentItemToHistory() {
54 model.addElement((String) getEditor().getItem());
55 }
56
57 /**
58 * Sets the elements of the ComboBox to the given items
59 * @param history the items to set
60 * @see ComboBoxHistory#setItemsAsString(java.util.List)
61 */
62 public void setHistory(List<String> history) {
63 model.setItemsAsString(history);
64 }
65
66 /**
67 * Returns the items as strings
68 * @return the items as strings
69 * @see ComboBoxHistory#asStringList()
70 */
71 public List<String> getHistory() {
72 return model.asStringList();
73 }
74}
Note: See TracBrowser for help on using the repository browser.