Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Application Event Framwork

 
Jason Moors
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm currently developing a large application and have therefore separated functionality into a number of classes which extend JPanel and handle all events locally. These classes are created in the MainClass along with a JMenuBar and JToolBar.
I have also created a number of Action classes which extend AbstractAction which are used by the MenuBar and Toolbar, such as CopyAction, CutAction, etc.
I need a framework for informing objects, contained within the JPanels and child JPanels that a cut/copy event has occurred. I've read about the HMVC (Hierarchical Model View Controller) paradigm but I think it's a bit heavy-weight for what I'm trying to achieve.
Anyone got any ideas?
Thanks
Jason.
 
Chris Shepherd
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've done something like this. I set up a listener interface for my objects that have to be aware of changes made somewhere else. Then in the aware object(the one that causes/knows about the changes) I kept an array/vector of the objects that were registered as listeners then had to run through a for loop and hit each one whenever there was a change. It makes it slightly inconvenient because all your objects that are listeners have to be custom(although just barely) so that they know what to do when you tell them you copied or pasted something. You could set everything up to listen to the same reports no matter what kind of report it was, or you could go so far as to break each different type of action into it's own set of listeners.
Its a pain to setup sometimes, but it really makes updating stuff and triggering special events alot easier. If you need more details, I can give you some examples of what I did.
HTH
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!