Objective-C/Java interaction - java

I have some java code that I use on a windows machine that runs as a service and has a tray icon that I want to port to Mac OS X. From what I can tell there is no good way to make a menu bar icon using java, so I want to basically wrap my java code with objective-c so I can have a nice menu bar icon and still interact with the java code as I am able to when running the code on my windows box. Is there a good way to do this?
My java code makes web requests every so often so the main functionality I'm looking for is to start/stop the web client, as well as receive updates from the java code on the status of the web requests (more or less push notifications).
Thanks for your help everyone!

If all you're trying to do is get your application's icon displayed in the Dock & the Finder, you don't need to write an objective-C wrapper; all you need to do is bundle the Java code up in with the icons in an OS X "application bundle". See Apple's Java Deployment Guide
You might also want to look into the com.apple.eawt package (see questions/1319805/java-os-x-dock-menu), which provides some features to allow a Java app to appear more like a native OS X application to the user (for example, supporting drag-and-dropping a file to the application icon).

Related

How to disable windows keys programmatically?

I want to write a programm which will start Chrome or Firefox browser in full screen with a given URL and will also disable windows keys so that the user can not come out of full screen mode.
User should not be able to do Ctrl-Alt-Del or press windows keys or Alt-Tab etc.
What is the best way to do this? In which programming languages it will be easy to do this?
You should use Winform. WinForms is a graphical (GUI) class library included as a part of Microsoft .NET Framework or Mono Framework, providing a platform to write rich client applications for desktop, laptop, and tablet PCs

How to be able to embed a graphical application inside another

I'm looking for some ideas on the general architecture for creating a Windows application (I'm open to suggestions: Java, C++, C# and also for frameworks) in which I can show another application running inside of it. Very similar to the iframe concept, where a web page is rendered within the frame.
I think I would need to instal the framed application as part of a custom installer, or even assume it is preinstalled in the OS. The important part initially is to be able to framed a graphical application inside another.

Java: Frame/Window between Desktop and Desktop Icons

I just want to know if it is possible in Java to create a frame which is located between the desktop background and the icons on it.
Basically I try to create an "animated desktop background" in Java using Windows 7.
I found some tutorials on how to create a fully transparent window, but the problem remaining is, that this window is still in front of the desktop icons, so its more like a "desktop foreground".
Is there a way to make this foreground to a background?
Are there other ways to achieve this in "pure" Java?
But I guess the only way realizing it with Java is native code via JNI/JNA.
Hopefully you can tell me that I'm wrong ;)
You cannot do it using Swing/AWT. Since the windows api is in c++, it is possible to call some of the functions using JNI.

Launch another instance of Java app on Mac

I have a Mac Java app bundle that has problems opening an OpenGL window from a SWT dialog in a single process. It just doesn't work.
To solve this problem I would like to open a SWT dialog in one instance of the Java app and then have it launch another instance of itself with a parameter saying "this time open the OpenGL window". The part I don't know how to do is finding out what "itself" is on a Mac.
How can I do that?
You might be able to adapt this Swing based Launcher that uses
exec() to run programs in a separate JVM. If you need to include your own dynamic libraries, you might be able to use one of the relative path symbols described in man dyld under the heading Dynamic Library Loading.

Beautifying a SWT application on Mac

SWT is designed to be cross-platform, so it can run on a Mac. The problem is it commits the cardinal sin of Macland - it's UGLY. Toolbars don't look like Mac toolbars, status bars don't look like Mac status bars, etc.
Does anyone have any experience in making an SWT application look more like a Mac application? For example, by making platform-specific JNI calls via the 'OS' class in SWT? If so, how difficult was it?
(This question arises because we are looking at porting an existing SWT app designed to run on Windows)
Thanks
This is usually problem of Swing not SWT (SWT is directly linked to OS/framework provided widgets) - a quote from A gentle introduction to SWT and JFace 2:
SWT is a library that creates a Java
view of the native host operating
system GUI controls. It is host
implementation-dependent. This means
SWT-based applications have several
key characteristics:
1. They look, act, and perform like "native" applications.
2. The widgets provided reflect the widgets (the components and controls) provided on the host operating system.
3. Any special behavior
of the host GUI libraries is reflected
in SWT GUIs.
The pre 3.5 Milestone used to use Carbon framework and now the 3.5+ supports both 32/64bit Cocoa framework 1 so perhaps that has caused you confusion? Or can you be more specific, give us the version you use and some screenshots / sample code to reproduce?
I have been developing java application based on SWT/Eclipse RCP for a while on OSX and have not found and major problem with look&feel (of cause it does not 100% comply the Apple HID 3 as it complies with Eclipse UIG)
The best I can offer is to use either MacWidgets or Quaqua which are both free and in different stages of maturity. The bad news would be that they are both Swing based which is probably not what you want to hear.
You can make your application look and behave like mac application easily. Apple supplies a application called JarBundler with it you can put your menu items up where they belong it will also build a double click able executable, and you can set a icon.
Swing components on Mac OS X looks a lot like their cocoa components, and for OS X you can set some special flags that will make them just like their cocoa counter parts, such as you can set a flag for a JTextField and make it look like cocoa search field.
Also all Macs come with java pre-installed so thats one less worry.
I created support for the Mac OS native toolbar first for Carbon then for the Cocoa version of SWT. At the time I managed to transfer the eclipse perspective switcher to a native toolbar. I had no Obj-C experience so the Cocoa version was more work than the Carbon version, but when all is told, it is not really hard. After supporting the toolbar, I wrote some code to support Alpha Compositing, native image transparency, hardware accelerated effects (CAAnimation). For these, the more difficult part was to understand why some APIs were not even available to be generated by the Eclipse JNI generator. Turned out that the python bridge generator that provided by apple had not been upgraded for the Obj-C 2.0 Property syntax. When I fixed that, I was able to have the SWT JNI Generator spit out the missing APIs. From there, using them was the easy part. You can find some partial pieces of this in the eclipse.org bugzilla server.
I can't say it is always simple, but if you already know Obj-C, then you should be able to do anything you want. A couple days ago I started working on SWT Cocoa again, to add support for ARGB images (as opposed to the limited transparency support offered by ImageData).
Good luck.
I often use the odd "platform queries" to tweak an app. For example, its not really about dressing up an app and more about (for example) making the exit menu option say "Quit" on Mac and "Exit on windows. There are some Mac style guidelines that I can't get round like this but it may help.
See Patform.java for the switching class and ExitAction.java for an example of its use.
Good luck with it :D

Categories