SWT on OS X: how to handle reopen events - java

Usually, on OS X when a user clicks the dock icon of a running application, it will show a window - either brings an existing one to front, de-iconifies an existing one or creates a new one.
How to provide a call-back which is invoked when clicking the dock icon of an SWT application?

Have a look at SWT: how to handle application events correctly on OS X
Also, if you just want to see when a window (or Shell in SWT) is shown, then attach an SWT.Activation listener...

Related

How to keep a program running in background until user clicks its icon to make the window visible?

I am creating a java program that behaves like the Windows' start menu. I want it to run at startup and keep running in the background. When the user clicks application icon i want the window to become visible and again dissapear when the user is finished. The reason i want it to keep running in background is to make the window appear quickly as there are lots of images that need to be preloaded.
I assume that your java application is based on Swing/AWT.
Step1: In Batch file/Shell script, please add & symbol at last and the java program will run it in background.
Example:
Content of batch file / shell script
java XYZ &
Step2: Please ensure that the your application has toplevel container which consists of
Sub container which has Icon (which is visible always)
Sub container like Jpanel/JFrame are initially drawn/painted with
'hide' option.
It ensures that your application is not visible to normal user, but icon container is visible
Step3: Based on user action on icon cotainer, you will hide/show the sub container of JPanel/JFrame.
Step3: Please ensure that icon of your application

How to correctly implement SystemTray/Pinned Taskbar applications on Windows with Java

On OSX my Java application has a dock menu (using Apples extension to Java com.apple.eawt.Application.getApplication().setDockMenu) , allowing tasks to be started by right clicking on the dock icon, also files can be dropped onto the dock icon (Using Apples com.apple.eawt.OpenFilesHandler) and my application starts processing the dropped files.
I'm trying to replicate this functionality if sensible on Windows, if this behaviour on Windows is weird I don't want to do it. I cannot find a way to add tasks to to the popup menu for the application icon on the taskbar (my application is has an .exe wrapper provided by winrun4j), is that possible ?
But I have used java.awt.SystemTray to add a right click menu to that, and it works but I'm unclear in Windows when one would use the taskbar icon and when the SystemTray. What I cannot do is have the SystemTray respond to files being dropped onto it, and according to this Oracle Java issue it will never happen http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=7119272. What I'm unclear about is if the Windows System tray is never meant to respond to things being dropped on it, or if this is just missing functionality in the Java implementation.
And is there way to drag files onto the taskbar icon instead, or is this whole notion of dragging files onto minimized icons purely an OSX thing and not relevent to Windows ?
To answer my own question files cannot be dropped directly onto pinned taskbar icon or the toolbar icon, but if you drag files onto the taskbar icon it should cause the main window to be displayed and then the files can be dropped onto the window instead, and this behaviour happens automtically with no coding required on my part.

Create an inspector style window using Swing/AWT

Is there a way to create a window using Swing or AWT that behaves and looks like an inspector window on Mac OS X? An example of an inspector window would be the window that opens in Finder when Command-Option-I is pressed.
I'm looking for a way to create a window that has a half-height title bar, that always stays on top and that does not get focus e.g. when dragged around.
It is only necessary for the solution to work on Mac OS X, so platform-specific libraries are allowed. But if there is a standard way, event if it has minor drawbacks, it is preferred.
Leopard added some Swing client properties to improve the UI of OS X Java apps – these are described in Technical Note TN2196. The one you're looking for is Window.style:
This property determines if the window has a Utility-style title bar. In order to make this window style also float above all others you must additionally call setAlwaysOnTop(true). Windows that have both the "small" style and are set to always be on top will automatically hide themselves when your application is no longer frontmost. This is similar to how native applications behave.
This property has to be set on the JRootPane of a window before it's native peer is created:
dialog.getRootPane().putClientProperty("Window.style", "small");
ModalityTypes are platform dependent, you have to look for JDialog#ModalityTypes

SWT on Mac OS X: Make program reappear when user clicks on dock icon

I have an SWT application running on Mac OS X. When the user clicks on the 'close' button of the shell, I ignore the close request and just hide the shell by calling Shell.setVisible(false).
Now, how do I make my program reappear when the user clicks on the dock icon? I've tried attaching various listeners to the shell, to no avail. Couldn't find anything helpful via Google either. Thanks in advance.
Courtesy of one of the SmartGit developers (it's this message, but you need to join the group to see it) - they've logged a bug about this:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=358376

System Tray (Menu Extras) icon in Mac Os using Java

I'm developing a desktop application using Java. I want to put an icon (with a contextual menu) on the system tray (called Menu Extras in Mac Os). Java 6 comes with support for doing this in Windows and Linux, but it doesn't work in Mac Os.
I have seen some applications doing what I want in all three operating systems (e.g. DropBox), but I don't know if they are made with Java.
How can I achieve this?
If it's not possible in Java, is there any other cross-platform language able to do that?
Thanks.
AWT / Swing
According to documentation, OSX 10.5 update 1 and newer support TrayIcons
TrayIcons are represented on Mac OS X
using NSStatusMenus that are presented
to the left of the standard system
menu extras. The java.awt.Image
artwork for a TrayIcon is presented in
grayscale as per the Mac OS X standard
for menu extras.
TrayIcon.displayMessage() presents a
small non-modal dialog positioned
under the TrayIcon. The ActionListener
for the TrayIcon is only fired if the
"OK" button on the non-modal dialog is
pressed, and not if the window is
closed using the window close button.
Multiple calls to
TrayIcon.displayMessage() will dismiss
prior messages and leave only the last
message. If the application is not in
the foreground when
TrayIcon.displayMessage() is called,
the application bounces its icon in
the Dock. Message windows are badged
with the application's icon to
identify the which application
triggered the notification.
noah provided this sample:
java.awt.SystemTray.getSystemTray().add(new java.awt.TrayIcon(java.awt.Toolkit.getDefaultToolkit().getImage("foo.png")));
Note that you'll probably want to attach a menu to that icon before adding it to the tray, though.
SWT
According to documentation, SWT 3.3 and newer supports TrayItem icons on OSX.
Icons placed on the system tray will now appear when running on OS X in the status bar.
This snippet shows how to create a menu and icon and put them in the Tray.
I ported a Windows application to my Mac with little difficulty. One thing I noticed is that the icons are in full, living color (not following the Mac convention). I'll need to add a little OS-specific code to convert myself. But this is a big step up from the DLL dependent Desktop integration version from earlier iterations of Java.

Categories

Resources