eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'RangeAdaptor':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: RangeAdaptor


Inheritance:

   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

Description:


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)

copyright

COPYRIGHT (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.

Class protocol:

instance creation
o  on: aSubject start: startNr stop: endNr
return a range adaptor which starts at startNr, ends at endNr; no grid

o  on: aSubject start: startNr stop: endNr grid: gridNr

o  on: aSubject stop: endNr
return a range adaptor which starts at 0; no grid

o  on: aSubject stop: endNr grid: gridNr
return a range adaptor which starts at 0


Instance protocol:

accessing
o  beLinear

o  beLogarithmic

o  characteristic
nil or #log

o  characteristic: logOrLinearSymbol
logOrLinearSymbol: nil or #log

o  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

o  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

o  rangeStart
return the value of the instance variable 'rangeStart' (automatically generated)

o  rangeStart: something
set the value of the instance variable 'rangeStart' (automatically generated)

o  rangeStop
return the value of the instance variable 'rangeStop' (automatically generated)

o  rangeStop: something
set the value of the instance variable 'rangeStop' (automatically generated)

o  setValue: aNumber
physically set my value, without change notifications;
my value in 0..1 is mapped to the subjects range rangeStart..rangeStop

o  subject

o  subject: aValue

o  value
return my value.
That is the subject's value which is rangeStart..rangeEnd
mapped back into 0..1

o  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
o  decrement
decrement my value by grid (which defaults to 0.01 for 100 steps)

o  increment
increment my value by the grid value (which defaults to 0.01 for 100 steps)

change & update
o  update: anAspect with: aParameter from: changedObject
translate an update from the model into a #value-change
via my depenedents ...

dependents access
o  addDependent: anObject
make the argument, anObject be a dependent of the receiver

o  release
remove all dependencies from the receiver

o  removeDependent: anObject
make the argument, anObject be independent of the receiver

initialization
o  initialize
(comment from inherited method)
just to ignore initialize to objects which do not need it

private
o  setSubjectsValue: aNewValue


Examples:


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}'.
 ].


ST/X 7.7.0.0; WebServer 1.702 at 20f6060372b9.unknown:8081; Sun, 22 Dec 2024 05:01:02 GMT