Package jahuwaldt.swing
Class MacOSUtilities
- java.lang.Object
-
- jahuwaldt.swing.MacOSUtilities
-
public class MacOSUtilities extends java.lang.Object
A set of utilities that are used by my programs when running under MacOS only. These static methods provide Mac specific functionality but all the methods in it can be called safely from any platform. On non-Mac systems, the worst that will happen when calling these methods is nothing and sometimes appropriate non-Mac behavior is provided.Modified by: Joseph A. Huwaldt
- Version:
- December 3, 2023
- Author:
- Joseph A. Huwaldt Date: September 3, 2000
-
-
Constructor Summary
Constructors Constructor Description MacOSUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.io.File
getProxyIcon(javax.swing.JFrame window)
Return the contents of the "Window.documentFile" client property (which can return null).static java.io.File
getResource(java.lang.String resourceName, java.lang.String defaultAppName)
Returns the a File reference to the specified resource in the MacOS X application bundle's Resource directory.static java.io.File
getResource(java.lang.String resourceName, java.lang.String subDirName, java.lang.String defaultAppName)
Returns the a File reference to the specified resource in the specified sub-directory of the application bundle's Resource directory.static boolean
isMacOS()
Returns true if this program is running in any MacOS 8/9/X environment, false is returned otherwise.static java.lang.Boolean
isMarkedModified(javax.swing.JFrame window)
Return the state of the "Window.documentModified" client property for the specified frame.static void
setModifiedMark(javax.swing.JFrame window, boolean modified)
Sets the "Window.documentModified" client property on the frame's root pane to the value indicated.static void
setProxyIcon(javax.swing.JFrame window, java.io.File file)
Set's the title bar proxy icon.
-
-
-
Constructor Detail
-
MacOSUtilities
public MacOSUtilities()
-
-
Method Detail
-
isMacOS
public static boolean isMacOS()
Returns true if this program is running in any MacOS 8/9/X environment, false is returned otherwise.
-
getResource
public static java.io.File getResource(java.lang.String resourceName, java.lang.String defaultAppName) throws java.io.FileNotFoundException
Returns the a File reference to the specified resource in the MacOS X application bundle's Resource directory. This method takes advantage of the application bundle's used by MacOS X to hide resources from the user. If not running on a MacOS X system, then the resource is searched for in three locations. 1st the directory that the application is running in. 2nd the default application name supplied is combined with ".app/Contents/Resources/" + resourceName and searched for in the current directory. This is how a MacOS X application bundle would appear on a non-Mac system. Third, the default application name is combined with ".app/Contents/Resources/" + resourceName and searched for in the install directory (if it can be determined).- Parameters:
resourceName
- The name of the resource file.defaultAppName
- The default application name to use if not running on MacOS.- Throws:
java.io.FileNotFoundException
- if the specified resource file could not be found.
-
getResource
public static java.io.File getResource(java.lang.String resourceName, java.lang.String subDirName, java.lang.String defaultAppName) throws java.io.FileNotFoundException
Returns the a File reference to the specified resource in the specified sub-directory of the application bundle's Resource directory. This method takes advantage of the application bundle's used by MacOS X to hide resources from the user. If not running on a MacOS X system, then the resource is searched for in three locations. 1st the directory that the application is running in. 2nd the default application name supplied is combined with ".app/Contents/Resources/" + resourceName and searched for in the current directory. This is how a MacOS X application bundle would appear on a non-Mac system. Third, the default application name is combined with ".app/Contents/Resources/" + resourceName and searched for in the install directory (if it can be determined).- Parameters:
resourceName
- The name of the resource file.subDirName
- The name of the sub-directory under Resources.defaultAppName
- The default application name to use if not running on MacOS.- Throws:
java.io.FileNotFoundException
- if the specified resource file could not be found.
-
setModifiedMark
public static void setModifiedMark(javax.swing.JFrame window, boolean modified)
Sets the "Window.documentModified" client property on the frame's root pane to the value indicated. On a Mac, the modified-document mark is standardized as a black dot in the center of the red close button on the title bar. The proxy icon, if present, is also dimmed ifmodified
is set to true.- Parameters:
window
- The JFrame to have the modified mark set on.modified
- Set to true to indicate that the document represented by frame is modified. Set to false to indicate that it has not been modified since it was last created, read in, or saved.
-
isMarkedModified
public static java.lang.Boolean isMarkedModified(javax.swing.JFrame window)
Return the state of the "Window.documentModified" client property for the specified frame. On a Mac, the modified-document mark is standardized as a black dot in the center of the red close button on the title bar. It is used to indicate that a document has been modified.- Parameters:
window
- The frame to have the document modified client property read from.
-
setProxyIcon
public static void setProxyIcon(javax.swing.JFrame window, java.io.File file)
Set's the title bar proxy icon. On a Mac, document windows have a proxy icon to the left of the title text. Users can click and drag the icon to other windows or right-click/command-click to get a path to the document.- Parameters:
window
- The JFrame to have a proxy icon added to the title bar.file
- The file who's icon should be added to the title bar. The Mac automatically finds the correct icon for the file or folder.
-
getProxyIcon
public static java.io.File getProxyIcon(javax.swing.JFrame window)
Return the contents of the "Window.documentFile" client property (which can return null). On a Mac, document windows have a proxy icon to the left of the title text. Users can click and drag the icon to other windows or right-click/command-click to get a path to the document. The file who's icon is used as the proxy icon, is retrieved from a frame with this method.- Parameters:
window
- The JFrame to have the proxy icon file retrieved.- Returns:
- The file who's icon is used as the proxy icon or null if there is none.
-
-