Ignore:
Timestamp:
2011-02-07T09:35:27+01:00 (15 years ago)
Author:
bastiK
Message:

extended mappaint style dialog

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r3862 r3863  
    102102
    103103        for (SourceEntry entry : sourceEntries) {
    104             StyleSource style = null;
     104            StyleSource source = fromSourceEntry(entry);
     105            if (source != null) {
     106                styles.add(source);
     107            }
     108        }
     109        for (StyleSource source : styles.getStyleSources()) {
     110            source.loadStyleSource();
     111        }
     112       
     113        fireMapPaintSylesUpdated();
     114    }
     115
     116    private static StyleSource fromSourceEntry(SourceEntry entry) {
     117        MirroredInputStream in = null;
     118        try {
     119            in = new MirroredInputStream(entry.url);
     120            InputStream zip = in.getZipEntry("xml", "style");
     121            if (zip != null) {
     122                return new XmlStyleSource(entry);
     123            }
     124            zip = in.getZipEntry("mapcss", "style");
     125            if (zip != null) {
     126                return new MapCSSStyleSource(entry);
     127            }
     128            if (entry.url.toLowerCase().endsWith(".mapcss")) {
     129                return new MapCSSStyleSource(entry);
     130            } else {
     131                return new XmlStyleSource(entry);
     132            }
     133        } catch (IOException e) {
     134            System.err.println(tr("Warning: failed to load Mappaint styles from ''{0}''. Exception was: {1}", entry.url, e.toString()));
     135            e.printStackTrace();
     136        } finally {
    105137            try {
    106                 MirroredInputStream in = new MirroredInputStream(entry.url);
    107                 InputStream zip = in.getZipEntry("xml","style");
    108                 if (zip != null) {
    109                     style = new XmlStyleSource(entry);
    110                     styles.add(style);
    111                     continue;
    112                 }
    113                 zip = in.getZipEntry("mapcss","style");
    114                 if (zip != null) {
    115                     style = new MapCSSStyleSource(entry);
    116                     styles.add(style);
    117                     continue;
    118                 }
    119                 if (entry.url.toLowerCase().endsWith(".mapcss")) {
    120                     style = new MapCSSStyleSource(entry);
    121                 } else {
    122                     style = new XmlStyleSource(entry);
    123                 }
    124             } catch(IOException e) {
    125                 System.err.println(tr("Warning: failed to load Mappaint styles from ''{0}''. Exception was: {1}", entry.url, e.toString()));
    126                 e.printStackTrace();
    127                 if (style != null) {
    128                     style.hasError = true;
    129                 }
    130             }
    131             if (style != null) {
    132                 styles.add(style);
    133             }
    134         }
    135         for (StyleSource s : styles.getStyleSources()) {
    136             s.loadStyleSource();
    137         }
    138         fireMapPaintSylesUpdated();
     138                in.close();
     139            } catch (IOException ex) {
     140            }
     141        }
     142        return null;
    139143    }
    140144
     
    250254    }
    251255
     256    public static void addStyle(SourceEntry entry) {
     257        StyleSource source = fromSourceEntry(entry);
     258        if (source != null) {
     259            styles.add(source);
     260            source.loadStyleSource();
     261            MapPaintPrefMigration.INSTANCE.put(styles.getStyleSources());
     262            fireMapPaintSylesUpdated();
     263            styles.clearCached();
     264            Main.map.mapView.repaint();
     265        }
     266    }
     267
    252268    /***********************************
    253269     * MapPaintSylesUpdateListener & related code
Note: See TracChangeset for help on using the changeset viewer.