forked from shannah/Java-Objective-C-Bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoadNibSample.java
109 lines (78 loc) · 3.49 KB
/
LoadNibSample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package ca.weblite.objc;
import ca.weblite.objc.Client;
import ca.weblite.objc.NSObject;
import ca.weblite.objc.Proxy;
import ca.weblite.objc.annotations.Msg;
import static ca.weblite.objc.RuntimeUtils.*;
/**
*
* @author shannah
*/
public class LoadNibSample extends NSObject {
Proxy window;
public LoadNibSample(){
super();
init("NSObject");
}
@Msg(selector="setWindow:", like="NSSavePanel.setTitle:")
public void setWindow(Proxy window){
this.window = window;
}
@Msg(selector="window", like="NSObject.description")
public Proxy window(){
return this.window;
}
@Msg(selector="windowDidLoad", like="NSWindowController.windowDidLoad")
public void windowDidLoad(){
System.out.println("Window did load");
}
@Msg(selector="applicationDidFinishLaunching:", like="NSWindow.setTitle:")
public void applicationDidFinishLaunching(Proxy notification){
System.out.println("App did finish launching");
}
@Msg(selector="doMyAction:", like="NSWindow.setTitle")
public void doMyAction(Proxy sender){
System.out.println("Action was performed");
}
@Msg(selector="startApplication", like="NSObject.finalize")
public void startApplication(){
Client c = getClient();
Proxy app = c.chain("NSApplication", "sharedApplication");
Proxy topLevelObjects = c.chain("NSMutableArray", "array");
Proxy filesOwner = c.chain(
"NSDictionary",
"dictionaryWithObjectsAndKeys:",
this.getPeer(),
str("NSOwner"),
topLevelObjects.getPeer(),
str("NSTopLevelObjects"),
null
);
app.send("setDelegate:", this);
long res = (Long)c.send("NSBundle", "loadNibFile:externalNameTable:withZone:", "MainMenu.nib", filesOwner.getPeer(), null);
int numTopLevelObjects = ((Long)topLevelObjects.send("count")).intValue();
Proxy mainWindow = null;
for ( int i=0; i<numTopLevelObjects; i++){
Proxy obj = (Proxy)topLevelObjects.send("objectAtIndex:", i);
if ( (Long)obj.send("isKindOfClass:", cls("NSWindow")) > 0 ){
mainWindow = obj;
} else {
obj.dispose(false);
}
}
//Proxy windowController = c.chain("NSWindowController", "alloc").chain("initWithWindow:", mainWindow.getPeer());
//System.out.println("Window loaded? "+windowController.send("isWindowLoaded"));
//System.out.println("Window owner: "+windowController.send("owner"));
//System.out.println("Bundle loaded "+res);
//System.out.println("Num top level objects "+topLevelObjects.send("count"));
//System.out.println("Main window "+app.send("mainWindow"));
app.send("run");
}
public static void main(String[] args){
//NativeLibrary library = NativeLibrary.getInstance("AppKit");
//Pointer addr = library.getGlobalVariableAddress("NSNibOwner");
//System.out.println("Top level objects :"+str(addr.getLong(0)));System.exit(0);
LoadNibSample app = new LoadNibSample();
app.send("performSelectorOnMainThread:withObject:waitUntilDone:", sel("startApplication"), app, 1);
}
}