Changeset 5319 in osm for applications/editors/josm/plugins/wmsplugin/src
- Timestamp:
- 2007-11-05T02:51:55+01:00 (17 years ago)
- Location:
- applications/editors/josm/plugins/wmsplugin/src/wmsplugin
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/DownloadWMSTask.java
r5114 r5319 21 21 22 22 public DownloadWMSTask(String name, String wmsurl) { 23 24 23 super(tr("Downloading " + name)); 25 24 26 25 // simply check if we already have a layer created. if not, create; if yes, reuse. 27 28 26 if (wmsLayer == null) { 29 30 27 if (wmsurl.matches("(?i).*layers=npeoocmap.*") || wmsurl.matches("(?i).*layers=npe.*") ){ 31 28 //then we use the OSGBLayer 32 29 this.wmsLayer= new OSGBLayer(name, wmsurl); 33 } else { 30 } else { 34 31 this.wmsLayer = new WMSLayer(name, wmsurl); 35 36 32 } 37 33 } 34 38 35 } 39 36 … … 50 47 layerAdded = false; 51 48 for (Iterator it = Main.map.mapView.getAllLayers().iterator(); it.hasNext(); ) { 52 Object element = it.next(); 53 54 if (element.equals(wmsLayer)) layerAdded = true; 55 49 Object element = it.next(); 50 if (element.equals(wmsLayer)) layerAdded = true; 56 51 } 57 58 52 59 53 if ((wmsLayer != null) && (!layerAdded)) -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSDownloadAction.java
r2121 r5319 21 21 // download task here every time, then different layers are displayed even 22 22 // for images from the same server, and we don't want that. 23 23 System.out.println(info.url); 24 24 if (info.downloadTask == null) 25 25 info.downloadTask = new DownloadWMSTask(info.name, info.url); -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSImage.java
r5245 r5319 4 4 import java.awt.Image; 5 5 import java.awt.Point; 6 import java.awt.image.BufferedImage; 7 import java.awt.image.RenderedImage; 8 import java.io.Externalizable; 6 9 import java.io.IOException; 7 10 import java.io.InputStream; 11 import java.io.ObjectInput; 12 import java.io.ObjectInputStream; 13 import java.io.ObjectOutput; 14 import java.io.ObjectOutputStream; 15 import java.io.OutputStream; 16 import java.io.Serializable; 8 17 import java.net.MalformedURLException; 9 18 import java.net.URL; 10 19 11 20 import javax.imageio.ImageIO; 21 import javax.swing.ImageIcon; 12 22 13 23 import org.openstreetmap.josm.Main; … … 17 27 import org.openstreetmap.josm.io.ProgressInputStream; 18 28 19 public class WMSImage 29 public class WMSImage implements Serializable 20 30 { 21 31 String constURL; 22 protected Image theImage;32 protected BufferedImage theImage; 23 33 protected double grabbedScale; 24 34 protected EastNorth topLeft, bottomRight; … … 29 39 this.constURL = constURL; 30 40 } 41 42 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { 43 constURL = (String) in.readObject(); 44 topLeft = (EastNorth) in.readObject(); 45 bottomRight = (EastNorth) in.readObject(); 46 dEast = in.readDouble(); 47 dNorth = in.readDouble(); 48 grabbedScale = in.readDouble(); 49 theImage = (BufferedImage) ImageIO.read(ImageIO.createImageInputStream(in)); 50 } 51 52 private void writeObject(ObjectOutputStream out) throws IOException { 53 System.out.println("writ" + theImage.getWidth(null)); 54 out.writeObject(constURL); 55 out.writeObject(topLeft); 56 out.writeObject(bottomRight); 57 out.writeDouble(dEast); 58 out.writeDouble(dNorth); 59 out.writeDouble(grabbedScale); 60 ImageIO.write(theImage, "png", ImageIO.createImageOutputStream(out)); 61 } 31 62 32 63 public void grab(NavigatableComponent nc) throws IOException 33 64 { 34 35 EastNorth topLeft = nc.getEastNorth(0,0); 36 grabbedScale = nc.getScale(); // scale is enPerPixel 65 EastNorth topLeft = nc.getEastNorth(0,0); 66 grabbedScale = nc.getScale(); // scale is enPerPixel 37 67 38 68 this.topLeft = topLeft; … … 101 131 InputStream is = new ProgressInputStream( 102 132 url.openConnection(), Main.pleaseWaitDlg); 103 theImage = ImageIO.read(is) 133 theImage = ImageIO.read(is); 104 134 is.close(); 105 135 Main.map.repaint(); … … 126 156 public void paint(Graphics g,NavigatableComponent nc) 127 157 { 128 if (theImage!=null)158 if (theImage != null) 129 159 { 130 160 double zoomInFactor = grabbedScale / nc.getScale(); -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSLayer.java
r2121 r5319 6 6 import java.awt.Graphics; 7 7 import java.awt.Toolkit; 8 import java.awt.event.ActionEvent; 9 import java.io.File; 10 import java.io.FileInputStream; 11 import java.io.FileOutputStream; 8 12 import java.io.IOException; 13 import java.io.ObjectInputStream; 14 import java.io.ObjectOutputStream; 9 15 import java.util.ArrayList; 10 16 17 import javax.swing.AbstractAction; 11 18 import javax.swing.Icon; 12 19 import javax.swing.ImageIcon; 20 import javax.swing.JFileChooser; 13 21 import javax.swing.JMenuItem; 22 import javax.swing.JOptionPane; 14 23 import javax.swing.JSeparator; 24 import javax.swing.filechooser.FileFilter; 15 25 16 26 import org.openstreetmap.josm.Main; 27 import org.openstreetmap.josm.actions.ExtensionFileFilter; 28 import org.openstreetmap.josm.actions.SaveActionBase; 17 29 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 18 30 import org.openstreetmap.josm.data.projection.Projection; … … 21 33 import org.openstreetmap.josm.gui.dialogs.LayerListPopup; 22 34 import org.openstreetmap.josm.gui.layer.Layer; 35 import org.openstreetmap.josm.tools.ImageProvider; 23 36 import org.openstreetmap.josm.data.coor.EastNorth; 24 37 … … 29 42 public class WMSLayer extends Layer { 30 43 31 protected static Icon icon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(WMSPlugin.class.getResource("/images/wms.png"))); 32 44 protected static Icon icon = new ImageIcon(Toolkit.getDefaultToolkit().createImage(WMSPlugin.class.getResource("/images/wms_small.png"))); 33 45 protected final ArrayList<WMSImage> wmsImages; 34 35 46 protected final String url; 36 47 protected final int serializeFormatVersion = 1; 48 49 public WMSLayer() { 50 super("Blank Layer"); 51 wmsImages = new ArrayList<WMSImage>(); 52 url = ""; 53 } 37 54 public WMSLayer(String name, String url) { 38 55 super(name); … … 100 117 return new Component[]{ 101 118 new JMenuItem(new LayerListDialog.ShowHideLayerAction(this)), 102 new JMenuItem(new LayerListDialog.DeleteLayerAction(this)), 119 new JMenuItem(new LayerListDialog.DeleteLayerAction(this)), 120 new JMenuItem(new LoadWmsAction()), 121 new JMenuItem(new SaveWmsAction()), 103 122 new JSeparator(), 104 123 new JMenuItem(new LayerListPopup.InfoAction(this))}; … … 117 136 //to enable the removal of the images when the layer is removed. 118 137 public void destroy() { 119 120 138 wmsImages.clear(); 139 } 140 141 public class SaveWmsAction extends AbstractAction { 142 public SaveWmsAction() { 143 super(tr("Save WMS layer to file"), ImageProvider.get("save")); 144 } 145 public void actionPerformed(ActionEvent ev) { 146 File f = openFileDialog(false); 147 try { 148 FileOutputStream fos = new FileOutputStream(f); 149 ObjectOutputStream oos = new ObjectOutputStream(fos); 150 oos.writeInt(serializeFormatVersion); 151 oos.writeInt(wmsImages.size()); 152 for (WMSImage w : wmsImages) { 153 oos.writeObject(w); 154 } 155 oos.close(); 156 fos.close(); 157 } catch (Exception ex) { 158 ex.printStackTrace(System.out); 159 } 160 } 161 } 162 163 public class LoadWmsAction extends AbstractAction { 164 public LoadWmsAction() { 165 super(tr("Load WMS layer from file"), ImageProvider.get("load")); 166 } 167 public void actionPerformed(ActionEvent ev) { 168 File f = openFileDialog(true); 169 try { 170 FileInputStream fis = new FileInputStream(f); 171 ObjectInputStream ois = new ObjectInputStream(fis); 172 int sfv = ois.readInt(); 173 if (sfv != serializeFormatVersion) { 174 JOptionPane.showMessageDialog(Main.parent, 175 tr("Unsupported WMS file version; found {0}, expected {1}", sfv, serializeFormatVersion), 176 tr("File Format Error"), 177 JOptionPane.ERROR_MESSAGE); 178 return; 179 } 180 int numImg = ois.readInt(); 181 for (int i=0; i< numImg; i++) { 182 WMSImage img = (WMSImage) ois.readObject(); 183 wmsImages.add(img); 184 } 185 ois.close(); 186 fis.close(); 187 } catch (Exception ex) { 188 // FIXME be more specific 189 ex.printStackTrace(System.out); 190 JOptionPane.showMessageDialog(Main.parent, 191 tr("Error loading file"), 192 tr("Error"), 193 JOptionPane.ERROR_MESSAGE); 194 return; 195 } 196 } 197 } 198 199 protected static JFileChooser createAndOpenFileChooser(boolean open, boolean multiple) { 200 String curDir = Main.pref.get("lastDirectory"); 201 if (curDir.equals("")) 202 curDir = "."; 203 JFileChooser fc = new JFileChooser(new File(curDir)); 204 fc.setMultiSelectionEnabled(multiple); 205 for (int i = 0; i < ExtensionFileFilter.filters.length; ++i) 206 fc.addChoosableFileFilter(ExtensionFileFilter.filters[i]); 207 fc.setAcceptAllFileFilterUsed(true); 208 209 int answer = open ? fc.showOpenDialog(Main.parent) : fc.showSaveDialog(Main.parent); 210 if (answer != JFileChooser.APPROVE_OPTION) 211 return null; 121 212 213 if (!fc.getCurrentDirectory().getAbsolutePath().equals(curDir)) 214 Main.pref.put("lastDirectory", fc.getCurrentDirectory().getAbsolutePath()); 215 216 if (!open) { 217 File file = fc.getSelectedFile(); 218 if (file == null || (file.exists() && JOptionPane.YES_OPTION != 219 JOptionPane.showConfirmDialog(Main.parent, tr("File exists. Overwrite?"), tr("Overwrite"), JOptionPane.YES_NO_OPTION))) 220 return null; 221 } 122 222 223 return fc; 224 } 225 226 public static File openFileDialog(boolean open) { 227 JFileChooser fc = createAndOpenFileChooser(open, false); 228 if (fc == null) 229 return null; 230 231 File file = fc.getSelectedFile(); 232 233 String fn = file.getPath(); 234 if (fn.indexOf('.') == -1) { 235 FileFilter ff = fc.getFileFilter(); 236 if (ff instanceof ExtensionFileFilter) 237 fn = "." + ((ExtensionFileFilter)ff).defaultExtension; 238 else 239 fn += ".osm"; 240 file = new File(fn); 241 } 242 return file; 123 243 } 124 244 } -
applications/editors/josm/plugins/wmsplugin/src/wmsplugin/WMSPlugin.java
r2121 r5319 4 4 5 5 6 import java.awt.event.ActionEvent; 6 7 import java.util.ArrayList; 7 8 import java.util.Map; 8 9 import java.util.TreeSet; 10 11 import javax.swing.AbstractAction; 9 12 import javax.swing.JMenu; 10 13 import javax.swing.JMenuBar; … … 31 34 static ArrayList<WMSInfo> wmsList = new ArrayList<WMSInfo>(); 32 35 33 34 35 36 public WMSPlugin() { 36 37 37 refreshMenu(); 38 39 38 } 40 39 … … 110 109 111 110 wmsJMenu.addSeparator(); 111 wmsJMenu.add(new JMenuItem(new AbstractAction("Blank Layer") { 112 public void actionPerformed(ActionEvent ev) { 113 Main.main.addLayer(new WMSLayer()); 114 } 115 })); 116 wmsJMenu.addSeparator(); 112 117 wmsJMenu.add(new JMenuItem(new Help_WMSmenuAction())); 113 114 115 116 118 } 117 119 118 120 public void mapFrameInitialized(MapFrame oldFrame, MapFrame newFrame) { 119 if (oldFrame==null && newFrame!=null) {121 if (oldFrame==null && newFrame!=null) { 120 122 wmsJMenu.setEnabled(true); 121 123 Main.map.toolBarActions.addSeparator();
Note:
See TracChangeset
for help on using the changeset viewer.