@NotNull
 @Override
 protected String compute() {
   final Class<JavaFxHtmlPanel> clazz = JavaFxHtmlPanel.class;
   //noinspection StringBufferReplaceableByString
   return new StringBuilder()
       .append("<script src=\"")
       .append(clazz.getResource("scrollToElement.js"))
       .append("\"></script>\n")
       .append("<script src=\"")
       .append(clazz.getResource("processLinks.js"))
       .append("\"></script>\n")
       .toString();
 }
  /**
   * Create a splash screen (borderless graphic for display while other operations are taking
   * place).
   *
   * @param filename a class-relative path to the splash graphic
   * @param callingClass the class to which the graphic filename location is relative
   */
  public SplashScreen(String filename, Class callingClass) {
    super(new Frame());
    URL imageURL = callingClass.getResource(filename);
    image = Toolkit.getDefaultToolkit().createImage(imageURL);
    // Load the image
    MediaTracker mt = new MediaTracker(this);
    mt.addImage(image, 0);
    try {
      mt.waitForID(0);
    } catch (InterruptedException ie) {
    }

    // Center the window on the screen
    int imgWidth = image.getWidth(this);
    int imgHeight = image.getHeight(this);
    setSize(imgWidth, imgHeight);
    Dimension screenDim = Toolkit.getDefaultToolkit().getScreenSize();
    setLocation((screenDim.width - imgWidth) / 2, (screenDim.height - imgHeight) / 2);

    setVisible(true);
    repaint();
    // if on a single processor machine, wait for painting (see Fast Java Splash Screen.pdf)
    if (!EventQueue.isDispatchThread()) {
      synchronized (this) {
        while (!this.paintCalled) {
          try {
            this.wait();
          } catch (InterruptedException e) {
          }
        }
      }
    }
  }
 /**
  * Returns icon for the specified name.
  *
  * @param icon can be either String icon name, ImageIcon, Image, image File or image URL
  * @return icon for the specified name
  */
 public ImageIcon getIcon(final Object icon) {
   if (icon != null) {
     if (icon instanceof String) {
       try {
         if (nearClass != null) {
           return new ImageIcon(nearClass.getResource(path + icon + extension));
         } else {
           return new ImageIcon(new File(path, icon + extension).getAbsolutePath());
         }
       } catch (final Throwable e) {
         Log.warn("Unable to find menu icon for path: " + path + icon + extension, e);
         return null;
       }
     } else if (icon instanceof ImageIcon) {
       return (ImageIcon) icon;
     } else if (icon instanceof Image) {
       return new ImageIcon((Image) icon);
     } else if (icon instanceof File) {
       return new ImageIcon(((File) icon).getAbsolutePath());
     } else if (icon instanceof URL) {
       return new ImageIcon((URL) icon);
     } else {
       Log.warn("Unknown icon object type provided: " + icon);
       return null;
     }
   } else {
     return null;
   }
 }
Example #4
0
  // .getResource is called at resourceOwner. This method is available at all Class objects
  public void setPage(String filename, Class<?> resourceOwner) {

    // Check for anchor
    int indexOf = filename.indexOf('#');
    String file;
    String anchorName = null;

    if (indexOf != -1) {
      file = filename.substring(0, indexOf);
      anchorName = filename.substring(indexOf + 1);
    } else {
      file = filename;
    }

    String middle = prefs.get(JabRefPreferences.LANGUAGE) + '/';

    URL old = getPage();

    // First check in specified language
    URL resource = resourceOwner.getResource(GUIGlobals.helpPre + middle + file);

    // If not available fallback to english
    if (resource == null) {
      resource = resourceOwner.getResource(GUIGlobals.helpPre + "en/" + file);
      LOGGER.info("No localization available for file '" + file + "'. Falling back to English.");
    }

    // If still not available print a warning
    if (resource == null) {
      // TODO show warning to user
      LOGGER.error("Could not find html-help for file '" + file + "'.");
      return;
    }

    setPageOnly(resource, anchorName);

    forw.removeAllElements();
    if (old != null) {
      history.push(old);
    }
  }
  @Nullable
  public static Icon findIcon(
      @NotNull String path, @NotNull final Class aClass, boolean computeNow) {
    path = undeprecate(path);
    if (isReflectivePath(path)) return getReflectiveIcon(path, aClass.getClassLoader());

    URL myURL = aClass.getResource(path);
    if (myURL == null) {
      if (STRICT) throw new RuntimeException("Can't find icon in '" + path + "' near " + aClass);
      return null;
    }
    return findIcon(myURL);
  }
Example #6
0
  private Object getResource(String key) {

    URL url = null;
    String name = key;

    if (name != null) {

      try {
        Class c = Class.forName("content.AdvancedPanel");
        url = c.getResource(name);
      } catch (ClassNotFoundException cnfe) {
        System.err.println("Unable to find Main class");
      }
      return url;
    } else return null;
  }
 private static URL packageRelativeResource(String resourceName, Class<?> clazz) {
   String directoryPrefix = '/' + clazz.getPackage().getName().replaceAll("\\.", "/") + '/';
   return clazz.getResource(directoryPrefix + resourceName);
 }