| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.gui.mappaint;
|
|---|
| 3 |
|
|---|
| 4 | import static org.openstreetmap.josm.tools.I18n.trn;
|
|---|
| 5 |
|
|---|
| 6 | import java.io.File;
|
|---|
| 7 | import java.io.IOException;
|
|---|
| 8 | import java.io.InputStream;
|
|---|
| 9 | import java.util.ArrayList;
|
|---|
| 10 | import java.util.Collection;
|
|---|
| 11 | import java.util.Collections;
|
|---|
| 12 | import java.util.List;
|
|---|
| 13 |
|
|---|
| 14 | import javax.swing.ImageIcon;
|
|---|
| 15 |
|
|---|
| 16 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
|---|
| 17 | import org.openstreetmap.josm.gui.preferences.SourceEntry;
|
|---|
| 18 | import org.openstreetmap.josm.tools.ImageProvider;
|
|---|
| 19 |
|
|---|
| 20 | abstract public class StyleSource extends SourceEntry {
|
|---|
| 21 |
|
|---|
| 22 | private List<Throwable> errors = new ArrayList<Throwable>();
|
|---|
| 23 | public File zipIcons;
|
|---|
| 24 |
|
|---|
| 25 | public StyleSource(String url, String name, String shortdescription) {
|
|---|
| 26 | super(url, name, shortdescription, true);
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | public StyleSource(SourceEntry entry) {
|
|---|
| 30 | super(entry.url, entry.name, entry.shortdescription, entry.active);
|
|---|
| 31 | }
|
|---|
| 32 |
|
|---|
| 33 | abstract public void apply(MultiCascade mc, OsmPrimitive osm, double scale, OsmPrimitive multipolyOuterWay, boolean pretendWayIsClosed);
|
|---|
| 34 |
|
|---|
| 35 | abstract public void loadStyleSource();
|
|---|
| 36 |
|
|---|
| 37 | abstract public InputStream getSourceInputStream() throws IOException;
|
|---|
| 38 |
|
|---|
| 39 | public void logError(Throwable e) {
|
|---|
| 40 | errors.add(e);
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | public Collection<Throwable> getErrors() {
|
|---|
| 44 | return Collections.unmodifiableCollection(errors);
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | protected void clearErrors() {
|
|---|
| 48 | errors.clear();
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | private static ImageIcon pencil;
|
|---|
| 52 |
|
|---|
| 53 | protected ImageIcon getSourceIcon() {
|
|---|
| 54 | if (pencil == null) {
|
|---|
| 55 | pencil = ImageProvider.get("dialogs/mappaint", "pencil");
|
|---|
| 56 | }
|
|---|
| 57 | return pencil;
|
|---|
| 58 | }
|
|---|
| 59 |
|
|---|
| 60 | final public ImageIcon getIcon() {
|
|---|
| 61 | if (getErrors().isEmpty())
|
|---|
| 62 | return getSourceIcon();
|
|---|
| 63 | else
|
|---|
| 64 | return ImageProvider.overlay(getSourceIcon(),
|
|---|
| 65 | "dialogs/mappaint/error_small",
|
|---|
| 66 | ImageProvider.OverlayPosition.SOUTHEAST);
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | public String getToolTipText() {
|
|---|
| 70 | if (errors.isEmpty())
|
|---|
| 71 | return null;
|
|---|
| 72 | else
|
|---|
| 73 | return trn("There was an error when loading this style. Select ''Info'' from the right click menu for details.",
|
|---|
| 74 | "There were {0} errors when loading this style. Select ''Info'' from the right click menu for details.",
|
|---|
| 75 | errors.size(), errors.size());
|
|---|
| 76 | }
|
|---|
| 77 | }
|
|---|