I created a Mac Java Swing application, and I installed the extension file (* .pkkt) for it in the Info.plist file, so when I double-click on this file it opens my application.
When I do this, the program works fine. Now I need to load the project (* .pkkt) into the program, but the file path is not passed as an argument to the main (...) method on the Mac, as it does on the Windows operating system.
After some searching, I found the Apple processing bank " MRJToolkitStubs ", which has the MRJOpenDocumentHandler interface for handling such click files. I tried to use it to download this file by implementing this interface in the main class of the program, but it does not work. The implemented method is never called when the program starts.
How does this interface work?
----------------------------------------------- - Edit: Add sample code
Here is the code I'm using:
public static void main( final String[] args ) {
.
.
.
MacOpenHandler macOpenHandler = new MacOpenHandler();
String projectFilePath = macOpenHandler.getProjectFilePath();
}
class MacOpenHandler implements MRJOpenDocumentHandler {
private String projectFilePath = "";
public MacOpenHandler () {
com.apple.mrj.MRJApplicationUtils.registerOpenDocumentHandler(this) ;
}
@Override
public void handleOpenFile( File projectFile ) {
try {
if( projectFile != null ) {
projectFilePath = projectFile.getCanonicalPath();
System.out.println( projectFilePath );
}
} catch (IOException e) {}
}
public String getProjectFilePath() {
return projectFilePath;
}
}
As mentioned in the comment above, "getProjectFilePath ()" is always empty!
source
share