Skip to content

Commit 3d255b2

Browse files
Steve HannahSteve Hannah
authored andcommitted
Added single arg string constructor for NSObject that takes an Objective-C class name for the parameter.
Also fixed issue with calling selectors on anonymous classes.
1 parent 35ca14d commit 3d255b2

File tree

10 files changed

+149
-7
lines changed

10 files changed

+149
-7
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>BuildMachineOSBuild</key>
6+
<string>11G63b</string>
7+
<key>CFBundleDevelopmentRegion</key>
8+
<string>English</string>
9+
<key>CFBundleExecutable</key>
10+
<string>TestBundle</string>
11+
<key>CFBundleIdentifier</key>
12+
<string>ca.weblite.TestBundle</string>
13+
<key>CFBundleInfoDictionaryVersion</key>
14+
<string>6.0</string>
15+
<key>CFBundleName</key>
16+
<string>TestBundle</string>
17+
<key>CFBundlePackageType</key>
18+
<string>BNDL</string>
19+
<key>CFBundleShortVersionString</key>
20+
<string>1.0</string>
21+
<key>CFBundleSignature</key>
22+
<string>????</string>
23+
<key>CFBundleVersion</key>
24+
<string>1</string>
25+
<key>DTCompiler</key>
26+
<string></string>
27+
<key>DTPlatformBuild</key>
28+
<string>4G2008a</string>
29+
<key>DTPlatformVersion</key>
30+
<string>GM</string>
31+
<key>DTSDKBuild</key>
32+
<string>12C37</string>
33+
<key>DTSDKName</key>
34+
<string>macosx10.8</string>
35+
<key>DTXcode</key>
36+
<string>0452</string>
37+
<key>DTXcodeBuild</key>
38+
<string>4G2008a</string>
39+
<key>NSHumanReadableCopyright</key>
40+
<string>Copyright © 2013 Web Lite Solutions Corp. All rights reserved.</string>
41+
</dict>
42+
</plist>
21.2 KB
Binary file not shown.
3.35 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

java/nbproject/build-impl.xml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,11 @@ is divided into following sections:
370370
</and>
371371
</condition>
372372
</target>
373+
<target name="-init-test-properties">
374+
<property name="test.binaryincludes" value="&lt;nothing&gt;"/>
375+
<property name="test.binarytestincludes" value=""/>
376+
<property name="test.binaryexcludes" value=""/>
377+
</target>
373378
<target if="${nb.junit.single}" name="-init-macrodef-junit-single" unless="${nb.junit.batch}">
374379
<macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
375380
<attribute default="${includes}" name="includes"/>
@@ -393,7 +398,7 @@ is divided into following sections:
393398
</sequential>
394399
</macrodef>
395400
</target>
396-
<target if="${nb.junit.batch}" name="-init-macrodef-junit-batch" unless="${nb.junit.single}">
401+
<target depends="-init-test-properties" if="${nb.junit.batch}" name="-init-macrodef-junit-batch" unless="${nb.junit.single}">
397402
<macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
398403
<attribute default="${includes}" name="includes"/>
399404
<attribute default="${excludes}" name="excludes"/>
@@ -407,6 +412,9 @@ is divided into following sections:
407412
<fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
408413
<filename name="@{testincludes}"/>
409414
</fileset>
415+
<fileset dir="${build.test.classes.dir}" excludes="@{excludes},${excludes},${test.binaryexcludes}" includes="${test.binaryincludes}">
416+
<filename name="${test.binarytestincludes}"/>
417+
</fileset>
410418
</batchtest>
411419
<syspropertyset>
412420
<propertyref prefix="test-sys-prop."/>
@@ -534,7 +542,7 @@ is divided into following sections:
534542
</sequential>
535543
</macrodef>
536544
</target>
537-
<target if="${nb.junit.batch}" name="-init-macrodef-junit-debug-batch">
545+
<target depends="-init-test-properties" if="${nb.junit.batch}" name="-init-macrodef-junit-debug-batch">
538546
<macrodef name="junit-debug" uri="http://www.netbeans.org/ns/j2se-project/3">
539547
<attribute default="${includes}" name="includes"/>
540548
<attribute default="${excludes}" name="excludes"/>
@@ -548,6 +556,9 @@ is divided into following sections:
548556
<fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
549557
<filename name="@{testincludes}"/>
550558
</fileset>
559+
<fileset dir="${build.test.classes.dir}" excludes="@{excludes},${excludes},${test.binaryexcludes}" includes="${test.binaryincludes}">
560+
<filename name="${test.binarytestincludes}"/>
561+
</fileset>
551562
</batchtest>
552563
<syspropertyset>
553564
<propertyref prefix="test-sys-prop."/>
@@ -920,7 +931,7 @@ is divided into following sections:
920931
<target if="has.persistence.xml" name="-copy-persistence-xml">
921932
<mkdir dir="${build.classes.dir}/META-INF"/>
922933
<copy todir="${build.classes.dir}/META-INF">
923-
<fileset dir="${meta.inf.dir}" includes="persistence.xml"/>
934+
<fileset dir="${meta.inf.dir}" includes="persistence.xml orm.xml"/>
924935
</copy>
925936
</target>
926937
<target name="-post-compile">

