Changeset 3863 in josm


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

extended mappaint style dialog

Location:
trunk
Files:
5 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java

    r3570 r3863  
    199199            file = new File(fn);
    200200        }
    201         if(file == null || (file.exists())) {
     201        if (!confirmOverride(file))
     202            return null;
     203        return file;
     204    }
     205
     206    public static boolean confirmOverride(File file) {
     207        if (file == null || (file.exists())) {
    202208            ExtendedDialog dialog = new ExtendedDialog(
    203209                    Main.parent,
     
    208214            dialog.setButtonIcons(new String[] {"save_as.png", "cancel.png"});
    209215            dialog.showDialog();
    210             if (dialog.getValue() != 1) return null;
    211         }
    212         return file;
     216            return (dialog.getValue() == 1);
     217        }
     218        return true;
    213219    }
    214220}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java

    r3855 r3863  
    55
    66import java.awt.BorderLayout;
     7import java.awt.Component;
    78import java.awt.Dimension;
     9import java.awt.Font;
     10import java.awt.GridBagLayout;
    811import java.awt.Point;
    912import java.awt.Rectangle;
     
    1114import java.awt.event.KeyEvent;
    1215import java.awt.event.MouseEvent;
     16import java.io.BufferedInputStream;
     17import java.io.BufferedOutputStream;
     18import java.io.BufferedReader;
     19import java.io.File;
     20import java.io.FileOutputStream;
     21import java.io.InputStream;
     22import java.io.InputStreamReader;
     23import java.io.IOException;
     24import java.util.ArrayList;
     25import java.util.List;
    1326
    1427import javax.swing.AbstractAction;
    1528import javax.swing.DefaultListSelectionModel;
     29import javax.swing.JFileChooser;
     30import javax.swing.JLabel;
    1631import javax.swing.JPanel;
    1732import javax.swing.JPopupMenu;
    1833import javax.swing.JScrollPane;
     34import javax.swing.JTabbedPane;
    1935import javax.swing.JTable;
     36import javax.swing.JTextArea;
    2037import javax.swing.JViewport;
    2138import javax.swing.ListSelectionModel;
     39import javax.swing.SingleSelectionModel;
    2240import javax.swing.SwingUtilities;
    2341import javax.swing.UIManager;
     42import javax.swing.event.ChangeEvent;
     43import javax.swing.event.ChangeListener;
    2444import javax.swing.event.ListSelectionEvent;
    2545import javax.swing.event.ListSelectionListener;
    2646import javax.swing.table.AbstractTableModel;
     47import javax.swing.table.DefaultTableCellRenderer;
    2748import javax.swing.table.TableModel;
    2849
    2950import org.openstreetmap.josm.Main;
     51import org.openstreetmap.josm.actions.SaveActionBase;
     52import org.openstreetmap.josm.gui.ExtendedDialog;
     53import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    3054import org.openstreetmap.josm.gui.SideButton;
    3155import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
     
    3357import org.openstreetmap.josm.gui.mappaint.StyleSource;
    3458import org.openstreetmap.josm.gui.preferences.PreferenceDialog;
     59import org.openstreetmap.josm.gui.preferences.SourceEntry;
     60import org.openstreetmap.josm.gui.widgets.HtmlPanel;
    3561import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher;
     62import org.openstreetmap.josm.tools.GBC;
    3663import org.openstreetmap.josm.tools.ImageProvider;
    3764import org.openstreetmap.josm.tools.Shortcut;
     
    6794        tblStyles.getColumnModel().getColumn(0).setMaxWidth(1);
    6895        tblStyles.getColumnModel().getColumn(0).setResizable(false);
     96        tblStyles.getColumnModel().getColumn(1).setCellRenderer(new StyleSourceRenderer());
    6997        tblStyles.setShowGrid(false);
    7098        tblStyles.setIntercellSpacing(new Dimension(0, 0));
     
    124152    protected class StylesModel extends AbstractTableModel implements MapPaintSylesUpdateListener {
    125153
     154        List<StyleSource> data = new ArrayList<StyleSource>();
     155
     156        public StylesModel() {
     157            data = new ArrayList<StyleSource>(MapPaintStyles.getStyles().getStyleSources());
     158        }
     159
    126160        private StyleSource getRow(int i) {
    127             return MapPaintStyles.getStyles().getStyleSources().get(i);
     161            return data.get(i);
    128162        }
    129163
     
    135169        @Override
    136170        public int getRowCount() {
    137             return MapPaintStyles.getStyles().getStyleSources().size();
     171            return data.size();
    138172        }
    139173       
     
    143177                return getRow(row).active;
    144178            else
    145                 return getRow(row).getDisplayString();
     179                return getRow(row);
    146180        }
    147181
     
    171205         * views of this model.
    172206         */
    173         protected void ensureSelectedIsVisible() {
     207        public void ensureSelectedIsVisible() {
    174208            int index = selectionModel.getMinSelectionIndex();
    175209            if (index < 0) return;
     
    185219        @Override
    186220        public void mapPaintStylesUpdated() {
     221            data = new ArrayList<StyleSource>(MapPaintStyles.getStyles().getStyleSources());
    187222            fireTableDataChanged();
    188223            tblStyles.repaint();
     
    191226        @Override
    192227        public void mapPaintStyleEntryUpdated(int idx) {
     228            data = new ArrayList<StyleSource>(MapPaintStyles.getStyles().getStyleSources());
    193229            fireTableRowsUpdated(idx, idx);
    194230            tblStyles.repaint();
     231        }
     232    }
     233
     234    private static class StyleSourceRenderer extends DefaultTableCellRenderer {
     235        @Override
     236        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
     237            StyleSource s = (StyleSource) value;
     238            JLabel label = (JLabel)super.getTableCellRendererComponent(table,
     239                    s.getDisplayString(), isSelected, hasFocus, row, column);
     240            label.setIcon(s.getIcon());
     241            label.setToolTipText(s.getToolTipText());
     242            return label;
    195243        }
    196244    }
     
    227275     */
    228276    class MoveUpDownAction extends AbstractAction implements ListSelectionListener {
     277
    229278        final int increment;
     279
    230280        public MoveUpDownAction(boolean isDown) {
    231281            increment = isDown ? 1 : -1;
     
    320370    }
    321371   
     372    protected class SaveAsAction extends AbstractAction {
     373
     374        public SaveAsAction() {
     375            putValue(NAME, tr("Save as..."));
     376            putValue(SHORT_DESCRIPTION, tr("Save a copy of this Style to file and add it to the list"));
     377            putValue(SMALL_ICON, ImageProvider.get("copy"));
     378            setEnabled(tblStyles.getSelectedRows().length == 1);
     379        }
     380
     381        @Override
     382        public void actionPerformed(ActionEvent e) {
     383            int sel = tblStyles.getSelectionModel().getLeadSelectionIndex();
     384            if (sel < 0 || sel >= model.getRowCount())
     385                return;
     386            final StyleSource s = model.getRow(sel);
     387
     388            String curDir = Main.pref.get("mappaint.clone-style.lastDirectory", System.getProperty("user.home"));
     389
     390            String suggestion = curDir + File.separator + s.getFileNamePart();
     391            JFileChooser fc = new JFileChooser();
     392            fc.setSelectedFile(new File(suggestion));
     393
     394            int answer = fc.showSaveDialog(Main.parent);
     395            if (answer != JFileChooser.APPROVE_OPTION)
     396                return;
     397
     398            if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) {
     399                Main.pref.put("mappaint.clone-style.lastDirectory", fc.getCurrentDirectory().getAbsolutePath());
     400            }
     401            File file = fc.getSelectedFile();
     402
     403            if (!SaveActionBase.confirmOverride(file))
     404                return;
     405
     406            Main.worker.submit(new SaveToFileTask(s, file));
     407        }
     408
     409        private class SaveToFileTask extends PleaseWaitRunnable {
     410            private StyleSource s;
     411            private File file;
     412
     413            private boolean canceled;
     414            private boolean error;
     415
     416            public SaveToFileTask(StyleSource s, File file) {
     417                super(tr("Reloading style sources"));
     418                this.s = s;
     419                this.file = file;
     420            }
     421
     422            @Override
     423            protected void cancel() {
     424                canceled = true;
     425            }
     426
     427            @Override
     428            protected void realRun() {
     429                getProgressMonitor().indeterminateSubTask(
     430                        tr("Save style ''{0}'' as ''{1}''", s.getDisplayString(), file.getPath()));
     431                BufferedInputStream bis = null;
     432                BufferedOutputStream bos = null;
     433                try {
     434                    bis = new BufferedInputStream(s.getSourceInputStream());
     435                    bos = new BufferedOutputStream(new FileOutputStream(file));
     436                    byte[] buffer = new byte[4096];
     437                    int length;
     438                    while ((length = bis.read(buffer)) > -1 && !canceled) {
     439                        bos.write(buffer, 0, length);
     440                    }
     441                } catch (IOException e) {
     442                    error = true;
     443                } finally {
     444                    if (bis != null) {
     445                        try {
     446                            bis.close();
     447                        } catch (IOException e) {
     448                            e.printStackTrace();
     449                        }
     450                    }
     451                    if (bos != null) {
     452                        try {
     453                            bos.close();
     454                        } catch (IOException e) {
     455                            e.printStackTrace();
     456                        }
     457                    }
     458                }
     459            }
     460
     461            @Override
     462            protected void finish() {
     463                SwingUtilities.invokeLater(new Runnable() {
     464                    @Override
     465                    public void run() {
     466                        if (!error && !canceled) {
     467                            SourceEntry se = new SourceEntry(s);
     468                            se.url = file.getPath();
     469                            MapPaintStyles.addStyle(se);
     470                            tblStyles.getSelectionModel().setSelectionInterval(model.getRowCount() - 1 , model.getRowCount() - 1);
     471                            model.ensureSelectedIsVisible();
     472                        }
     473                    }
     474                });
     475            }
     476        }
     477    }
     478
     479    protected class InfoAction extends AbstractAction {
     480
     481        boolean errorsTabLoaded;
     482        boolean sourceTabLoaded;
     483
     484        public InfoAction() {
     485            putValue(NAME, tr("Info"));
     486            putValue(SHORT_DESCRIPTION, tr("view meta information, error log and source definition"));
     487            putValue(SMALL_ICON, ImageProvider.get("info"));
     488            setEnabled(tblStyles.getSelectedRows().length == 1);
     489        }
     490
     491        @Override
     492        public void actionPerformed(ActionEvent e) {
     493            int sel = tblStyles.getSelectionModel().getLeadSelectionIndex();
     494            if (sel < 0 || sel >= model.getRowCount())
     495                return;
     496            final StyleSource s = model.getRow(sel);
     497            ExtendedDialog info = new ExtendedDialog(Main.parent, tr("Map Style info"), new String[] {"Close"});
     498            info.setPreferredSize(new Dimension(600, 400));
     499            info.setButtonIcons(new String[] {"ok.png"});
     500
     501            final JTabbedPane tabs = new JTabbedPane();
     502
     503            tabs.add("Info", buildInfoPanel(s));
     504            JLabel lblInfo = new JLabel(tr("Info"));
     505            lblInfo.setFont(lblInfo.getFont().deriveFont(Font.PLAIN));
     506            tabs.setTabComponentAt(0, lblInfo);
     507
     508            final JPanel pErrors = new JPanel(new GridBagLayout());
     509            tabs.add("Errors", pErrors);
     510            JLabel lblErrors;
     511            if (s.getErrors().isEmpty()) {
     512                lblErrors = new JLabel(tr("Errors"));
     513                lblErrors.setFont(lblInfo.getFont().deriveFont(Font.PLAIN));
     514                lblErrors.setEnabled(false);
     515                tabs.setTabComponentAt(1, lblErrors);
     516                tabs.setEnabledAt(1, false);
     517            } else {
     518                lblErrors = new JLabel(tr("Errors"), ImageProvider.get("misc", "error"), JLabel.HORIZONTAL);
     519                tabs.setTabComponentAt(1, lblErrors);
     520            }
     521
     522            final JPanel pSource = new JPanel(new GridBagLayout());
     523            tabs.addTab("Source", pSource);
     524            JLabel lblSource = new JLabel(tr("Source"));
     525            lblSource.setFont(lblSource.getFont().deriveFont(Font.PLAIN));
     526            tabs.setTabComponentAt(2, lblSource);
     527
     528            tabs.getModel().addChangeListener(new ChangeListener() {
     529                @Override
     530                public void stateChanged(ChangeEvent e) {
     531                    if (!errorsTabLoaded && ((SingleSelectionModel) e.getSource()).getSelectedIndex() == 1) {
     532                        errorsTabLoaded = true;
     533                        buildErrorsPanel(s, pErrors);
     534                    }
     535                    if (!sourceTabLoaded && ((SingleSelectionModel) e.getSource()).getSelectedIndex() == 2) {
     536                        sourceTabLoaded = true;
     537                        buildSourcePanel(s, pSource);
     538                    }
     539                }
     540            });
     541            info.setContent(tabs, false);
     542            info.showDialog();
     543        }
     544
     545        private JPanel buildInfoPanel(StyleSource s) {
     546            JPanel p = new JPanel(new GridBagLayout());
     547            StringBuilder text = new StringBuilder("<table cellpadding=3><tr><td>");
     548            text.append("<b>" + tr("Name:") + "</b></td><td>" + s.getDisplayString() + "</td></tr>");
     549            text.append("<tr><td>");
     550            if (s.url.startsWith("http://")) {
     551                text.append("<b>" + tr("URL:") + "</b></td><td>" + s.url + "</td></tr>");
     552            } else if (s.url.startsWith("resource://")) {
     553                text.append("<b>" + tr("Built-in Style, internal path:</b>") + "</b></td><td>" + s.url + "</td></tr>");
     554            } else {
     555                text.append("<b>" + tr("Path:") + "</b></td><td>" + s.url + "</td></tr>");
     556            }
     557            text.append("<tr><td><b>" + tr("Style is currently active?") + "</b></td><td>" + (s.active ? tr("Yes") : tr("No")) + "</td></tr>");
     558            text.append("</table>");
     559            p.add(new JScrollPane(new HtmlPanel(text.toString())), GBC.eol().fill(GBC.BOTH));
     560            return p;
     561        }
     562
     563        private void buildSourcePanel(StyleSource s, JPanel p) {
     564            JTextArea txtSource = new JTextArea();
     565            txtSource.setFont(new Font("Monospaced", txtSource.getFont().getStyle(), txtSource.getFont().getSize()));
     566            txtSource.setEditable(false);
     567            p.add(new JScrollPane(txtSource), GBC.std().fill());
     568
     569            InputStream is = null;
     570            try {
     571                is = s.getSourceInputStream();
     572                BufferedReader reader = new BufferedReader(new InputStreamReader(is));
     573                String line;
     574                while ((line = reader.readLine()) != null) {
     575                    txtSource.append(line + "\n");
     576                }
     577            } catch (IOException ex) {
     578                txtSource.append("<ERROR: failed to read file!>");
     579            } finally {
     580                try {
     581                    is.close();
     582                } catch (IOException ex) {
     583                }
     584            }
     585        }
     586
     587        private void buildErrorsPanel(StyleSource s, JPanel p) {
     588            JTextArea txtErrors = new JTextArea();
     589            txtErrors.setFont(new Font("Monospaced", txtErrors.getFont().getStyle(), txtErrors.getFont().getSize()));
     590            txtErrors.setEditable(false);
     591            p.add(new JScrollPane(txtErrors), GBC.std().fill());
     592            for (Throwable t : s.getErrors()) {
     593                txtErrors.append(t.toString() + "\n");
     594            }
     595        }
     596    }
     597
    322598    class PopupMenuHandler extends PopupMenuLauncher {
    323599        @Override
     
    339615        public MapPaintPopup() {
    340616            add(reloadAction);
     617            add(new SaveAsAction());
     618            addSeparator();
     619            add(new InfoAction());
    341620        }
    342621    }
  • 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
  • trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java

    r3843 r3863  
    22package org.openstreetmap.josm.gui.mappaint;
    33
     4import static org.openstreetmap.josm.tools.I18n.trn;
     5
    46import java.io.File;
     7import java.io.IOException;
     8import java.io.InputStream;
     9import java.util.ArrayList;
     10import java.util.Collection;
     11import java.util.Collections;
     12import java.util.List;
     13
     14import javax.swing.ImageIcon;
    515
    616import org.openstreetmap.josm.data.osm.OsmPrimitive;
    717import org.openstreetmap.josm.gui.preferences.SourceEntry;
     18import org.openstreetmap.josm.tools.ImageProvider;
    819
    920abstract public class StyleSource extends SourceEntry {
    10     public boolean hasError = false;
     21
     22    private List<Throwable> errors = new ArrayList<Throwable>();
    1123    public File zipIcons;
    1224
     
    2234
    2335    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 ImageIcon pencil = ImageProvider.get("dialogs/mappaint", "pencil");
     52
     53    protected ImageIcon getSourceIcon() {
     54        return pencil;
     55    }
     56
     57    final public ImageIcon getIcon() {
     58        if (getErrors().isEmpty())
     59            return getSourceIcon();
     60        else
     61            return ImageProvider.overlay(getSourceIcon(),
     62                    "dialogs/mappaint/error_small",
     63                    ImageProvider.OverlayPosition.SOUTHEAST);
     64    }
     65
     66    public String getToolTipText() {
     67        if (errors.isEmpty())
     68            return null;
     69        else
     70            return trn("There was an error when loading this style. Select ''Info'' from the right click menu for details.",
     71                    "There were {0} errors when loading this style. Select ''Info'' from the right click menu for details.",
     72                    errors.size(), errors.size());
     73    }
    2474}
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java

    r3860 r3863  
    4242    public void loadStyleSource() {
    4343        rules.clear();
    44         hasError = false;
     44        clearErrors();
    4545        try {
    46             MirroredInputStream in = new MirroredInputStream(url);
    47             InputStream zip = in.getZipEntry("mapcss", "style");
    48             InputStream input;
    49             if (zip != null) {
    50                 input = zip;
    51                 zipIcons = in.getFile();
    52             } else {
    53                 input = in;
    54                 zipIcons = null;
    55             }
    56             MapCSSParser parser = new MapCSSParser(input, "UTF-8");
     46            MapCSSParser parser = new MapCSSParser(getSourceInputStream(), "UTF-8");
    5747            parser.sheet(this);
    5848            loadMeta();
     
    6050            System.err.println(tr("Warning: failed to load Mappaint styles from ''{0}''. Exception was: {1}", url, e.toString()));
    6151            e.printStackTrace();
    62             hasError = true;
     52            logError(e);
    6353        } catch (TokenMgrError e) {
    6454            System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. Error was: {1}", url, e.getMessage()));
    6555            e.printStackTrace();
    66             hasError = true;
     56            logError(e);
    6757        } catch (ParseException e) {
    6858            System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. Error was: {1}", url, e.getMessage()));
    6959            e.printStackTrace();
    70             hasError = true;
     60            logError(e);
     61        }
     62    }
     63
     64    public InputStream getSourceInputStream() throws IOException {
     65        MirroredInputStream in = new MirroredInputStream(url);
     66        InputStream zip = in.getZipEntry("mapcss", "style");
     67        if (zip != null) {
     68            zipIcons = in.getFile();
     69            return zip;
     70        } else {
     71            zipIcons = null;
     72            return in;
    7173        }
    7274    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/parser/MapCSSParser.java

    r3856 r3863  
    1717
    1818public class MapCSSParser implements MapCSSParserConstants {
     19    MapCSSStyleSource sheet;
    1920
    2021/*************
     
    171172    MapCSSRule r;
    172173    Token com = null;
     174      this.sheet = sheet;
    173175    w();
    174176    label_3:
     
    779781
    780782  void error_skipto(int kind) throws ParseException {
    781   ParseException e = generateParseException();
    782   System.err.println(e);
    783   Token t;
    784   do {
    785     t = getNextToken();
    786   } while (t.kind != kind);
     783    ParseException e = generateParseException();
     784    System.err.println(e);
     785    if (sheet != null) {
     786        sheet.logError(e);
     787    }
     788    Token t;
     789    do {
     790        t = getNextToken();
     791    } while (t.kind != kind);
    787792  }
    788793
     
    813818    catch(LookaheadSuccess ls) { return true; }
    814819    finally { jj_save(3, xla); }
     820  }
     821
     822  private boolean jj_3R_20() {
     823    if (jj_scan_token(COMMA)) return true;
     824    return false;
     825  }
     826
     827  private boolean jj_3R_16() {
     828    if (jj_scan_token(EXCLAMATION)) return true;
     829    return false;
     830  }
     831
     832  private boolean jj_3R_25() {
     833    if (jj_scan_token(STRING)) return true;
     834    return false;
     835  }
     836
     837  private boolean jj_3R_12() {
     838    Token xsp;
     839    xsp = jj_scanpos;
     840    if (jj_3R_16()) jj_scanpos = xsp;
     841    if (jj_3R_17()) return true;
     842    return false;
     843  }
     844
     845  private boolean jj_3R_14() {
     846    if (jj_3R_19()) return true;
     847    Token xsp;
     848    if (jj_3R_20()) return true;
     849    while (true) {
     850      xsp = jj_scanpos;
     851      if (jj_3R_20()) { jj_scanpos = xsp; break; }
     852    }
     853    return false;
     854  }
     855
     856  private boolean jj_3R_23() {
     857    if (jj_3R_25()) return true;
     858    return false;
     859  }
     860
     861  private boolean jj_3R_15() {
     862    if (jj_scan_token(IDENT)) return true;
     863    if (jj_3R_21()) return true;
     864    if (jj_scan_token(LPAR)) return true;
     865    return false;
     866  }
     867
     868  private boolean jj_3R_26() {
     869    if (jj_scan_token(COMMENT_START)) return true;
     870    return false;
     871  }
     872
     873  private boolean jj_3R_19() {
     874    Token xsp;
     875    xsp = jj_scanpos;
     876    if (jj_scan_token(3)) {
     877    jj_scanpos = xsp;
     878    if (jj_scan_token(2)) return true;
     879    }
     880    return false;
     881  }
     882
     883  private boolean jj_3_2() {
     884    if (jj_3R_13()) return true;
     885    return false;
     886  }
     887
     888  private boolean jj_3R_24() {
     889    Token xsp;
     890    xsp = jj_scanpos;
     891    if (jj_scan_token(7)) {
     892    jj_scanpos = xsp;
     893    if (jj_3R_26()) return true;
     894    }
     895    return false;
     896  }
     897
     898  private boolean jj_3_1() {
     899    if (jj_3R_12()) return true;
     900    if (jj_scan_token(RSQUARE)) return true;
     901    return false;
     902  }
     903
     904  private boolean jj_3R_21() {
     905    Token xsp;
     906    while (true) {
     907      xsp = jj_scanpos;
     908      if (jj_3R_24()) { jj_scanpos = xsp; break; }
     909    }
     910    return false;
     911  }
     912
     913  private boolean jj_3_3() {
     914    if (jj_3R_14()) return true;
     915    return false;
     916  }
     917
     918  private boolean jj_3_4() {
     919    if (jj_3R_15()) return true;
     920    return false;
     921  }
     922
     923  private boolean jj_3R_18() {
     924    if (jj_scan_token(EXCLAMATION_EQUAL)) return true;
     925    return false;
     926  }
     927
     928  private boolean jj_3R_17() {
     929    Token xsp;
     930    xsp = jj_scanpos;
     931    if (jj_3R_22()) {
     932    jj_scanpos = xsp;
     933    if (jj_3R_23()) return true;
     934    }
     935    return false;
     936  }
     937
     938  private boolean jj_3R_22() {
     939    if (jj_scan_token(IDENT)) return true;
     940    return false;
    815941  }
    816942
     
    824950    }
    825951    if (jj_3R_17()) return true;
    826     return false;
    827   }
    828 
    829   private boolean jj_3R_20() {
    830     if (jj_scan_token(COMMA)) return true;
    831     return false;
    832   }
    833 
    834   private boolean jj_3R_16() {
    835     if (jj_scan_token(EXCLAMATION)) return true;
    836     return false;
    837   }
    838 
    839   private boolean jj_3R_25() {
    840     if (jj_scan_token(STRING)) return true;
    841     return false;
    842   }
    843 
    844   private boolean jj_3R_12() {
    845     Token xsp;
    846     xsp = jj_scanpos;
    847     if (jj_3R_16()) jj_scanpos = xsp;
    848     if (jj_3R_17()) return true;
    849     return false;
    850   }
    851 
    852   private boolean jj_3R_14() {
    853     if (jj_3R_19()) return true;
    854     Token xsp;
    855     if (jj_3R_20()) return true;
    856     while (true) {
    857       xsp = jj_scanpos;
    858       if (jj_3R_20()) { jj_scanpos = xsp; break; }
    859     }
    860     return false;
    861   }
    862 
    863   private boolean jj_3R_23() {
    864     if (jj_3R_25()) return true;
    865     return false;
    866   }
    867 
    868   private boolean jj_3R_15() {
    869     if (jj_scan_token(IDENT)) return true;
    870     if (jj_3R_21()) return true;
    871     if (jj_scan_token(LPAR)) return true;
    872     return false;
    873   }
    874 
    875   private boolean jj_3R_26() {
    876     if (jj_scan_token(COMMENT_START)) return true;
    877     return false;
    878   }
    879 
    880   private boolean jj_3R_19() {
    881     Token xsp;
    882     xsp = jj_scanpos;
    883     if (jj_scan_token(3)) {
    884     jj_scanpos = xsp;
    885     if (jj_scan_token(2)) return true;
    886     }
    887     return false;
    888   }
    889 
    890   private boolean jj_3_2() {
    891     if (jj_3R_13()) return true;
    892     return false;
    893   }
    894 
    895   private boolean jj_3R_24() {
    896     Token xsp;
    897     xsp = jj_scanpos;
    898     if (jj_scan_token(7)) {
    899     jj_scanpos = xsp;
    900     if (jj_3R_26()) return true;
    901     }
    902     return false;
    903   }
    904 
    905   private boolean jj_3R_21() {
    906     Token xsp;
    907     while (true) {
    908       xsp = jj_scanpos;
    909       if (jj_3R_24()) { jj_scanpos = xsp; break; }
    910     }
    911     return false;
    912   }
    913 
    914   private boolean jj_3_1() {
    915     if (jj_3R_12()) return true;
    916     if (jj_scan_token(RSQUARE)) return true;
    917     return false;
    918   }
    919 
    920   private boolean jj_3_3() {
    921     if (jj_3R_14()) return true;
    922     return false;
    923   }
    924 
    925   private boolean jj_3_4() {
    926     if (jj_3R_15()) return true;
    927     return false;
    928   }
    929 
    930   private boolean jj_3R_18() {
    931     if (jj_scan_token(EXCLAMATION_EQUAL)) return true;
    932     return false;
    933   }
    934 
    935   private boolean jj_3R_17() {
    936     Token xsp;
    937     xsp = jj_scanpos;
    938     if (jj_3R_22()) {
    939     jj_scanpos = xsp;
    940     if (jj_3R_23()) return true;
    941     }
    942     return false;
    943   }
    944 
    945   private boolean jj_3R_22() {
    946     if (jj_scan_token(IDENT)) return true;
    947952    return false;
    948953  }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/parser/MapCSSParser.jj

    r3856 r3863  
    2222
    2323public class MapCSSParser {
     24    MapCSSStyleSource sheet;
    2425}
    2526PARSER_END(MapCSSParser)
     
    185186}
    186187{
     188    { this.sheet = sheet; }
    187189    w()
    188190    ( r=rule() { sheet.rules.add(r); } w() )*
     
    437439JAVACODE
    438440void error_skipto(int kind) {
    439   ParseException e = generateParseException();
    440   System.err.println(e);
    441   Token t;
    442   do {
    443     t = getNextToken();
    444   } while (t.kind != kind);
    445 }
    446 
     441    ParseException e = generateParseException();
     442    System.err.println(e);
     443    if (sheet != null) {
     444        sheet.logError(e);
     445    }
     446    Token t;
     447    do {
     448        t = getNextToken();
     449    } while (t.kind != kind);
     450}
     451
  • trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSource.java

    r3858 r3863  
    5151
    5252    protected void init() {
    53         hasError = false;
     53        clearErrors();
    5454        icons.clear();
    5555        lines.clear();
     
    6666        init();
    6767        try {
    68             MirroredInputStream in = new MirroredInputStream(url);
    69             InputStream zip = in.getZipEntry("xml", "style");
    70             InputStreamReader reader = null;
    71             if (zip != null) {
    72                 reader = new InputStreamReader(zip);
    73                 zipIcons = in.getFile();
    74             } else {
    75                 reader = new InputStreamReader(in);
    76                 zipIcons = null;
    77             }
    78 
     68            InputStreamReader reader = new InputStreamReader(getSourceInputStream());
    7969            XmlObjectParser parser = new XmlObjectParser(new XmlStyleSourceHandler(this));
    8070            parser.startWithValidation(reader,
     
    8777            System.err.println(tr("Warning: failed to load Mappaint styles from ''{0}''. Exception was: {1}", url, e.toString()));
    8878            e.printStackTrace();
    89             hasError = true;
     79            logError(e);
    9080        } catch(SAXParseException e) {
    9181            System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. Error was: [{1}:{2}] {3}", url, e.getLineNumber(), e.getColumnNumber(), e.getMessage()));
    9282            e.printStackTrace();
    93             hasError = true;
     83            logError(e);
    9484        } catch(SAXException e) {
    9585            System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. Error was: {1}", url, e.getMessage()));
    9686            e.printStackTrace();
    97             hasError = true;
     87            logError(e);
     88        }
     89    }
     90
     91    public InputStream getSourceInputStream() throws IOException {
     92        MirroredInputStream in = new MirroredInputStream(url);
     93        InputStream zip = in.getZipEntry("xml", "style");
     94        if (zip != null) {
     95            zipIcons = in.getFile();
     96            return zip;
     97        } else {
     98            zipIcons = null;
     99            return in;
    98100        }
    99101    }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSourceHandler.java

    r3856 r3863  
    7474
    7575    private void error(String message) {
    76         System.out.println(style.getDisplayString() + " (" + rule.cond.key + "=" + rule.cond.value + "): " + message);
     76        String warning = style.getDisplayString() + " (" + rule.cond.key + "=" + rule.cond.value + "): " + message;
     77        System.err.println(warning);
     78        style.logError(new Exception(warning));
    7779    }
    7880
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEntry.java

    r3855 r3863  
    8989        if (shortdescription != null)
    9090            return shortdescription;
    91         /**
    92          * extract file part from url, e.g.:
    93          * http://www.test.com/file.xml?format=text  --> file.xml
    94          */
     91        else
     92            return getFileNamePart();
     93    }
     94
     95    /**
     96     * extract file part from url, e.g.:
     97     * http://www.test.com/file.xml?format=text  --> file.xml
     98     */
     99    public String getFileNamePart() {
    95100        Pattern p = Pattern.compile("([^/\\\\]*?)([?].*)?$");
    96101        Matcher m = p.matcher(url);
Note: See TracChangeset for help on using the changeset viewer.