Package jme3utilities

Class Heart

java.lang.Object
jme3utilities.Heart

public final class Heart extends Object
Miscellaneous utility methods in the Heart Library. All methods should be static.
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Test whether assertions are enabled.
    static boolean
    browseWeb(String startUriString)
    Open the specified web page in a new browser or browser tab.
    static <T> T
    deepCopy(T object)
    Copy the specified object using deepClone() if it's cloneable.
    static void
    deleteStoredSettings(String applicationName)
    Delete the application's stored settings, if any.
    static <T extends com.jme3.app.state.AppState>
    void
    detachAll(com.jme3.app.state.AppStateManager stateManager, Class<T> whichClass)
    Detach all app states which are subclasses of a specified class.
    static Map<String,File>
    Construct a map from drive paths (roots) to file objects.
    static <T> T
    first(Collection<T> collection)
    Access the first member of a collection.
    static String
    fixedPath(File inputFile)
    Canonicalize a file's path and convert backslashes to slashes.
    static String
    fixPath(String inputPath)
    Canonicalize a file path and convert backslashes to slashes.
    Access the pre-existing FileHandler for logging, or if none is found, create one and use that.
    static com.jme3.post.FilterPostProcessor
    getFpp(com.jme3.renderer.ViewPort viewPort, com.jme3.asset.AssetManager assetManager, int numSamples)
    Access the pre-existing FilterPostProcessor of the specified view port, or if it has none, add a new FPP and use that.
    static com.jme3.input.KeyInput
    getKeyInput(com.jme3.input.InputManager inputManager)
    Access the keyboard interface of the specified InputManager.
    static boolean
    hasStoredSettings(String applicationName)
    Test whether the named application has stored settings.
    static String
    homePath(String fileName)
    Generate a canonical filesystem path to the named file in the user's home directory.
    static List<String>
    listZipEntries(String zipPath, String namePrefix)
    Enumerate all entries (in the specified JAR or ZIP) whose names begin with the specified prefix.
    static String
    Load UTF-8 text from the named resource.
    static void
    parseAppArgs(com.jme3.app.SimpleApplication application, String... arguments)
    Parse some conventional command-line arguments and apply them to the specified SimpleApplication.
    static void
    setGrayPixel(Graphics2D graphics, int x, int y, float brightness, float opacity)
    Set the specified pixel to the specified brightness and opacity.
    static void
    Alter the logging levels of all known loggers.
    static String
    Read the verbose version string for this library.
    static String
    Return the terse version string for this library.
    static void
    writeImage(String filePath, RenderedImage image)
    Write an image to a file, attempting to overwrite any pre-existing file.
    static void
    writeJ3O(String filePath, com.jme3.export.Savable savable)
    Write a Savable to a J3O file.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • areAssertionsEnabled

      public static boolean areAssertionsEnabled()
      Test whether assertions are enabled.
      Returns:
      true if enabled, otherwise false
    • browseWeb

      public static boolean browseWeb(String startUriString)
      Open the specified web page in a new browser or browser tab.
      Parameters:
      startUriString - URI of the web page (not null)
      Returns:
      true if successful, otherwise false
    • deepCopy

      public static <T> T deepCopy(T object)
      Copy the specified object using deepClone() if it's cloneable. This works around JME issue #879, but still doesn't handle all classes.
      Type Parameters:
      T - the type of object to be copied
      Parameters:
      object - the input (unaffected)
      Returns:
      an instance equivalent to the input
    • deleteStoredSettings

      public static void deleteStoredSettings(String applicationName)
      Delete the application's stored settings, if any.
      Parameters:
      applicationName - the name of the application
    • detachAll

      public static <T extends com.jme3.app.state.AppState> void detachAll(com.jme3.app.state.AppStateManager stateManager, Class<T> whichClass)
      Detach all app states which are subclasses of a specified class.
      Type Parameters:
      T - class to scan for
      Parameters:
      stateManager - (not null)
      whichClass - (not null)
    • driveMap

      public static Map<String,File> driveMap()
      Construct a map from drive paths (roots) to file objects.
      Returns:
      a new map from canonical file-system paths to files
    • first

      public static <T> T first(Collection<T> collection)
      Access the first member of a collection.
      Type Parameters:
      T - the type of the member
      Parameters:
      collection - the collection to access (not null)
      Returns:
      the pre-existing member, or null if none
    • fixedPath

      public static String fixedPath(File inputFile)
      Canonicalize a file's path and convert backslashes to slashes.
      Parameters:
      inputFile - the input file (not null, not empty)
      Returns:
      the fixed file path (not null, not empty)
    • fixPath

      public static String fixPath(String inputPath)
      Canonicalize a file path and convert backslashes to slashes.
      Parameters:
      inputPath - the file path to fix (not null, not empty)
      Returns:
      the fixed file path (not null, not empty)
    • getFileHandler

      public static FileHandler getFileHandler()
      Access the pre-existing FileHandler for logging, or if none is found, create one and use that.
      Returns:
      not null
    • getFpp

      public static com.jme3.post.FilterPostProcessor getFpp(com.jme3.renderer.ViewPort viewPort, com.jme3.asset.AssetManager assetManager, int numSamples)
      Access the pre-existing FilterPostProcessor of the specified view port, or if it has none, add a new FPP and use that.
      Parameters:
      viewPort - which view port (not null)
      assetManager - (not null)
      numSamples - number of samples for anti-aliasing (≥1, ≤16) or 0 for the FPP default
      Returns:
      not null
    • getKeyInput

      public static com.jme3.input.KeyInput getKeyInput(com.jme3.input.InputManager inputManager)
      Access the keyboard interface of the specified InputManager.
      Parameters:
      inputManager - the InputManager to access (not null, unaffected)
      Returns:
      the pre-existing instance
    • hasStoredSettings

      public static boolean hasStoredSettings(String applicationName)
      Test whether the named application has stored settings.
      Parameters:
      applicationName - the name of the application
      Returns:
      true if it has stored settings, otherwise false
    • homePath

      public static String homePath(String fileName)
      Generate a canonical filesystem path to the named file in the user's home directory.
      Parameters:
      fileName - file name to use (not null, not empty)
      Returns:
      the file-system path (not null, not empty)
    • listZipEntries

      public static List<String> listZipEntries(String zipPath, String namePrefix)
      Enumerate all entries (in the specified JAR or ZIP) whose names begin with the specified prefix.
      Parameters:
      zipPath - filesystem path to the JAR or ZIP (not null, not empty)
      namePrefix - (not null)
      Returns:
      a new list of entry names
    • loadResourceAsString

      public static String loadResourceAsString(String resourceName)
      Load UTF-8 text from the named resource.
      Parameters:
      resourceName - the name of the classpath resource to load (not null)
      Returns:
      the text (possibly multiple lines)
    • parseAppArgs

      public static void parseAppArgs(com.jme3.app.SimpleApplication application, String... arguments)
      Parse some conventional command-line arguments and apply them to the specified SimpleApplication.
      Parameters:
      application - the application to modify (not null)
      arguments - array of command-line arguments (not null)
    • setGrayPixel

      public static void setGrayPixel(Graphics2D graphics, int x, int y, float brightness, float opacity)
      Set the specified pixel to the specified brightness and opacity.
      Parameters:
      graphics - rendering context of the pixel (not null)
      x - pixel's first coordinate (<width, ≥0)
      y - pixel's 2nd coordinate (<height, ≥0)
      brightness - (≤1, ≥0, 0 → black, 1 → white)
      opacity - (≤1, ≥0, 0 → transparent, 1 → opaque)
    • setLoggingLevels

      public static void setLoggingLevels(Level newLevel)
      Alter the logging levels of all known loggers.
      Parameters:
      newLevel - the desired level (not null)
      See Also:
    • version

      public static String version()
      Read the verbose version string for this library.
      Returns:
      project name, library name, branch, and revision
    • versionShort

      public static String versionShort()
      Return the terse version string for this library.
      Returns:
      the branch name and revision string (not null, not empty)
    • writeImage

      public static void writeImage(String filePath, RenderedImage image) throws IOException
      Write an image to a file, attempting to overwrite any pre-existing file.
      Parameters:
      filePath - the path to the output file (not null, not empty)
      image - the image to be written (not null)
      Throws:
      IOException - if the file cannot be written
    • writeJ3O

      public static void writeJ3O(String filePath, com.jme3.export.Savable savable)
      Write a Savable to a J3O file.
      Parameters:
      filePath - (not null, not empty, should end in ".j3o")
      savable - (not null, unaffected)