Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #3160

Re: Singletons and Swing

From "tar" <tar@THRWHITE.remove-dii-this>
Subject Re: Singletons and Swing
Message-ID <ymi63wryxie.fsf@blackcat.isi.edu> (permalink)
Newsgroups comp.lang.java.gui
References <74523a1e-4294-4626-a555-7b1fe5a1c4b3@s19g2000prg.googlegroups.com>
Date 2011-04-27 15:43 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui
Jason Cavett <jason.cavett@gmail.com> writes:


[Snip discussion about MenuItems only being in one menu at a time]

> The reason I want InsertMenu to be static is because I want it to
> update everywhere.  Using the Observable pattern didn't really fit
> well in here either.

Well, the standard Swing approach is to use some type of data model,
which is shared among different realizations.  You then build a factory
that keeps a single data model and arranges for all of the components
that can change it to each use the same one.

Now, for menu items this is a bit trickier, since they don't normally
have an explicit model associated with them.  What is it that needs to
be updated everywhere?  What does InsertMenu do anyway?

Perhaps the answer is to build your own subclass of MenuItem that does
have a model which can be shared among instances, and that will take
care of doing the appropriate updating.

> Your suggestions seems to be a good one, except one thing.  If the
> user closes a project, how can I make sure that the InsertMenu
> associated with that project is destroyed?

Well, normally you don't need to worry about such destruction.  I
suppose if you go the factory route, you don't want to keep old items
around that are no longer needed (since that would inhibit garbage
collection).

If you went to a shared model architecture, that should largely take
care of itself, unless you had a reverse link between the model and its
realizations.

I suppose in either case, you could try making use of one of the weak
reference methods to keep one direction of reference, so that the links
wouldn't inhibit garbage collection.

On the other hand, unless there are really going to be a really big
number of these items, it might not be worth the trouble to worry
about. 


-- 
Thomas A. Russ,  USC/Information Sciences Institute

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Singletons and Swing "Jason Cavett" <jason.cavett@THRWHITE.remove-dii-this> - 2011-04-27 15:43 +0000
  Re: Singletons and Swing "Peter Duniho" <peter.duniho@THRWHITE.remove-dii-this> - 2011-04-27 15:43 +0000
    Re: Singletons and Swing "Jason Cavett" <jason.cavett@THRWHITE.remove-dii-this> - 2011-04-27 15:43 +0000
      Re: Singletons and Swing "Peter Duniho" <peter.duniho@THRWHITE.remove-dii-this> - 2011-04-27 15:43 +0000
      Re: Singletons and Swing "tar" <tar@THRWHITE.remove-dii-this> - 2011-04-27 15:43 +0000
  Re: Singletons and Swing "Daniel Pitts" <daniel.pitts@THRWHITE.remove-dii-this> - 2011-04-27 15:43 +0000
    Re: Singletons and Swing "Jason Cavett" <jason.cavett@THRWHITE.remove-dii-this> - 2011-04-27 15:43 +0000

csiph-web