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:

> How do you decide to set the
>modified indicator (dot in the close widget on a Mac)?

Since this was specifically unanswered, I figured I'd say how I do it.

In the app I'm working on, my document-model maintains an isUnsaved state.
Whenever any action occurs that can changed the state, I subsequently call
the model's isUnsaved() method, and then do the dot-in-close-widget thing.

At the time I originally wrote the code, I had no idea how long it took for
the windowModified client-property to be processed, so I wrote it to check
the property first and only call setClientProperty() if the unsavedness
state of the document-model differs from the state currently illustrated by
the close-widget. Even if setClientProperty() doesn't take long by itself,
it will potentially send property-change events to listeners. I wanted to
avoid all those, except the necessary ones which actually represent a
change in state. So there was potential value in only updating the
property on genuine state changes.

This turns out to be about a half-dozen lines of code, so I made a private
method for it, illustrateUnsaved(), and call that method in all the
requisite places after a potential document-model change. The
document-model object itself knows nothing of this. It simply exposes
isUnsaved(), and lets the JComponent presenting the model handle the
expression of the isUnsaved() state.

The document-model's unsaved-state is also affected by Undo/Redo/Revert, so
there was a little extra management there, i.e. I had to call
illustrateUnsaved() in the methods that perform those actions on the model.
I support unlimited Undo/Redo between file-saves, so it wasn't really that
big a deal in the overall Undo/Redo/Revert design, since Revert had to do
it anyway.

FWIW, there's a secondary indicator of unsavedness, for platforms that
don't have dots in their close-widgets. Since that indicator is always
driven by an event that delivers a collection of displayable data, all I
had to do there is put the isUnsaved() state of the model into the
collection and deliver it to the listener. What gets displayed where and
how was left entirely to the listener.

-- GG
_______________________________________________
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.