• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Messaging System For TrayIcon

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
author
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Scott. I'll look into it.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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've got no option but to sell you all for scientific experiments. Or a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic