Class Resource

java.lang.Object
ucar.unidata.util.Resource

public class Resource extends Object
Cover for fetching files using Class.getResource(). If the application is started from a jar file, then it looks in there. If the application is started from a class file, then it looks in the disk file heirarchy, using directories in the classpath as root(s). 1. Filenames. use "/" as path seperator when embedded in a string. This works on both Windows and Unix. 2. Filepath. Use a resourcePath starting with a forward slash. getResource() then searches relative to the classpath. otherwise it will search reletive to ucar.unidata.util, which is probably not what you want.
  • Constructor Details

    • Resource

      public Resource()
  • Method Details

    • getIcon

      public static ImageIcon getIcon(String fullIconName, boolean errMsg)
      Get a gif file, make it into an ImageIcon.
      Parameters:
      fullIconName - full path name of gif file (use forward slashes!)
      errMsg - print err message on failure
      Returns:
      ImageIcon or null on failure
    • getImage

      public static Image getImage(String fullImageName)
      Get a gif file, make it into an Image.
      Parameters:
      fullImageName - full path name of gif file (use forward slashes!)
      Returns:
      Image or null on failure
    • getImageIcon

      public static ImageIcon getImageIcon(String fullImageName)
      Get a gif file, make it into an ImageIcon.
      Parameters:
      fullImageName - full path name of gif file (use forward slashes!)
      Returns:
      Image or null on failure
    • getURL

      public static URL getURL(String filename)
      Get a file as a URL
      Parameters:
      filename - full path name of file (use forward slashes!)
      Returns:
      URL or null on failure
    • makeCursor

      public static Cursor makeCursor(String name)
      Get a gif file, make it into a Cursor.
      Parameters:
      name - full path name of gif file (use forward slashes!)
      Returns:
      Cursor or null on failure
    • getFileResource

      public static InputStream getFileResource(String resourcePath, String fileName)
      Open a resource as a Stream. First try ClassLoader.getResourceAsStream(). If that fails, try a plain old FileInputStream().
      Parameters:
      resourcePath - name of file path (use forward slashes!)
      fileName - name of file (use forward slashes!)
      Returns:
      InputStream or null on failure
    • main

      public static void main(String[] args)
      testing
      Parameters:
      args -