Changeset 5459 in josm for trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java
- Timestamp:
- 2012-08-20T01:11:45+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/WMSLayer.java
r5457 r5459 33 33 import javax.swing.Action; 34 34 import javax.swing.JCheckBoxMenuItem; 35 import javax.swing.JFileChooser;36 35 import javax.swing.JMenuItem; 37 36 import javax.swing.JOptionPane; … … 39 38 import org.openstreetmap.gui.jmapviewer.AttributionSupport; 40 39 import org.openstreetmap.josm.Main; 41 import org.openstreetmap.josm.actions.DiskAccessAction;42 40 import org.openstreetmap.josm.actions.SaveActionBase; 43 41 import org.openstreetmap.josm.data.Bounds; … … 62 60 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 63 61 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 64 import org.openstreetmap.josm.gui.progress.NullProgressMonitor;65 62 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 66 import org.openstreetmap.josm.io.WMSLayerExporter;67 63 import org.openstreetmap.josm.io.WMSLayerImporter; 68 64 import org.openstreetmap.josm.io.imagery.Grabber; … … 70 66 import org.openstreetmap.josm.io.imagery.WMSGrabber; 71 67 import org.openstreetmap.josm.io.imagery.WMSRequest; 72 import org.openstreetmap.josm.tools.ImageProvider;73 68 74 69 … … 124 119 protected boolean settingsChanged; 125 120 protected ImageryInfo info; 126 protected MapView mv;127 121 public WmsCache cache; 128 122 private AttributionSupport attribution = new AttributionSupport(); … … 178 172 @Override 179 173 public void hookUpMapView() { 180 mv = Main.map.mapView;181 174 if (info.getUrl() != null) { 182 175 for (WMSLayer layer: Main.map.mapView.getLayersOfType(WMSLayer.class)) { … … 194 187 this.info.setPixelPerDegree(getPPD()); 195 188 } 196 resolution = mv.getDist100PixelText();189 resolution = Main.map.mapView.getDist100PixelText(); 197 190 198 191 final MouseAdapter adapter = new MouseAdapter() { … … 484 477 SeparatorLayerAction.INSTANCE, 485 478 new OffsetAction(), 486 new L oadWmsAction(),487 new SaveWmsAction(),479 new LayerSaveAction(this), 480 new LayerSaveAsAction(this), 488 481 new BookmarkWmsAction(), 489 482 SeparatorLayerAction.INSTANCE, … … 523 516 return -1; 524 517 525 EastNorth cursorEastNorth = mv.getEastNorth(mv.lastMEvent.getX(), mv.lastMEvent.getY()); 518 MouseEvent lastMEvent = Main.map.mapView.lastMEvent; 519 EastNorth cursorEastNorth = Main.map.mapView.getEastNorth(lastMEvent.getX(), lastMEvent.getY()); 526 520 int mouseX = getImageXIndex(cursorEastNorth.east()); 527 521 int mouseY = getImageYIndex(cursorEastNorth.north()); … … 605 599 if (request.getState() != null && !request.isPrecacheOnly()) { 606 600 finishedRequests.add(request); 607 mv.repaint();601 Main.map.mapView.repaint(); 608 602 } 609 603 } finally { … … 669 663 ); 670 664 } else { 671 downloadAndPaintVisible( mv.getGraphics(), mv, true);665 downloadAndPaintVisible(Main.map.mapView.getGraphics(), Main.map.mapView, true); 672 666 } 673 667 } … … 680 674 681 675 private void changeResolution(WMSLayer layer) { 682 layer.resolution = layer.mv.getDist100PixelText();676 layer.resolution = Main.map.mapView.getDist100PixelText(); 683 677 layer.info.setPixelPerDegree(layer.getPPD()); 684 678 layer.settingsChanged = true; … … 761 755 } 762 756 } 763 mv.repaint();757 Main.map.mapView.repaint(); 764 758 } 765 759 @Override … … 775 769 } 776 770 777 public class SaveWmsAction extends AbstractAction {778 public SaveWmsAction() {779 super(tr("Save WMS layer to file"), ImageProvider.get("save"));780 }781 @Override782 public void actionPerformed(ActionEvent ev) {783 File f = SaveActionBase.createAndOpenSaveFileChooser(784 tr("Save WMS layer"), WMSLayerImporter.FILE_FILTER);785 try {786 new WMSLayerExporter().exportData(f, WMSLayer.this);787 } catch (Exception ex) {788 ex.printStackTrace(System.out);789 }790 }791 }792 793 public class LoadWmsAction extends AbstractAction {794 public LoadWmsAction() {795 super(tr("Load WMS layer from file"), ImageProvider.get("open"));796 }797 @Override798 public void actionPerformed(ActionEvent ev) {799 JFileChooser fc = DiskAccessAction.createAndOpenFileChooser(true,800 false, tr("Load WMS layer"), WMSLayerImporter.FILE_FILTER, JFileChooser.FILES_ONLY, null);801 if (fc == null) return;802 File f = fc.getSelectedFile();803 if (f == null) return;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);808 return;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 817 771 /** 818 772 * This action will add a WMS layer menu entry with the current WMS layer … … 860 814 } 861 815 } 862 mv.repaint();816 Main.map.mapView.repaint(); 863 817 } 864 818 } … … 952 906 } 953 907 954 protected Grabber getGrabber(boolean localOnly) {955 if (getInfo().getImageryType() == ImageryType.HTML)956 return new HTMLGrabber( mv, this, localOnly);957 else if (getInfo().getImageryType() == ImageryType.WMS)958 return new WMSGrabber( mv, this, localOnly);908 protected Grabber getGrabber(boolean localOnly) { 909 if (getInfo().getImageryType() == ImageryType.HTML) 910 return new HTMLGrabber(Main.map.mapView, this, localOnly); 911 else if (getInfo().getImageryType() == ImageryType.WMS) 912 return new WMSGrabber(Main.map.mapView, this, localOnly); 959 913 else throw new IllegalStateException("getGrabber() called for non-WMS layer type"); 960 914 } … … 1042 996 1043 997 settingsChanged = true; 1044 mv.repaint(); 998 if (Main.isDisplayingMapView()) { 999 Main.map.mapView.repaint(); 1000 } 1045 1001 if (cache != null) { 1046 1002 cache.saveIndex(); 1047 1003 cache = null; 1048 1004 } 1005 } 1006 1007 @Override 1008 public void onPostLoadFromFile() { 1049 1009 if (info.getUrl() != null) { 1050 1010 cache = new WmsCache(info.getUrl(), imageSize); … … 1052 1012 } 1053 1013 } 1014 1015 @Override 1016 public boolean isSavable() { 1017 return true; // With WMSLayerExporter 1018 } 1019 1020 @Override 1021 public File createAndOpenSaveFileChooser() { 1022 return SaveActionBase.createAndOpenSaveFileChooser(tr("Save WMS file"), WMSLayerImporter.FILE_FILTER); 1023 } 1054 1024 }
Note:
See TracChangeset
for help on using the changeset viewer.