Ignore:
Timestamp:
2009-09-16T17:55:01+02:00 (15 years ago)
Author:
stoecker
Message:

applied #3061 - patch by avar - search in plugin list

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/plugins/PluginSelection.java

    r2056 r2147  
    3131import javax.swing.JOptionPane;
    3232import javax.swing.JPanel;
     33import javax.swing.JTextField;
    3334import javax.swing.UIManager;
    3435import javax.swing.event.HyperlinkEvent;
     
    4546    private Map<String, PluginInformation> availablePlugins;
    4647    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    }
    4755
    4856    public void updateDescription(JPanel pluginPanel) {
     
    213221            }
    214222
     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
    215234            final JCheckBox pluginCheck = new JCheckBox(
    216235                    tr("{0}: Version {1}{2}", plugin.name, remoteversion, localversion),
     
    253272        }
    254273        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;
    255299    }
    256300
Note: See TracChangeset for help on using the changeset viewer.