Package edu.cnu.mdi.util
Class Environment
java.lang.Object
edu.cnu.mdi.util.Environment
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final StringClasspath prefix for resources bundled with MDI. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidfilteredTrace(String startsWith) Print a filtered stack trace that only includes elements whose class name starts with the supplied prefix (for example,"edu.cnu.mdi").static StringReturns the application name.Get the JVM class pathReturns the configuration file used by the application.Returns the current working directory.Returns the developer-configured default data directory: the initial location file dialogs open to before they have any purpose-specific history of their own.static doubleReturns the display scale factor for the default screen device based on the default affine transform.Get the current frame size.static GraphicsDevice[]Returns the available graphics devices (monitors).Returns the user's home directory.Returns the primary IPv4 address of the local host, if it can be determined.static EnvironmentReturns the singletonEnvironmentinstance.static intReturns the major Java runtime version (e.g.Returns the operating system name.Returns an ImageIO PNG image writer, ornullif none is available.Returns the JVM's configured temporary directory.Returns the user name of the current user.booleanisLinux()Returnstrueif the current operating system is a Linux variant.booleanisMac()Returnstrueif the current operating system is a macOS variant.booleanReturnstrueif the current operating system is a Windows variant.static StringmemoryReport(String message) Produces a simple memory usage report as a string.static voidsetApplicationName(String applicationName) Sets the application name.voidsetDataDirectory(String dataDirectory) Sets the developer-configured default data directory (seegetDataDirectory()) -- typically called once at startup, e.g.voidsetFrameSize(Dimension frameSize) Set the current frame size.String[]Splits the JVM class path into individual entries.String[]Splits an arbitrary path using the platform path separator.static StringBuild a concise framework, JVM, operating-system, and monitor summary.Returns a short, human-readable summary string containing the user name, operating system and current working directory.toString()Returns a multi-line description of the environment, including paths, display information and memory usage.
-
Field Details
-
MDI_RESOURCE_PATH
Classpath prefix for resources bundled with MDI.- See Also:
-
-
Method Details
-
getInstance
Returns the singletonEnvironmentinstance.- Returns:
- the shared
Environmentinstance
-
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
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
Get the JVM class path- Returns:
- the class path
-
getCurrentWorkingDirectory
Returns the current working directory.- Returns:
- the current working directory
-
getHomeDirectory
Returns the user's home directory.- Returns:
- the home directory
-
getOsName
Returns the operating system name.- Returns:
- the OS name
-
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 --
FileDialogstracks 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
Sets the developer-configured default data directory (seegetDataDirectory()) -- typically called once at startup, e.g. from a command-line argument or environment variable.- Parameters:
dataDirectory- the default data directory to set
-
getTempDirectory
Returns the JVM's configured temporary directory.- Returns:
- a unique temp directory
-
getUserName
Returns the user name of the current user.- Returns:
- the user name
-
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
nullif it cannot be resolved
-
isLinux
public boolean isLinux()Returnstrueif the current operating system is a Linux variant.- Returns:
trueif running on Linux
-
isWindows
public boolean isWindows()Returnstrueif the current operating system is a Windows variant.- Returns:
trueif running on Windows
-
isMac
public boolean isMac()Returnstrueif the current operating system is a macOS variant.- Returns:
trueif 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
Returns the available graphics devices (monitors).- Returns:
- array of graphics devices
-
getPngWriter
Returns an ImageIO PNG image writer, ornullif none is available.- Returns:
- PNG image writer, or
null
-
getApplicationName
Returns the application name. This is used to derive configuration and preference file names.- Returns:
- the application name, or
nullif not set
-
setApplicationName
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
Returns the configuration file used by the application. The file name is derived from the application name with a.xmlextension. 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
nullif the application name is unknown
-
summaryString
Returns a short, human-readable summary string containing the user name, operating system and current working directory. -
splitClassPath
Splits the JVM class path into individual entries.- Returns:
- array of class path entries (never
null)
-
splitPath
Splits an arbitrary path using the platform path separator.- Parameters:
path- path to split- Returns:
- array of segments (never
null)
-
memoryReport
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 benull)- Returns:
- a formatted memory report
-
startupReport
Build a concise framework, JVM, operating-system, and monitor summary.- Returns:
- multi-line startup report
-
toString
Returns a multi-line description of the environment, including paths, display information and memory usage. -
getJavaMajorVersion
public static int getJavaMajorVersion()Returns the major Java runtime version (e.g. 8, 11, 17). -
filteredTrace
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
-