Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
URLOpener.java
1 package ij.plugin;
2 import java.awt.*;
3 import java.io.*;
4 import ij.*;
5 import ij.io.*;
6 import ij.gui.*;
7 
13 public class URLOpener implements PlugIn {
14 
15  private static String url = "http://rsb.info.nih.gov/ij/images/clown.gif";
16 
21  public void run(String urlOrName) {
22  if (!urlOrName.equals("")) {
23  String url = urlOrName.indexOf("://")>0?urlOrName:Prefs.getImagesURL()+urlOrName;
24  ImagePlus imp = new ImagePlus(url);
25  if (imp.getType()==ImagePlus.COLOR_RGB)
26  Opener.convertGrayJpegTo8Bits(imp);
27  imp.show();
28  return;
29  }
30 
31  GenericDialog gd = new GenericDialog("Enter a URL");
32  gd.addMessage("Enter the URL of a TIFF, JPEG or GIF image:");
33  gd.addStringField("", url, 40);
34  gd.showDialog();
35  if (gd.wasCanceled())
36  return;
37  url = gd.getNextString();
38  url = url.trim();
39  if (url.indexOf("://")==-1)
40  url = "http://" + url;
41  if (url.endsWith("/"))
42  IJ.runPlugIn("ij.plugin.BrowserLauncher", url.substring(0, url.length()-1));
43  else {
44  IJ.showStatus("Opening: " + url);
45  ImagePlus imp = new ImagePlus(url);
46  imp.show();
47  IJ.showStatus("");
48  }
49  IJ.register(URLOpener.class); // keeps this class from being GC'd
50  }
51 }