Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to distinguish between user selection and programatic selection with ListSelectionListener



Jim Hagen wrote:
| I can't believe this thread is still lingering, but maybe it'll help if
| I explain the approach I've settled on after constructing many
| different data-editing UIs.

What you described is a perfectly good Model-View-Controller design. One not enforcing separation of the parts as determinedly as some might wish, but clearly good enough for your needs. Were it mine, I'd add one more step:

4.5: when the document data is changed, the document broadcasts a "document changed" notification (probably, a PropertyChangeEvent) to alert the interested UI components that what they display needs updating. There would likely be many different flavors of notification, to allow each component to be notified only when *its* datum changed. (This is instead of having each UI object check the document after every change.) If necessary, the notification can carry additional information identifying the location (line, paragraph, table row, whatever) of the changed value(s). (Yes, this makes for lots of listeners, but that isn't a problem in itself. Each one has a very limited responsibility--updating its companion UI component--so things still stay clean.)


| It's not elegant in that I'm not creating a full-on model for a view,

The point isn't "creating a full-on model", but simply storing the document data someplace other than the UI components, so it can be meddled with independently of the UI. Your approach does that. (A "model", after all, is nothing fancier than a data container that can be used separately from the UI classes.)


| and my code often ends up being a 'view is controller' model, where the
| 'view' extends JPanel or JFrame.

Since JPanels don't *directly* display anything, I'd still call it a pure controller. The views are the assorted JTextFields, JTables, JCheckBoxes, and so on which have *visible* state. (If the JPanel is *also* storing document data, then it's part model and part controller, and I'd move the data somewhere else.)


| But I'm writing a minimum of
| action/focus listeners, and I've never had to handle 'user' actions
| differently from 'programatic' actions, probably because the effect of
| any action is pretty limited.

More likely, because all changes funnel through the model, with the views being responsible only for keeping themselves in synch with the model.


Glen Fisher
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: How to distinguish between user selection and programatic selection with ListSelectionListener (From: "John St. Ledger" <email@hidden>)
 >Re: How to distinguish between user selection and programatic selection with ListSelectionListener (From: Scott Palmer <email@hidden>)
 >Re: How to distinguish between user selection and programatic selection with ListSelectionListener (From: Jim Hagen <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.