Ticket #7230: 7230_alpha.patch

File 7230_alpha.patch, 11.7 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..4cfdcd2 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;
    1518import java.util.Collection;
    1619import java.util.Collections;
    import java.util.LinkedList;  
    1922import java.util.List;
    2023import java.util.Map;
    2124
    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;
     25import javax.swing.*;
     26import javax.swing.text.BadLocationException;
    2827
    2928import org.openstreetmap.josm.Main;
    3029import org.openstreetmap.josm.actions.ActionParameter;
    public class SearchAction extends JosmAction implements ParameterizedAction {  
    153152        }
    154153    }
    155154
     155    private static class SearchKeywordLabel extends JLabel {
     156
     157        public SearchKeywordLabel(final HistoryComboBox hcb, final String text, String description) {
     158            super("<html><style>td{border:1px solid gray;" + (text.contains("img") ? "background:#99ff99;" : "") + "</style><table><tr><td><code>"
     159                    + text
     160                    + "</code></td></tr></table></html>");
     161            setToolTipText("<html>" + description + "</html>");
     162            addMouseListener(new MouseAdapter() {
     163
     164                @Override
     165                public void mouseClicked(MouseEvent e) {
     166                    try {
     167                        JTextField tf = (JTextField) hcb.getEditor().getEditorComponent();
     168                        tf.getDocument().insertString(tf.getCaretPosition(), " " + text, null);
     169                    } catch (BadLocationException ex) {
     170                        throw new RuntimeException(ex.getMessage(), ex);
     171                    }
     172                }
     173            });
     174        }
     175    }
     176
    156177    public static SearchSetting showSearchDialog(SearchSetting initialValues) {
    157178        if (initialValues == null) {
    158179            initialValues = new SearchSetting();
    public class SearchAction extends JosmAction implements ParameterizedAction {  
    205226            left.add(addOnToolbar, GBC.eol());
    206227        }
    207228
    208         JPanel right = new JPanel();
     229        JPanel right = new JPanel(new GridBagLayout());
    209230        DescriptionTextBuilder descriptionText = new DescriptionTextBuilder();
    210231        descriptionText.append("<html><style>li.header{font-size:110%; list-style-type:none; margin-top:5px;}</style><ul>");
    211232        descriptionText.appendItem(tr("<b>Baker Street</b> - ''Baker'' and ''Street'' in any key"));
    public class SearchAction extends JosmAction implements ParameterizedAction {  
    216237        descriptionText.appendItem(tr("<b>key=*</b> - key ''key'' with any value. Try also <b>*=value</b>, <b>key=</b>, <b>*=*</b>, <b>*=</b>"));
    217238        descriptionText.appendItem(tr("<b>key:</b> - key ''key'' set to any value"));
    218239        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         }
     240
    244241        /* I18n: don't translate the bold text keyword */ descriptionText.appendItem(tr("Use <b>|</b> or <b>OR</b> to combine with logical or"));
    245242        descriptionText.appendItem(tr("Use <b>\"</b> to quote operators (e.g. if key contains <b>:</b>)")
    246243                + "<br/>"
    public class SearchAction extends JosmAction implements ParameterizedAction {  
    249246        descriptionText.append("</ul></html>");
    250247        JLabel description = new JLabel(descriptionText.toString());
    251248        description.setFont(description.getFont().deriveFont(Font.PLAIN));
    252         right.add(description);
     249        right.add(description,GBC.eol());
     250
     251        if (Main.pref.getBoolean("expert", false)) {
     252            JPanel ext = new JPanel(new GridBagLayout());
     253            right.add(ext, GBC.eol().fill(GBC.HORIZONTAL));
     254            final GBC same = GBC.std().insets(0, 0, 5, 5);
     255            final GBC next = GBC.eol().fill(GBC.HORIZONTAL).insets(0, 0, 5, 5);
     256            ext.add(new SearchKeywordLabel(hcbSearchString, "<img src=\"http://josm.openstreetmap.de/export/4326/josm/trunk/images/Mf_node.png\">type:node", tr("all nodes")), same);
     257            ext.add(new SearchKeywordLabel(hcbSearchString, "<img src=\"http://josm.openstreetmap.de/export/4326/josm/trunk/images/Mf_way.png\">type:way", tr("all ways")), same);
     258            ext.add(new SearchKeywordLabel(hcbSearchString, "<img src=\"http://josm.openstreetmap.de/export/4326/josm/trunk/images/Mf_relation.png\">type:relation", tr("all relations")), same);
     259            ext.add(new SearchKeywordLabel(hcbSearchString, "<img src=\"http://josm.openstreetmap.de/export/4326/josm/trunk/images/Mf_closedway.png\">closed", tr("all closed ways")), next);
     260            ext.add(new SearchKeywordLabel(hcbSearchString, "user:", tr("objects changed by user")), same);
     261            ext.add(new SearchKeywordLabel(hcbSearchString, "user:anonymous", tr("objects changed by anonymous users")), same);
     262            ext.add(new SearchKeywordLabel(hcbSearchString, "id:", tr("objects with given ID (0 for new objects)")), same);
     263            ext.add(new SearchKeywordLabel(hcbSearchString, "version:", tr("objects with given version (0 objects without an assigned version)")), same);
     264            ext.add(new SearchKeywordLabel(hcbSearchString, "changeset:", tr("objects with given changeset ID (0 objects without an assigned changeset)")), same);
     265            ext.add(new SearchKeywordLabel(hcbSearchString, "timestamp:2008/2011-02-04T12", tr("objects with last modification timestamp within range")), next);
     266            ext.add(new SearchKeywordLabel(hcbSearchString, "nodes:20-", tr("objects with at least 20 nodes")), same);
     267            ext.add(new SearchKeywordLabel(hcbSearchString, "tags:5-10", tr("objects having 5 to 10 tags")), same);
     268            ext.add(new SearchKeywordLabel(hcbSearchString, "role:", tr("objects with given role in a relation")), same);
     269            ext.add(new SearchKeywordLabel(hcbSearchString, "areasize:-100", tr("closed ways with an area of 100 m\u00b2")), next);
     270            ext.add(new SearchKeywordLabel(hcbSearchString, "modified", tr("all modified objects")), same);
     271            ext.add(new SearchKeywordLabel(hcbSearchString, "new", tr("all new objects")), same);
     272            ext.add(new SearchKeywordLabel(hcbSearchString, "selected", tr("all selected objects")), same);
     273            ext.add(new SearchKeywordLabel(hcbSearchString, "incomplete", tr("all incomplete objects")), next);
     274            //ext.add(new SearchKeywordLabel(hcbSearchString, "untagged", tr("all untagged objects"))); // == "tags:0"?
     275            ext.add(new SearchKeywordLabel(hcbSearchString, "child building", tr("all children of objects matching the expression (e.g., building)")), same);
     276            ext.add(new SearchKeywordLabel(hcbSearchString, "parent bus_stop", tr("all parents of objects matching the expression (e.g., bus_stop)")), next);
     277            ext.add(new SearchKeywordLabel(hcbSearchString, "inview", tr("objects in current view")), same);
     278            ext.add(new SearchKeywordLabel(hcbSearchString, "allinview", tr("objects (and all its way nodes / relation members) in current view")), same);
     279            ext.add(new SearchKeywordLabel(hcbSearchString, "indownloadedarea", tr("objects in downloaded area")), same);
     280            ext.add(new SearchKeywordLabel(hcbSearchString, "allindownloadedarea", tr("objects (and all its way nodes / relation members) in downloaded area")), next);
     281        }
    253282
    254283        final JPanel p = new JPanel(new GridBagLayout());
    255284        p.add(top, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 5, 0));