File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Messaging System For TrayIcon Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Messaging System For TrayIcon" Watch "Messaging System For TrayIcon" New topic
Author

Messaging System For TrayIcon

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Here's what I've got. I've been playing around with the TrayIcon API from the JDIC project. Pretty cool stuff. It's really easy to show those annoying albeit sometimes useful baloon messages.

And here is what I'd like to do. I'd like a simple way for a large application to display messages when necessary. I'd prefer not to have to pass the TrayIcon object around to every class that *might* need it. I'd like to create some sort of observable pattern so that I can notify the object that there is a message to display and what that message is.

Anyone have any suggestions?


GenRocket - Experts at Building Test Data
Scott Delap
author
Ranch Hand

Joined: Apr 05, 2005
Posts: 73
Gregg,

There are a couple options. You could have an observer pattern where some sort of tray icon "view" listens to events. However, you would still have to register your view with the "model" that is firing events. Perhaps one way to address this is to use an EventManager class. You would basically have a central manager to send events to. The tray view would then only have to listen to it. The EventManager itself could be a classic singleton accessed through EventManager.getInstance() or intialized by some flavor of IoC. A similar concept is

http://www.werx.org/werx2/werx2index.jsp

This project creates a bus and channels for it on the fly based on methods that exist in your classes. I would recommend defining marker interfaces for the event methods if you go the werx route however. Hope that helps.

Scott Delap
ClientJava.com
Desktop Java Live
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Thanks Scott. I'll look into it.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15300
    
    6

Ok, test #1. This first way is very simple but I am not sure about it's usablility or if it might come back to bite me later. I create the following class.



Then, when I create my TrayIcon I register it with the EventManager like so:



And then from any other class anywhere I can do the following:



Comments? Good? Bad? I am stupid?
[ June 09, 2005: Message edited by: Gregg Bolinger ]
Scott Delap
author
Ranch Hand

Joined: Apr 05, 2005
Posts: 73
Well the event manager should probably be a little more generic. Instead of having a tray icon specifically, I'd have a generic observer interface. You would create the tray icon and then add it as a listener to the event manager. Your events would have some sort of type so when the tray icon receives one it could say ... "ok this is a display message" I should process it. As things get more complex you also might want to add the idea of a consumable event (Swing does this). So the tray icon would consume the event so other listeners wouldn't have to deal with it.

Scott Delap
ClientJava.com
Desktop Java Live
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Messaging System For TrayIcon