- Timestamp:
- 2011-02-07T09:35:27+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java
r3570 r3863 199 199 file = new File(fn); 200 200 } 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())) { 202 208 ExtendedDialog dialog = new ExtendedDialog( 203 209 Main.parent, … … 208 214 dialog.setButtonIcons(new String[] {"save_as.png", "cancel.png"}); 209 215 dialog.showDialog(); 210 if(dialog.getValue()!= 1) return null;211 } 212 return file;216 return (dialog.getValue() == 1); 217 } 218 return true; 213 219 } 214 220 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
r3855 r3863 5 5 6 6 import java.awt.BorderLayout; 7 import java.awt.Component; 7 8 import java.awt.Dimension; 9 import java.awt.Font; 10 import java.awt.GridBagLayout; 8 11 import java.awt.Point; 9 12 import java.awt.Rectangle; … … 11 14 import java.awt.event.KeyEvent; 12 15 import java.awt.event.MouseEvent; 16 import java.io.BufferedInputStream; 17 import java.io.BufferedOutputStream; 18 import java.io.BufferedReader; 19 import java.io.File; 20 import java.io.FileOutputStream; 21 import java.io.InputStream; 22 import java.io.InputStreamReader; 23 import java.io.IOException; 24 import java.util.ArrayList; 25 import java.util.List; 13 26 14 27 import javax.swing.AbstractAction; 15 28 import javax.swing.DefaultListSelectionModel; 29 import javax.swing.JFileChooser; 30 import javax.swing.JLabel; 16 31 import javax.swing.JPanel; 17 32 import javax.swing.JPopupMenu; 18 33 import javax.swing.JScrollPane; 34 import javax.swing.JTabbedPane; 19 35 import javax.swing.JTable; 36 import javax.swing.JTextArea; 20 37 import javax.swing.JViewport; 21 38 import javax.swing.ListSelectionModel; 39 import javax.swing.SingleSelectionModel; 22 40 import javax.swing.SwingUtilities; 23 41 import javax.swing.UIManager; 42 import javax.swing.event.ChangeEvent; 43 import javax.swing.event.ChangeListener; 24 44 import javax.swing.event.ListSelectionEvent; 25 45 import javax.swing.event.ListSelectionListener; 26 46 import javax.swing.table.AbstractTableModel; 47 import javax.swing.table.DefaultTableCellRenderer; 27 48 import javax.swing.table.TableModel; 28 49 29 50 import org.openstreetmap.josm.Main; 51 import org.openstreetmap.josm.actions.SaveActionBase; 52 import org.openstreetmap.josm.gui.ExtendedDialog; 53 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 30 54 import org.openstreetmap.josm.gui.SideButton; 31 55 import org.openstreetmap.josm.gui.mappaint.MapPaintStyles; … … 33 57 import org.openstreetmap.josm.gui.mappaint.StyleSource; 34 58 import org.openstreetmap.josm.gui.preferences.PreferenceDialog; 59 import org.openstreetmap.josm.gui.preferences.SourceEntry; 60 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 35 61 import org.openstreetmap.josm.gui.widgets.PopupMenuLauncher; 62 import org.openstreetmap.josm.tools.GBC; 36 63 import org.openstreetmap.josm.tools.ImageProvider; 37 64 import org.openstreetmap.josm.tools.Shortcut; … … 67 94 tblStyles.getColumnModel().getColumn(0).setMaxWidth(1); 68 95 tblStyles.getColumnModel().getColumn(0).setResizable(false); 96 tblStyles.getColumnModel().getColumn(1).setCellRenderer(new StyleSourceRenderer()); 69 97 tblStyles.setShowGrid(false); 70 98 tblStyles.setIntercellSpacing(new Dimension(0, 0)); … … 124 152 protected class StylesModel extends AbstractTableModel implements MapPaintSylesUpdateListener { 125 153 154 List<StyleSource> data = new ArrayList<StyleSource>(); 155 156 public StylesModel() { 157 data = new ArrayList<StyleSource>(MapPaintStyles.getStyles().getStyleSources()); 158 } 159 126 160 private StyleSource getRow(int i) { 127 return MapPaintStyles.getStyles().getStyleSources().get(i);161 return data.get(i); 128 162 } 129 163 … … 135 169 @Override 136 170 public int getRowCount() { 137 return MapPaintStyles.getStyles().getStyleSources().size();171 return data.size(); 138 172 } 139 173 … … 143 177 return getRow(row).active; 144 178 else 145 return getRow(row) .getDisplayString();179 return getRow(row); 146 180 } 147 181 … … 171 205 * views of this model. 172 206 */ 173 p rotectedvoid ensureSelectedIsVisible() {207 public void ensureSelectedIsVisible() { 174 208 int index = selectionModel.getMinSelectionIndex(); 175 209 if (index < 0) return; … … 185 219 @Override 186 220 public void mapPaintStylesUpdated() { 221 data = new ArrayList<StyleSource>(MapPaintStyles.getStyles().getStyleSources()); 187 222 fireTableDataChanged(); 188 223 tblStyles.repaint(); … … 191 226 @Override 192 227 public void mapPaintStyleEntryUpdated(int idx) { 228 data = new ArrayList<StyleSource>(MapPaintStyles.getStyles().getStyleSources()); 193 229 fireTableRowsUpdated(idx, idx); 194 230 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; 195 243 } 196 244 } … … 227 275 */ 228 276 class MoveUpDownAction extends AbstractAction implements ListSelectionListener { 277 229 278 final int increment; 279 230 280 public MoveUpDownAction(boolean isDown) { 231 281 increment = isDown ? 1 : -1; … … 320 370 } 321 371 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 322 598 class PopupMenuHandler extends PopupMenuLauncher { 323 599 @Override … … 339 615 public MapPaintPopup() { 340 616 add(reloadAction); 617 add(new SaveAsAction()); 618 addSeparator(); 619 add(new InfoAction()); 341 620 } 342 621 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r3862 r3863 102 102 103 103 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 { 105 137 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; 139 143 } 140 144 … … 250 254 } 251 255 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 252 268 /*********************************** 253 269 * MapPaintSylesUpdateListener & related code -
trunk/src/org/openstreetmap/josm/gui/mappaint/StyleSource.java
r3843 r3863 2 2 package org.openstreetmap.josm.gui.mappaint; 3 3 4 import static org.openstreetmap.josm.tools.I18n.trn; 5 4 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; 5 15 6 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 7 17 import org.openstreetmap.josm.gui.preferences.SourceEntry; 18 import org.openstreetmap.josm.tools.ImageProvider; 8 19 9 20 abstract public class StyleSource extends SourceEntry { 10 public boolean hasError = false; 21 22 private List<Throwable> errors = new ArrayList<Throwable>(); 11 23 public File zipIcons; 12 24 … … 22 34 23 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 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 } 24 74 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r3860 r3863 42 42 public void loadStyleSource() { 43 43 rules.clear(); 44 hasError = false;44 clearErrors(); 45 45 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"); 57 47 parser.sheet(this); 58 48 loadMeta(); … … 60 50 System.err.println(tr("Warning: failed to load Mappaint styles from ''{0}''. Exception was: {1}", url, e.toString())); 61 51 e.printStackTrace(); 62 hasError = true;52 logError(e); 63 53 } catch (TokenMgrError e) { 64 54 System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. Error was: {1}", url, e.getMessage())); 65 55 e.printStackTrace(); 66 hasError = true;56 logError(e); 67 57 } catch (ParseException e) { 68 58 System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. Error was: {1}", url, e.getMessage())); 69 59 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; 71 73 } 72 74 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/parser/MapCSSParser.java
r3856 r3863 17 17 18 18 public class MapCSSParser implements MapCSSParserConstants { 19 MapCSSStyleSource sheet; 19 20 20 21 /************* … … 171 172 MapCSSRule r; 172 173 Token com = null; 174 this.sheet = sheet; 173 175 w(); 174 176 label_3: … … 779 781 780 782 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); 787 792 } 788 793 … … 813 818 catch(LookaheadSuccess ls) { return true; } 814 819 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; 815 941 } 816 942 … … 824 950 } 825 951 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;947 952 return false; 948 953 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/parser/MapCSSParser.jj
r3856 r3863 22 22 23 23 public class MapCSSParser { 24 MapCSSStyleSource sheet; 24 25 } 25 26 PARSER_END(MapCSSParser) … … 185 186 } 186 187 { 188 { this.sheet = sheet; } 187 189 w() 188 190 ( r=rule() { sheet.rules.add(r); } w() )* … … 437 439 JAVACODE 438 440 void 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 51 51 52 52 protected void init() { 53 hasError = false;53 clearErrors(); 54 54 icons.clear(); 55 55 lines.clear(); … … 66 66 init(); 67 67 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()); 79 69 XmlObjectParser parser = new XmlObjectParser(new XmlStyleSourceHandler(this)); 80 70 parser.startWithValidation(reader, … … 87 77 System.err.println(tr("Warning: failed to load Mappaint styles from ''{0}''. Exception was: {1}", url, e.toString())); 88 78 e.printStackTrace(); 89 hasError = true;79 logError(e); 90 80 } catch(SAXParseException e) { 91 81 System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. Error was: [{1}:{2}] {3}", url, e.getLineNumber(), e.getColumnNumber(), e.getMessage())); 92 82 e.printStackTrace(); 93 hasError = true;83 logError(e); 94 84 } catch(SAXException e) { 95 85 System.err.println(tr("Warning: failed to parse Mappaint styles from ''{0}''. Error was: {1}", url, e.getMessage())); 96 86 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; 98 100 } 99 101 } -
trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSourceHandler.java
r3856 r3863 74 74 75 75 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)); 77 79 } 78 80 -
trunk/src/org/openstreetmap/josm/gui/preferences/SourceEntry.java
r3855 r3863 89 89 if (shortdescription != null) 90 90 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() { 95 100 Pattern p = Pattern.compile("([^/\\\\]*?)([?].*)?$"); 96 101 Matcher m = p.matcher(url);
Note:
See TracChangeset
for help on using the changeset viewer.