Changeset 6553 in josm for trunk/src/org
- Timestamp:
- 2013-12-28T01:03:35+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java
r6552 r6553 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.BufferedReader; 7 import java.io.File; 8 import java.io.FileInputStream; 6 9 import java.io.InputStreamReader; 7 10 import java.io.Reader; 8 11 import java.util.ArrayList; 9 12 import java.util.Collection; 13 import java.util.Collections; 10 14 import java.util.HashMap; 11 15 import java.util.LinkedHashMap; … … 16 20 import java.util.regex.Pattern; 17 21 22 import org.openstreetmap.josm.Main; 18 23 import org.openstreetmap.josm.command.ChangePropertyCommand; 19 24 import org.openstreetmap.josm.command.ChangePropertyKeyCommand; … … 25 30 import org.openstreetmap.josm.data.osm.Tag; 26 31 import org.openstreetmap.josm.data.osm.Way; 32 import org.openstreetmap.josm.data.preferences.CollectionProperty; 27 33 import org.openstreetmap.josm.data.validation.FixableTestError; 28 34 import org.openstreetmap.josm.data.validation.Severity; … … 38 44 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.MapCSSParser; 39 45 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException; 46 import org.openstreetmap.josm.gui.widgets.EditableList; 40 47 import org.openstreetmap.josm.tools.CheckParameterUtil; 48 import org.openstreetmap.josm.tools.GBC; 41 49 import org.openstreetmap.josm.tools.Predicate; 42 50 import org.openstreetmap.josm.tools.Utils; 43 51 52 import javax.swing.JLabel; 44 53 import javax.swing.JPanel; 45 54 … … 384 393 addMapCSS("power"); 385 394 addMapCSS("geometry"); 386 } 395 for (final String i : sourcesProperty.get()) { 396 final String file = new File(i).getAbsolutePath(); 397 try { 398 Main.info(tr("Adding {0} to tag checker", file)); 399 addMapCSS(new BufferedReader(new InputStreamReader(new FileInputStream(i), Utils.UTF_8))); 400 } catch (Exception ex) { 401 Main.warn(new RuntimeException(tr("Failed to add {0} to tag checker", file), ex)); 402 } 403 } 404 } 405 406 protected EditableList sourcesList; 407 protected final CollectionProperty sourcesProperty = new CollectionProperty( 408 "validator." + this.getClass().getName() + ".sources", Collections.<String>emptyList()); 387 409 388 410 @Override 389 411 public void addGui(JPanel testPanel) { 390 412 super.addGui(testPanel); 413 sourcesList = new EditableList(tr("TagChecker source")); 414 sourcesList.setItems(sourcesProperty.get()); 415 testPanel.add(new JLabel(tr("Data sources ({0})", "*.mapcss")), GBC.eol().insets(23, 0, 0, 0)); 416 testPanel.add(sourcesList, GBC.eol().fill(GBC.HORIZONTAL).insets(23, 0, 0, 0)); 391 417 } 392 418 393 419 @Override 394 420 public boolean ok() { 421 sourcesProperty.put(sourcesList.getItems()); 395 422 return super.ok(); 396 423 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
r6552 r6553 5 5 import static org.openstreetmap.josm.tools.I18n.tr; 6 6 7 import java.awt.BorderLayout; 7 8 import java.awt.Dimension; 8 9 import java.awt.GridBagConstraints; 9 import java.awt.GridBagLayout;10 10 import java.awt.event.ActionEvent; 11 11 import java.awt.event.ActionListener; … … 18 18 import java.util.Arrays; 19 19 import java.util.Collection; 20 import java.util.Collections; 20 21 import java.util.HashMap; 21 22 import java.util.List; … … 27 28 import java.util.regex.PatternSyntaxException; 28 29 29 import javax.swing.DefaultListModel;30 import javax.swing.JButton;31 30 import javax.swing.JCheckBox; 32 31 import javax.swing.JLabel; 33 import javax.swing.JList;34 import javax.swing.JOptionPane;35 32 import javax.swing.JPanel; 36 import javax.swing.JScrollPane;37 33 38 34 import org.openstreetmap.josm.Main; … … 59 55 import org.openstreetmap.josm.gui.tagging.TaggingPresetItems.CheckGroup; 60 56 import org.openstreetmap.josm.gui.tagging.TaggingPresetItems.KeyedItem; 57 import org.openstreetmap.josm.gui.widgets.EditableList; 61 58 import org.openstreetmap.josm.io.MirroredInputStream; 62 59 import org.openstreetmap.josm.tools.GBC; … … 128 125 protected JCheckBox prefUseSpellFile; 129 126 130 protected JButton addSrcButton;131 protected JButton editSrcButton;132 protected JButton deleteSrcButton;133 134 127 protected static final int EMPTY_VALUES = 1200; 135 128 protected static final int INVALID_KEY = 1201; … … 145 138 /** 1250 and up is used by tagcheck */ 146 139 147 /** List of sources for spellcheck data */ 148 protected JList sourcesList; 140 protected EditableList sourcesList; 149 141 150 142 protected static final Entities entities = new Entities(); … … 533 525 testPanel.add(prefCheckComplexBeforeUpload, a); 534 526 535 sourcesList = new JList(new DefaultListModel()); 536 537 String sources = Main.pref.get( PREF_SOURCES ); 538 if (sources != null && sources.length() > 0) { 539 for (String source : sources.split(";")) { 540 ((DefaultListModel)sourcesList.getModel()).addElement(source); 541 } 542 } 543 544 addSrcButton = new JButton(tr("Add")); 545 addSrcButton.addActionListener(new ActionListener() { 546 @Override 547 public void actionPerformed(ActionEvent e) { 548 String source = JOptionPane.showInputDialog( 549 Main.parent, 550 tr("TagChecker source"), 551 tr("TagChecker source"), 552 JOptionPane.QUESTION_MESSAGE); 553 if (source != null) { 554 ((DefaultListModel)sourcesList.getModel()).addElement(source); 555 } 556 sourcesList.clearSelection(); 557 } 558 }); 559 560 editSrcButton = new JButton(tr("Edit")); 561 editSrcButton.addActionListener(new ActionListener() { 562 @Override 563 public void actionPerformed(ActionEvent e) { 564 int row = sourcesList.getSelectedIndex(); 565 if (row == -1 && sourcesList.getModel().getSize() == 1) { 566 sourcesList.setSelectedIndex(0); 567 row = 0; 568 } 569 if (row == -1) { 570 if (sourcesList.getModel().getSize() == 0) { 571 String source = JOptionPane.showInputDialog(Main.parent, tr("TagChecker source"), tr("TagChecker source"), JOptionPane.QUESTION_MESSAGE); 572 if (source != null) { 573 ((DefaultListModel)sourcesList.getModel()).addElement(source); 574 } 575 } else { 576 JOptionPane.showMessageDialog( 577 Main.parent, 578 tr("Please select the row to edit."), 579 tr("Information"), 580 JOptionPane.INFORMATION_MESSAGE 581 ); 582 } 583 } else { 584 String source = (String)JOptionPane.showInputDialog(Main.parent, 585 tr("TagChecker source"), 586 tr("TagChecker source"), 587 JOptionPane.QUESTION_MESSAGE, null, null, 588 sourcesList.getSelectedValue()); 589 if (source != null) { 590 ((DefaultListModel)sourcesList.getModel()).setElementAt(source, row); 591 } 592 } 593 sourcesList.clearSelection(); 594 } 595 }); 596 597 deleteSrcButton = new JButton(tr("Delete")); 598 deleteSrcButton.addActionListener(new ActionListener() { 599 @Override 600 public void actionPerformed(ActionEvent e) { 601 if (sourcesList.getSelectedIndex() == -1) { 602 JOptionPane.showMessageDialog(Main.parent, tr("Please select the row to delete."), tr("Information"), JOptionPane.QUESTION_MESSAGE); 603 } else { 604 ((DefaultListModel)sourcesList.getModel()).remove(sourcesList.getSelectedIndex()); 605 } 606 } 607 }); 608 sourcesList.setMinimumSize(new Dimension(300,50)); 609 sourcesList.setVisibleRowCount(3); 610 611 sourcesList.setToolTipText(tr("The sources (URL or filename) of spell check (see http://wiki.openstreetmap.org/index.php/User:JLS/speller) or tag checking data files.")); 612 addSrcButton.setToolTipText(tr("Add a new source to the list.")); 613 editSrcButton.setToolTipText(tr("Edit the selected source.")); 614 deleteSrcButton.setToolTipText(tr("Delete the selected source from the list.")); 615 616 testPanel.add(new JLabel(tr("Data sources")), GBC.eol().insets(23,0,0,0)); 617 testPanel.add(new JScrollPane(sourcesList), GBC.eol().insets(23,0,0,0).fill(GridBagConstraints.HORIZONTAL)); 618 final JPanel buttonPanel = new JPanel(new GridBagLayout()); 619 testPanel.add(buttonPanel, GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 620 buttonPanel.add(addSrcButton, GBC.std().insets(0,5,0,0)); 621 buttonPanel.add(editSrcButton, GBC.std().insets(5,5,5,0)); 622 buttonPanel.add(deleteSrcButton, GBC.std().insets(0,5,0,0)); 527 final String sources = Main.pref.get(PREF_SOURCES); 528 sourcesList = new EditableList(tr("TagChecker source")); 529 sourcesList.setItems(sources != null ? Arrays.asList(sources.split(";")) : Collections.<String>emptyList()); 530 testPanel.add(new JLabel(tr("Data sources ({0})", "*.cfg")), GBC.eol().insets(23, 0, 0, 0)); 531 testPanel.add(sourcesList, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(23, 0, 0, 0)); 623 532 624 533 ActionListener disableCheckActionListener = new ActionListener() { … … 667 576 boolean selected = prefCheckKeys.isSelected() || prefCheckKeysBeforeUpload.isSelected() 668 577 || prefCheckComplex.isSelected() || prefCheckComplexBeforeUpload.isSelected(); 669 sourcesList.setEnabled( selected ); 670 addSrcButton.setEnabled(selected); 671 editSrcButton.setEnabled(selected); 672 deleteSrcButton.setEnabled(selected); 578 sourcesList.setEnabled(selected); 673 579 } 674 580 … … 690 596 Main.pref.put(PREF_USE_IGNORE_FILE, prefUseIgnoreFile.isSelected()); 691 597 Main.pref.put(PREF_USE_SPELL_FILE, prefUseSpellFile.isSelected()); 692 StringBuilder sources = new StringBuilder(); 693 if (sourcesList.getModel().getSize() > 0) { 694 for (int i = 0; i < sourcesList.getModel().getSize(); ++i) { 695 if (sources.length() > 0) { 696 sources.append(";"); 697 } 698 sources.append(sourcesList.getModel().getElementAt(i)); 699 } 700 } 701 return Main.pref.put(PREF_SOURCES, sources.length() > 0 ? sources.toString() : null); 598 final List<String> sources = sourcesList.getItems(); 599 return Main.pref.put(PREF_SOURCES, sources.isEmpty() ? null : Utils.join(";", sources)); 702 600 } 703 601
Note:
See TracChangeset
for help on using the changeset viewer.