Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #4395
| From | "ram" <ram@THRWHITE.remove-dii-this> |
|---|---|
| Subject | Re: false edit trigger |
| Message-ID | <fireChange-20081021203458@ram.dialup.fu-berlin.de> (permalink) |
| Newsgroups | comp.lang.java.gui |
| References | <2908b4b4-ca46-400b-b595-38cee345ac36@x1g2000prh.googlegroup |
| Date | 2011-04-27 15:50 +0000 |
| Organization | TDS.net |
To: comp.lang.java.gui
Srik <srikanth.a.r@gmail.com> writes:
>This is actually false edit trigger, the edit has happened only
>programmatically.
This question is an FAQ.
Sometimes people set a flag to indicate programmatic edits.
But maybe this effect also is a sympton showing that something
is wrong with the way the application is built.
Assume a model with a temperature that is being displayed
in two fields +celsius2 and +fahrenheit2.
Then, we have four different operations:
- SCV: set the celsius value alone
- SFV: set the fahrenheit value alone
- STC: set the temperature by a celsius value
- STF: set the temperature by a fahrenheit value
The first two operations only change a single display value,
while the last two will change both display values.
The last two will invoke the first two, but not the last
two themselves (to avoid the recursion mentioned).
Possible implementation (simplified):
SCV( final double t ){ celsiusField.set( String.valueOf( t )); }
SFV( final double t ){ fahrenheitField.set( String.valueOf( t )); }
STC( final double t ){ model.setFromCelsius( t ); /* fire change */ }
STF( final double t ){ model.setFromFahrenheit( t ); /* fire change */ }
model:
setFromCelsius( final double t )
{ this.t = t; display.SCV( t ); display.SFV( t * 180 / 100 + 32 ); }
setFromFahrenheit( final double t )
{ this.t =( t - 32 )* 100 / 180; display.SCV(( t - 32 )* 100 / 180 );
display.SFV( t ); }
The model uses +SCV2 and +SFV2, not +STC2 and +STF2, so it avoids
recursion.
However, this suggestion needs model-view separation that is controlled
by the application program. It might not work when using Swing components,
which are a single unit including /both/ the UI-delegate /and/ the model,
because in this case there is only a single change call to change the
value, and we want to have two different calls.
---
* 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 | Next | Find similar
Re: false edit trigger "ram" <ram@THRWHITE.remove-dii-this> - 2011-04-27 15:50 +0000
csiph-web