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



This is one of the major things I find missing from the Swing design: there is no consistent model for making the distinction between "set the state" and "set the state and notify listeners". It makes it difficult to drive the gui programmatically (which is where I'm concerned).

Fundamentally, the state setting has been encapsulated within the model, and the model is supposed to take care of updating the view; the view (actually often the LAF component) handles translating input into listener notifications.

So if you don't have control over the listeners, there's not really a good solution other than using custom models.

With 1.4, you can grab the listener list for most things, so you could potentially remove all listeners while you make the change, and replace them after. You could also temporarily swap out the model for your target component, then swap it back after the change (don't know if that would trigger notifications itself...). Essentially you have to figure out an acceptible (for you) way of disconnecting the listeners while you make the triggering changes, since there is no standard API for doing so.

On Feb 5, 2004, at 9:57 PM, Scott Palmer wrote:

On Feb 5, 2004, G.G. wrote:

The model itself should manage whether the document is modified or not.

This is entirely unreasonable. You are effectively saying that I must replace the default model of almost every single GUI widget in my application

Your views, all of them, should set or query that state from the model.

The default views of Swing components already do this, don't they?

If you have a document model, then you should be able to represent a new
document with that model. Or a modified one, or whatever else the
conceptual model needs.

What does that have to do with what I wrote above?

Maybe I'm missing something, but I still can't see why, with a proper
model/view relationship, you have to make the distinction between
user-initiated and program-initiated events. I *CAN* understand why this
would be convenient if one doesn't have the proper model/view relationship.

Ideally my document would be the model for many of the GUI components. But implementing things that way would be a lot more work than simply using the default models for swing controls and differentiating between initializing the GUI from a newly loaded document and user events intended to modify the document.

But adding a feature to correct avoidable design problems strikes me as a
fundamentally bad idea.

I agree - but it depends on how easily avoidable the design problems are. I still haven't seen a reasonable suggestion as to how to avoid the 'design problem'.

Since this discussion is now entirely theoretical,

Hardly, it relates directly to almost every swing application I have written.

maybe a good example
where the feature's necessity is obvious would be worth seeing. I admit I
can't think of one, so may be someone else can.

If you load a document/project and need to initialize the GUI without the Swing components calling back to listeners that end up marking the document as modified or triggering intensive processing unless you have additional logic in the listeners to ignore the 'programmatic changes' to the model..

Scott
_______________________________________________
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.
_______________________________________________
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>)



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.