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



Scott Palmer <email@hidden> wrote:

I don't wan the GUI components to fire events that
cause me to update my project document or otherwise mark it as
'modified' by the user.

I always felt that there should be a method to set the state without
trigger listeners.. but it seems that would require two kinds of
listeners... if views listen to the model to show the proper state then
initializing the model from some document should fire those events to
cause the GUI to show the correct state. However if my listeners are
tracking changes to the model to change my document based on user
actions, I don't want these to be called when initializing the model
from the project document.

The model itself should manage whether the document is modified or not.
Your views, all of them, should set or query that state from the model.

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.

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.
But adding a feature to correct avoidable design problems strikes me as a
fundamentally bad idea.

Since this discussion is now entirely theoretical, 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.

-- GG



Greg,

Maybe this falls into what you would call an avoidable design problem, but here goes:

I have a JTabbedPane that a user enters data in to define a geology for a calculational tool. (I'm not allowed to rewrite the calculational tool.) Each geological layer is defined with a depth to the layer, and 7 material properties, in JTextFields. A geology can have up to 22 layers (don't ask why 22). This is a lot of data to fat finger. So for each layer, I have two JComboBoxes. The first JComboBox gives the user the choice of using a predefined set of material properties, or of defining a new material. The second JComboBox allows the user to select a unique predefined material property number, or, if the user wants to define a new material, it generates and selects a unique number to identify that layer. Everything is fine so far, but at the top of the JTabbedPane, I have some other controls. One JButton is labeled: "Set Default Input". A nice control to have. But when the user presses this button, up to 44 JComboBoxes have setSelectedItem () called on them, which fires at least 44 events, which in the action listeners sometimes call setSelectedItem() to make sure their "paired" JComboBox has a consistent selection, and these method calls fire still more events. I have JComboBoxes to insert layers, remove layers, and set the number of layers in the geology. I also have a button to set the inputs to the exact condition they had for a previous saved calculation. All of these involve calling setSelectedItem().

It seems to me that a JComboBox is good way to allow the user to select from a list of choices. Having multiple JComboBoxes that are used in combination to define a geology makes a nice, compact, easy to user interface. I don't want to have to rewrite the model or the view. I want to set the view, and have the model in a state consistent with the view, but I don't want to fire an event to any of my registered listeners. Seems like a simple enough request.

John
--
____________________
John St. Ledger | "There are 10 kinds of people in email@hidden | the world. Those that understand
(505) 667-1154 | binary, and those that don't."
FAX: (505) 665-5283 | Anon
_______________________________________________
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.


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.