- Timestamp:
- 2012-08-19T02:23:40+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java
r5456 r5457 224 224 } 225 225 file = new File(fn); 226 }227 if (!confirmOverwrite(file))228 return null;226 if (!confirmOverwrite(file)) 227 return null; 228 } 229 229 return file; 230 230 } -
trunk/src/org/openstreetmap/josm/gui/dialogs/MapPaintDialog.java
r5438 r5457 529 529 if (fc == null) 530 530 return; 531 532 File file = fc.getSelectedFile(); 533 534 if (!SaveActionBase.confirmOverwrite(file)) 535 return; 536 537 Main.worker.submit(new SaveToFileTask(s, file)); 531 Main.worker.submit(new SaveToFileTask(s, fc.getSelectedFile())); 538 532 } 539 533 -
trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java
r5391 r5457 14 14 import java.awt.image.BufferedImage; 15 15 import java.awt.image.ImageObserver; 16 import java.io.Externalizable; 16 17 import java.io.File; 17 import java.io. FileInputStream;18 import java.io. FileOutputStream;19 import java.io.ObjectInput Stream;20 import java.io.ObjectOutput Stream;18 import java.io.IOException; 19 import java.io.InvalidClassException; 20 import java.io.ObjectInput; 21 import java.io.ObjectOutput; 21 22 import java.util.ArrayList; 22 23 import java.util.Collections; … … 35 36 import javax.swing.JMenuItem; 36 37 import javax.swing.JOptionPane; 37 import javax.swing.SwingUtilities;38 38 39 39 import org.openstreetmap.gui.jmapviewer.AttributionSupport; … … 62 62 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 63 63 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 64 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 64 65 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 66 import org.openstreetmap.josm.io.WMSLayerExporter; 67 import org.openstreetmap.josm.io.WMSLayerImporter; 65 68 import org.openstreetmap.josm.io.imagery.Grabber; 66 69 import org.openstreetmap.josm.io.imagery.HTMLGrabber; … … 74 77 * fetched this way is tiled and managed to the disc to reduce server load. 75 78 */ 76 public class WMSLayer extends ImageryLayer implements ImageObserver, PreferenceChangedListener {79 public class WMSLayer extends ImageryLayer implements ImageObserver, PreferenceChangedListener, Externalizable { 77 80 78 81 public static class PrecacheTask { … … 459 462 } 460 463 } 461 cache.setAreaToCache(areaToCache); 464 if (cache != null) { 465 cache.setAreaToCache(areaToCache); 466 } 462 467 } 463 468 … … 611 616 try { 612 617 613 ProjectionBounds b = getBounds(request); 614 // Checking for exact match is fast enough, no need to do it in separated thread 615 request.setHasExactMatch(cache.hasExactMatch(Main.getProjection(), request.getPixelPerDegree(), b.minEast, b.minNorth)); 616 if (request.isPrecacheOnly() && request.hasExactMatch()) 617 return; // We already have this tile cached 618 if (cache != null) { 619 ProjectionBounds b = getBounds(request); 620 // Checking for exact match is fast enough, no need to do it in separated thread 621 request.setHasExactMatch(cache.hasExactMatch(Main.getProjection(), request.getPixelPerDegree(), b.minEast, b.minNorth)); 622 if (request.isPrecacheOnly() && request.hasExactMatch()) 623 return; // We already have this tile cached 624 } 618 625 619 626 if (!requestQueue.contains(request) && !finishedRequests.contains(request) && !processingRequests.contains(request)) { … … 649 656 650 657 public class DownloadAction extends AbstractAction { 651 private static final long serialVersionUID = -7183852461015284020L;652 658 public DownloadAction() { 653 659 super(tr("Download visible tiles")); … … 776 782 public void actionPerformed(ActionEvent ev) { 777 783 File f = SaveActionBase.createAndOpenSaveFileChooser( 778 tr("Save WMS layer"), ".wms");784 tr("Save WMS layer"), WMSLayerImporter.FILE_FILTER); 779 785 try { 780 if (f != null) { 781 ObjectOutputStream oos = new ObjectOutputStream( 782 new FileOutputStream(f) 783 ); 784 oos.writeInt(serializeFormatVersion); 785 oos.writeInt(dax); 786 oos.writeInt(day); 787 oos.writeInt(imageSize); 788 oos.writeDouble(info.getPixelPerDegree()); 789 oos.writeObject(info.getName()); 790 oos.writeObject(info.getExtendedUrl()); 791 oos.writeObject(images); 792 oos.close(); 793 } 786 new WMSLayerExporter().exportData(f, WMSLayer.this); 794 787 } catch (Exception ex) { 795 788 ex.printStackTrace(System.out); … … 805 798 public void actionPerformed(ActionEvent ev) { 806 799 JFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true, 807 false, tr("Load WMS layer"), "wms");808 if (fc == null) return;800 false, tr("Load WMS layer"), WMSLayerImporter.FILE_FILTER, JFileChooser.FILES_ONLY, null); 801 if (fc == null) return; 809 802 File f = fc.getSelectedFile(); 810 803 if (f == null) return; 811 try 812 { 813 FileInputStream fis = new FileInputStream(f); 814 ObjectInputStream ois = new ObjectInputStream(fis); 815 int sfv = ois.readInt(); 816 if (sfv != serializeFormatVersion) { 817 JOptionPane.showMessageDialog(Main.parent, 818 tr("Unsupported WMS file version; found {0}, expected {1}", sfv, serializeFormatVersion), 819 tr("File Format Error"), 820 JOptionPane.ERROR_MESSAGE); 821 return; 822 } 823 autoDownloadEnabled = false; 824 dax = ois.readInt(); 825 day = ois.readInt(); 826 imageSize = ois.readInt(); 827 info.setPixelPerDegree(ois.readDouble()); 828 doSetName((String)ois.readObject()); 829 info.setExtendedUrl((String) ois.readObject()); 830 images = (GeorefImage[][])ois.readObject(); 831 ois.close(); 832 fis.close(); 833 for (GeorefImage[] imgs : images) { 834 for (GeorefImage img : imgs) { 835 if (img != null) { 836 img.setLayer(WMSLayer.this); 837 } 838 } 839 } 840 settingsChanged = true; 841 mv.repaint(); 842 if (cache != null) { 843 cache.saveIndex(); 844 cache = null; 845 } 846 if(info.getUrl() != null) 847 { 848 cache = new WmsCache(info.getUrl(), imageSize); 849 startGrabberThreads(); 850 } 851 } 852 catch (Exception ex) { 853 // FIXME be more specific 854 ex.printStackTrace(System.out); 855 JOptionPane.showMessageDialog(Main.parent, 856 tr("Error loading file"), 857 tr("Error"), 858 JOptionPane.ERROR_MESSAGE); 804 try { 805 new WMSLayerImporter(WMSLayer.this).importData(f, NullProgressMonitor.INSTANCE); 806 } catch (InvalidClassException ex) { 807 JOptionPane.showMessageDialog(Main.parent, ex.getMessage(), tr("File Format Error"), JOptionPane.ERROR_MESSAGE); 859 808 return; 860 } 861 } 862 } 809 } catch (Exception ex) { 810 ex.printStackTrace(); 811 JOptionPane.showMessageDialog(Main.parent, ex.getMessage(), tr("Error loading file"), JOptionPane.ERROR_MESSAGE); 812 return; 813 } 814 } 815 } 816 863 817 /** 864 818 * This action will add a WMS layer menu entry with the current WMS layer … … 1052 1006 } 1053 1007 1008 @Override 1009 public void writeExternal(ObjectOutput out) throws IOException { 1010 out.writeInt(serializeFormatVersion); 1011 out.writeInt(dax); 1012 out.writeInt(day); 1013 out.writeInt(imageSize); 1014 out.writeDouble(info.getPixelPerDegree()); 1015 out.writeObject(info.getName()); 1016 out.writeObject(info.getExtendedUrl()); 1017 out.writeObject(images); 1018 } 1019 1020 @Override 1021 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { 1022 int sfv = in.readInt(); 1023 if (sfv != serializeFormatVersion) { 1024 throw new InvalidClassException(tr("Unsupported WMS file version; found {0}, expected {1}", sfv, serializeFormatVersion)); 1025 } 1026 autoDownloadEnabled = false; 1027 dax = in.readInt(); 1028 day = in.readInt(); 1029 imageSize = in.readInt(); 1030 info.setPixelPerDegree(in.readDouble()); 1031 doSetName((String)in.readObject()); 1032 info.setExtendedUrl((String)in.readObject()); 1033 images = (GeorefImage[][])in.readObject(); 1034 1035 for (GeorefImage[] imgs : images) { 1036 for (GeorefImage img : imgs) { 1037 if (img != null) { 1038 img.setLayer(WMSLayer.this); 1039 } 1040 } 1041 } 1042 1043 settingsChanged = true; 1044 mv.repaint(); 1045 if (cache != null) { 1046 cache.saveIndex(); 1047 cache = null; 1048 } 1049 if (info.getUrl() != null) { 1050 cache = new WmsCache(info.getUrl(), imageSize); 1051 startGrabberThreads(); 1052 } 1053 } 1054 1054 } -
trunk/src/org/openstreetmap/josm/gui/widgets/JFileChooserManager.java
r5438 r5457 1 1 package org.openstreetmap.josm.gui.widgets; 2 3 import static org.openstreetmap.josm.tools.I18n.tr;4 2 5 3 import java.awt.Component; … … 14 12 import org.openstreetmap.josm.actions.DiskAccessAction; 15 13 import org.openstreetmap.josm.actions.ExtensionFileFilter; 16 import org.openstreetmap.josm. gui.ExtendedDialog;14 import org.openstreetmap.josm.actions.SaveActionBase; 17 15 18 16 /** … … 206 204 if (!open) { 207 205 File file = fc.getSelectedFile(); 208 if (file != null && file.exists()) { 209 ExtendedDialog dialog = new ExtendedDialog( 210 Main.parent, 211 tr("Overwrite"), 212 new String[] {tr("Overwrite"), tr("Cancel")} 213 ); 214 dialog.setContent(tr("File exists. Overwrite?")); 215 dialog.setButtonIcons(new String[] {"save_as.png", "cancel.png"}); 216 dialog.showDialog(); 217 if (dialog.getValue() != 1) { 218 return null; 219 } 206 if (!SaveActionBase.confirmOverwrite(file)) { 207 return null; 220 208 } 221 209 } -
trunk/src/org/openstreetmap/josm/io/WMSLayerExporter.java
r5361 r5457 2 2 package org.openstreetmap.josm.io; 3 3 4 import java.io.File; 5 import java.io.FileOutputStream; 6 import java.io.IOException; 7 import java.io.ObjectOutputStream; 8 9 import org.openstreetmap.josm.gui.layer.Layer; 10 import org.openstreetmap.josm.gui.layer.WMSLayer; 11 import org.openstreetmap.josm.tools.CheckParameterUtil; 12 13 /** 14 * Export a WMS layer to a serialized binary file that can be imported later via {@link WMSLayerImporter}. 15 * 16 * @since 5457 17 */ 4 18 public class WMSLayerExporter extends FileExporter { 5 19 20 /** 21 * Constructs a new {@code WMSLayerExporter} 22 */ 6 23 public WMSLayerExporter() { 7 24 super(WMSLayerImporter.FILE_FILTER); 8 25 } 26 27 @Override 28 public void exportData(File file, Layer layer) throws IOException { 29 CheckParameterUtil.ensureParameterNotNull(file, "file"); 30 CheckParameterUtil.ensureParameterNotNull(layer, "layer"); 31 if (layer instanceof WMSLayer) { 32 ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file)); 33 try { 34 ((WMSLayer)layer).writeExternal(oos); 35 } finally { 36 oos.close(); 37 } 38 } 39 } 9 40 } -
trunk/src/org/openstreetmap/josm/io/WMSLayerImporter.java
r5361 r5457 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.File; 7 import java.io.FileInputStream; 8 import java.io.IOException; 9 import java.io.ObjectInputStream; 10 6 11 import org.openstreetmap.josm.actions.ExtensionFileFilter; 12 import org.openstreetmap.josm.gui.layer.WMSLayer; 13 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 14 import org.openstreetmap.josm.tools.CheckParameterUtil; 7 15 16 /** 17 * Import a WMS layer from a serialized binary file previously exported via {@link WMSLayerExporter}. 18 * @since 5457 19 */ 8 20 public class WMSLayerImporter extends FileImporter { 9 21 22 /** 23 * The file filter used in "open" and "save" dialogs for WMS layers. 24 */ 10 25 public static final ExtensionFileFilter FILE_FILTER = new ExtensionFileFilter( 11 26 "wms", "wms", tr("WMS Files (*.wms)")); 12 27 28 private final WMSLayer wmsLayer; 29 30 /** 31 * Constructs a new {@code WMSLayerImporter}. 32 */ 13 33 public WMSLayerImporter() { 34 this(new WMSLayer()); 35 } 36 37 /** 38 * Constructs a new {@code WMSLayerImporter} that will import data to the specified WMS layer. 39 * @param wmsLayer The WMS layer. 40 */ 41 public WMSLayerImporter(WMSLayer wmsLayer) { 14 42 super(FILE_FILTER); 43 this.wmsLayer = wmsLayer; 44 } 45 46 @Override 47 public void importData(File file, ProgressMonitor progressMonitor) throws IOException, IllegalDataException { 48 CheckParameterUtil.ensureParameterNotNull(file, "file"); 49 ObjectInputStream ois = new ObjectInputStream(new FileInputStream(file)); 50 try { 51 wmsLayer.readExternal(ois); 52 } catch (ClassNotFoundException e) { 53 throw new IllegalDataException(e); 54 } finally { 55 ois.close(); 56 } 57 } 58 59 /** 60 * Replies the imported WMS layer. 61 * @return The imported WMS layer. 62 * @see #importData(File, ProgressMonitor) 63 */ 64 public final WMSLayer getWmsLayer() { 65 return wmsLayer; 15 66 } 16 67 }
Note:
See TracChangeset
for help on using the changeset viewer.