- Timestamp:
- 2009-11-14T20:05:18+01:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java
r2357 r2451 8 8 import java.awt.event.ActionEvent; 9 9 import java.awt.event.KeyEvent; 10 import java.util.ArrayList; 10 11 import java.util.Collection; 12 import java.util.Collections; 11 13 import java.util.LinkedList; 14 import java.util.List; 12 15 13 16 import javax.swing.ButtonGroup; … … 17 20 import javax.swing.JPanel; 18 21 import javax.swing.JRadioButton; 19 import javax.swing.JTextField;20 22 21 23 import org.openstreetmap.josm.Main; 22 24 import org.openstreetmap.josm.actions.JosmAction; 25 import org.openstreetmap.josm.data.osm.DataSet; 26 import org.openstreetmap.josm.data.osm.Filter; 23 27 import org.openstreetmap.josm.data.osm.OsmPrimitive; 24 28 import org.openstreetmap.josm.gui.ExtendedDialog; 29 import org.openstreetmap.josm.gui.widgets.HistoryComboBox; 25 30 import org.openstreetmap.josm.tools.GBC; 26 31 import org.openstreetmap.josm.tools.Shortcut; 27 import org.openstreetmap.josm.data.osm.Filter;28 import org.openstreetmap.josm.data.osm.DataSet;29 32 30 33 public class SearchAction extends JosmAction{ … … 49 52 if (!isEnabled()) 50 53 return; 51 if (Main.map == null) {52 JOptionPane.showMessageDialog(53 Main.parent,54 tr("Can't search because there is no loaded data."),55 tr("Warning"),56 JOptionPane.WARNING_MESSAGE57 );58 return;59 }60 54 SearchSetting s = lastSearch; 61 55 if (s == null) { 62 s = new SearchSetting("", SearchMode.replace, false , false);56 s = new SearchSetting("", SearchMode.replace, false /* case insensitive */, false /* no regexp */); 63 57 } 64 58 SearchSetting se = showSearchDialog(s); … … 68 62 } 69 63 64 public static List<String> getSearchExpressionHistory() { 65 ArrayList<String> ret = new ArrayList<String>(searchHistory.size()); 66 for (SearchSetting ss: searchHistory) { 67 ret.add(ss.text); 68 } 69 return ret; 70 } 71 70 72 public static SearchSetting showSearchDialog(SearchSetting initialValues) { 73 74 // -- prepare the combo box with the search expressions 75 // 71 76 JLabel label = new JLabel( initialValues instanceof Filter ? tr("Please enter a filter string.") : tr("Please enter a search string.")); 72 final JTextField input = new JTextField(initialValues.text); 73 input.selectAll(); 74 input.requestFocusInWindow(); 77 final HistoryComboBox hcbSearchString = new HistoryComboBox(); 78 hcbSearchString.setText(initialValues.text); 79 hcbSearchString.getEditor().selectAll(); 80 hcbSearchString.getEditor().getEditorComponent().requestFocusInWindow(); 81 hcbSearchString.setToolTipText(tr("Enter the search expression")); 82 // we have to reverse the history, because ComboBoxHistory will reverse it again 83 // in addElement() 84 // 85 List<String> searchExpressionHistory = getSearchExpressionHistory(); 86 Collections.reverse(searchExpressionHistory); 87 hcbSearchString.setPossibleItems(searchExpressionHistory); 88 75 89 JRadioButton replace = new JRadioButton(tr("replace selection"), initialValues.mode == SearchMode.replace); 76 90 JRadioButton add = new JRadioButton(tr("add to selection"), initialValues.mode == SearchMode.add); … … 88 102 JPanel left = new JPanel(new GridBagLayout()); 89 103 left.add(label, GBC.eop()); 90 left.add( input, GBC.eop().fill(GBC.HORIZONTAL));104 left.add(hcbSearchString, GBC.eop().fill(GBC.HORIZONTAL)); 91 105 left.add(replace, GBC.eol()); 92 DataSet ds = Main.main.getCurrentDataSet();93 106 left.add(add, GBC.eol()); 94 107 left.add(remove, GBC.eol()); … … 147 160 : (add.isSelected() ? SearchAction.SearchMode.add 148 161 : (remove.isSelected() ? SearchAction.SearchMode.remove : SearchAction.SearchMode.in_selection)); 149 initialValues.text = input.getText();162 initialValues.text = hcbSearchString.getText(); 150 163 initialValues.mode = mode; 151 164 initialValues.caseSensitive = caseSensitive.isSelected(); … … 164 177 searchHistory.addFirst(new SearchSetting(s)); 165 178 } 166 while (searchHistory.size() > Main.pref.getInteger("search.history-size", DEFAULT_SEARCH_HISTORY_SIZE)) { 179 int maxsize = Main.pref.getInteger("search.history-size", DEFAULT_SEARCH_HISTORY_SIZE); 180 while (searchHistory.size() > maxsize) { 167 181 searchHistory.removeLast(); 168 182 }
Note:
See TracChangeset
for help on using the changeset viewer.