|
Class: RangeAdaptor
Object
|
+--Model
|
+--ValueModel
|
+--ValueHolder
|
+--RangeAdaptor
- Package:
- stx:libview2
- Category:
- Interface-Support-Models
- Version:
- rev:
1.8
date: 2023/07/15 18:32:32
- user: cg
- file: RangeAdaptor.st directory: libview2
- module: stx stc-classLibrary: libview2
Range Adaptor is a kind of UpdateAdaptor that can be used to turn an
arbitrary number (either an Integer or a Float) into a Float normalized between
0 and 1.
Typically, this is used to map a slider or thumbwheel which varies between 0 and 1
into a physical value in another range (for example, a temperature between 20 and 200 degrees)
copyrightCOPYRIGHT (c) 1994 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
instance creation
-
on: aSubject start: startNr stop: endNr
-
return a range adaptor which starts at startNr, ends at endNr; no grid
-
on: aSubject start: startNr stop: endNr grid: gridNr
-
-
on: aSubject stop: endNr
-
return a range adaptor which starts at 0; no grid
-
on: aSubject stop: endNr grid: gridNr
-
return a range adaptor which starts at 0
accessing
-
beLinear
-
-
beLogarithmic
-
-
characteristic
-
nil or #log
-
characteristic: logOrLinearSymbol
-
logOrLinearSymbol: nil or #log
-
grid
-
returns the snap-grid; values are rounded to that grid;
also, increment and decrements use this as step value.
The default grid is off
-
grid: aNumberOrNil
-
sets the snap-grid; values are rounded to that grid;
also, increment and decrements use this as step value if defined.
The default grid nil
-
rangeStart
-
return the value of the instance variable 'rangeStart' (automatically generated)
-
rangeStart: something
-
set the value of the instance variable 'rangeStart' (automatically generated)
-
rangeStop
-
return the value of the instance variable 'rangeStop' (automatically generated)
-
rangeStop: something
-
set the value of the instance variable 'rangeStop' (automatically generated)
-
setValue: aNumber
-
physically set my value, without change notifications;
my value in 0..1 is mapped to the subjects range rangeStart..rangeStop
-
subject
-
-
subject: aValue
-
-
value
-
return my value.
That is the subject's value which is rangeStart..rangeEnd
mapped back into 0..1
-
value: aNumber
-
physically set my value, without change notifications.
Notice, that my value range is 0..1, whereas the subject's range
is rangeStart to rangeEnd
Usage example(s):
|model adaptor|
model := 100 asValue.
adaptor := RangeAdaptor on:model start:100 stop:500.
Transcript showCR:model value.
adaptor value:0.
Transcript showCR:e'0 -> {model value}'.
adaptor value:1.
Transcript showCR:e'1 -> {model value}'.
0 to:1 by:0.1 do:[:aV |
adaptor value:aV.
Transcript showCR:e'{aV} -> {model value}'.
].
'changing the subject...'.
100 to:500 by:50 do:[:mV |
model value:mV.
Transcript showCR:e'reverse; {mV} -> {adaptor value}'.
]
|
actions
-
decrement
-
decrement my value by grid (which defaults to 0.01 for 100 steps)
-
increment
-
increment my value by the grid value (which defaults to 0.01 for 100 steps)
change & update
-
update: anAspect with: aParameter from: changedObject
-
translate an update from the model into a #value-change
via my depenedents ...
dependents access
-
addDependent: anObject
-
make the argument, anObject be a dependent of the receiver
-
release
-
remove all dependencies from the receiver
-
removeDependent: anObject
-
make the argument, anObject be independent of the receiver
initialization
-
initialize
-
(comment from inherited method)
just to ignore initialize to objects which do not need it
private
-
setSubjectsValue: aNewValue
-
scale values 0..1 in the range adaptor to 0..100 in the original model:
|m r|
m := 0 asValue.
r := RangeAdaptor on:m start:0 stop:100 grid:0.01.
m inspect.
r inspect.
|
|m r|
m := 20 degreesCelsius asValue.
r := RangeAdaptor on:m start:20 degreesCelsius stop:200 degreesCelsius grid:0.01.
m inspect.
r inspect.
|
|model adaptor|
model := 100 asValue.
adaptor := RangeAdaptor on:model start:100 stop:500.
Transcript showCR:model value.
adaptor value:0.
Transcript showCR:e'0 -> {model value}'.
adaptor value:1.
Transcript showCR:e'1 -> {model value}'.
'changing the adaptor...updating the subject'.
0 to:1 by:0.1 do:[:aV |
adaptor value:aV.
Transcript showCR:e'{aV} -> {model value}'.
].
'changing the subject...updating the adaptor'.
100 to:500 by:50 do:[:mV |
model value:mV.
Transcript showCR:e'reverse; {mV} -> {adaptor value}'.
].
'stepping the adaptor...updating the subject'.
20 timesRepeat:[
adaptor decrement.
Transcript showCR:e'{adaptor value} -> {model value}'.
].
20 timesRepeat:[
adaptor increment.
Transcript showCR:e'{adaptor value} -> {model value}'.
].
|
typical use: as an adaptor for a slider, scroller or thumbWheel:
The slider slides from 100 to 500.
The adapter goes from 0..1
|v slider thumbWheel display model rangeAdaptor|
model := ValueHolder with:0.
rangeAdaptor := RangeAdaptor on:model start:100 stop:500.
v := TopView new.
slider := Slider origin:(0@0) corner:(10@200) in:v.
slider model:rangeAdaptor.
thumbWheel := ThumbWheel origin:(20@0) corner:(40@100) in:v.
thumbWheel model:rangeAdaptor.
display := DigitalLedDisplay origin:(50@0) in:v.
display numberOfDigits:5.
display model:model.
v open.
|
new feature: logarithmic characteristic
|model adaptor|
model := 100 asValue.
adaptor := RangeAdaptor on:model start:100 stop:500.
adaptor characteristic:#log.
Transcript showCR:model value.
adaptor value:0.
Transcript showCR:e'0 -> {model value}'.
adaptor value:1.
Transcript showCR:e'1 -> {model value}'.
'changing the adaptor...updating the subject'.
0 to:1 by:0.1 do:[:aV |
adaptor value:aV.
Transcript showCR:e'{aV} -> {model value}'.
].
'changing the subject...updating the adaptor'.
100 to:500 by:50 do:[:mV |
model value:mV.
Transcript showCR:e'reverse; {mV} -> {adaptor value}'.
].
'stepping the adaptor...updating the subject'.
20 timesRepeat:[
adaptor decrement.
Transcript showCR:e'{adaptor value} -> {model value}'.
].
20 timesRepeat:[
adaptor increment.
Transcript showCR:e'{adaptor value} -> {model value}'.
].
|
|