- Timestamp:
- 2016-01-07T01:53:58+01:00 (9 years ago)
- Location:
- trunk
- Files:
-
- 1 deleted
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
r9280 r9334 2 2 package org.openstreetmap.josm.gui.dialogs; 3 3 4 import static org.openstreetmap.josm.tools.I18n.marktr; 4 5 import static org.openstreetmap.josm.tools.I18n.tr; 5 6 … … 26 27 import java.util.ArrayList; 27 28 import java.util.Arrays; 29 import java.util.Collection; 28 30 import java.util.List; 29 31 … … 31 33 import javax.swing.DefaultButtonModel; 32 34 import javax.swing.DefaultListSelectionModel; 35 import javax.swing.ImageIcon; 33 36 import javax.swing.JCheckBox; 34 37 import javax.swing.JFileChooser; … … 544 547 545 548 private boolean errorsTabLoaded; 549 private boolean warningsTabLoaded; 546 550 private boolean sourceTabLoaded; 547 551 … … 573 577 tabs.setTabComponentAt(0, lblInfo); 574 578 575 final JPanel pErrors = new JPanel(new GridBagLayout()); 576 tabs.add("Errors", pErrors); 577 JLabel lblErrors; 578 if (s.getErrors().isEmpty()) { 579 lblErrors = new JLabel(tr("Errors")); 580 lblErrors.setFont(lblInfo.getFont().deriveFont(Font.PLAIN)); 581 lblErrors.setEnabled(false); 582 tabs.setTabComponentAt(1, lblErrors); 583 tabs.setEnabledAt(1, false); 584 } else { 585 lblErrors = new JLabel(tr("Errors"), ImageProvider.get("misc", "error"), JLabel.HORIZONTAL); 586 tabs.setTabComponentAt(1, lblErrors); 587 } 579 final JPanel pErrors = addErrorOrWarningTab(tabs, lblInfo, 580 s.getErrors(), marktr("Errors"), 1, ImageProvider.get("misc", "error")); 581 final JPanel pWarnings = addErrorOrWarningTab(tabs, lblInfo, 582 s.getWarnings(), marktr("Warnings"), 2, ImageProvider.get("warning-small")); 588 583 589 584 final JPanel pSource = new JPanel(new GridBagLayout()); … … 591 586 JLabel lblSource = new JLabel(tr("Source")); 592 587 lblSource.setFont(lblSource.getFont().deriveFont(Font.PLAIN)); 593 tabs.setTabComponentAt( 2, lblSource);588 tabs.setTabComponentAt(3, lblSource); 594 589 595 590 tabs.getModel().addChangeListener(new ChangeListener() { … … 598 593 if (!errorsTabLoaded && ((SingleSelectionModel) e.getSource()).getSelectedIndex() == 1) { 599 594 errorsTabLoaded = true; 600 buildErrors Panel(s, pErrors);595 buildErrorsOrWarningPanel(s.getErrors(), pErrors); 601 596 } 602 if (!sourceTabLoaded && ((SingleSelectionModel) e.getSource()).getSelectedIndex() == 2) { 597 if (!warningsTabLoaded && ((SingleSelectionModel) e.getSource()).getSelectedIndex() == 2) { 598 warningsTabLoaded = true; 599 buildErrorsOrWarningPanel(s.getWarnings(), pWarnings); 600 } 601 if (!sourceTabLoaded && ((SingleSelectionModel) e.getSource()).getSelectedIndex() == 3) { 603 602 sourceTabLoaded = true; 604 603 buildSourcePanel(s, pSource); … … 608 607 info.setContent(tabs, false); 609 608 info.showDialog(); 609 } 610 611 private JPanel addErrorOrWarningTab(final JTabbedPane tabs, JLabel lblInfo, 612 Collection<?> items, String title, int pos, ImageIcon icon) { 613 final JPanel pErrors = new JPanel(new GridBagLayout()); 614 tabs.add(title, pErrors); 615 if (items.isEmpty()) { 616 JLabel lblErrors = new JLabel(tr(title)); 617 lblErrors.setFont(lblInfo.getFont().deriveFont(Font.PLAIN)); 618 lblErrors.setEnabled(false); 619 tabs.setTabComponentAt(pos, lblErrors); 620 tabs.setEnabledAt(pos, false); 621 } else { 622 JLabel lblErrors = new JLabel(tr(title), icon, JLabel.HORIZONTAL); 623 tabs.setTabComponentAt(pos, lblErrors); 624 } 625 return pErrors; 610 626 } 611 627 … … 658 674 } 659 675 660 private void buildErrorsPanel(StyleSources, JPanel p) {676 private <T> void buildErrorsOrWarningPanel(Collection<T> items, JPanel p) { 661 677 JosmTextArea txtErrors = new JosmTextArea(); 662 678 txtErrors.setFont(GuiHelper.getMonospacedFont(txtErrors)); 663 679 txtErrors.setEditable(false); 664 680 p.add(new JScrollPane(txtErrors), GBC.std().fill()); 665 for (T hrowable t : s.getErrors()) {681 for (T t : items) { 666 682 txtErrors.append(t + "\n"); 667 683 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r9299 r9334 11 11 import java.util.Arrays; 12 12 import java.util.Collection; 13 import java.util.Collections;14 13 import java.util.HashSet; 15 14 import java.util.LinkedList; … … 270 269 } 271 270 } 272 if (Main.isDebugEnabled() || !source. getErrors().isEmpty()) {271 if (Main.isDebugEnabled() || !source.isValid()) { 273 272 final long elapsedTime = System.currentTimeMillis() - startTime; 274 273 String message = "Initializing map style " + source.url + " completed in " + Utils.getDurationString(elapsedTime); 275 if (!source. getErrors().isEmpty()) {276 Main.warn(message + " (" + source.getErrors().size() + " errors )");274 if (!source.isValid()) { 275 Main.warn(message + " (" + source.getErrors().size() + " errors, " + source.getWarnings().size() + " warnings)"); 277 276 } else { 278 277 Main.debug(message); … … 445 444 * Add a new map paint style. 446 445 * @param entry map paint style 447 * @return l ist of errors that occured during loading448 */ 449 public static Collection<Throwable>addStyle(SourceEntry entry) {446 * @return loaded style source, or {@code null} 447 */ 448 public static StyleSource addStyle(SourceEntry entry) { 450 449 StyleSource source = fromSourceEntry(entry); 451 450 if (source != null) { … … 458 457 Main.map.mapView.repaint(); 459 458 } 460 return source.getErrors(); 461 } 462 return Collections.emptyList(); 459 } 460 return source; 463 461 } 464 462 -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java
r9078 r9334 14 14 import java.util.List; 15 15 import java.util.Map; 16 import java.util.Set; 17 import java.util.concurrent.CopyOnWriteArrayList; 18 import java.util.concurrent.CopyOnWriteArraySet; 16 19 17 20 import javax.swing.ImageIcon; … … 33 36 public abstract class StyleSource extends SourceEntry { 34 37 35 private final List<Throwable> errors = new ArrayList<>(); 38 private final List<Throwable> errors = new CopyOnWriteArrayList<>(); 39 private final Set<String> warnings = new CopyOnWriteArraySet<>(); 36 40 public File zipIcons; 37 41 … … 42 46 private static ImageProvider defaultIconProvider; 43 47 44 /****** 45 * The following fields is additional information found in the header 46 * of the source file. 48 /** 49 * The following fields is additional information found in the header of the source file. 47 50 */ 48 51 public String icon; … … 121 124 } 122 125 126 /** 127 * Log an error that occured with this style. 128 * @param e error 129 */ 123 130 public void logError(Throwable e) { 124 131 errors.add(e); 125 132 } 126 133 134 /** 135 * Log a warning that occured with this style. 136 * @param w warnings 137 */ 138 public void logWarning(String w) { 139 warnings.add(w); 140 } 141 142 /** 143 * Replies the collection of errors that occured with this style. 144 * @return collection of errors 145 */ 127 146 public Collection<Throwable> getErrors() { 128 147 return Collections.unmodifiableCollection(errors); 148 } 149 150 /** 151 * Replies the collection of warnings that occured with this style. 152 * @return collection of warnings 153 */ 154 public Collection<String> getWarnings() { 155 return Collections.unmodifiableCollection(warnings); 156 } 157 158 /** 159 * Determines if this style is valid (no error, no warning). 160 * @return {@code true} if this style has 0 errors and 0 warnings 161 */ 162 public boolean isValid() { 163 return errors.isEmpty() && warnings.isEmpty(); 129 164 } 130 165 … … 180 215 ImageProvider i = getSourceIconProvider(); 181 216 if (!getErrors().isEmpty()) { 182 i = new ImageProvider(i).addOverlay(new ImageOverlay(new ImageProvider("dialogs/mappaint/error_small"))); 217 i = new ImageProvider(i).addOverlay(new ImageOverlay(new ImageProvider("misc", "error"), 0.5, 0.5, 1, 1)); 218 } else if (!getWarnings().isEmpty()) { 219 i = new ImageProvider(i).addOverlay(new ImageOverlay(new ImageProvider("warning-small"), 0.5, 0.5, 1, 1)); 183 220 } 184 221 return i; … … 200 237 */ 201 238 public String getToolTipText() { 202 if (errors.isEmpty() )239 if (errors.isEmpty() && warnings.isEmpty()) 203 240 return null; 204 else205 206 207 errors.size(), errors.size());241 int n = errors.size() + warnings.size(); 242 return trn("There was an error when loading this style. Select ''Info'' from the right click menu for details.", 243 "There were {0} errors when loading this style. Select ''Info'' from the right click menu for details.", 244 n, n); 208 245 } 209 246 -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r9278 r9334 535 535 backgroundColorOverride = c.get("background-color", null, Color.class); 536 536 if (backgroundColorOverride != null) { 537 Main.warn(tr("Detected deprecated ''{0}'' in ''{1}'' which will be removed shortly. Use ''{2}'' instead.", 538 "canvas{background-color}", url, "fill-color")); 537 String msg = tr("Detected deprecated ''{0}'' in ''{1}'' which will be removed shortly. Use ''{2}'' instead.", 538 "canvas{background-color}", url, "fill-color"); 539 logWarning(msg); 540 Main.warn(msg); 539 541 } 540 542 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/styleelement/MapImage.java
r9278 r9334 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.mappaint.styleelement; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import java.awt.Graphics; … … 102 104 synchronized (MapImage.this) { 103 105 if (result == null) { 106 source.logWarning(tr("Failed to locate image ''{0}''", name)); 104 107 ImageIcon noIcon = MapPaintStyles.getNoIcon_Icon(source); 105 108 img = noIcon == null ? null : (BufferedImage) noIcon.getImage(); -
trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java
r9239 r9334 701 701 public String link; 702 702 public String description; 703 /** Style type: can only have one value: "xml". Used to filter out old XML styles. For MapCSS styles, the value is not set. */ 704 public String styleType; 703 705 public Integer minJosmVersion; 704 706 … … 1418 1420 } 1419 1421 } 1422 } else if ("style-type".equals(key)) { 1423 last.styleType = value; 1420 1424 } 1421 1425 } -
trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/ImageEntryTest.java
r9329 r9334 5 5 6 6 import java.io.File; 7 import java.io.IOException;8 7 9 8 import org.junit.Test; 10 9 import org.openstreetmap.josm.TestUtils; 11 import org.openstreetmap.josm.io.IllegalDataException;12 import org.xml.sax.SAXException;13 10 14 11 /** … … 19 16 /** 20 17 * Non-regression test for ticket <a href="https://josm.openstreetmap.de/ticket/12255">#12255</a>. 21 * @throws IllegalDataException if an error was found while parsing the data from the source22 * @throws IOException if any I/O error occurs23 * @throws SAXException if any XML error occurs24 18 */ 25 19 @Test 26 public void testTicket12255() throws IllegalDataException, IOException, SAXException{20 public void testTicket12255() { 27 21 ImageEntry e = new ImageEntry(new File(TestUtils.getRegressionDataFile(12255, "G0016941.JPG"))); 28 22 e.extractExif(); -
trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/MapPaintPreferenceTest.java
r9166 r9334 14 14 import org.openstreetmap.josm.JOSMFixture; 15 15 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; 16 import org.openstreetmap.josm.gui.mappaint.StyleSource; 16 17 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException; 17 18 import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry; … … 41 42 assertFalse(sources.isEmpty()); 42 43 Map<String, Collection<Throwable>> allErrors = new HashMap<>(); 44 Map<String, Collection<String>> allWarnings = new HashMap<>(); 43 45 for (ExtendedSourceEntry source : sources) { 44 System.out.println(source.url); 45 Collection<Throwable> errors = MapPaintStyles.addStyle(source); 46 System.out.println(errors.isEmpty() ? " => OK" : " => KO"); 47 if (!errors.isEmpty()) { 48 allErrors.put(source.url, errors); 46 // Do not validate XML styles 47 if (!"xml".equalsIgnoreCase(source.styleType)) { 48 System.out.println(source.url); 49 StyleSource style = MapPaintStyles.addStyle(source); 50 System.out.println(style.isValid() ? " => OK" : " => KO"); 51 Collection<Throwable> errors = style.getErrors(); 52 Collection<String> warnings = style.getWarnings(); 53 if (!errors.isEmpty()) { 54 allErrors.put(source.url, errors); 55 } 56 if (!warnings.isEmpty()) { 57 allWarnings.put(source.url, warnings); 58 } 49 59 } 50 60 } 51 assertTrue(allErrors.toString() , allErrors.isEmpty());61 assertTrue(allErrors.toString()+"\n"+allWarnings.toString(), allErrors.isEmpty() && allWarnings.isEmpty()); 52 62 } 53 63 }
Note:
See TracChangeset
for help on using the changeset viewer.