Class Environment

java.lang.Object
edu.cnu.mdi.util.Environment

public final class Environment extends Object
Environment information for the mdi framework. This class acts as a central place to query basic system properties (home directory, host name, screen DPI, etc.)

The class is implemented as a simple, lazily-initialized singleton.

  • Field Details

    • MDI_RESOURCE_PATH

      public static final String MDI_RESOURCE_PATH
      Classpath prefix for resources bundled with MDI.
      See Also:
  • Method Details

    • getInstance

      public static Environment getInstance()
      Returns the singleton Environment instance.
      Returns:
      the shared Environment instance
    • getFrameSize

      public Dimension getFrameSize()
      Get the current frame size. This is updated by BaseMDIApplication when the main application window is resized, and can be used by views to set their initial size.
      Returns:
      the default frame size for new frames
    • setFrameSize

      public void setFrameSize(Dimension frameSize)
      Set the current frame size. This is updated by BaseMDIApplication when the main application window is resized, and can be used by views to set their initial size.
      Parameters:
      frameSize - the default frame size for new frames
    • getClassPath

      public String getClassPath()
      Get the JVM class path
      Returns:
      the class path
    • getCurrentWorkingDirectory

      public String getCurrentWorkingDirectory()
      Returns the current working directory.
      Returns:
      the current working directory
    • getHomeDirectory

      public String getHomeDirectory()
      Returns the user's home directory.
      Returns:
      the home directory
    • getOsName

      public String getOsName()
      Returns the operating system name.
      Returns:
      the OS name
    • getDataDirectory

      public String getDataDirectory()
      Returns the developer-configured default data directory: the initial location file dialogs open to before they have any purpose-specific history of their own. Defaults to the user's home directory.

      This is a single, application-wide default, not a "most recently used" location -- FileDialogs tracks per-purpose history itself (persisted across restarts) and does not write back to this field, so it stays whatever the developer set it to.

      Returns:
      the default data directory
    • setDataDirectory

      public void setDataDirectory(String dataDirectory)
      Sets the developer-configured default data directory (see getDataDirectory()) -- typically called once at startup, e.g. from a command-line argument or environment variable.
      Parameters:
      dataDirectory - the default data directory to set
    • getTempDirectory

      public String getTempDirectory()
      Returns the JVM's configured temporary directory.
      Returns:
      a unique temp directory
    • getUserName

      public String getUserName()
      Returns the user name of the current user.
      Returns:
      the user name
    • getHostAddress

      public String getHostAddress()
      Returns the primary IPv4 address of the local host, if it can be determined. The result is cached after the first successful lookup.
      Returns:
      the host address or null if it cannot be resolved
    • isLinux

      public boolean isLinux()
      Returns true if the current operating system is a Linux variant.
      Returns:
      true if running on Linux
    • isWindows

      public boolean isWindows()
      Returns true if the current operating system is a Windows variant.
      Returns:
      true if running on Windows
    • isMac

      public boolean isMac()
      Returns true if the current operating system is a macOS variant.
      Returns:
      true if running on macOS
    • getDisplayScaleFactor

      public static double getDisplayScaleFactor()
      Returns the display scale factor for the default screen device based on the default affine transform.
      Returns:
      the display scale factor (typically 1.0, 1.25, 1.5, 2.0, ...)
    • getGraphicsDevices

      public static GraphicsDevice[] getGraphicsDevices()
      Returns the available graphics devices (monitors).
      Returns:
      array of graphics devices
    • getPngWriter

      public ImageWriter getPngWriter()
      Returns an ImageIO PNG image writer, or null if none is available.
      Returns:
      PNG image writer, or null
    • getApplicationName

      public static String getApplicationName()
      Returns the application name. This is used to derive configuration and preference file names.
      Returns:
      the application name, or null if not set
    • setApplicationName

      public static void setApplicationName(String applicationName)
      Sets the application name. This is used to derive configuration and preference file names. Set by basemdiapplication then never changed
      Parameters:
      applicationName - the application name to set
    • getConfigurationFile

      public File getConfigurationFile()
      Returns the configuration file used by the application. The file name is derived from the application name with a .xml extension. On Unix-like systems the file is written as a "dot" file in the user's home directory (e.g. ~/.myapp.xml); on Windows the leading dot is omitted.
      Returns:
      configuration file, or null if the application name is unknown
    • summaryString

      public String summaryString()
      Returns a short, human-readable summary string containing the user name, operating system and current working directory.
    • splitClassPath

      public String[] splitClassPath()
      Splits the JVM class path into individual entries.
      Returns:
      array of class path entries (never null)
    • splitPath

      public String[] splitPath(String path)
      Splits an arbitrary path using the platform path separator.
      Parameters:
      path - path to split
      Returns:
      array of segments (never null)
    • memoryReport

      public static String memoryReport(String message)
      Produces a simple memory usage report as a string. A full garbage collection is requested before the numbers are computed.
      Parameters:
      message - optional message to prefix in the report (may be null)
      Returns:
      a formatted memory report
    • startupReport

      public static String startupReport()
      Build a concise framework, JVM, operating-system, and monitor summary.
      Returns:
      multi-line startup report
    • toString

      public String toString()
      Returns a multi-line description of the environment, including paths, display information and memory usage.
      Overrides:
      toString in class Object
    • getJavaMajorVersion

      public static int getJavaMajorVersion()
      Returns the major Java runtime version (e.g. 8, 11, 17).
    • filteredTrace

      public static void filteredTrace(String startsWith)
      Print a filtered stack trace that only includes elements whose class name starts with the supplied prefix (for example, "edu.cnu.mdi").
      Parameters:
      startsWith - package or class name prefix used to filter the trace