Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8090986

Specifying resources by __DIR__ is not enough flexible

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • fx1.2
    • javafx

      For locating resources FX currently uses __DIR__ magic prefix, which points to the jar where the class using this prefix is stored. This is not enough flexible, as it does not scale across more than one jar and does not allow plugging additional protocols to url. Instead of __DIR__ we for specifying resources we should use this approach:

      Relative local resources:
      source: "image.png" - this loads image.png from the same package where the class using it exists.
      source "res/image.png" - this loads image.png from the res subpackage of the current package.

      Absolute local resources:
      source: "/com/sun/javafx/res/image.png" - this loads image.png from com.sun.javafx.res package

      Fully specified resources:
      http://www.sun.com/res/image.png - this loads image.png from www.sun.com web address
      file:///space/res/image.png - this loads image.png from the local file system

      What is also important is to allow custom protocols to be registered in FX, so we could use something like:
      fxz://graphics.fxz/image.png - this loads image.png from graphics.fxz file

      To achieve this functionality we need to add a class called ResourceHandler, which has the following functions:
      instance:
      handle(url:String):Resource
      static:
      register(protocol:String,handler:ResourceHandler)
      unregister(handler)
      getHandler(protocol:String) // gets handler for given protocol
      getResource(url:String):Resource // gets handler for the used protocol and using it returns the actual resource

      Important part of the fix is also change of the way how classes retrieving external resources (e.g. Image, Font, Media, FeedTask, Storage ..) handle their source/url/location. There are two fixes:
      - the name of the variable should be unified, instead of using location, url, source we should agree on the unified name. "source" seems to be the best option for now
      - the code should handle the source always using the ResourceHandler class, so it will need to use Resource (which uses InputStream) for loading the external asset.
      - ideally we might want to use a specific data type for this - e.g. Source and compiler would allow automatic assignment of URL strings to this data type.

            Unassigned Unassigned
            mbrehovskjfx Martin Brehovsky (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Imported: