Skip to content

Instantly share code, notes, and snippets.

@shannah
Created November 15, 2015 17:38
Show Gist options
  • Save shannah/2640dc55aadb988a51c0 to your computer and use it in GitHub Desktop.
Save shannah/2640dc55aadb988a51c0 to your computer and use it in GitHub Desktop.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package ca.weblite.objc;
import static ca.weblite.objc.RuntimeUtils.*;
import ca.weblite.objc.annotations.Msg;
import com.sun.jna.Library;
import com.sun.jna.Native;
import javax.swing.JFrame;
/**
*
* @author shannah
*/
public class TestPDFView extends NSObject {
// JNA interface for webkit framework
public static interface WebKit extends Library {
public final static TestPDFView.WebKit INSTANCE = (TestPDFView.WebKit)Native.loadLibrary("WebKit", TestPDFView.WebKit.class);
}
public static interface PDFKit extends Library {
//public final static TestPDFView.PDFKit INSTANCE = (TestPDFView.PDFKit)Native.loadLibrary("Quartz", TestPDFView.PDFKit.class);
}
public TestPDFView(){
super("NSObject");
}
// Initialization method
@Msg(selector="myInit", like="NSObject.finalize")
public void myInit(){
// Get objective-c client
Client c = getClient();
//PDFDocument *pdfDoc;
//pdfDoc = [[PDFDocument alloc] initWithURL: [NSURL fileURLWithPath: [self fileName]]];
//[_pdfView setDocument: pdfDoc];
Proxy pdfAlloc = c.sendProxy("PDFDocument", "alloc");
// Load the bundle code
// Includes TestWindowController class
Proxy bundle = c.sendProxy("NSBundle", "bundleWithPath:", "TestBundle.bundle");
bundle.send("load");
// Initialize TestWindowController object used to work with the TestWindowController nib file.
Proxy window = c.sendProxy("TestWindowController","alloc");
window = window.sendProxy("initWithWindowNibPath:owner:", "TestBundle.bundle/Contents/Resources/TestWindowController.nib", window.getPeer());
// Open the window
window.send("showWindow:", window);
// Get the webView in the window and load a URL in it
Proxy webView = window.sendProxy("webView");
webView.send("setMainFrameURL:", "http://www.google.com");
}
public void someFuncWithMultipleArgs(String arg1, int arg2){
System.out.println("Arg 1 is "+arg1+"; arg 2 is "+arg2);
}
public static void main(String[] args){
// Easy way to start event loop so app doesn't exit... start swing.
new JFrame();
// Load the WebKit framework
Native.loadLibrary("WebKit", TestPDFView.WebKit.class);
Native.loadLibrary("Quartz", PDFKit.class);
final TestPDFView v = new TestPDFView();
final String arg1 = "A first argument";
final int arg2 = 100;
(new NSObject("NSObject"){
@Msg(selector="doBlock", like="NSObject.finalize")
public void doBlock(){
v.myInit();
v.someFuncWithMultipleArgs(arg1, arg2);
}
}).send("performSelectorOnMainThread:withObject:waitUntilDone:", sel("doBlock"), null, 1);
// Run on the main thread
//v.send("performSelectorOnMainThread:withObject:waitUntilDone:", sel("myInit"), v, 1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment