Ticket #14840: ticket14840.patch
| File ticket14840.patch, 15.0 KB (added by , 9 years ago) |
|---|
-
src/org/openstreetmap/josm/actions/search/SearchAction.java
9 9 import java.awt.Cursor; 10 10 import java.awt.Dimension; 11 11 import java.awt.FlowLayout; 12 import java.awt.GraphicsEnvironment;13 12 import java.awt.GridBagLayout; 14 13 import java.awt.event.ActionEvent; 15 14 import java.awt.event.KeyEvent; … … 28 27 import java.util.Set; 29 28 import java.util.function.Predicate; 30 29 31 import javax.swing.ButtonGroup;32 30 import javax.swing.JCheckBox; 33 31 import javax.swing.JLabel; 34 32 import javax.swing.JOptionPane; … … 36 34 import javax.swing.JRadioButton; 37 35 import javax.swing.text.BadLocationException; 38 36 import javax.swing.text.JTextComponent; 37 import javax.swing.BorderFactory; 39 38 40 39 import org.openstreetmap.josm.Main; 41 40 import org.openstreetmap.josm.actions.ActionParameter; … … 67 66 68 67 private static final String SEARCH_EXPRESSION = "searchExpression"; 69 68 70 /**71 * Search mode.72 */73 69 public enum SearchMode { 74 70 /** replace selection */ 75 71 replace('R'), … … 265 261 JRadioButton add = new JRadioButton(tr("add to selection"), initialValues.mode == SearchMode.add); 266 262 JRadioButton remove = new JRadioButton(tr("remove from selection"), initialValues.mode == SearchMode.remove); 267 263 JRadioButton inSelection = new JRadioButton(tr("find in selection"), initialValues.mode == SearchMode.in_selection); 268 ButtonGroup bg = new ButtonGroup();269 bg.add(replace);270 bg.add(add);271 bg.add(remove);272 bg.add(inSelection);273 264 274 finalJCheckBox caseSensitive = new JCheckBox(tr("case sensitive"), initialValues.caseSensitive);265 JCheckBox caseSensitive = new JCheckBox(tr("case sensitive"), initialValues.caseSensitive); 275 266 JCheckBox allElements = new JCheckBox(tr("all objects"), initialValues.allElements); 276 267 allElements.setToolTipText(tr("Also include incomplete and deleted objects in search.")); 277 final JRadioButton standardSearch = new JRadioButton(tr("standard"), !initialValues.regexSearch && !initialValues.mapCSSSearch); 278 final JRadioButton regexSearch = new JRadioButton(tr("regular expression"), initialValues.regexSearch); 279 final JRadioButton mapCSSSearch = new JRadioButton(tr("MapCSS selector"), initialValues.mapCSSSearch); 280 final JCheckBox addOnToolbar = new JCheckBox(tr("add toolbar button"), false); 281 final ButtonGroup bg2 = new ButtonGroup(); 282 bg2.add(standardSearch); 283 bg2.add(regexSearch); 284 bg2.add(mapCSSSearch); 268 JCheckBox addOnToolbar = new JCheckBox(tr("add toolbar button"), false); 285 269 286 JPanel top = new JPanel(new GridBagLayout()); 287 top.add(label, GBC.std().insets(0, 0, 5, 0)); 288 top.add(hcbSearchString, GBC.eol().fill(GBC.HORIZONTAL)); 270 JRadioButton standardSearch = new JRadioButton(tr("standard"), !initialValues.regexSearch && !initialValues.mapCSSSearch); 271 JRadioButton regexSearch = new JRadioButton(tr("regular expression"), initialValues.regexSearch); 272 JRadioButton mapCSSSearch = new JRadioButton(tr("MapCSS selector"), initialValues.mapCSSSearch); 273 289 274 JPanel left = new JPanel(new GridBagLayout()); 290 left.add(replace, GBC.eol()); 291 left.add(add, GBC.eol()); 292 left.add(remove, GBC.eol()); 293 left.add(inSelection, GBC.eop()); 294 left.add(caseSensitive, GBC.eol()); 295 if (Main.pref.getBoolean("expert", false)) { 296 left.add(allElements, GBC.eol()); 297 left.add(addOnToolbar, GBC.eop()); 298 left.add(standardSearch, GBC.eol()); 299 left.add(regexSearch, GBC.eol()); 300 left.add(mapCSSSearch, GBC.eol()); 275 276 JPanel selectionSettings = new JPanel(new GridBagLayout()); 277 selectionSettings.setBorder(BorderFactory.createTitledBorder(tr("Selection settings"))); 278 selectionSettings.add(replace, GBC.eol()); 279 selectionSettings.add(add, GBC.eol()); 280 selectionSettings.add(remove, GBC.eol()); 281 selectionSettings.add(inSelection, GBC.eop()); 282 283 JPanel additionalSettings = new JPanel(new GridBagLayout()); 284 additionalSettings.setBorder(BorderFactory.createTitledBorder(tr("Additional settings"))); 285 additionalSettings.add(caseSensitive, GBC.eol()); 286 287 if (Main.pref.getBoolean("expert", false)){ 288 additionalSettings.add(allElements, GBC.eol()); 289 additionalSettings.add(addOnToolbar, GBC.eop()); 290 291 JPanel searchOptions = new JPanel(new GridBagLayout()); 292 searchOptions.setBorder(BorderFactory.createTitledBorder(tr("Search Options"))); 293 searchOptions.add(standardSearch, GBC.eol()); 294 searchOptions.add(regexSearch, GBC.eol()); 295 searchOptions.add(mapCSSSearch, GBC.eol()); 296 297 left.add(selectionSettings, GBC.eol().fill(GBC.BOTH)); 298 left.add(additionalSettings, GBC.eol().fill(GBC.BOTH)); 299 left.add(searchOptions, GBC.eol().fill(GBC.BOTH)); 300 }else{ 301 left.add(selectionSettings, GBC.eol().fill(GBC.BOTH)); 302 left.add(additionalSettings, GBC.eol().fill(GBC.BOTH)); 301 303 } 302 304 303 final JPanel right; 304 right = new JPanel(new GridBagLayout()); 305 buildHints(right, hcbSearchString); 305 final JPanel right = SearchAction.buildHintsSection(hcbSearchString); 306 final JPanel top = new JPanel(new GridBagLayout()); 307 top.add(label, GBC.std().insets(0, 0, 5, 0)); 308 top.add(hcbSearchString, GBC.eol().fill(GBC.HORIZONTAL)); 306 309 307 310 final JTextComponent editorComponent = hcbSearchString.getEditorComponent(); 308 311 editorComponent.getDocument().addDocumentListener(new AbstractTextComponentValidator(editorComponent) { … … 334 337 335 338 final JPanel p = new JPanel(new GridBagLayout()); 336 339 p.add(top, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 5, 0)); 337 p.add(left, GBC.std().anchor(GBC.NORTH).insets(5, 10, 10, 0)); 338 p.add(right, GBC.eol()); 340 p.add(left, GBC.std().anchor(GBC.NORTH).insets(5, 10, 10, 0).fill(GBC.VERTICAL)); 341 p.add(right, GBC.eol().fill(GBC.BOTH).insets(0, 10, 0, 0)); 342 339 343 ExtendedDialog dialog = new ExtendedDialog( 340 344 Main.parent, 341 345 initialValues instanceof Filter ? tr("Filter") : tr("Search"), 342 initialValues instanceof Filter ? tr("Submit filter") : tr("Start Search"), 343 tr("Cancel") 346 new String[] { 347 initialValues instanceof Filter ? tr("Submit filter") : tr("Start Search"), 348 tr("Cancel")} 344 349 ) { 345 350 @Override 346 351 protected void buttonAction(int buttonIndex, ActionEvent evt) { … … 366 371 } 367 372 } 368 373 }; 369 dialog.setButtonIcons( "dialogs/search", "cancel");374 dialog.setButtonIcons(new String[] {"dialogs/search", "cancel"}); 370 375 dialog.configureContextsensitiveHelp("/Action/Search", true /* show help button */); 371 376 dialog.setContent(p); 377 dialog.showDialog(); 378 int result = dialog.getValue(); 372 379 373 if ( dialog.showDialog().getValue()!= 1) return null;380 if (result != 1) return null; 374 381 375 382 // User pressed OK - let's perform the search 376 383 SearchMode mode = replace.isSelected() ? SearchAction.SearchMode.replace … … 399 406 return initialValues; 400 407 } 401 408 402 private static void buildHints(JPanel right, HistoryComboBox hcbSearchString) { 403 right.add(new SearchKeywordRow(hcbSearchString) 404 .addTitle(tr("basic examples")) 409 private static JPanel buildHintsSection(HistoryComboBox hcbSearchString) { 410 JPanel hintPanel = new JPanel(new GridBagLayout()); 411 hintPanel.setBorder(BorderFactory.createTitledBorder(tr("Search hints"))); 412 413 hintPanel.add(new SearchKeywordRow(hcbSearchString) 414 .addTitle(tr("basics")) 405 415 .addKeyword(tr("Baker Street"), null, tr("''Baker'' and ''Street'' in any key")) 406 .addKeyword(tr("\"Baker Street\""), "\"\"", tr("''Baker Street'' in any key")), 407 GBC.eol()); 408 right.add(new SearchKeywordRow(hcbSearchString) 409 .addTitle(tr("basics")) 416 .addKeyword(tr("\"Baker Street\""), "\"\"", tr("''Baker Street'' in any key")) 410 417 .addKeyword("<i>key</i>:<i>valuefragment</i>", null, 411 418 tr("''valuefragment'' anywhere in ''key''"), "name:str matches name=Bakerstreet") 412 .addKeyword("-<i>key</i>:<i>valuefragment</i>", null, tr("''valuefragment'' nowhere in ''key''")) 419 .addKeyword("-<i>key</i>:<i>valuefragment</i>", null, tr("''valuefragment'' nowhere in ''key''")), 420 GBC.eol()); 421 hintPanel.add(new SearchKeywordRow(hcbSearchString) 413 422 .addKeyword("<i>key</i>=<i>value</i>", null, tr("''key'' with exactly ''value''")) 414 423 .addKeyword("<i>key</i>=*", null, tr("''key'' with any value")) 415 424 .addKeyword("*=<i>value</i>", null, tr("''value'' in any key")) … … 417 426 .addKeyword("<i>key</i>><i>value</i>", null, tr("matches if ''key'' is greater than ''value'' (analogously, less than)")) 418 427 .addKeyword("\"key\"=\"value\"", "\"\"=\"\"", 419 428 tr("to quote operators.<br>Within quoted strings the <b>\"</b> and <b>\\</b> characters need to be escaped " + 420 "by a preceding <b>\\</b> (e.g. <b>\\\"</b> and <b>\\\\</b>)."),429 "by a preceding <b>\\</b> (e.g. <b>\\\"</b> and <b>\\\\</b>)."), 421 430 "\"addr:street\""), 422 GBC.eol() );423 right.add(new SearchKeywordRow(hcbSearchString)431 GBC.eol().anchor(GBC.CENTER)); 432 hintPanel.add(new SearchKeywordRow(hcbSearchString) 424 433 .addTitle(tr("combinators")) 425 434 .addKeyword("<i>expr</i> <i>expr</i>", null, tr("logical and (both expressions have to be satisfied)")) 426 435 .addKeyword("<i>expr</i> | <i>expr</i>", "| ", tr("logical or (at least one expression has to be satisfied)")) … … 430 439 GBC.eol()); 431 440 432 441 if (Main.pref.getBoolean("expert", false)) { 433 right.add(new SearchKeywordRow(hcbSearchString)442 hintPanel.add(new SearchKeywordRow(hcbSearchString) 434 443 .addTitle(tr("objects")) 435 444 .addKeyword("type:node", "type:node ", tr("all nodes")) 436 445 .addKeyword("type:way", "type:way ", tr("all ways")) … … 438 447 .addKeyword("closed", "closed ", tr("all closed ways")) 439 448 .addKeyword("untagged", "untagged ", tr("object without useful tags")), 440 449 GBC.eol()); 441 right.add(new SearchKeywordRow(hcbSearchString)450 hintPanel.add(new SearchKeywordRow(hcbSearchString) 442 451 .addTitle(tr("metadata")) 443 452 .addKeyword("user:", "user:", tr("objects changed by user", "user:anonymous")) 444 453 .addKeyword("id:", "id:", tr("objects with given ID"), "id:0 (new objects)") … … 448 457 .addKeyword("timestamp:", "timestamp:", tr("objects with last modification timestamp within range"), "timestamp:2012/", 449 458 "timestamp:2008/2011-02-04T12"), 450 459 GBC.eol()); 451 right.add(new SearchKeywordRow(hcbSearchString)460 hintPanel.add(new SearchKeywordRow(hcbSearchString) 452 461 .addTitle(tr("properties")) 453 462 .addKeyword("nodes:<i>20-</i>", "nodes:", tr("ways with at least 20 nodes, or relations containing at least 20 nodes")) 454 463 .addKeyword("ways:<i>3-</i>", "ways:", tr("nodes with at least 3 referring ways, or relations containing at least 3 ways")) … … 457 466 .addKeyword("areasize:<i>-100</i>", "areasize:", tr("closed ways with an area of 100 m\u00b2")) 458 467 .addKeyword("waylength:<i>200-</i>", "waylength:", tr("ways with a length of 200 m or more")), 459 468 GBC.eol()); 460 right.add(new SearchKeywordRow(hcbSearchString)469 hintPanel.add(new SearchKeywordRow(hcbSearchString) 461 470 .addTitle(tr("state")) 462 471 .addKeyword("modified", "modified ", tr("all modified objects")) 463 472 .addKeyword("new", "new ", tr("all new objects")) … … 465 474 .addKeyword("incomplete", "incomplete ", tr("all incomplete objects")) 466 475 .addKeyword("deleted", "deleted ", tr("all deleted objects (checkbox <b>{0}</b> must be enabled)", tr("all objects"))), 467 476 GBC.eol()); 468 right.add(new SearchKeywordRow(hcbSearchString)477 hintPanel.add(new SearchKeywordRow(hcbSearchString) 469 478 .addTitle(tr("related objects")) 470 479 .addKeyword("child <i>expr</i>", "child ", tr("all children of objects matching the expression"), "child building") 471 480 .addKeyword("parent <i>expr</i>", "parent ", tr("all parents of objects matching the expression"), "parent bus_stop") … … 476 485 .addKeyword("nth%:<i>7</i>", "nth%:", 477 486 tr("every n-th member of relation and/or every n-th node of way"), "nth%:100 (child waterway)"), 478 487 GBC.eol()); 479 right.add(new SearchKeywordRow(hcbSearchString)488 hintPanel.add(new SearchKeywordRow(hcbSearchString) 480 489 .addTitle(tr("view")) 481 490 .addKeyword("inview", "inview ", tr("objects in current view")) 482 491 .addKeyword("allinview", "allinview ", tr("objects (and all its way nodes / relation members) in current view")) … … 485 494 tr("objects (and all its way nodes / relation members) in downloaded area")), 486 495 GBC.eol()); 487 496 } 497 498 return hintPanel; 488 499 } 489 500 490 501 /** … … 593 604 } else { 594 605 msg = null; 595 606 } 596 if (Main.map != null) { 597 Main.map.statusLine.setHelpText(msg); 598 } 599 if (!GraphicsEnvironment.isHeadless()) { 600 JOptionPane.showMessageDialog( 601 Main.parent, 602 msg, 603 tr("Warning"), 604 JOptionPane.WARNING_MESSAGE 605 ); 606 } 607 } else if (Main.map != null) { 607 Main.map.statusLine.setHelpText(msg); 608 JOptionPane.showMessageDialog( 609 Main.parent, 610 msg, 611 tr("Warning"), 612 JOptionPane.WARNING_MESSAGE 613 ); 614 } else { 608 615 Main.map.statusLine.setHelpText(tr("Found {0} matches", foundMatches)); 609 616 } 610 617 }