java/nbproject/genfiles.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ [email protected]
44
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
55
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
66
nbproject/build-impl.xml.data.CRC32=bdde2110
7-
nbproject/build-impl.xml.script.CRC32=35ccd0f1
8-
nbproject/build-impl.xml.stylesheet.CRC32=6ddba6b6@1.53.1.46
7+
nbproject/build-impl.xml.script.CRC32=33aeb395
8+
nbproject/build-impl.xml.stylesheet.CRC32=c6d2a60f@1.56.1.46

java/nbproject/private/private.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ do.depend=false
33
do.jar=true
44
javac.debug=true
55
javadoc.preview=true
6-
user.properties.file=/Users/shannah/Library/Application Support/NetBeans/7.2/build.properties
6+
user.properties.file=/Users/shannah/Library/Application Support/NetBeans/7.3/build.properties

java/src/ca/weblite/objc/NSObject.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ protected static Map<String,Method> getMethodMap(Class cls){
9898
}
9999

100100

101+
public NSObject(String className){
102+
this();
103+
init(className);
104+
}
101105

102106
/**
103107
* Creates null proxy (i.e. a proxy around a null pointer). In order
@@ -484,7 +488,7 @@ public void forwardInvocation(long linvocation) {
484488
}
485489

486490
try {
487-
491+
method.setAccessible(true);
488492
Object res = method.invoke(this, args);
489493

490494
// We should release the arguments now since we retained them before
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* To change this template, choose Tools | Templates
3+
* and open the template in the editor.
4+
*/
5+
package ca.weblite.objc;
6+
7+
import static ca.weblite.objc.RuntimeUtils.*;
8+
import ca.weblite.objc.annotations.Msg;
9+
import com.sun.jna.Library;
10+
import com.sun.jna.Native;
11+
12+
import javax.swing.JFrame;
13+
/**
14+
*
15+
* @author shannah
16+
*/
17+
public class TestWebView extends NSObject {
18+
19+
// JNA interface for webkit framework
20+
public static interface WebKit extends Library {
21+
public final static TestWebView.WebKit INSTANCE = (TestWebView.WebKit)Native.loadLibrary("WebKit", TestWebView.WebKit.class);
22+
}
23+
24+
public TestWebView(){
25+
super("NSObject");
26+
27+
}
28+
29+
// Initialization method
30+
@Msg(selector="myInit", like="NSObject.finalize")
31+
public void myInit(){
32+
33+
// Get objective-c client
34+
Client c = getClient();
35+
36+
// Load the bundle code
37+
// Includes TestWindowController class
38+
Proxy bundle = c.sendProxy("NSBundle", "bundleWithPath:", "TestBundle.bundle");
39+
bundle.send("load");
40+
41+
// Initialize TestWindowController object used to work with the TestWindowController nib file.
42+
Proxy window = c.sendProxy("TestWindowController","alloc");
43+
window = window.sendProxy("initWithWindowNibPath:owner:", "TestBundle.bundle/Contents/Resources/TestWindowController.nib", window.getPeer());
44+
45+
// Open the window
46+
window.send("showWindow:", window);
47+
48+
// Get the webView in the window and load a URL in it
49+
Proxy webView = window.sendProxy("webView");
50+
webView.send("setMainFrameURL:", "http://www.google.com");
51+
52+
}
53+
54+
public void someFuncWithMultipleArgs(String arg1, int arg2){
55+
System.out.println("Arg 1 is "+arg1+"; arg 2 is "+arg2);
56+
}
57+
58+
public static void main(String[] args){
59+
60+
// Easy way to start event loop so app doesn't exit... start swing.
61+
new JFrame();
62+
63+
// Load the WebKit framework
64+
Native.loadLibrary("WebKit", TestWebView.WebKit.class);
65+
66+
67+
final TestWebView v = new TestWebView();
68+
final String arg1 = "A first argument";
69+
final int arg2 = 100;
70+
71+
(new NSObject("NSObject"){
72+
73+
@Msg(selector="doBlock", like="NSObject.finalize")
74+
public void doBlock(){
75+
v.myInit();
76+
v.someFuncWithMultipleArgs(arg1, arg2);
77+
}
78+
}).send("performSelectorOnMainThread:withObject:waitUntilDone:", sel("doBlock"), null, 1);
79+
80+
81+
// Run on the main thread
82+
//v.send("performSelectorOnMainThread:withObject:waitUntilDone:", sel("myInit"), v, 1);
83+
84+
}
85+
}

0 commit comments

Comments
 (0)