Changeset 32673 in osm for applications/editors/josm/plugins/roadsigns/src/org/openstreetmap
- Timestamp:
- 2016-07-18T23:29:28+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/roadsigns/src/org/openstreetmap/josm/plugins/roadsigns
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/roadsigns/src/org/openstreetmap/josm/plugins/roadsigns/ParametrizedString.java
r30737 r32673 1 // License: GPL (v2 or later)1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.roadsigns; 3 3 … … 28 28 * types have a single String object as their backing data. 29 29 */ 30 public staticinterface StringOrParameter {30 public interface StringOrParameter { 31 31 } 32 32 -
applications/editors/josm/plugins/roadsigns/src/org/openstreetmap/josm/plugins/roadsigns/RoadSignInputDialog.java
r32507 r32673 1 // License: GPL (v2 or later)1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.roadsigns; 3 3 … … 109 109 private MultiSplitPane multiSplitPane; 110 110 111 publicRoadSignInputDialog() {111 RoadSignInputDialog() { 112 112 super(Main.parent, tr("Road Sign Plugin"), new String[] {tr("OK"), tr("Cancel")}, false /* modal */); 113 113 setRememberWindowGeometry(getClass().getName() + ".geometry", … … 116 116 this.signs = RoadSignsPlugin.signs; 117 117 sel = new SignSelection(); 118 setButtonIcons(new String[] { "ok.png", "cancel.png"});118 setButtonIcons(new String[] {"ok.png", "cancel.png"}); 119 119 final JTabbedPane tabs = new JTabbedPane(); 120 120 tabs.add(tr("signs"), buildSignsPanel()); … … 168 168 private Command createCommand(Collection<OsmPrimitive> selPrim) { 169 169 List<Command> cmds = new LinkedList<>(); 170 for (int i =0; i<previewModel.getRowCount(); i++) {170 for (int i = 0; i < previewModel.getRowCount(); i++) { 171 171 String key = (String) previewModel.getValueAt(i, 0); 172 172 String value = (String) previewModel.getValueAt(i, 1); … … 230 230 multiSplitPane.add(new JScrollPane(pnlSignSelection), "upperleft"); 231 231 multiSplitPane.add(buildPreviewPanel(), "upperright"); 232 JScrollPane scroll1 = new JScrollPane(pnlPossibleSigns, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 232 JScrollPane scroll1 = new JScrollPane(pnlPossibleSigns, 233 JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 233 234 scroll1.setPreferredSize(new Dimension(10, 10)); 234 235 multiSplitPane.add(scroll1, "middleleft"); 235 236 236 JScrollPane scroll2 = new JScrollPane(pnlPossibleSupplements, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 237 JScrollPane scroll2 = new JScrollPane(pnlPossibleSupplements, 238 JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); 237 239 scroll2.setPreferredSize(new Dimension(10, 10)); 238 240 multiSplitPane.add(scroll2, "middleright"); … … 244 246 info.addHyperlinkListener(new HyperlinkListener() { 245 247 @Override 246 248 public void hyperlinkUpdate(HyperlinkEvent e) { 247 249 if (e == null || e.getURL() == null) 248 250 return; … … 289 291 * Manages the update of gui elements when the selection changes. 290 292 */ 291 public class SignSelection 292 private final LinkedList<SignCombination> combos =new LinkedList<>();293 public class SignSelection { 294 private final LinkedList<SignCombination> combos = new LinkedList<>(); 293 295 294 296 public void remove(SignCombination sc) { … … 335 337 336 338 private int findIndex(SignCombination scFind) { 337 int i =0;339 int i = 0; 338 340 for (SignCombination sc : combos) { 339 341 if (sc == scFind) { … … 346 348 347 349 private Pair<Integer, Integer> findIndex(SignWrapper swFind) { 348 int selIdx =0;350 int selIdx = 0; 349 351 for (SignCombination sc : combos) { 350 int combIdx =0;352 int combIdx = 0; 351 353 for (SignWrapper sw : sc.signs) { 352 354 if (swFind == sw) { … … 364 366 panel.setLayout(new GridBagLayout()); 365 367 GridBagConstraints gbc = new GridBagConstraints(); 366 gbc.anchor =GridBagConstraints.NORTHWEST;367 gbc.gridx =0;368 gbc.gridy =0;369 gbc.weightx =0;370 gbc.weighty =1.0;368 gbc.anchor = GridBagConstraints.NORTHWEST; 369 gbc.gridx = 0; 370 gbc.gridy = 0; 371 gbc.weightx = 0; 372 gbc.weighty = 1.0; 371 373 gbc.insets = new Insets(10, 10, 0, 10); 372 374 … … 395 397 public LinkedList<SignWrapper> signs; 396 398 397 publicSignCombination() {399 SignCombination() { 398 400 signs = new LinkedList<>(); 399 401 } … … 407 409 panel.setBorder(BorderFactory.createCompoundBorder(etched, empty)); 408 410 409 int i =0;411 int i = 0; 410 412 for (SignWrapper sw : signs) { 411 413 GridBagConstraints gbc = new GridBagConstraints(); … … 429 431 public void add(final Sign sign) { 430 432 if (!signs.isEmpty() && !sign.isSupplementing) 431 throw new IllegalArgumentException("any sign but the first must be a supplement sign"); //FIXME433 throw new IllegalArgumentException("any sign but the first must be a supplement sign"); //FIXME 432 434 final SignWrapper signWrp = new SignWrapper(sign); 433 435 signs.add(signWrp); … … 447 449 JPanel paramsPanel; 448 450 Map<String, String> paramValues = new HashMap<>(); 449 public SignWrapper(Sign sign) { 451 452 SignWrapper(Sign sign) { 450 453 this.sign = sign; 451 454 for (final SignParameter p : this.sign.params) { … … 453 456 } 454 457 } 458 455 459 @Override 456 460 public String toString() { … … 475 479 return paramsPanel; 476 480 paramsPanel = new JPanel(new GridBagLayout()); 477 int i =0;481 int i = 0; 478 482 for (final SignParameter p : this.sign.params) { 479 483 JPanel pnlInput = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); … … 491 495 class TFDocumentListener implements DocumentListener { 492 496 @Override 493 497 public void insertUpdate(DocumentEvent e) { 494 498 update(); 495 499 } 496 500 497 501 @Override 498 502 public void removeUpdate(DocumentEvent e) { 499 503 update(); 500 504 } 501 505 502 506 @Override 503 507 public void changedUpdate(DocumentEvent e) { 504 508 update(); 505 509 } 510 506 511 public void update() { 507 512 paramValues.put(p.ident, tf.getText()); 508 513 previewModel.update(); 509 514 } 510 }; 515 } 516 511 517 TFDocumentListener listener = new TFDocumentListener(); 512 518 tf.getDocument().addDocumentListener(listener); … … 523 529 gbc.gridy = i; 524 530 gbc.anchor = GridBagConstraints.WEST; 525 paramsPanel.add(pnlInput, gbc);531 paramsPanel.add(pnlInput, gbc); 526 532 i++; 527 533 } 528 if (i >0) {534 if (i > 0) { 529 535 paramsPanel.setBorder(BorderFactory.createEmptyBorder(0, 3, 0, 0)); 530 536 } … … 562 568 previewTable = new JTable(data, columnNames) { 563 569 @Override 564 570 public String getToolTipText(MouseEvent e) { 565 571 int rowIndex = rowAtPoint(e.getPoint()); 566 572 int colIndex = columnAtPoint(e.getPoint()); … … 587 593 addTrafficSignTag.addActionListener(new ActionListener() { 588 594 @Override 589 595 public void actionPerformed(ActionEvent e) { 590 596 previewModel.update(); 591 597 } … … 601 607 private List<String> values = new ArrayList<>(); 602 608 603 int rows =3;609 int rows = 3; 604 610 String[] header = {tr("Key"), tr("Value")}; 605 611 606 612 @Override 607 613 public int getRowCount() { 608 614 return keys.size(); 609 615 } 610 616 611 617 @Override 612 618 public int getColumnCount() { 613 619 return 2; 614 620 } 615 621 616 622 @Override 617 623 public Object getValueAt(int rowIndex, int columnIndex) { 618 624 if (columnIndex == 0) { 619 625 return keys.get(rowIndex); … … 633 639 */ 634 640 public void update() { 635 final TreeMap<String, String> map = new TreeMap<>();641 final TreeMap<String, String> map = new TreeMap<>(); 636 642 String traffic_sign = ""; 637 643 … … 649 655 List<String> values = new ArrayList<>(); 650 656 List<String> conditions = new ArrayList<>(); 651 //String ident; 652 public TagEvaluater(Tag t) { 657 TagEvaluater(Tag t) { 653 658 key = t.key.evaluate(env); 654 659 default_value = t.value.evaluate(env); 655 //ident = t.ident;656 660 } 657 661 … … 672 676 for (String v : values) { 673 677 value += sep+v; 674 sep =";";678 sep = ";"; 675 679 } 676 680 } … … 690 694 Map<String, TagEvaluater> tags = new LinkedHashMap<>(); 691 695 for (SignWrapper sw : sc.signs) { 692 for (Map.Entry<String, String> entry : sw.paramValues.entrySet()) {696 for (Map.Entry<String, String> entry : sw.paramValues.entrySet()) { 693 697 env.put(entry.getKey(), entry.getValue()); 694 698 } … … 713 717 TagEvaluater te = tags.get(t.tag_ref); 714 718 if (te == null) { 715 System.err.println(String.format("warning: referenced tag with ident '%s' not found for appending tag %s.",t.tag_ref, t.toString())); 719 System.err.println(String.format("warning: referenced tag with ident '%s' not found for appending tag %s.", 720 t.tag_ref, t.toString())); 716 721 } else { 717 722 te.append_value(t.append_value.evaluate(env)); … … 720 725 TagEvaluater te = tags.get(t.tag_ref); 721 726 if (te == null) { 722 System.err.println(String.format("warning: referenced tag with ident '%s' not found for condition tag %s.",t.tag_ref, t.toString())); 727 System.err.println(String.format("warning: referenced tag with ident '%s' not found for condition tag %s.", 728 t.tag_ref, t.toString())); 723 729 } else { 724 730 te.condition(t.condition.evaluate(env)); 725 731 } 726 732 } else { 727 System.err.println(String.format("warning: found tag_ref but neither append_value nor condition for tag %s.", t.toString())); 733 System.err.println(String.format("warning: found tag_ref but neither append_value nor condition for tag %s.", 734 t.toString())); 728 735 } 729 736 } else if (t.ident != null) { … … 738 745 map.put(t.key.evaluate(env), t.value.evaluate(env)); 739 746 } 740 741 747 } 742 748 } … … 776 782 private class SignClickListener extends MouseAdapter { 777 783 private Sign sign; 778 publicSignClickListener(Sign sign) {784 SignClickListener(Sign sign) { 779 785 this.sign = sign; 780 786 } 787 781 788 @Override 782 789 public void mouseClicked(MouseEvent e) { 783 790 info.setText(longText()); 784 791 /* scroll up again */ 785 SwingUtilities.invokeLater(new Runnable() {792 SwingUtilities.invokeLater(new Runnable() { 786 793 @Override 787 794 public void run() { 788 795 scrollInfo.getVerticalScrollBar().setValue(0); 789 796 } … … 814 821 txt.append("<br>"); 815 822 } 816 if (sign.wiki != null && ! 823 if (sign.wiki != null && !sign.wiki.equals(sign.loc_wiki)) { 817 824 String link = wikiPrefix+sign.wiki; 818 825 txt.append("<a href=\""+link+"\">"+link+"</a>"); … … 831 838 */ 832 839 public static class FixedWidthPanel extends JPanel implements Scrollable { 833 publicFixedWidthPanel() {840 FixedWidthPanel() { 834 841 super(new FlowLayout(FlowLayout.LEFT)); 835 842 } … … 846 853 847 854 @Override 848 855 public Dimension getPreferredScrollableViewportSize() { 849 856 return super.getPreferredSize(); 850 857 } 851 858 852 859 @Override 853 public int getScrollableUnitIncrement( Rectangle visibleRect, int orientation, int direction) {860 public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) { 854 861 final int FRAC = 20; 855 862 int inc = (orientation == SwingConstants.VERTICAL ? getParent().getHeight() : getParent().getWidth()) / FRAC; … … 858 865 859 866 @Override 860 public int getScrollableBlockIncrement( Rectangle visibleRect, int orientation, int direction) {867 public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) { 861 868 return orientation == SwingConstants.VERTICAL ? getParent().getHeight() : getParent().getWidth(); 862 869 } 863 870 864 871 @Override 865 872 public boolean getScrollableTracksViewportWidth() { 866 873 return true; 867 874 } 868 875 869 876 @Override 870 877 public boolean getScrollableTracksViewportHeight() { 871 878 return false; 872 879 } … … 893 900 JRadioButton rbAll, rbUseful; 894 901 895 publicSettingsPanel(boolean standalone, final Action update) {902 SettingsPanel(boolean standalone, final Action update) { 896 903 super(new GridBagLayout()); 897 904 presetsData = RoadSignsPlugin.getAvailablePresetsMetaData(); -
applications/editors/josm/plugins/roadsigns/src/org/openstreetmap/josm/plugins/roadsigns/RoadSignsPlugin.java
r30962 r32673 1 // License: GPL (v2 or later)1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.roadsigns; 3 3 … … 44 44 public static RoadSignsPlugin plugin; 45 45 46 public final static PresetMetaData PRESET_BE = new PresetMetaData("BE", tr("Belgium"), "resource://data/roadsignpresetBE.xml", "resource://images/BE/"); 47 public final static PresetMetaData PRESET_ES = new PresetMetaData("ES", tr("Spain"), "resource://data/roadsignpresetES.xml", "resource://images/ES/"); 48 public final static PresetMetaData PRESET_DE = new PresetMetaData("DE", tr("Germany"), "resource://data/roadsignpresetDE.xml", "resource://images/DE/"); 49 public final static PresetMetaData PRESET_PL = new PresetMetaData("PL", tr("Poland"), "resource://data/roadsignpresetPL.xml", "resource://images/PL/"); 50 public final static PresetMetaData PRESET_SK = new PresetMetaData("SK", tr("Slovakia"), "resource://data/roadsignpresetSK.xml", "resource://images/SK/"); 51 public final static Collection<PresetMetaData> DEFAULT_PRESETS = Arrays.asList(PRESET_BE, PRESET_ES, PRESET_DE, PRESET_PL, PRESET_SK); 46 public static final PresetMetaData PRESET_BE = new PresetMetaData( 47 "BE", tr("Belgium"), "resource://data/roadsignpresetBE.xml", "resource://images/BE/"); 48 public static final PresetMetaData PRESET_ES = new PresetMetaData( 49 "ES", tr("Spain"), "resource://data/roadsignpresetES.xml", "resource://images/ES/"); 50 public static final PresetMetaData PRESET_DE = new PresetMetaData( 51 "DE", tr("Germany"), "resource://data/roadsignpresetDE.xml", "resource://images/DE/"); 52 public static final PresetMetaData PRESET_PL = new PresetMetaData( 53 "PL", tr("Poland"), "resource://data/roadsignpresetPL.xml", "resource://images/PL/"); 54 public static final PresetMetaData PRESET_SK = new PresetMetaData( 55 "SK", tr("Slovakia"), "resource://data/roadsignpresetSK.xml", "resource://images/SK/"); 56 public static final Collection<PresetMetaData> DEFAULT_PRESETS = Arrays.asList(PRESET_BE, PRESET_ES, PRESET_DE, PRESET_PL, PRESET_SK); 52 57 53 58 public RoadSignsPlugin(PluginInformation info) { … … 69 74 btn.setText(null); 70 75 btn.setBorder(BorderFactory.createEmptyBorder()); 71 btn.setPreferredSize(new Dimension(18, 18));76 btn.setPreferredSize(new Dimension(18, 18)); 72 77 PropertiesDialog.pluginHook.add(btn); 73 78 PropertiesDialog.pluginHook.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0)); … … 76 81 77 82 private static class RoadSignAction extends JosmAction { 78 publicRoadSignAction() {83 RoadSignAction() { 79 84 super(tr("Roadsign tagging"), "pref/roadsigns-small", tr("Add tags by clicking on road signs"), 80 Shortcut.registerShortcut("plugin:roadsigns:dialog", tr("Roadsigns plugin: open dialog"), KeyEvent.VK_Q, Shortcut.ALT_SHIFT), false); 85 Shortcut.registerShortcut("plugin:roadsigns:dialog", tr("Roadsigns plugin: open dialog"), 86 KeyEvent.VK_Q, Shortcut.ALT_SHIFT), false); 81 87 } 82 88 83 89 @Override 84 90 public void actionPerformed(ActionEvent e) { 85 91 String code = Main.pref.get("plugin.roadsigns.preset.selection", null); 86 92 if (code == null) { 87 ExtendedDialog ed = new ExtendedDialog(Main.parent, tr("Settings"), new String[] { tr("Ok"), tr("Cancel")});93 ExtendedDialog ed = new ExtendedDialog(Main.parent, tr("Settings"), new String[] {tr("Ok"), tr("Cancel")}); 88 94 ed.setButtonIcons(new String[] {"ok", "cancel"}); 89 95 SettingsPanel settings = new SettingsPanel(true, null); … … 196 202 197 203 protected static void loadSignPreset() throws IOException { 198 List<PresetMetaData> presetsData = 204 List<PresetMetaData> presetsData = getAvailablePresetsMetaData(); 199 205 String code = Main.pref.get("plugin.roadsigns.preset.selection", null); 200 206 … … 224 230 JOptionPane.showMessageDialog( 225 231 Main.parent, 226 tr("Could not read tagging preset source: ''{0}''", source),232 tr("Could not read tagging preset source: ''{0}''", source), 227 233 tr("Error"), 228 234 JOptionPane.ERROR_MESSAGE … … 245 251 */ 246 252 @SuppressWarnings("resource") 247 253 public static InputStream getInputStream(String source) throws IOException { 248 254 InputStream in = null; 249 255 if (source.startsWith("http://") || source.startsWith("https://") || source.startsWith("ftp://")) { -
applications/editors/josm/plugins/roadsigns/src/org/openstreetmap/josm/plugins/roadsigns/RoadSignsReader.java
r30737 r32673 1 // License: GPL (v2 or later)1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.roadsigns; 3 3 … … 15 15 import javax.xml.parsers.SAXParserFactory; 16 16 17 import org.xml.sax.Attributes;18 import org.xml.sax.InputSource;19 import org.xml.sax.Locator;20 import org.xml.sax.SAXException;21 import org.xml.sax.SAXParseException;22 import org.xml.sax.helpers.DefaultHandler;23 17 import org.openstreetmap.josm.Main; 24 18 import org.openstreetmap.josm.plugins.roadsigns.Sign.SignParameter; … … 28 22 import org.openstreetmap.josm.tools.LanguageInfo; 29 23 import org.openstreetmap.josm.tools.XmlParsingException; 24 import org.xml.sax.Attributes; 25 import org.xml.sax.InputSource; 26 import org.xml.sax.Locator; 27 import org.xml.sax.SAXException; 28 import org.xml.sax.SAXParseException; 29 import org.xml.sax.helpers.DefaultHandler; 30 30 31 31 /** … … 60 60 this.locator = locator; 61 61 } 62 63 62 64 63 @Override public void startElement(String ns, String lname, String qname, Attributes atts) throws SAXException { … … 160 159 161 160 if (debug) { 162 for (int i =0; i<atts.getLength(); ++i) {161 for (int i = 0; i < atts.getLength(); ++i) { 163 162 System.err.println(" "+atts.getQName(i)+": "+atts.getValue(i)); 164 163 } 165 164 } 166 165 } 166 167 167 @Override public void endElement(String ns, String lname, String qname) throws SAXException { 168 168 if (debug) System.err.print("</"+qname+"> |"); … … 185 185 if (debug) System.err.println("|"); 186 186 } 187 187 188 @Override public void characters(char[] ch, int start, int length) { 188 189 String s = new String(ch, start, length); … … 222 223 throw new ExtendedParsingException(e).rememberLocation(locator); 223 224 } 225 224 226 protected void throwException(String msg) throws XmlParsingException { 225 227 throw new XmlParsingException(msg).rememberLocation(locator); … … 233 235 } 234 236 } 237 235 238 public void wireSupplements() throws XmlParsingException { 236 239 Map<String, Sign> map = new HashMap<>(); … … 250 253 } 251 254 } 252 253 255 254 256 public static class ExtendedParsingException extends SAXException { … … 304 306 * 305 307 * @return True if file was properly parsed, false if there was error during parsing but some data were parsed anyway 306 * @throws SAXException307 * @throws IOException308 308 */ 309 309 public List<Sign> parse() throws SAXException, IOException { -
applications/editors/josm/plugins/roadsigns/src/org/openstreetmap/josm/plugins/roadsigns/Sign.java
r30737 r32673 1 // License: GPL (v2 or later)1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.roadsigns; 3 3 … … 53 53 54 54 public static class SignParameter { 55 public enum Input {TEXTFIELD, COMBO}; 55 public enum Input { TEXTFIELD, COMBO } 56 56 57 public String ident; 57 58 public Input input; … … 73 74 return deflt == null ? "" : deflt; 74 75 } 76 75 77 public String getPrefix() { 76 78 return prefix == null ? "" : prefix; 77 79 } 80 78 81 public String getSuffix() { 79 82 return suffix == null ? "" : suffix; … … 101 104 r = r.replaceAll("\\[.*\\]", ""); 102 105 if (r.startsWith("DE:")) { 103 r =r.replaceAll("DE:", "");106 r = r.replaceAll("DE:", ""); 104 107 /* normal sign: starts with 3 digits, then a non-digit */ 105 { 106 Pattern p = Pattern.compile("^\\d{3}(\\D|$)"); 107 Matcher m = p.matcher(r); 108 if (m.find()) 109 return tr("Sign {0}", r); 110 } 108 Pattern p1 = Pattern.compile("^\\d{3}(\\D|$)"); 109 Matcher m1 = p1.matcher(r); 110 if (m1.find()) 111 return tr("Sign {0}", r); 111 112 /* supplementary sign: starts with 4 digits, then a non-digit */ 112 { 113 Pattern p = Pattern.compile("^\\d{4}(\\D|$)"); 114 Matcher m = p.matcher(r); 115 if (m.find()) 116 return tr("Additional sign {0}", r); 117 } 113 Pattern p2 = Pattern.compile("^\\d{4}(\\D|$)"); 114 Matcher m2 = p2.matcher(r); 115 if (m2.find()) 116 return tr("Additional sign {0}", r); 118 117 return null; 119 118 }
Note:
See TracChangeset
for help on using the changeset viewer.