Ticket #7230: 7230_beta.patch

File 7230_beta.patch, 14.9 KB (added by simon04, 14 years ago)
  • src/org/openstreetmap/josm/actions/search/SearchAction.java

    diff --git a/src/org/openstreetmap/josm/actions/search/SearchAction.java b/src/org/openstreetmap/josm/actions/search/SearchAction.java
    index 7b9ca85..da07509 100644
    a b import static org.openstreetmap.josm.tools.I18n.tr;  
    77import static org.openstreetmap.josm.tools.I18n.trc;
    88
    99import java.awt.Dimension;
     10import java.awt.FlowLayout;
    1011import java.awt.Font;
    1112import java.awt.GridBagLayout;
    1213import java.awt.event.ActionEvent;
    1314import java.awt.event.KeyEvent;
     15import java.awt.event.MouseAdapter;
     16import java.awt.event.MouseEvent;
    1417import java.util.ArrayList;
     18import java.util.Arrays;
    1519import java.util.Collection;
    1620import java.util.Collections;
    1721import java.util.HashSet;
    import java.util.LinkedList;  
    1923import java.util.List;
    2024import java.util.Map;
    2125
    22 import javax.swing.ButtonGroup;
    23 import javax.swing.JCheckBox;
    24 import javax.swing.JLabel;
    25 import javax.swing.JOptionPane;
    26 import javax.swing.JPanel;
    27 import javax.swing.JRadioButton;
     26import javax.swing.*;
     27import javax.swing.text.BadLocationException;
    2828
    2929import org.openstreetmap.josm.Main;
    3030import org.openstreetmap.josm.actions.ActionParameter;
    import org.openstreetmap.josm.gui.widgets.HistoryComboBox;  
    4141import org.openstreetmap.josm.tools.GBC;
    4242import org.openstreetmap.josm.tools.Property;
    4343import org.openstreetmap.josm.tools.Shortcut;
     44import org.openstreetmap.josm.tools.Utils;
    4445
    4546public class SearchAction extends JosmAction implements ParameterizedAction {
    4647
    public class SearchAction extends JosmAction implements ParameterizedAction {  
    153154        }
    154155    }
    155156
     157    private static class SearchKeywordRow extends JPanel {
     158
     159        private final HistoryComboBox hcb;
     160
     161        public SearchKeywordRow(HistoryComboBox hcb) {
     162            super(new FlowLayout(FlowLayout.LEFT));
     163            this.hcb = hcb;
     164        }
     165
     166        public SearchKeywordRow addTitle(String title) {
     167            add(new JLabel(tr("{0}: ", title)));
     168            return this;
     169        }
     170
     171        public SearchKeywordRow addKeyword(String displayText, final String insertText, String description, String... examples) {
     172            JLabel label = new JLabel("<html><style>td{border:1px solid gray;}</style><table><tr><td>" + displayText + "</td></tr></table></html>");
     173            add(label);
     174            if (description != null || examples.length > 0) {
     175                label.setToolTipText("<html>"
     176                        + description
     177                        + (examples.length > 0 ? ("<ul><li>" + Utils.join("</li><li>", Arrays.asList(examples)) + "</li></ul>") : "")
     178                        + "</html>");
     179            }
     180            if (insertText != null) {
     181                label.addMouseListener(new MouseAdapter() {
     182
     183                    @Override
     184                    public void mouseClicked(MouseEvent e) {
     185                        try {
     186                            JTextField tf = (JTextField) hcb.getEditor().getEditorComponent();
     187                            tf.getDocument().insertString(tf.getCaretPosition(), " " + insertText, null);
     188                        } catch (BadLocationException ex) {
     189                            throw new RuntimeException(ex.getMessage(), ex);
     190                        }
     191                    }
     192                });
     193            }
     194            return this;
     195        }
     196    }
     197
    156198    public static SearchSetting showSearchDialog(SearchSetting initialValues) {
    157199        if (initialValues == null) {
    158200            initialValues = new SearchSetting();
    public class SearchAction extends JosmAction implements ParameterizedAction {  
    205247            left.add(addOnToolbar, GBC.eol());
    206248        }
    207249
    208         JPanel right = new JPanel();
    209         DescriptionTextBuilder descriptionText = new DescriptionTextBuilder();
    210         descriptionText.append("<html><style>li.header{font-size:110%; list-style-type:none; margin-top:5px;}</style><ul>");
    211         descriptionText.appendItem(tr("<b>Baker Street</b> - ''Baker'' and ''Street'' in any key"));
    212         descriptionText.appendItem(tr("<b>\"Baker Street\"</b> - ''Baker Street'' in any key"));
    213         descriptionText.appendItem(tr("<b>key:Bak</b> - ''Bak'' anywhere in the key ''key''"));
    214         descriptionText.appendItem(tr("<b>-key:Bak</b> - ''Bak'' nowhere in the key ''key''"));
    215         descriptionText.appendItem(tr("<b>key=value</b> - key ''key'' with value exactly ''value''"));
    216         descriptionText.appendItem(tr("<b>key=*</b> - key ''key'' with any value. Try also <b>*=value</b>, <b>key=</b>, <b>*=*</b>, <b>*=</b>"));
    217         descriptionText.appendItem(tr("<b>key:</b> - key ''key'' set to any value"));
    218         descriptionText.appendItem(tr("<b>key?</b> - key ''key'' with the value ''yes'', ''true'', ''1'' or ''on''"));
    219         if(Main.pref.getBoolean("expert", false))
    220         {
    221             descriptionText.appendItemHeader(tr("Special targets"));
    222             /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>type:</b>... - objects with corresponding type (<b>node</b>, <b>way</b>, <b>relation</b>)"));
    223             /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>user:</b>... - objects changed by user"));
    224             /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>user:anonymous</b> - objects changed by anonymous users"));
    225             /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>id:</b>... - objects with given ID (0 for new objects)"));
    226             /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>version:</b>... - objects with given version (0 objects without an assigned version)"));
    227             /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>changeset:</b>... - objects with given changeset ID (0 objects without an assigned changeset)"));
    228             /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>nodes:</b>... - objects with given number of nodes (<b>nodes:</b>count, <b>nodes:</b>min-max, <b>nodes:</b>min- or <b>nodes:</b>-max)"));
    229             /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>tags:</b>... - objects with given number of tags (<b>tags:</b>count, <b>tags:</b>min-max, <b>tags:</b>min- or <b>tags:</b>-max)"));
    230             /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>role:</b>... - objects with given role in a relation"));
    231             /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>timestamp:</b>timestamp - objects with this last modification timestamp (2009-11-12T14:51:09Z, 2009-11-12 or T14:51 ...)"));
    232             /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>timestamp:</b>min/max - objects with last modification within range"));
    233             /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>areasize:</b>... - closed ways with given area in m\u00b2 (<b>areasize:</b>min-max or <b>areasize:</b>max)"));
    234             /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>modified</b> - all changed objects"));
    235             /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>selected</b> - all selected objects"));
    236             /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>incomplete</b> - all incomplete objects"));
    237             /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>untagged</b> - all untagged objects"));
    238             /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>closed</b> - all closed ways (a node is not considered closed)"));
    239             /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>child <i>expr</i></b> - all children of objects matching the expression"));
    240             /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>parent <i>expr</i></b> - all parents of objects matching the expression"));
    241             /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>(all)indownloadedarea</b> - objects (and all its way nodes / relation members) in downloaded area"));
    242             /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("<b>(all)inview</b> - objects (and all its way nodes / relation members) in current view"));
    243         }
    244         /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("Use <b>|</b> or <b>OR</b> to combine with logical or"));
    245         descriptionText.appendItem(tr("Use <b>\"</b> to quote operators (e.g. if key contains <b>:</b>)")
    246                 + "<br/>"
    247                 + tr("Within quoted strings the <b>\"</b> and <b>\\</b> characters need to be escaped by a preceding <b>\\</b> (e.g. <b>\\\"</b> and <b>\\\\</b>)."));
    248         descriptionText.appendItem(tr("Use <b>(</b> and <b>)</b> to group expressions"));
    249         descriptionText.append("</ul></html>");
    250         JLabel description = new JLabel(descriptionText.toString());
    251         description.setFont(description.getFont().deriveFont(Font.PLAIN));
    252         right.add(description);
     250        JPanel right = new JPanel(new GridBagLayout());
     251        right.add(new SearchKeywordRow(hcbSearchString)
     252                .addTitle(tr("basic examples"))
     253                .addKeyword("Baker Street", "Baker Street", tr("''Baker'' and ''Street'' in any key"))
     254                .addKeyword("\"Baker Street\"", "\"Baker Street\"", tr("''Baker Street'' in any key"))
     255                , GBC.eol());
     256        right.add(new SearchKeywordRow(hcbSearchString)
     257                .addTitle(tr("basics"))
     258                .addKeyword("<i>key</i>:<i>valuefragment</i>", null, tr("''valuefragment'' anywhere in ''key''"))
     259                .addKeyword("-<i>key</i>:<i>valuefragment</i>", null, tr("''valuefragment'' nowhere in ''key''"))
     260                .addKeyword("<i>key</i>=<i>value</i>", null, tr("''key'' with exactly ''value''"))
     261                .addKeyword("<i>key</i>=*", null, tr("''key'' with any value"))
     262                .addKeyword("*=<i>value</i>", null, tr("''value'' in any key"))
     263                .addKeyword("<i>key</i>=", null, null)
     264                , GBC.eol());
     265        right.add(new SearchKeywordRow(hcbSearchString)
     266                .addTitle(tr("combinators"))
     267                .addKeyword("<i>expr</i> <i>expr</i>", null, tr("logical and (both expressions have to be satisfied)"))
     268                .addKeyword("<i>expr</i> | <i>expr</i>", "| ", tr("logical or (at least one expression has to be satisfied)"))
     269                .addKeyword("<i>expr</i> OR <i>expr</i>", "OR ", tr("logical or (at least one expression has to be satisfied)"))
     270                .addKeyword("-<i>expr</i>", null, tr("logical not"))
     271                .addKeyword("(<i>expr</i>)", null, tr("use parenthesis to group expressions"))
     272                .addKeyword("\"key\"=\"value\"", null, tr("to quote operators.<br>Within quoted strings the <b>\"</b> and <b>\\</b> characters need to be escaped by a preceding <b>\\</b> (e.g. <b>\\\"</b> and <b>\\\\</b>)."), "\"addr:street\"")
     273                , GBC.eol());
     274
     275        if (Main.pref.getBoolean("expert", false)) {
     276            right.add(new SearchKeywordRow(hcbSearchString)
     277                .addTitle(tr("objects"))
     278                .addKeyword("<img src=\"http://josm.openstreetmap.de/export/4326/josm/trunk/images/Mf_node.png\">&nbsp;type:node", "type:node", tr("all ways"))
     279                .addKeyword("<img src=\"http://josm.openstreetmap.de/export/4326/josm/trunk/images/Mf_way.png\">&nbsp;type:way", "type:way", tr("all ways"))
     280                .addKeyword("<img src=\"http://josm.openstreetmap.de/export/4326/josm/trunk/images/Mf_relation.png\">&nbsp;type:relation", "type:relation", tr("all relations"))
     281                .addKeyword("<img src=\"http://josm.openstreetmap.de/export/4326/josm/trunk/images/Mf_closedway.png\">&nbsp;closed", "closed", tr("all closed ways"))
     282                , GBC.eol());
     283            right.add(new SearchKeywordRow(hcbSearchString)
     284                .addTitle(tr("metadata"))
     285                .addKeyword("user:", "user:", tr("objects changed by user", "user:anonymous"))
     286                .addKeyword("id:", "id:", tr("objects with given ID (0 for new objects)"))
     287                .addKeyword("version:", "version:", tr("objects with given version (0 objects without an assigned version)"))
     288                .addKeyword("changeset:", "changeset:", tr("objects with given changeset ID (0 objects without an assigned changeset)"))
     289                .addKeyword("timestamp:", "timestamp:", tr("objects with last modification timestamp within range", "timestamp:2012/", "timestamp:2008/2011-02-04T12"))
     290                , GBC.eol());
     291            right.add(new SearchKeywordRow(hcbSearchString)
     292                .addTitle(tr("properties"))
     293                .addKeyword("nodes:<i>20-</i>", "nodes:", tr("objects with at least 20 nodes"))
     294                .addKeyword("tags:<i>5-10</i>", "tags:", tr("objects having 5 to 10 tags"))
     295                .addKeyword("role:", "role:", tr("objects with given role in a relation"))
     296                .addKeyword("areasize:<i>-100</i>", "areasize", tr("closed ways with an area of 100 m\u00b2"))
     297                , GBC.eol());
     298            right.add(new SearchKeywordRow(hcbSearchString)
     299                .addTitle(tr("state"))
     300                .addKeyword("modified", "modified", tr("all modified objects"))
     301                .addKeyword("new", "new", tr("all new objects"))
     302                .addKeyword("selected", "selected", tr("all selected objects"))
     303                .addKeyword("incomplete", "incomplete", tr("all incomplete objects"))
     304                , GBC.eol());
     305            right.add(new SearchKeywordRow(hcbSearchString)
     306                .addTitle(tr("relations"))
     307                .addKeyword("child <i>expr</i>", "child", tr("all children of objects matching the expression", "child building"))
     308                .addKeyword("parent <i>expr</i>", "parent", tr("all parents of objects matching the expression", "parent bus_stop"))
     309                , GBC.eol());
     310            right.add(new SearchKeywordRow(hcbSearchString)
     311                .addTitle(tr("view"))
     312                .addKeyword("inview", "inview", tr("objects in current view"))
     313                .addKeyword("allinview", "allinview", tr("objects (and all its way nodes / relation members) in current view"))
     314                .addKeyword("indownloadedarea", "indownloadedarea", tr("objects in downloaded area"))
     315                .addKeyword("allindownloadedarea", "allindownloadedarea", tr("objects (and all its way nodes / relation members) in downloaded area"))
     316                , GBC.eol());
     317        }
    253318
    254319        final JPanel p = new JPanel(new GridBagLayout());
    255320        p.add(top, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 5, 0));