- Timestamp:
- 2009-09-16T17:55:01+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/PluginPreference.java
r2017 r2147 17 17 import javax.swing.JLabel; 18 18 import javax.swing.JList; 19 import javax.swing.JTextField; 19 20 import javax.swing.JOptionPane; 20 21 import javax.swing.JPanel; 21 22 import javax.swing.JScrollPane; 22 23 import javax.swing.Scrollable; 24 import javax.swing.event.DocumentEvent; 25 import javax.swing.event.DocumentListener; 23 26 24 27 import org.openstreetmap.josm.Main; … … 40 43 private JScrollPane pluginPane; 41 44 private PluginSelection selection = new PluginSelection(); 45 private JTextField txtFilter; 42 46 43 47 public void addGui(final PreferenceDialog gui) { 44 48 this.gui = gui; 45 49 plugin = gui.createPreferenceTab("plugin", tr("Plugins"), tr("Configure available plugins."), false); 50 51 txtFilter = new JTextField(); 52 JLabel lbFilter = new JLabel(tr("Search: ")); 53 lbFilter.setLabelFor(txtFilter); 54 plugin.add(lbFilter); 55 plugin.add(txtFilter, GBC.eol().fill(GBC.HORIZONTAL)); 56 txtFilter.getDocument().addDocumentListener(new DocumentListener(){ 57 public void changedUpdate(DocumentEvent e) { 58 action(); 59 } 60 61 public void insertUpdate(DocumentEvent e) { 62 action(); 63 } 64 65 public void removeUpdate(DocumentEvent e) { 66 action(); 67 } 68 69 private void action() { 70 selection.drawPanel(pluginPanel); 71 } 72 }); 73 plugin.add(GBC.glue(0,10), GBC.eol()); 74 75 /* main plugin area */ 46 76 pluginPane = new JScrollPane(pluginPanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); 47 77 pluginPane.setBorder(null); 48 78 plugin.add(pluginPane, GBC.eol().fill(GBC.BOTH)); 49 79 plugin.add(GBC.glue(0,10), GBC.eol()); 80 81 /* buttons at the bottom */ 50 82 JButton morePlugins = new JButton(tr("Download List")); 51 83 morePlugins.addActionListener(new ActionListener(){ … … 72 104 plugin.add(configureSites, GBC.std()); 73 105 106 selection.passTxtFilter(txtFilter); 74 107 selection.drawPanel(pluginPanel); 75 108 } -
trunk/src/org/openstreetmap/josm/plugins/PluginSelection.java
r2056 r2147 31 31 import javax.swing.JOptionPane; 32 32 import javax.swing.JPanel; 33 import javax.swing.JTextField; 33 34 import javax.swing.UIManager; 34 35 import javax.swing.event.HyperlinkEvent; … … 45 46 private Map<String, PluginInformation> availablePlugins; 46 47 private Map<String, PluginInformation> localPlugins; 48 49 private JTextField txtFilter = null; 50 51 /* Get a copy of PluginPreference's txtField so we can use it for searching */ 52 public void passTxtFilter(JTextField filter) { 53 txtFilter = filter; 54 } 47 55 48 56 public void updateDescription(JPanel pluginPanel) { … … 213 221 } 214 222 223 /* If this plugin doesn't match our search parameters we don't want to display it */ 224 if (txtFilter.getText() != null) { 225 boolean matches = filterNameAndDescription(txtFilter.getText(),plugin.name, 226 plugin.getLinkDescription(), 227 remoteversion, localversion); 228 if (!matches) { 229 /* This is not the plugin you're looking for */ 230 continue; 231 } 232 } 233 215 234 final JCheckBox pluginCheck = new JCheckBox( 216 235 tr("{0}: Version {1}{2}", plugin.name, remoteversion, localversion), … … 253 272 } 254 273 pluginPanel.updateUI(); 274 } 275 276 private static boolean filterNameAndDescription(String filter, final String name, final String description, 277 final String remoteversion, final String localversion) { 278 final String input[] = filter.split("\\s+"); 279 /* We're doing case-insensitive matching */ 280 final String name_lc = name.toLowerCase(); 281 final String description_lc = description.toLowerCase(); 282 final String remoteversion_lc = remoteversion.toLowerCase(); 283 final String localversion_lc = localversion.toLowerCase(); 284 285 boolean canHas = true; 286 287 /* Make 'foo bar' search for 'bar' or 'foo' in both name and description */ 288 for (String bit : input) { 289 final String lc_bit = bit.toLowerCase(); 290 if (!name_lc.contains(lc_bit) && 291 !description_lc.contains(lc_bit) && 292 !remoteversion_lc.contains(lc_bit) && 293 !localversion_lc.contains(lc_bit)) { 294 canHas = false; 295 } 296 } 297 298 return canHas; 255 299 } 256 300
Note:
See TracChangeset
for help on using the changeset viewer.