Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: com.apple.eawt/jdic/menu extras



I did something similar to this by writing my MenuExtra in Cocoa and then having it communicate with my Java code using XMLRPC. 

On the Cocoa side, I sent out the XMLRPC commands using the following:

- (OSStatus)sendMessage:(NSString *)message withParamString:(NSString *)param result:(NSDictionary **)result
{
NSString *command = [self commandForMessage:message withParamString:param];
NSAppleScript *script = [[[NSAppleScript alloc] initWithSource:source] autorelease];
NSAppleEventDescriptor *descriptor = [script executeAndReturnError:result];
        ... error checking goes here ...
}

- (NSString *)commandForMessage:(NSString *)message withParamString:(NSString *)params
{
return [NSString stringWithFormat:@"\
tell application \"http://localhost:%d\"            \n\
with timeout of 15 seconds          \n\
return call xmlrpc {method name:\"%@\", parameters:{%@}} \n\
             end timeout                         \n\
end tell",
[self port], message, params];
}

And on the Java side I used the Apache XMLRPC code to handle the incoming messages. An example of calling a method named "echo" would look something like:

Cocoa:
       messager = ... init messager object, passing in correct port ...
[messager sendMessage:@"echo" withParamString:@"\"some text\"" result:&result];

Java:
public String echo(String input) {
System.out.println(input);
return input;
}


To enable my menu extra, I used MenuExtraEnabler by unsanity.com. There is a lot of info out there on writing menu extras, so even if you're not familiar with Cocoa you should be able to get something up and running and then do most of your work in Java.


I hope this helps!

John






using unsanity.com's MenuExtraEnabler to make it accessible in the menubar)
On Jan 28, 2008, at 6:31 PM, gonzalo gon wrote:

Hello everyone:

I'm trying to accomplish this: 

I have a java.swing application, and I need to have a
menu that is always user accessible at any point. This
menu has to contain entries like, status, progress,
etc. So how can I accomplish this without having to
implement a menu for each frame of my application?

I've looked at com.apple.eawt javadocs and it gives me
handles to pre-defined entries, but I can't really
make my own(or at least I haven't seen a way to), I've
also looked to the jdic that provides a Tray class,
but Im not sure if this will work under OSX and
finally I've been looking into the posibility of
implementing a menu extra, to acomplish this, but
haven't found too much info on how to do it under
java.

Any suggestions/advice?

Thanks.


      ____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.