public class NSObject extends Proxy implements PeerableRecipient
The parent object is used as a sort of superclass so that messages that aren't explicitly handled by the Java class can be handled by the superclass.
The following example shows a subclass of NSObject that is used as a delegate for an NSOpenPanel. Notice, that, by using the @Msg annotation, the start() method is effectively called via Objective-C. Similarly, the panelSelectionDidChange() method is called by the NSOpenPanel class to respond to events when the user clicks on a different item in the open dialog.
/* | |
* To change this template, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package ca.weblite.objc; | |
import ca.weblite.objc.annotations.Msg; | |
import static ca.weblite.objc.RuntimeUtils.*; | |
/** | |
* | |
* @author shannah | |
*/ | |
public class NSOpenPanelSample extends NSObject { | |
public NSOpenPanelSample(){ | |
super(); | |
init("NSObject"); | |
} | |
@Msg(selector="panelSelectionDidChange:", signature="v@:@") | |
public void panelSelectionDidChange(Proxy sender){ | |
System.out.println("---------In panel selection did change---------"); | |
} | |
@Msg(selector="start", signature="v@:") | |
public void start(){ | |
Proxy openPanel = getClient().sendProxy("NSOpenPanel", "openPanel"); | |
openPanel.send("setDelegate:", this); | |
int result = openPanel.sendInt("runModal"); | |
if ( result == 1 ){ | |
// File was selected | |
// Use the -[URLs] message on NSOpen panel to get an NSArray | |
// of the selected files | |
Proxy selectedUrls = openPanel.sendProxy("URLs"); | |
System.out.println("The following urls were selected :"+selectedUrls); | |
} else { | |
// File was not selected. | |
System.out.println("No file was selected"); | |
} | |
} | |
public static void main(String[] args){ | |
NSOpenPanelSample sample = new NSOpenPanelSample(); | |
// Any interaction with the GUI must happen on the main thread | |
// for cocoa, so we'll use NSObject's performSelectorOnMainThread: | |
// message to | |
sample.send("performSelectorOnMainThread:withObject:waitUntilDone:", sel("start"), sample, true); | |
} | |
} |
If you run this application, it will open an NSOpenPanel modal dialog and allow you to select a file. If you run this program and select a single file, the output will look something like:
---------In panel selection did change--------- | |
The following urls were selected :( | |
"file://localhost/Applications/Time%20Machine.app" | |
) |
NSOpenPanelSample
Modifier and Type | Field and Description |
---|---|
com.sun.jna.Pointer |
parent
Pointer to the parent objective-c object of this object.
|
Constructor and Description |
---|
NSObject()
Creates null proxy (i.e.
|
NSObject(Client c)
Creates a null proxy using the specified client as the default client
with which to send messages to the objective-c runtime.
|
NSObject(Client c,
com.sun.jna.Pointer peer)
Creates a proxy for the specified objective-c object.
|
NSObject(com.sun.jna.Pointer peer)
Creates an NSObject to wrap (i.e.
|
Modifier and Type | Method and Description |
---|---|
NSObject |
chain(Message... msgs)
Deprecated.
|
NSObject |
chain(com.sun.jna.Pointer selector,
java.lang.Object... args)
Deprecated.
|
NSObject |
chain(java.lang.String selector,
java.lang.Object... args)
Deprecated.
|
NSObject |
dealloc()
Deprecated.
|
void |
forwardInvocation(long linvocation)
Handles a method invocation.
|
void |
forwardInvocation(com.sun.jna.Pointer invocation)
Handles a method invocation.
|
void |
forwardInvocationToParent(long linvocation)
Forwards an NSInvocation to the parent object to be handled.
|
void |
forwardInvocationToParent(com.sun.jna.Pointer invocation)
Forwards an NSInvocation to the parent object to be handled.
|
protected static java.util.Map<java.lang.String,java.lang.reflect.Method> |
getMethodMap(java.lang.Class cls)
Returns the method map for a particular class.
|
NSObject |
init(com.sun.jna.Pointer parent)
Initializes this object and registers it with the Objective-C runtime.
|
NSObject |
init(java.lang.String cls)
Initializes this object and registers it with the Objective-C runtime.
|
java.lang.reflect.Method |
methodForSelector(java.lang.String selector)
Returns the java method that responds to a specific selector for the
current object.
|
long |
methodSignatureForSelector(long lselector)
Returns the NSMethodSignature (Objective-C) object pointer for the
specified selector.
|
com.sun.jna.Pointer |
methodSignatureForSelector(com.sun.jna.Pointer selector)
Returns the NSMethodSignature (Objective-C) object pointer for the
specified selector.
|
boolean |
respondsToSelector(long lselector)
Checks whether this object responds to the given selector.
|
boolean |
respondsToSelector(com.sun.jna.Pointer selector)
Checks whether this object responds to the given selector.
|
dispose, equals, get, getBoolean, getClient, getDouble, getInt, getPeer, getPointer, getProxy, hashCode, load, send, send, send, sendBoolean, sendBoolean, sendDouble, sendDouble, sendInt, sendInt, sendPointer, sendPointer, sendProxy, sendProxy, sendRaw, sendRaw, sendRaw, sendString, sendString, set, setClient, setPeer, toString
public com.sun.jna.Pointer parent
public NSObject()
public NSObject(com.sun.jna.Pointer peer)
peer
- public NSObject(Client c)
c
- The client that should be used to send messages in this
object.public NSObject(Client c, com.sun.jna.Pointer peer)
c
- The client that should be used for sending messages via this proxy.peer
- The peer object.protected static java.util.Map<java.lang.String,java.lang.reflect.Method> getMethodMap(java.lang.Class cls)
cls
- The class whose map we wish to obtainpublic NSObject init(com.sun.jna.Pointer parent)
parent
- A pointer to a parent object that is used as a sort of
super class. I.e. messages that this object doesn't handle will be
passed to this parent object transparently in the background. It
acts 100% as a superclass would.public NSObject init(java.lang.String cls)
parent
- A pointer to a parent object that is used as a sort of
super class. I.e. messages that this object doesn't handle will be
passed to this parent object transparently in the background. It
acts 100% as a superclass would.cls
- The name of the class to use as the super class for this object.public java.lang.reflect.Method methodForSelector(java.lang.String selector)
selector
- TheRuntimeUtils.sel()
public com.sun.jna.Pointer methodSignatureForSelector(com.sun.jna.Pointer selector)
selector
- public long methodSignatureForSelector(long lselector)
methodSignatureForSelector
in interface Recipient
selector
- public void forwardInvocationToParent(com.sun.jna.Pointer invocation)
invocation
- Pointer to the objective-c NSInvocation object.public void forwardInvocationToParent(long linvocation)
invocation
- Pointer to the objective-c NSInvocation object.public void forwardInvocation(com.sun.jna.Pointer invocation)
invocation
- NSInvocation Objective-C object that is to be invoked.public void forwardInvocation(long linvocation)
forwardInvocation
in interface Recipient
invocation
- NSInvocation Objective-C object that is to be invoked.public boolean respondsToSelector(com.sun.jna.Pointer selector)
selector
- Pointer to the selector to check.RuntimeUtils.sel()
,
Objective-C selectors referencepublic boolean respondsToSelector(long lselector)
respondsToSelector
in interface Recipient
selector
- Pointer to the selector to check.RuntimeUtils.sel()
,
Objective-C selectors referencepublic NSObject chain(com.sun.jna.Pointer selector, java.lang.Object... args)
public NSObject chain(java.lang.String selector, java.lang.Object... args)
public NSObject dealloc()