TypeConverter.st
author sr
Mon, 13 May 2019 16:23:44 +0200
changeset 4262 b69be50550bb
parent 4178 57a7491ecadb
child 4422 11f7d9bc365f
permissions -rw-r--r--
#BUGFIX by Stefan Reise class: ActiveHelp changed: #basicHelpTextFor:at: care for nil in #aDevicePointOrNil
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4178
57a7491ecadb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 3973
diff changeset
     1
"{ Encoding: utf8 }"
57a7491ecadb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 3973
diff changeset
     2
1355
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
     3
"
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
     4
 COPYRIGHT (c) 1997 eXept Software AG
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
     5
              All Rights Reserved
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
     6
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
     7
 This software is furnished under a license and may be used
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
     8
 only in accordance with the terms of that license and with the
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
    10
 be provided or otherwise made available to, or used by, any
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
    11
 other person.  No title to or ownership of the software is
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
    12
 hereby transferred.
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
    13
"
1406
7cd10ca1a425 smalltalkObject conversion fixed (allow nil)
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
    14
"{ Package: 'stx:libview2' }"
7cd10ca1a425 smalltalkObject conversion fixed (allow nil)
Claus Gittinger <cg@exept.de>
parents: 1355
diff changeset
    15
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
    16
"{ NameSpace: Smalltalk }"
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
    17
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
PluggableAdaptor subclass:#TypeConverter
1426
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
    19
	instanceVariableNames:''
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
    20
	classVariableNames:''
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
    21
	poolDictionaries:''
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
    22
	category:'Interface-Support-Models'
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
!
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    25
!TypeConverter class methodsFor:'documentation'!
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
1355
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
    27
copyright
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
    28
"
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
    29
 COPYRIGHT (c) 1997 eXept Software AG
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
    30
              All Rights Reserved
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
    31
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
    32
 This software is furnished under a license and may be used
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
    33
 only in accordance with the terms of that license and with the
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
    35
 be provided or otherwise made available to, or used by, any
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
    36
 other person.  No title to or ownership of the software is
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
    37
 hereby transferred.
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
    38
"
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
    39
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
    40
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
    41
!
55f97e2d97d2 copyrights
Claus Gittinger <cg@exept.de>
parents: 1335
diff changeset
    42
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
documentation
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
"
722
ea6d08251333 added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
    45
    a typeConverter can be used as an editFields model
ea6d08251333 added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
    46
    (remember, that an editField expects a string in its model),
ea6d08251333 added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
    47
    to convert the fields string value to some object and vice versa.
ea6d08251333 added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
    48
    Its main use is when building interfaces with inputFields,
ea6d08251333 added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
    49
    where the datum to be entered is a non-string and you
ea6d08251333 added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
    50
    want to have the entered value be converted automatically.
ea6d08251333 added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
    51
    (and vice versa, to convert the datum to a string).
ea6d08251333 added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
    52
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
    No real new functionality is added here - all is inherited
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
    from PluggableAdapter; however, some specialized instance creation
947
a5325410e4fd *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 946
diff changeset
    55
    methods are added here.
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
    Notice: 
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
        this class was implemented using protocol information
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
        from alpha testers - it may not be complete or compatible to
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
        the corresponding ST-80 class. 
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
        If you encounter any incompatibilities, please forward a note 
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    62
        describing the incompatibility verbal (i.e. no code) to the ST/X team.
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    63
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    64
    [author:]
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    65
        Claus Gittinger
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    66
"
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    67
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    68
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    69
!
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    70
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    71
examples 
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    72
"
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    73
    convert a number to a string:
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
                                                                        [exBegin]
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    75
        |v t i|
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
        v := 1 asValue.
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    79
        t := HorizontalPanelView new.
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    80
        t extent:200@50.
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    81
        t horizontalLayout:#fitSpace.
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    82
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    83
        i := EditField in:t.
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    84
        i model:(TypeConverter onNumberValue:v).
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    85
        t open.
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    86
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    87
        (Delay forSeconds:3) wait.
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    88
        v value:2.
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    89
                                                                        [exEnd]
942
54949af3f3c1 number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
    90
    convert a number to a string with range:
54949af3f3c1 number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
    91
                                                                        [exBegin]
54949af3f3c1 number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
    92
        |v t i|
54949af3f3c1 number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
    93
54949af3f3c1 number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
    94
        v := 1 asValue.
54949af3f3c1 number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
    95
54949af3f3c1 number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
    96
        t := HorizontalPanelView new.
54949af3f3c1 number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
    97
        t extent:200@50.
54949af3f3c1 number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
    98
        t horizontalLayout:#fitSpace.
54949af3f3c1 number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
    99
54949af3f3c1 number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   100
        i := EditField in:t.
54949af3f3c1 number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   101
        i model:(TypeConverter onNumberValue:v minValue:0 maxValue:100).
54949af3f3c1 number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   102
        t open.
54949af3f3c1 number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   103
54949af3f3c1 number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   104
        (Delay forSeconds:3) wait.
54949af3f3c1 number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   105
        v value:2.
54949af3f3c1 number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   106
                                                                        [exEnd]
487
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   107
    convert a date to a string:
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   108
                                                                        [exBegin]
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   109
        |d v|
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   110
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   111
        v := nil asValue.
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   112
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   113
        d := DialogBox new.
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   114
        d addInputFieldOn:(TypeConverter onDateValue:v).
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   115
        d addOkButton.
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   116
        d open.
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   117
        d accepted ifTrue:[
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   118
            Transcript showCR:v value
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   119
        ]
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   120
                                                                        [exEnd]
2379
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
   121
    convert with thousands:
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
   122
                                                                        [exBegin]
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
   123
        |d v|
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
   124
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
   125
        v := 1234567 asValue.
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
   126
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
   127
        d := DialogBox new.
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
   128
        d addInputFieldOn:((TypeConverter on:v) integerWithThousandsSeparator:$').
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
   129
        d addOkButton.
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
   130
        d open.
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
   131
        d accepted ifTrue:[
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
   132
            Transcript showCR:v value
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
   133
        ]
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
   134
                                                                        [exEnd]
2613
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   135
    convert with scale character:
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   136
                                                                        [exBegin]
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   137
        |d v|
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   138
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   139
        v := 1234567 asValue.
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   140
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   141
        d := DialogBox new.
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   142
        d addInputFieldOn:((TypeConverter on:v) numberWithOptionalScale).
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   143
        d addOkButton.
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   144
        d open.
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   145
        d accepted ifTrue:[
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   146
            Transcript showCR:v value
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   147
        ]
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   148
                                                                        [exEnd]
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   149
    convert with scale character and thousands separator:
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   150
                                                                        [exBegin]
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   151
        |d v scaleDict|
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   152
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   153
        scaleDict := Dictionary new.
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   154
        scaleDict at:$t put:1000.
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   155
        scaleDict at:$k put:1000.
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   156
        scaleDict at:$m put:1000000.
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   157
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   158
        v := 1234567 asValue.
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   159
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   160
        d := DialogBox new.
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   161
        d addInputFieldOn:((TypeConverter on:v) 
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   162
                            numberWithOptionalScales:scaleDict 
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   163
                            andThousandsSeparator:$').
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   164
        d addOkButton.
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   165
        d open.
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   166
        d accepted ifTrue:[
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   167
            Transcript showCR:v value
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   168
        ]
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
   169
                                                                        [exEnd]
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   170
"
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   171
! !
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   172
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   173
!TypeConverter class methodsFor:'instance creation'!
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   174
486
f21ed8fd7df3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 447
diff changeset
   175
onDateValue:aValueHolder
f21ed8fd7df3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 447
diff changeset
   176
    "create and return a typeConverter, which retrieves
f21ed8fd7df3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 447
diff changeset
   177
     a date via #value, and converts
f21ed8fd7df3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 447
diff changeset
   178
     a date-string to a date via #value:.
f21ed8fd7df3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 447
diff changeset
   179
     Useful as an editFields model, which operates on some
f21ed8fd7df3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 447
diff changeset
   180
     date value (or aspectAdaptor, which adapts to a numeric slot)"
f21ed8fd7df3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 447
diff changeset
   181
f21ed8fd7df3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 447
diff changeset
   182
    ^ (self on:aValueHolder) dateToText
f21ed8fd7df3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 447
diff changeset
   183
f21ed8fd7df3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 447
diff changeset
   184
    "Modified: 21.2.1997 / 18:46:11 / cg"
f21ed8fd7df3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 447
diff changeset
   185
    "Created: 4.3.1997 / 12:30:49 / cg"
f21ed8fd7df3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 447
diff changeset
   186
!
f21ed8fd7df3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 447
diff changeset
   187
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   188
onNumberValue:aValueHolder
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   189
    "create and return a typeConverter, which retrieves
3973
440d7bd84437 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   190
     a value's string representation via #value, and converts
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   191
     a number-string to a value via #value:.
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
     Useful as an editFields model, which operates on some
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   193
     numeric value (or aspectAdaptor, which adapts to a numeric slot)"
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   194
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   195
    ^ (self on:aValueHolder) numberToText
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
3973
440d7bd84437 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   197
    "Modified: / 21-02-1997 / 18:46:11 / cg"
440d7bd84437 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3853
diff changeset
   198
    "Modified (comment): / 24-08-2017 / 16:22:21 / cg"
446
e4a8087792d9 checkin from browser
ca
parents: 442
diff changeset
   199
!
e4a8087792d9 checkin from browser
ca
parents: 442
diff changeset
   200
487
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   201
onNumberValue:aValueHolder format:formatString
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   202
    "create and return a typeConverter, which retrieves
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   203
     a values string representation via #value, and converts
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   204
     a number-string to a value via #value:.
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   205
     Useful as an editFields model, which operates on some
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   206
     numeric value (or aspectAdaptor, which adapts to a numeric slot)"
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   207
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   208
    ^ (self on:aValueHolder) numberToTextFormattedBy:formatString
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   209
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   210
    "Created: 4.3.1997 / 11:51:25 / cg"
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   211
    "Modified: 4.3.1997 / 11:51:41 / cg"
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   212
!
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   213
1426
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
   214
onNumberValue:aValueHolder leftPaddedTo:aSize with:aCharacter
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
   215
    "create and return a typeConverter, which retrieves
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
   216
     a values string representation via #value, and converts
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
   217
     a number-string to a value via #value:.
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
   218
     Useful as an editFields model, which operates on some
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
   219
     numeric value (or aspectAdaptor, which adapts to a numeric slot)"
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
   220
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
   221
    ^ (self on:aValueHolder) numberToTextLeftPaddedTo:aSize with:aCharacter
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
   222
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
   223
"
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
   224
  |m|
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
   225
  m := 5 asValue.
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
   226
  ((EditField model:(TypeConverter onNumberValue:m leftPaddedTo:2 with:$-)) width:100) openAt:(200@200).
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
   227
  m inspect.
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
   228
"
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
   229
!
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
   230
941
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
   231
onNumberValue:aValueHolder minValue:min maxValue:max
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
   232
    "create and return a typeConverter, which retrieves
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
   233
     a values string representation via #value, and converts
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
   234
     a number-string to a value via #value:.
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
   235
     Useful as an editFields model, which operates on some
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
   236
     numeric value (or aspectAdaptor, which adapts to a numeric slot)"
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
   237
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
   238
    ^ (self on:aValueHolder) numberToTextMinValue:min maxValue:max
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
   239
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
   240
    "Created: 4.3.1997 / 11:51:25 / cg"
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
   241
    "Modified: 4.3.1997 / 11:51:41 / cg"
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
   242
!
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
   243
747
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   244
onNumberValue:aValueHolder postDecimalDigits:numPostDecimalDigits
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   245
    "create and return a typeConverter, which retrieves
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   246
     a values string representation via #value, and converts
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   247
     a number-string to a value via #value:.
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   248
     Useful as an editFields model, which operates on some
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   249
     numeric value (or aspectAdaptor, which adapts to a numeric slot)"
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   250
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   251
    ^ (self on:aValueHolder) numberToText:numPostDecimalDigits
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   252
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   253
    "Modified: / 21.2.1997 / 18:46:11 / cg"
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   254
    "Created: / 5.12.1997 / 02:55:18 / cg"
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   255
!
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
   256
446
e4a8087792d9 checkin from browser
ca
parents: 442
diff changeset
   257
onSymbolValue:aValueHolder
e4a8087792d9 checkin from browser
ca
parents: 442
diff changeset
   258
    "create and return a typeConverter, which retrieves
e4a8087792d9 checkin from browser
ca
parents: 442
diff changeset
   259
     a symbol-values string representation via #value, and converts
e4a8087792d9 checkin from browser
ca
parents: 442
diff changeset
   260
     a string to a symbol via #value:.
e4a8087792d9 checkin from browser
ca
parents: 442
diff changeset
   261
     Useful as an editFields model, which operates on some
e4a8087792d9 checkin from browser
ca
parents: 442
diff changeset
   262
     numeric value (or aspectAdaptor, which adapts to a numeric slot)"
e4a8087792d9 checkin from browser
ca
parents: 442
diff changeset
   263
e4a8087792d9 checkin from browser
ca
parents: 442
diff changeset
   264
    ^ (self on:aValueHolder) symbolOrNil
e4a8087792d9 checkin from browser
ca
parents: 442
diff changeset
   265
e4a8087792d9 checkin from browser
ca
parents: 442
diff changeset
   266
    "Modified: 21.2.1997 / 18:46:11 / cg"
487
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   267
!
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   268
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   269
onTimeValue:aValueHolder
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   270
    "create and return a typeConverter, which retrieves
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   271
     a time via #value, and converts
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   272
     a time-string to a time via #value:.
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   273
     Useful as an editFields model, which operates on some
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   274
     date value (or aspectAdaptor, which adapts to a numeric slot)"
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   275
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   276
    ^ (self on:aValueHolder) timeToText
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   277
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   278
    "Modified: 21.2.1997 / 18:46:11 / cg"
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   279
    "Created: 4.3.1997 / 11:52:10 / cg"
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   280
! !
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   281
2868
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   282
!TypeConverter class methodsFor:'queries'!
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   283
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   284
possiblePrintConverterTypes
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   285
    "presented in the typeConverter UI-builder menu"
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   286
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   287
    ^ #( 
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   288
        #string
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   289
        #password
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   290
        #number
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   291
        #numberInRange
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   292
        #numberOrNil
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   293
        #numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   294
        #numberOrPointOrNil
3214
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
   295
        #numberOrStringOrSymbolOrNil
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
   296
        #numberOrSymbolOrNil
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
   297
        #numberWithOptionalScale
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
   298
        #integer
2868
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   299
        #integerInRange
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   300
        #integerWithThousandsSeparator
3510
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
   301
        #integerCStyle
2868
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   302
        #fileSize
3252
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
   303
        #frequency
2868
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   304
        #hexadecimal
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   305
        #hexIntegerInRange
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   306
        #symbolOrNil
3214
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
   307
        #symbolOrBooleanOrNil
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
   308
        #symbolOrNumberOrNil
2868
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   309
        #smalltalkObject
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   310
        #smalltalkPoint
3214
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
   311
        #literal
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
   312
        #date
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
   313
        #dateOrNil
2868
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   314
        #dateDDMMYYYY
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   315
        #dateMMDDYYYY
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   316
        #time12H
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   317
        #time24H
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   318
        #time
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   319
        #timeOrNil
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   320
        #timestamp
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   321
        #timestampOrNil 
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   322
        #timeDuration
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   323
        #timeDurationOrNil 
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   324
    ).
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   325
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   326
    "Created: / 25-09-2010 / 11:27:58 / cg"
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   327
! !
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
   328
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   329
!TypeConverter methodsFor:'accessing'!
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   330
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   331
subject
2406
0f7d2545e089 #dateWithFormat: - allow string dates
Stefan Vogel <sv@exept.de>
parents: 2401
diff changeset
   332
    "return the subject to be converted"
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   333
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   334
    ^ model
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   335
!
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   336
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   337
value:newValue
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   338
    "convert and change"
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   339
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   340
    self setValue:newValue
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   341
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   342
    "Created: 21.2.1997 / 18:45:39 / cg"
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   343
! !
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   344
1001
b1517a7164a3 update dependents for not valid inputs
tz
parents: 1000
diff changeset
   345
!TypeConverter methodsFor:'input testing'!
b1517a7164a3 update dependents for not valid inputs
tz
parents: 1000
diff changeset
   346
b1517a7164a3 update dependents for not valid inputs
tz
parents: 1000
diff changeset
   347
setNumberValue: value inModel: model fromInput: string
1463
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
   348
    "for invalid numbers, the model is set to nil. 
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
   349
     By this, the dependents are forced to update their contents
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
   350
     (that is: a bad input string will lead to a cleared input field here)."
1001
b1517a7164a3 update dependents for not valid inputs
tz
parents: 1000
diff changeset
   351
1463
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
   352
    |lastInputChar needChange|
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
   353
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
   354
    string notEmpty ifTrue:[
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
   355
        1 to: string size - 1 do: [:i| (string at: i) isLetter ifTrue: [needChange := true]].
1001
b1517a7164a3 update dependents for not valid inputs
tz
parents: 1000
diff changeset
   356
        lastInputChar := string at: string size.
b1517a7164a3 update dependents for not valid inputs
tz
parents: 1000
diff changeset
   357
        (lastInputChar isDigit not and: [lastInputChar isPrintable and: [
b1517a7164a3 update dependents for not valid inputs
tz
parents: 1000
diff changeset
   358
        (string size > 1               or: [lastInputChar ~~ $-])  and: [
1463
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
   359
        (string occurrencesOf: $.) > 1 or: [lastInputChar ~~ $.]]]]) ifTrue: [needChange := true].
1001
b1517a7164a3 update dependents for not valid inputs
tz
parents: 1000
diff changeset
   360
    ].
b1517a7164a3 update dependents for not valid inputs
tz
parents: 1000
diff changeset
   361
1463
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
   362
    needChange == true ifTrue:[
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
   363
        value notNil ifTrue:[
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
   364
            model setValue:nil
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
   365
        ] ifFalse:[
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
   366
            model value isNil ifTrue:[
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
   367
                model changed:#value.
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
   368
                ^ self
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
   369
            ]
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
   370
        ].
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
   371
    ].
1001
b1517a7164a3 update dependents for not valid inputs
tz
parents: 1000
diff changeset
   372
    model value:value
b1517a7164a3 update dependents for not valid inputs
tz
parents: 1000
diff changeset
   373
! !
b1517a7164a3 update dependents for not valid inputs
tz
parents: 1000
diff changeset
   374
3001
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   375
!TypeConverter methodsFor:'standard converters-date & time'!
722
ea6d08251333 added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
   376
2607
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   377
convertOldVWDateFormatSpecifierToNewSTXFormat:oldFormatSpec
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   378
    "private helper to convert an old (VW) format-Array
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   379
     of the form:
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   380
        'mm/dd/yyyy'      (VW-backward compatibility)
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   381
     into:
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   382
        '%m %d %y'        (new ST/X format)
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   383
    "
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   384
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   385
    |in out c nDigits|
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   386
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   387
    oldFormatSpec isArray ifTrue:[^ oldFormatSpec].
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   388
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   389
    out := '' writeStream.
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   390
    in := oldFormatSpec readStream.
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   391
    [in atEnd] whileFalse:[
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   392
        c := in next.
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   393
        nDigits := 1.
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   394
        c == $m ifTrue:[
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   395
            [in peek == $m] whileTrue:[ nDigits := nDigits + 1. in next ].
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   396
            nDigits == 1 ifTrue:[
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   397
                out nextPutAll:'%M'.    "/ unpadded
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   398
            ] ifFalse:[
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   399
                out nextPutAll:'%m'.
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   400
            ].
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   401
        ] ifFalse:[
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   402
            c == $d ifTrue:[
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   403
                [in peek == $d] whileTrue:[ nDigits := nDigits + 1. in next ].
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   404
                nDigits == 1 ifTrue:[
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   405
                    out nextPutAll:'%D'.    "/ unpadded
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   406
                ] ifFalse:[
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   407
                    out nextPutAll:'%d'.
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   408
                ].
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   409
            ] ifFalse:[
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   410
                c == $y ifTrue:[
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   411
                    [in peek == $y] whileTrue:[ nDigits := nDigits + 1. in next ].
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   412
                    nDigits == 2 ifTrue:[
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   413
                        out nextPutAll:'%Y'.    "/ 2 digits only
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   414
                    ] ifFalse:[
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   415
                        out nextPutAll:'%y'.
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   416
                    ].
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   417
                ] ifFalse:[
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   418
                    out nextPut:c.
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   419
                ].
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   420
            ].
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   421
        ].
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   422
    ].
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   423
    ^ out contents.
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   424
!
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   425
2401
6ce0d64635e0 Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents: 2379
diff changeset
   426
date
6ce0d64635e0 Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents: 2379
diff changeset
   427
    "setup the converter to convert from a string to a date
6ce0d64635e0 Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents: 2379
diff changeset
   428
     and vice versa. Nil is converted to todays date-string,
6ce0d64635e0 Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents: 2379
diff changeset
   429
     likewise, an empty string is converted back to todays date."
6ce0d64635e0 Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents: 2379
diff changeset
   430
6ce0d64635e0 Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents: 2379
diff changeset
   431
    ^ self dateWithFormat:nil orDefault:Date today
6ce0d64635e0 Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents: 2379
diff changeset
   432
!
6ce0d64635e0 Typeconverters for #time #timeOrNil #timestamp #timestampOrNil
Stefan Vogel <sv@exept.de>
parents: 2379
diff changeset
   433
1047
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
   434
dateDDMMYYYY
1026
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   435
    "setup the converter to convert from a string to a date formatted by printFormat
2607
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   436
     DD-MM-YYYY; see also Date>>printFormat:
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   437
     This is a backward compatibility method for very old code to print european-style dates.
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   438
     Please use dateWithFormat: which is much more flexible."
1026
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   439
1266
3420e3a98217 Fix output format of european date.
Stefan Vogel <sv@exept.de>
parents: 1265
diff changeset
   440
    self dateToTextFormattedBy: #(1 2 3 $- 1 1 true)
2607
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   441
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   442
    "
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   443
     |vh|
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   444
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   445
     vh := Date today asValue.
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   446
     TypeConverter new
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   447
        dateDDMMYYYY
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   448
            model:vh;
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   449
            value.    
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   450
     vh value       
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   451
    "
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   452
    "
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   453
     |vh|
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   454
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   455
     vh := Date today asValue.
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   456
     TypeConverter new
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   457
        dateDDMMYYYY
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   458
            model:vh;
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   459
            value:'12-01-2008'.    
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   460
     vh value       
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   461
    "
1026
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   462
!
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   463
1047
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
   464
dateMMDDYYYY
1026
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   465
    "setup the converter to convert from a string to a date formatted by printFormat
2607
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   466
     MM/DD/YYYY; see also Date>>printFormat:
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   467
     This is a backward compatibility method for very old code to print us-style dates.
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   468
     Please use dateWithFormat: which is much more flexible."
1026
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   469
1266
3420e3a98217 Fix output format of european date.
Stefan Vogel <sv@exept.de>
parents: 1265
diff changeset
   470
    self dateToTextFormattedBy: #(2 1 3 $/ 1 1 true)
2607
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   471
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   472
    "
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   473
     |vh|
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   474
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   475
     vh := Date today asValue.
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   476
     TypeConverter new
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   477
        dateMMDDYYYY
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   478
            model:vh;
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   479
            value.    
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   480
     vh value       
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   481
    "
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   482
    "
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   483
     |vh|
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   484
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   485
     vh := Date today asValue.
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   486
     TypeConverter new
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   487
        dateMMDDYYYY
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   488
            model:vh;
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   489
            value:'01/12/2008'.    
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   490
     vh value       
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   491
    "
1026
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   492
!
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   493
487
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   494
dateOrNil
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   495
    "setup the converter to convert from a string to a date
722
ea6d08251333 added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
   496
     and vice versa. Invalid dates are converted to nil; likewise,
ea6d08251333 added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
   497
     a nil date is converted to an empty string."
487
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   498
1832
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   499
    ^ self dateWithFormat:nil orDefault:nil
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   500
!
487
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   501
1832
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   502
dateOrNilWithFormat:aFormatString
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   503
    "setup the converter to convert from a string to a date
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   504
     and vice versa. Invalid dates are converted to nil; likewise,
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   505
     a nil date is converted to an empty string.
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   506
     The format string must have one of the forms:
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   507
        'mm/dd/yyyy'      (for VW-backward compatibility)
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   508
     or:
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   509
        '%m %d %y'
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   510
    "
487
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   511
1832
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   512
    ^ self dateWithFormat:aFormatString orDefault:nil
487
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   513
!
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
   514
486
f21ed8fd7df3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 447
diff changeset
   515
dateToText
f21ed8fd7df3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 447
diff changeset
   516
    "setup the converter to convert from a string to a date
722
ea6d08251333 added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
   517
     and vice versa. Nil is converted to todays date-string,
ea6d08251333 added #arrayLiteralOrSymbolOrNil
Claus Gittinger <cg@exept.de>
parents: 508
diff changeset
   518
     likewise, an empty string is converted back to todays date."
486
f21ed8fd7df3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 447
diff changeset
   519
1832
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   520
    ^ self dateWithFormat:nil orDefault:Date today
486
f21ed8fd7df3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 447
diff changeset
   521
!
f21ed8fd7df3 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 447
diff changeset
   522
1026
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   523
dateToTextFormattedBy: printFormat
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   524
    "setup the converter to convert from a string to a date formatted by printFormat
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   525
     and vice versa. Nil is converted to todays date-string,
1697
3111ef381ed1 *** empty log message ***
penk
parents: 1696
diff changeset
   526
     likewise, an empty string is converted back to todays date.
3111ef381ed1 *** empty log message ***
penk
parents: 1696
diff changeset
   527
     Uses the old, obsolete ST80 printFormat (see Date printFormat:)"
1026
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   528
1832
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   529
    ^ self dateWithFormat:printFormat orDefault:Date today
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   530
!
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   531
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   532
dateWithFormat:aFormatString
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   533
    "setup the converter to convert from a string to a date
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   534
     and vice versa. Invalid dates are converted to nil; likewise,
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   535
     a nil date is converted to an empty string.
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   536
     The format string must have one of the forms:
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   537
        'mm/dd/yyyy'      (for VW-backward compatibility)
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   538
     or:
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   539
        '%m %d %y'
2607
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   540
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   541
     see Date addPrintBindingsTo:language: for a format description.
1832
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   542
    "
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   543
2882
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   544
    ^ self dateWithFormat:aFormatString orDefault:Date today language:nil
2607
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   545
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   546
    "
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   547
     |vh|
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   548
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   549
     vh := Date today asValue.
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   550
     (TypeConverter new
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   551
        dateWithFormat:'%m%d%y')
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   552
            model:vh;
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   553
            value.    
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   554
     vh value       
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   555
    "
2882
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   556
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   557
    "Modified: / 16-01-2011 / 11:20:20 / cg"
1832
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   558
!
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   559
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   560
dateWithFormat:aFormatString orDefault:defaultValue
2882
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   561
    "setup the converter to convert from a string to a date and vice versa. 
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   562
     Invalid dates are converted to nil; 
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   563
     likewise, a nil date is converted to an empty string.
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   564
     The format string must have one of the forms:
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   565
        'mm/dd/yyyy'      (for VW-backward compatibility)
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   566
     or:
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   567
        '%m %d %y'
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   568
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   569
     see Date addPrintBindingsTo:language: for a format description.
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   570
    "
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   571
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   572
    ^ self dateWithFormat:aFormatString orDefault:defaultValue language:nil
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   573
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   574
    "Modified: / 16-01-2011 / 11:19:47 / cg"
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   575
!
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   576
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   577
dateWithFormat:aFormatString orDefault:defaultValue language:lang
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   578
    "setup the converter to convert from a string to a date and vice versa. 
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   579
     Invalid dates are converted to nil; 
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   580
     likewise, a nil date is converted to an empty string.
1832
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   581
     The format string must have one of the forms:
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   582
        'mm/dd/yyyy'      (for VW-backward compatibility)
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   583
     or:
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   584
        '%m %d %y'
2607
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   585
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   586
     see Date addPrintBindingsTo:language: for a format description.
1832
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   587
    "
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   588
2607
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   589
    |stxFormat|
1832
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   590
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   591
    aFormatString notNil ifTrue:[
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   592
        (aFormatString includes:$%) ifTrue:[
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   593
            "/ a new (ST/X) formatString
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   594
            stxFormat := aFormatString
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   595
        ] ifFalse:[
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   596
            "/ an old (VW) formatString
2607
2f81fde8732a comments and examples; old-style VW format fixed.
Claus Gittinger <cg@exept.de>
parents: 2560
diff changeset
   597
            stxFormat := self convertOldVWDateFormatSpecifierToNewSTXFormat:aFormatString
1832
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   598
        ].
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   599
    ].
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   600
1026
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   601
    self
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   602
        getBlock:[:model |
1832
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   603
                |date|
1696
7dbac9fb8894 *** empty log message ***
penk
parents: 1695
diff changeset
   604
1832
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   605
                (date := model value) isNil ifTrue:[
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   606
                    date := defaultValue
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   607
                ].
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   608
                date isNil ifTrue:[
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   609
                    ''
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   610
                ] ifFalse:[
2882
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   611
                    date isString ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   612
                        date 
1832
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   613
                    ] ifFalse:[
2882
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   614
                        stxFormat isNil ifTrue:[
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   615
                            date printStringFormat:(date class defaultFormatString) language:lang
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   616
                        ] ifFalse:[
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   617
                            date printStringFormat:stxFormat language:lang
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   618
                        ].
2406
0f7d2545e089 #dateWithFormat: - allow string dates
Stefan Vogel <sv@exept.de>
parents: 2401
diff changeset
   619
                    ].
0f7d2545e089 #dateWithFormat: - allow string dates
Stefan Vogel <sv@exept.de>
parents: 2401
diff changeset
   620
                ]]
1026
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   621
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   622
        putBlock:
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   623
                [:model :string |
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   624
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   625
                |value|
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   626
2560
03c5e1535b9d isEmptyOrNil
sr
parents: 2559
diff changeset
   627
                string isEmptyOrNil ifTrue:[
1832
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   628
                    value := defaultValue
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   629
                ] ifFalse:[
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   630
                    stxFormat isNil ifTrue:[
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   631
                        value := Date readFrom:string onError:defaultValue
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   632
                    ] ifFalse:[
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   633
                        value := Date readFrom:string printFormat:stxFormat onError:defaultValue
fb54a0eabe13 date conversion cleanup.
Claus Gittinger <cg@exept.de>
parents: 1791
diff changeset
   634
                    ]
1026
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   635
                ].
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   636
                model value:value]
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   637
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   638
        updateBlock: [:m :a :p | true]
2882
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   639
Claus Gittinger <cg@exept.de>
parents: 2868
diff changeset
   640
    "Created: / 16-01-2011 / 11:17:46 / cg"
1026
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   641
!
6b18a2f8833f date + time converters added
tz
parents: 1002
diff changeset
   642
3734
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   643
monthAndYear
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   644
    "setup the converter to convert from a string to a date
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   645
     and vice versa. Invalid dates are converted to nil; likewise,
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   646
     a nil date is converted to an empty string.
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   647
     see Date addPrintBindingsTo:language: for a format description.
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   648
    "
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   649
3736
fd71e21e1136 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3734
diff changeset
   650
    ^ self dateWithFormat:'%y-%m'
3734
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   651
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   652
    "
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   653
     |vh|
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   654
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   655
     vh := Date today asValue.
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   656
     (TypeConverter new monthAndYear)
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   657
            model:vh;
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   658
            value.    
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   659
     vh value       
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   660
    "
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   661
!
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   662
3001
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   663
time
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   664
     ^ self time24H
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   665
!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   666
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   667
time12H
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   668
    "setup the converter to convert from a string to a time formatted by 12 hours
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   669
     and vice versa."
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   670
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   671
    self timeToTextFormattedBy: #printString12HourFormat
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   672
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   673
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   674
!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   675
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   676
time24H
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   677
    "setup the converter to convert from a string to a time formatted by 24 hours
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   678
     and vice versa."
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   679
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   680
    self timeToTextFormattedBy: #printString24HourFormat
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   681
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   682
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   683
!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   684
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   685
timeDuration
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   686
    "setup the converter to convert from a string to a timeduration and vice versa."
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   687
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   688
    ^ self timeOfClass:TimeDuration withFormat:nil orDefault:(0 seconds) language:nil
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   689
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   690
    "Created: / 25-09-2010 / 11:24:57 / cg"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   691
    "Modified: / 16-01-2011 / 11:21:54 / cg"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   692
!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   693
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   694
timeDurationOrNil
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   695
    "setup the converter to convert from a string to a timeDuration and vice versa."
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   696
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   697
    self objectOrNilOfType:TimeDuration
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   698
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   699
    "Created: / 25-09-2010 / 11:25:24 / cg"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   700
!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   701
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   702
timeOfClass:timeClass withFormat:aFormatString orDefault:defaultValue
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   703
    "setup the converter to convert from a string to a time and vice versa. 
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   704
     TimeClass is the class that should be used (e.g. Time or Timestamp). 
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   705
     Invalid times are converted to defaultValue; likewise,
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   706
     a nil time is converted to an empty string."
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   707
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   708
    ^ self timeOfClass:timeClass withFormat:aFormatString orDefault:defaultValue language:nil
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   709
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   710
    "Modified: / 16-01-2011 / 11:21:34 / cg"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   711
!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   712
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   713
timeOfClass:timeClass withFormat:aFormatString orDefault:defaultValue language:langOrNil
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   714
    "setup the converter to convert from a string to a time
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   715
     and vice versa. TimeClass is the class that should be used (e.g. Time or Timestamp). 
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   716
     Invalid times are converted to defaultValue; likewise,
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   717
     a nil time is converted to an empty string."
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   718
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   719
    self
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   720
        getBlock:[:model |
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   721
                |time fmt|
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   722
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   723
                (time := model value) isNil ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   724
                    time := defaultValue
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   725
                ].
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   726
                time isNil ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   727
                    ''
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   728
                ] ifFalse:[
3853
5a78ffcf69de #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3779
diff changeset
   729
                    time isString ifTrue:[
5a78ffcf69de #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3779
diff changeset
   730
                        time "/ not strictly ok, bit we don't want to get a DNU...
5a78ffcf69de #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3779
diff changeset
   731
                    ] ifFalse:[
5a78ffcf69de #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3779
diff changeset
   732
                        (fmt := aFormatString) isNil ifTrue:[
5a78ffcf69de #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3779
diff changeset
   733
                            timeClass = TimeDuration ifTrue:[
5a78ffcf69de #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3779
diff changeset
   734
                                time isInteger ifTrue:[
5a78ffcf69de #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3779
diff changeset
   735
                                    "backward compatibility - show integer time as seconds"
5a78ffcf69de #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3779
diff changeset
   736
                                    time := time seconds.
5a78ffcf69de #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3779
diff changeset
   737
                                ].
5a78ffcf69de #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3779
diff changeset
   738
                                fmt := time formatForPrinting.
5a78ffcf69de #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3779
diff changeset
   739
                            ] ifFalse:[
5a78ffcf69de #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3779
diff changeset
   740
                                fmt := timeClass defaultFormatString
3765
53f3e400ffce #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 3736
diff changeset
   741
                            ].
3001
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   742
                        ].
3853
5a78ffcf69de #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3779
diff changeset
   743
                        time printStringFormat:fmt language:langOrNil
5a78ffcf69de #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3779
diff changeset
   744
                    ]
3001
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   745
                ]]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   746
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   747
        putBlock:
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   748
                [:model :string |
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   749
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   750
                |value|
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   751
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   752
                string isEmptyOrNil ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   753
                    value := defaultValue
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   754
                ] ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   755
"/                    aFormatString isNil ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   756
                        value := timeClass readFrom:string onError:defaultValue
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   757
"/                    ] ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   758
"/                        value := timeClass readFrom:string printFormat:aFormatString onError:defaultValue
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   759
"/                    ]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   760
                ].
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   761
                model value:value]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   762
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   763
        updateBlock: [:m :a :p | true]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   764
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   765
    "Created: / 16-01-2011 / 11:21:07 / cg"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   766
!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   767
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   768
timeOrNil
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   769
    "setup the converter to convert from a string to a time and vice versa."
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   770
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   771
    self objectOrNilOfType:Time
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   772
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   773
    "Created: / 04-03-1997 / 11:52:47 / cg"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   774
    "Modified: / 12-01-2008 / 19:06:21 / cg"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   775
!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   776
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   777
timeStampOrNil
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   778
    <resource: #obsolete>
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   779
    "setup the converter to convert from a string to a timeStamp and vice versa."
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   780
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   781
    self timestampOrNil
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   782
!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   783
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   784
timeToText
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   785
    "setup the converter to convert from a string to a time
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   786
     and vice versa."
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   787
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   788
    self timeToTextFormattedBy: #printString
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   789
!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   790
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   791
timeToTextFormattedBy: format
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   792
    "setup the converter to convert from a string to a time formatted by format
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   793
     and vice versa."
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   794
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   795
    self
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   796
        getBlock:[:model |
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   797
                |time|
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   798
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   799
                (time := model value) isNil ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   800
                    Time now perform: format
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   801
                ] ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   802
                    time perform: format
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   803
                ]]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   804
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   805
        putBlock:
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   806
                [:model :string |
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   807
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   808
                |value|
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   809
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   810
                string isEmptyOrNil ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   811
                    value := Time now
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   812
                ] ifFalse:[              
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   813
                    value := Time readFrom:string onError:[Time now]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   814
                ].
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   815
                model value:value]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   816
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   817
        updateBlock: [:m :a :p | true]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   818
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   819
    "Modified: 21.2.1997 / 18:59:06 / cg"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   820
    "Created: 4.3.1997 / 11:52:47 / cg"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   821
!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   822
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   823
timestamp
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   824
    "setup the converter to convert from a string to a timestamp and vice versa."
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   825
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   826
    ^ self timeOfClass:Timestamp withFormat:nil orDefault:Timestamp now
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   827
!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   828
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   829
timestampOrNil
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   830
    "setup the converter to convert from a string to a timestamp and vice versa."
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   831
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   832
    self objectOrNilOfType:Timestamp
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   833
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   834
    "Modified: / 12-01-2008 / 19:06:06 / cg"
3734
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   835
!
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   836
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   837
year
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   838
    "setup the converter to convert from a string to a date
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   839
     and vice versa. Invalid dates are converted to nil; likewise,
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   840
     a nil date is converted to an empty string.
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   841
     see Date addPrintBindingsTo:language: for a format description.
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   842
    "
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   843
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   844
    ^ self dateWithFormat:'%y'
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   845
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   846
    "
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   847
     |vh|
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   848
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   849
     vh := Date today asValue.
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   850
     (TypeConverter new year)
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   851
            model:vh;
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   852
            value.    
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   853
     vh value       
65ddf082738a #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3510
diff changeset
   854
    "
3001
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   855
! !
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   856
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   857
!TypeConverter methodsFor:'standard converters-misc'!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   858
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   859
arrayLiteralOrStringOrSymbolOrNil
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   860
    "setup the converter to convert from a string to either a literal
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   861
     Array, a String or a symbol and vice versa. 
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   862
     Invalid strings (i.e. empty) are converted to nil;
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   863
     nil values are converted to an empty string.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   864
     This is a very special converter (for the GUI builder) 
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   865
     - probably not belonging to here"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   866
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   867
    self
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   868
        getBlock:[:model |
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   869
                |symbolValue|
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   870
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   871
                (symbolValue := model value) isNil ifTrue:[
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
   872
                    ''
3001
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   873
                ] ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   874
                    symbolValue storeString
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   875
                ]]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   876
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   877
        putBlock:
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   878
                [:model :string |
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   879
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   880
                |value s|
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   881
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   882
                string isEmptyOrNil ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   883
                    value := nil
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   884
                ] ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   885
                    s := string withoutSeparators.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   886
                    (s startsWith:'#(') ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   887
                        value := Array readFrom:s onError:nil
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   888
                    ] ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   889
                        (s startsWith:'''') ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   890
                            value := String readFrom:s onError:nil
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   891
                        ] ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   892
                            (s startsWith:'#') ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   893
                                s := s copyFrom:2
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   894
                            ].
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   895
                            value := s asSymbol
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   896
                        ]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   897
                    ]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   898
                ].
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   899
                model value:value]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   900
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   901
        updateBlock: [:m :a :p | true]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   902
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   903
    "Modified: / 26.10.1997 / 13:50:32 / cg"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   904
    "Created: / 26.10.1997 / 14:01:02 / cg"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   905
!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   906
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   907
arrayLiteralOrSymbolOrNil
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   908
    "setup the converter to convert from a string to either a literal
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   909
     Array or a symbol and vice versa. 
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   910
     Invalid strings (i.e. empty) are converted to nil;
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   911
     nil values are converted to an empty string.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   912
     This is a very special converter (for the GUI builder) 
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   913
     - probably not belonging to here"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   914
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   915
    self
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   916
        getBlock:[:model |
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   917
                |symbolValue|
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   918
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   919
                (symbolValue := model value) isNil ifTrue:[
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
   920
                    ''
3001
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   921
                ] ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   922
                    symbolValue isArray ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   923
                        symbolValue storeString
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   924
                    ] ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   925
                        '#' , symbolValue asString
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   926
                    ]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   927
                ]]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   928
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   929
        putBlock:
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   930
                [:model :string |
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   931
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   932
                |value s|
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   933
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   934
                string isEmptyOrNil ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   935
                    value := nil
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   936
                ] ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   937
                    s := string withoutSeparators.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   938
                    (s startsWith:'#(') ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   939
                        value := Array readFrom:s onError:nil
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   940
                    ] ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   941
                        (s startsWith:'#') ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   942
                            s := s copyFrom:2
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   943
                        ].
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   944
                        value := s asSymbol
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   945
                    ]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   946
                ].
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   947
                model value:value]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   948
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   949
        updateBlock: [:m :a :p | true]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   950
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   951
    "Modified: / 26.10.1997 / 13:50:32 / cg"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   952
    "Created: / 26.10.1997 / 14:01:02 / cg"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   953
!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
   954
1791
33b4fcbb69cf added fileSize converter
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
   955
fileSize
33b4fcbb69cf added fileSize converter
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
   956
    "setup the converter to convert from a fileSize string to a number
33b4fcbb69cf added fileSize converter
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
   957
     and vice versa.
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
   958
     A fileSize can have a scale of 1000 (k or kB), 1024 (ki or kiB),
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
   959
     1000*1000 (m or mB), 1024*1024 (mi or miB), 1000*1000*1000 (g or gB), 1024*1024*1024 (gi or giB)."
1791
33b4fcbb69cf added fileSize converter
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
   960
33b4fcbb69cf added fileSize converter
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
   961
    self
33b4fcbb69cf added fileSize converter
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
   962
        getBlock:[:model |
33b4fcbb69cf added fileSize converter
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
   963
                |numericValue|
33b4fcbb69cf added fileSize converter
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
   964
33b4fcbb69cf added fileSize converter
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
   965
                (numericValue := model value) isNumber ifFalse:[
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
   966
                    ''
1791
33b4fcbb69cf added fileSize converter
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
   967
                ] ifTrue:[  
33b4fcbb69cf added fileSize converter
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
   968
                    UnitConverter fileSizeStringFor:numericValue
33b4fcbb69cf added fileSize converter
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
   969
                ]]
33b4fcbb69cf added fileSize converter
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
   970
33b4fcbb69cf added fileSize converter
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
   971
        putBlock:
33b4fcbb69cf added fileSize converter
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
   972
                [:model :string |
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
   973
                    model value:(UnitConverter fileSizeFromString:string)]
1791
33b4fcbb69cf added fileSize converter
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
   974
33b4fcbb69cf added fileSize converter
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
   975
        updateBlock: [:m :a :p | true]
33b4fcbb69cf added fileSize converter
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
   976
!
33b4fcbb69cf added fileSize converter
Claus Gittinger <cg@exept.de>
parents: 1787
diff changeset
   977
3252
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
   978
frequency
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
   979
    "setup the converter to convert from a frequency string to a number
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
   980
     and vice versa.
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
   981
     A frequency can have a scale of 1000 (k or kHz),
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
   982
     1000*1000 (m or MHz), 1000*1000*1000 (g or GHz)."
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
   983
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
   984
    self
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
   985
        getBlock:[:model |
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
   986
                |numericValue|
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
   987
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
   988
                (numericValue := model value) isNumber ifFalse:[
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
   989
                    ''
3252
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
   990
                ] ifTrue:[  
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
   991
                    UnitConverter frequencyStringFor:numericValue
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
   992
                ]]
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
   993
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
   994
        putBlock:
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
   995
                [:model :string |
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
   996
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
   997
                model value:(UnitConverter frequencyFromString:string)]
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
   998
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
   999
        updateBlock: [:m :a :p | true]
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
  1000
!
974b0b2d3001 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3214
diff changeset
  1001
3001
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1002
literal
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1003
    "setup the converter to convert from a string to a literal
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1004
     and vice versa. Invalid symbols (i.e. empty) are converted to nil;
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1005
     nil values are converted to an empty string.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1006
     true, false, Numbers are parsed"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1007
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1008
    self
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1009
        getBlock:[:model |
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1010
                |val s|
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1011
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1012
                val := model value.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1013
                (val isLiteral and:[val notNil]) ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1014
                    val isSymbol ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1015
                        "print 'special' symbols as symbols i.e. as #'symbol'"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1016
                        (s := val storeString) second == $' ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1017
                            s
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1018
                        ] ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1019
                            val printString
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1020
                        ]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1021
                    ] ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1022
                        val storeString
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1023
                    ].
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1024
                ] ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1025
                    ''.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1026
                ]]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1027
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1028
        putBlock:
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1029
                [:model :string |
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1030
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1031
                |value s|
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1032
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1033
                string size == 0 ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1034
                    value := nil
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1035
                ] ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1036
                    s := string withoutSeparators.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1037
                    "be careful, #readFrom:onError: returns nil for an undefined identifier"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1038
                    s = 'true' ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1039
                        value := true.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1040
                    ] ifFalse:[s = 'false' ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1041
                        value := false.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1042
                    ] ifFalse:[s = 'nil' ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1043
                        value := nil.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1044
                    ] ifFalse:[s first isLetter ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1045
                        value := s asSymbol.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1046
                    ] ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1047
                        value := Object readFrom:s onError:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1048
                            s asSymbol
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1049
                        ].
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1050
                    ]]]].
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1051
                ].
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1052
                model value:value]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1053
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1054
        updateBlock: [:m :a :p | true]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1055
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1056
    "Created: / 21.2.1997 / 18:58:38 / cg"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1057
    "Modified: / 26.5.1998 / 15:06:06 / cg"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1058
!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1059
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1060
objectOrNilOfType:timeOrDateClass
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1061
    "common code for timeOrNil, dateOrNil and timeStampOrNil"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1062
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1063
    self
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1064
        getBlock:[:model |
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1065
                |timeOrDate|
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1066
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1067
                (timeOrDate := model value) isNil ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1068
                    ''
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1069
                ] ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1070
                    timeOrDate printString
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1071
                ]]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1072
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1073
        putBlock:
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1074
                [:model :string |
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1075
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1076
                |value|
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1077
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1078
                string isEmptyOrNil ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1079
                    value := nil
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1080
                ] ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1081
                    value := timeOrDateClass readFrom:string onError:nil
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1082
                ].
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1083
                model value:value]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1084
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1085
        updateBlock: [:m :a :p | true]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1086
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1087
    "Created: / 12-01-2008 / 19:05:18 / cg"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1088
!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1089
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1090
smalltalkObject
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1091
    "setup the converter to convert from a string to any smalltalk object
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1092
     and vice versa. The string used is the objects storeString.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1093
     Invalid strings (i.e. empty) are converted to nil.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1094
     This is a very special converter (for the GUI builder) 
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1095
     - probably not belonging to here"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1096
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1097
    ^ self smalltalkObjectWithClass:Object
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1098
!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1099
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1100
smalltalkObjectOrNil
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1101
    "setup the converter to convert from a string to any smalltalk object
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1102
     and vice versa. The string used is the objects storeString.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1103
     Invalid strings (i.e. empty) are converted to nil.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1104
     This is a very special converter (for the GUI builder) 
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1105
     - probably not belonging to here"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1106
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1107
    ^ self smalltalkObjectOrNilWithClass:Object
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1108
!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1109
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1110
smalltalkObjectOrNilWithClass:classOfObject
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1111
    "setup the converter to convert from a string to a smalltalk object
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1112
     and vice versa. The string used is the objects storeString.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1113
     Invalid strings (i.e. empty) are converted to nil.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1114
     This is a very special converter (for the GUI builder) 
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1115
     - probably not belonging to here"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1116
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1117
    self
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1118
        getBlock:[:model | |v s|
3103
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1119
                    v := model value.
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1120
                    v isNil ifTrue:[
3001
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1121
                        s := 'nil'
3103
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1122
                    ] ifFalse:[
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1123
                        s := v storeString.
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1124
                        (v isString or:[v isNumber]) ifFalse:[
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1125
                            s := s , ' "' , v class name , '" '
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1126
                        ]
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1127
                    ].
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1128
                    s
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1129
                ]
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1130
                
3001
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1131
        putBlock:
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1132
                [:model :string |
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1133
3103
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1134
                   |value|
3001
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1135
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1136
                    string size > 0 ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1137
                        value := classOfObject readFrom:string onError:nil.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1138
                        value := value ? string.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1139
                    ].
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1140
                    model value:value
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1141
                ]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1142
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1143
        updateBlock: [:m :a :p | true]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1144
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1145
    "Created: / 29-10-1997 / 15:50:16 / cg"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1146
    "Modified: / 05-09-2006 / 17:57:53 / cg"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1147
!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1148
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1149
smalltalkObjectWithClass:classOfObject
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1150
    "setup the converter to convert from a string to a smalltalk object
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1151
     and vice versa. The string used is the objects storeString.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1152
     Invalid strings (i.e. empty) are converted to nil.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1153
     This is a very special converter (for the GUI builder) 
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1154
     - probably not belonging to here"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1155
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1156
    self
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1157
        getBlock:[:model | |v s|
3103
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1158
                    v := model value.
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1159
                    v isNil ifTrue:[
3001
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1160
                        s := ''
3103
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1161
                    ] ifFalse:[
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1162
                        s := v storeString.
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1163
                        (v isString or:[v isNumber]) ifFalse:[
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1164
                            s := s , ' "' , v class name , '" '
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1165
                        ]
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1166
                    ].
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1167
                    s
3001
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1168
                 ]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1169
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1170
        putBlock:
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1171
                [:model :string |
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1172
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1173
                    |value|
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1174
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1175
                    string size > 0 ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1176
                        value := classOfObject readFrom:string onError:nil.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1177
                        model value:value ? string
3103
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1178
                    ] ifFalse:[
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1179
                         model value:value
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  1180
                    ]
3001
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1181
                ]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1182
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1183
        updateBlock: [:m :a :p | true]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1184
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1185
    "Created: / 29-10-1997 / 15:50:16 / cg"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1186
    "Modified: / 05-09-2006 / 17:57:37 / cg"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1187
!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1188
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1189
smalltalkPoint
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1190
    "setup the converter to convert from a string to a point object
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1191
     and vice versa. The string used is the points storeString.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1192
     Invalid strings (i.e. empty) are converted to nil.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1193
     This is a very special converter (for the GUI builder) 
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1194
     - probably not belonging to here"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1195
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1196
    ^ self smalltalkObjectWithClass:Point
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1197
!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1198
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1199
symbolOrBooleanOrNil
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1200
    "setup the converter to convert from a string to a symbol or boolean
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1201
     and vice versa. Invalid symbols (i.e. empty) are converted to nil;
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1202
     nil values are converted to an empty string.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1203
     In addition, the strings true/false convert to/from booleans."
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1204
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1205
    self
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1206
        getBlock:[:model |
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1207
                |symbolValue|
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1208
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1209
                ((symbolValue := model value) isSymbol 
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1210
                or:[symbolValue isBoolean]) 
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1211
                ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1212
                    ''
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1213
                ] ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1214
                    (symbolValue == #true or:[symbolValue == #false]) ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1215
                        symbolValue storeString  "/ to show the symbolness
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1216
                    ] ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1217
                        symbolValue printString. "/ storeString
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1218
                    ]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1219
                ]]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1220
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1221
        putBlock:
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1222
                [:model :string |
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1223
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1224
                |value s|
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1225
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1226
                string size == 0 ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1227
                    value := nil
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1228
                ] ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1229
                    s := string withoutSeparators.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1230
                    (s startsWith:'#') ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1231
                        s := s copyFrom:2.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1232
                        (s startsWith:$') ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1233
                            s := s copyFrom:2 to:(s size - 1)
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1234
                        ].
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1235
                        value := s asSymbol
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1236
                    ] ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1237
                        (#('true' 'false') includes:s) ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1238
                            value := Object readFromString:s.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1239
                        ] ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1240
                            value := s asSymbol
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1241
                        ]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1242
                    ].
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1243
                ].
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1244
                model value:value]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1245
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1246
        updateBlock: [:m :a :p | true]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1247
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1248
    "Created: / 21-02-1997 / 18:58:38 / cg"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1249
    "Modified (comment): / 20-03-2012 / 21:25:48 / cg"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1250
!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1251
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1252
symbolOrNil
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1253
    "setup the converter to convert from a string to a symbol
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1254
     and vice versa. Invalid symbols (i.e. empty) are converted to nil;
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1255
     nil values are converted to an empty string."
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1256
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1257
    self
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1258
        getBlock:[:model |
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1259
                |symbolValue|
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1260
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1261
                (symbolValue := model value) isSymbol ifFalse:[
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
  1262
                    ''
3001
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1263
                ] ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1264
                    symbolValue printString. "/ storeString
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1265
                ]]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1266
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1267
        putBlock:
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1268
                [:model :string |
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1269
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1270
                |value s|
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1271
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1272
                string size == 0 ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1273
                    value := nil
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1274
                ] ifFalse:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1275
                    s := string withoutSeparators.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1276
                    (s startsWith:'#') ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1277
                        s := s copyFrom:2.
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1278
                        (s startsWith:$') ifTrue:[
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1279
                            s := s copyFrom:2 to:(s size - 1)
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1280
                        ]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1281
                    ].
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1282
                    value := s asSymbol
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1283
                ].
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1284
                model value:value]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1285
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1286
        updateBlock: [:m :a :p | true]
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1287
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1288
    "Created: / 21.2.1997 / 18:58:38 / cg"
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1289
    "Modified: / 26.5.1998 / 15:06:06 / cg"
3214
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1290
!
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1291
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1292
symbolOrNumberOrNil
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1293
    "setup the converter to convert from a string to a symbol or number
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1294
     and vice versa. Invalid symbols (i.e. empty) are converted to nil;
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1295
     nil values are converted to an empty string."
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1296
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1297
    self
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1298
        getBlock:[:model |
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1299
                |symbolValue|
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1300
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1301
                ((symbolValue := model value) isSymbol 
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1302
                or:[symbolValue isNumber]) 
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1303
                ifFalse:[
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1304
                    ''
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1305
                ] ifTrue:[
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1306
                    symbolValue storeString.
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1307
                ]]
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1308
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1309
        putBlock:
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1310
                [:model :string |
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1311
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1312
                |value s|
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1313
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1314
                string size == 0 ifTrue:[
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1315
                    value := nil
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1316
                ] ifFalse:[
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1317
                    s := string withoutSeparators.
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1318
                    (s startsWith:'#') ifTrue:[
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1319
                        s := s copyFrom:2.
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1320
                        (s startsWith:$') ifTrue:[
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1321
                            s := s copyFrom:2 to:(s size - 1)
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1322
                        ].
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1323
                        value := s asSymbol
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1324
                    ] ifFalse:[
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1325
                        value := Number readFromString:s onError:[s asSymbol].
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1326
                    ].
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1327
                ].
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1328
                model value:value]
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1329
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1330
        updateBlock: [:m :a :p | true]
3001
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1331
! !
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1332
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1333
!TypeConverter methodsFor:'standard converters-numbers'!
053d437c248a category of:63 methods
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
  1334
1122
d8e73d8209d7 hexilein -> hexa
tm
parents: 1047
diff changeset
  1335
hexadecimal
1047
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1336
    "setup the converter to convert from a hexadecimal string to a number
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1337
     and vice versa."
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1338
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1339
    self
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1340
        getBlock:[:model |
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1341
                |hexValue|
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1342
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1343
                (hexValue := model value) isNumber ifFalse:[
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
  1344
                    ''
1047
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1345
                ] ifTrue:[  
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1346
                    hexValue hexPrintString
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1347
                ]]
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1348
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1349
        putBlock:
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1350
                [:model :string |
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1351
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1352
                |value|
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1353
2560
03c5e1535b9d isEmptyOrNil
sr
parents: 2559
diff changeset
  1354
                string isEmptyOrNil ifTrue:[
1047
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1355
                    value := 0
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1356
                ] ifFalse:[     
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1357
                    value := Integer readFrom: string radix:16 onError:[0]
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1358
                ].
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1359
                model value:value]
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1360
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1361
        updateBlock: [:m :a :p | true]
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1362
!
42201709a0bc converter names + hexidecimal converter added
tz
parents: 1027
diff changeset
  1363
2623
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1364
integer
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1365
    "setup the converter to convert from a string to an integer
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1366
     and vice versa. Invalid integers are converted to nil."
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1367
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1368
    self integerToText
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1369
!
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1370
3510
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1371
integerCStyle
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1372
    "setup the converter to convert from a string to an integer
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1373
     and vice versa. Supports CStyle 0x/0b and 0 prefixes
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1374
     Invalid integers are converted to nil."
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1375
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1376
    self integerToTextCStyle 
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1377
!
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1378
2982
6018ea07390a added: #integerOrNil
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  1379
integerOrNil
6018ea07390a added: #integerOrNil
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  1380
    "setup the converter to convert from a string to an integer
6018ea07390a added: #integerOrNil
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  1381
     and vice versa. Invalid numbers are converted to nil."
6018ea07390a added: #integerOrNil
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  1382
6018ea07390a added: #integerOrNil
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  1383
    self objectOrNilOfType:Integer
6018ea07390a added: #integerOrNil
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  1384
6018ea07390a added: #integerOrNil
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  1385
    "Modified: / 12-01-2008 / 19:08:42 / cg"
6018ea07390a added: #integerOrNil
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  1386
    "Created: / 22-01-2012 / 11:28:24 / cg"
6018ea07390a added: #integerOrNil
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  1387
!
6018ea07390a added: #integerOrNil
Claus Gittinger <cg@exept.de>
parents: 2941
diff changeset
  1388
2366
9865c8d52068 +integerToHex
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  1389
integerToHexTextMinValue:minVal maxValue:maxVal format:formatStringOrNil
9865c8d52068 +integerToHex
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  1390
    "setup the converter to convert from a string to a number
9865c8d52068 +integerToHex
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  1391
     and vice versa, but clamping the number into the range."
9865c8d52068 +integerToHex
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  1392
9865c8d52068 +integerToHex
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  1393
    ^ self integerToTextMinValue:minVal maxValue:maxVal radix:16 format:formatStringOrNil
9865c8d52068 +integerToHex
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  1394
!
9865c8d52068 +integerToHex
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  1395
2623
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1396
integerToText
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1397
    "setup the converter to convert from a string to a integer
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1398
     and vice versa."
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1399
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1400
    self
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1401
        getBlock:[:model |
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1402
                |numericValue|
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1403
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1404
                (numericValue := model value) isInteger ifFalse:[
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
  1405
                    ''
2623
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1406
                ] ifTrue:[
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1407
                    numericValue printString
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1408
                ]]
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1409
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1410
        putBlock:
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1411
                [:model :string |
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1412
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1413
                |value|
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1414
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1415
                string isEmptyOrNil ifTrue:[
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1416
                    value := 0
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1417
                ] ifFalse:[
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1418
                    value := Integer readFromString: string onError:[0]
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1419
                ].
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1420
                model value:value]
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1421
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1422
        updateBlock: [:m :a :p | true]
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1423
!
cadc459b3c53 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2620
diff changeset
  1424
3510
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1425
integerToTextCStyle
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1426
    "setup the converter to convert from a string to a integer
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1427
     and vice versa. SUpports C-style integers in the form 0x, 0b 0
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1428
     and also Smalltalk radix integers"
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1429
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1430
    self
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1431
        getBlock:[:model |
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1432
                |numericValue|
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1433
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1434
                (numericValue := model value) isInteger ifFalse:[
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1435
                    ''
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1436
                ] ifTrue:[
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1437
                    numericValue printString
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1438
                ]]
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1439
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1440
        putBlock:
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1441
                [:model :string |
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1442
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1443
                |value|
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1444
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1445
                string isEmptyOrNil ifTrue:[
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1446
                    value := 0
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1447
                ] ifFalse:[
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1448
                    (string startsWith:'0x') ifTrue:[
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1449
                            value := Integer readFromString: (string copyFrom:3) radix:16 onError:[0]
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1450
                    ] ifFalse:[    
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1451
                        (string startsWith:'0b') ifTrue:[
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1452
                            value := Integer readFromString: (string copyFrom:3) radix:2 onError:[0]
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1453
                        ] ifFalse:[    
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1454
                            (string startsWith:'0') ifTrue:[
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1455
                                value := Integer readFromString: string radix:8 onError:[0]
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1456
                            ] ifFalse:[
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1457
                                value := Integer readFromString: string onError:[0]
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1458
                            ]
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1459
                        ]
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1460
                    ]    
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1461
                ].
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1462
                model value:value]
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1463
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1464
        updateBlock: [:m :a :p | true]
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1465
!
c74ee13b72d8 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3486
diff changeset
  1466
1974
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1467
integerToTextMinValue:minVal maxValue:maxVal format:formatStringOrNil
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1468
    "setup the converter to convert from a string to a number
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1469
     and vice versa, but clamping the number into the range."
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1470
2366
9865c8d52068 +integerToHex
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  1471
    ^ self integerToTextMinValue:minVal maxValue:maxVal radix:10 format:formatStringOrNil
9865c8d52068 +integerToHex
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  1472
!
9865c8d52068 +integerToHex
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  1473
9865c8d52068 +integerToHex
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  1474
integerToTextMinValue:minVal maxValue:maxVal radix:radix format:formatStringOrNil
9865c8d52068 +integerToHex
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  1475
    "setup the converter to convert from a string to a number
9865c8d52068 +integerToHex
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  1476
     and vice versa, but clamping the number into the range."
9865c8d52068 +integerToHex
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  1477
1974
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1478
    self
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1479
        getBlock:[:model |
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1480
                |numericValue|
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1481
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1482
                (numericValue := model value) isNil ifTrue:[
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
  1483
                    ''
1974
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1484
                ] ifFalse:[
2379
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
  1485
                    numericValue isString ifTrue:[
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
  1486
                        numericValue    
1974
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1487
                    ] ifFalse:[
2379
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
  1488
                        formatStringOrNil isNil ifTrue:[    
2737
0c83579be3d3 changed #integerToTextMinValue:maxValue:radix:format:
Claus Gittinger <cg@exept.de>
parents: 2623
diff changeset
  1489
                            radix = 10 ifTrue:[
0c83579be3d3 changed #integerToTextMinValue:maxValue:radix:format:
Claus Gittinger <cg@exept.de>
parents: 2623
diff changeset
  1490
                                numericValue printString
0c83579be3d3 changed #integerToTextMinValue:maxValue:radix:format:
Claus Gittinger <cg@exept.de>
parents: 2623
diff changeset
  1491
                            ] ifFalse:[
0c83579be3d3 changed #integerToTextMinValue:maxValue:radix:format:
Claus Gittinger <cg@exept.de>
parents: 2623
diff changeset
  1492
                                numericValue printStringRadix:radix
0c83579be3d3 changed #integerToTextMinValue:maxValue:radix:format:
Claus Gittinger <cg@exept.de>
parents: 2623
diff changeset
  1493
                            ]
2379
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
  1494
                        ] ifFalse:[
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
  1495
                            numericValue printfPrintString:formatStringOrNil
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
  1496
                        ]
1974
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1497
                    ]
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1498
                ]]
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1499
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1500
        putBlock:
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1501
                [:model :string |
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1502
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1503
                |value c|
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1504
2560
03c5e1535b9d isEmptyOrNil
sr
parents: 2559
diff changeset
  1505
                string isEmptyOrNil ifTrue:[
1974
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1506
                    value := 0
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1507
                ] ifFalse:[
2366
9865c8d52068 +integerToHex
Claus Gittinger <cg@exept.de>
parents: 2199
diff changeset
  1508
                    value := Integer readFromString:string radix:radix onError:[0]. 
1974
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1509
                ].               
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1510
                minVal notNil ifTrue:[
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1511
                    (value < minVal and: [string notEmpty]) ifTrue: [model setValue:nil].
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1512
                    value := value max:minVal.
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1513
                ].
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1514
                maxVal notNil ifTrue:[
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1515
                    (value > maxVal and: [string notEmpty]) ifTrue: [model setValue:nil].
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1516
                    value := value min:maxVal.
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1517
                ].
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1518
                self setNumberValue: value inModel: model fromInput: string.
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1519
                ]
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1520
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1521
        updateBlock: [:m :a :p | true]
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1522
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1523
    "Modified: 21.2.1997 / 18:59:44 / cg"
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1524
!
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1525
2379
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
  1526
integerWithThousandsSeparator    
2613
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1527
    ^ self numberWithThousandsSeparator
2379
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
  1528
!
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
  1529
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
  1530
integerWithThousandsSeparator:sep
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
  1531
    "setup the converter to convert from a string to a number with thousands separator
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
  1532
     and vice versa."
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
  1533
2613
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1534
    ^ self numberWithThousandsSeparator:sep
2379
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
  1535
!
d884e4efa6e0 business number printing
Claus Gittinger <cg@exept.de>
parents: 2372
diff changeset
  1536
508
64ee54ff8a77 added #number
Claus Gittinger <cg@exept.de>
parents: 487
diff changeset
  1537
number
64ee54ff8a77 added #number
Claus Gittinger <cg@exept.de>
parents: 487
diff changeset
  1538
    "setup the converter to convert from a string to a number
64ee54ff8a77 added #number
Claus Gittinger <cg@exept.de>
parents: 487
diff changeset
  1539
     and vice versa. Invalid numbers are converted to nil."
64ee54ff8a77 added #number
Claus Gittinger <cg@exept.de>
parents: 487
diff changeset
  1540
64ee54ff8a77 added #number
Claus Gittinger <cg@exept.de>
parents: 487
diff changeset
  1541
    self numberToText
64ee54ff8a77 added #number
Claus Gittinger <cg@exept.de>
parents: 487
diff changeset
  1542
64ee54ff8a77 added #number
Claus Gittinger <cg@exept.de>
parents: 487
diff changeset
  1543
    "Created: 4.4.1997 / 12:46:14 / cg"
64ee54ff8a77 added #number
Claus Gittinger <cg@exept.de>
parents: 487
diff changeset
  1544
!
64ee54ff8a77 added #number
Claus Gittinger <cg@exept.de>
parents: 487
diff changeset
  1545
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1546
numberOrNil
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1547
    "setup the converter to convert from a string to a number
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1548
     and vice versa. Invalid numbers are converted to nil."
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1549
2372
abd41b275bee *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2366
diff changeset
  1550
    self objectOrNilOfType:Number
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1551
2372
abd41b275bee *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2366
diff changeset
  1552
    "Modified: / 12-01-2008 / 19:08:42 / cg"
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1553
!
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1554
1463
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1555
numberOrNilToTextMinValue:minVal maxValue:maxVal
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1556
    "setup the converter to convert from a string to a number or nil
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1557
     and vice versa, but clamping the number into the range."
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1558
1974
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1559
    self numberOrNilToTextMinValue:minVal maxValue:maxVal format:nil
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1560
!
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1561
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1562
numberOrNilToTextMinValue:minVal maxValue:maxVal format:formatStringOrNil
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1563
    "setup the converter to convert from a string to a number or nil
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1564
     and vice versa, but clamping the number into the range."
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1565
1463
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1566
    self
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1567
        getBlock:[:model |
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1568
                |numericValue|
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1569
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1570
                (numericValue := model value) isNil ifTrue:[
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
  1571
                    ''
1463
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1572
                ] ifFalse:[
1974
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1573
                    formatStringOrNil isNil ifTrue:[    
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1574
                        numericValue printString
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1575
                    ] ifFalse:[
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1576
                        numericValue printfPrintString:formatStringOrNil
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1577
                    ]
1463
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1578
                ]]
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1579
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1580
        putBlock:
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1581
                [:model :string |
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1582
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1583
                |value c|
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1584
4178
57a7491ecadb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 3973
diff changeset
  1585
                (string isNil or:[string isBlank]) ifTrue:[
1463
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1586
                    value := nil
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1587
                ] ifFalse:[
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1588
                    value := Number readFromString:string onError:[nil]. 
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1589
                    value isNil ifTrue:[
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1590
                        
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1591
                    ] ifFalse:[
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1592
                        minVal notNil ifTrue:[
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1593
                            (value < minVal and: [string notEmpty]) ifTrue: [model setValue:nil].
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1594
                            value := value max:minVal.
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1595
                        ].
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1596
                        maxVal notNil ifTrue:[
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1597
                            (value > maxVal and: [string notEmpty]) ifTrue: [model setValue:nil].
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1598
                            value := value min:maxVal.
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1599
                        ].
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1600
                    ].
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1601
                ].
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1602
                self setNumberValue: value inModel: model fromInput: string.
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1603
                ]
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1604
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1605
        updateBlock: [:m :a :p | true]
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1606
4178
57a7491ecadb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 3973
diff changeset
  1607
    "Modified: / 21-02-1997 / 18:59:44 / cg"
57a7491ecadb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 3973
diff changeset
  1608
    "Modified: / 14-09-2018 / 10:08:59 / Stefan Vogel"
1463
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1609
!
df2fec4aad9c added numberInRangeOrNil
Claus Gittinger <cg@exept.de>
parents: 1426
diff changeset
  1610
1335
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1611
numberOrPointOrNil
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1612
    "setup the converter to convert from a string to a number or point
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1613
     and vice versa. Invalid numbers/points are converted to nil."
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1614
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1615
    self
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1616
        getBlock:[:model |
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1617
                |value|
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1618
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1619
                (value := model value) isNil ifTrue:[
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
  1620
                    ''
1335
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1621
                ] ifFalse:[
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1622
                    value printString
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1623
                ]]
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1624
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1625
        putBlock:
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1626
                [:model :string |
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1627
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1628
                |value|
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1629
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1630
                string size > 0 ifTrue:[
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1631
                    value := Point readFrom:string onError:[
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1632
                        Number readFrom:string onError:nil
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1633
                    ]
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1634
                ]. 
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1635
                model value:value]
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1636
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1637
        updateBlock: [:m :a :p | true]
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1638
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1639
    "Created: / 5.2.2000 / 01:26:48 / cg"
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1640
!
275352274890 a new converter: numberOrPointOrNil.
Claus Gittinger <cg@exept.de>
parents: 1314
diff changeset
  1641
1149
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1642
numberOrStringOrSymbolOrNil
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1643
    "setup the converter to convert from a string to either a numeric literal
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1644
     or a symbol and vice versa. 
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1645
     Invalid strings (i.e. empty) are converted to nil;
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1646
     nil values are converted to an empty string.
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1647
     This is a very special converter (for the GUI builder) 
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1648
     - probably not belonging to here"
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1649
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1650
    self
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1651
        getBlock:[:model |
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1652
                |litValue|
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1653
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1654
                (litValue := model value) isNil ifTrue:[
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
  1655
                    ''
1149
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1656
                ] ifFalse:[
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1657
                    litValue storeString
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1658
                ]]
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1659
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1660
        putBlock:
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1661
                [:model :string |
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1662
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1663
                |value s|
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1664
2560
03c5e1535b9d isEmptyOrNil
sr
parents: 2559
diff changeset
  1665
                string isEmptyOrNil ifTrue:[
1149
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1666
                    value := nil
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1667
                ] ifFalse:[
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1668
                    value := Number readFrom:string onError:nil.
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1669
                    value isNil ifTrue:[
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1670
                        s := string withoutSeparators.
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1671
                        (s startsWith:'''') ifTrue:[
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1672
                            value := String readFrom:s readStream onError:nil
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1673
                        ] ifFalse:[
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1674
                            (s startsWith:'#') ifTrue:[
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1675
                                s := s copyFrom:2.
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1676
                                (s startsWith:$') ifTrue:[
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1677
                                    s := s copyFrom:2 to:(s size - 1)
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1678
                                ].
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1679
                            ].
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1680
                            value := s asSymbol
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1681
                        ]
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1682
                    ]
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1683
                ].
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1684
                model value:value]
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1685
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1686
        updateBlock: [:m :a :p | true]
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1687
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1688
    "Modified: / 26.10.1997 / 13:50:32 / cg"
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1689
    "Created: / 29.10.1997 / 15:49:26 / cg"
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1690
!
80a780b5a1b5 new converters
Claus Gittinger <cg@exept.de>
parents: 1122
diff changeset
  1691
726
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1692
numberOrSymbolOrNil
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1693
    "setup the converter to convert from a string to either a numeric literal
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1694
     or a symbol and vice versa. 
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1695
     Invalid strings (i.e. empty) are converted to nil;
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1696
     nil values are converted to an empty string.
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1697
     This is a very special converter (for the GUI builder) 
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1698
     - probably not belonging to here"
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1699
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1700
    self
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1701
        getBlock:[:model |
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1702
                |litValue|
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1703
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1704
                (litValue := model value) isNil ifTrue:[
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
  1705
                    ''
726
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1706
                ] ifFalse:[
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1707
                    litValue storeString
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1708
                ]]
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1709
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1710
        putBlock:
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1711
                [:model :string |
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1712
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1713
                |value s|
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1714
2560
03c5e1535b9d isEmptyOrNil
sr
parents: 2559
diff changeset
  1715
                string isEmptyOrNil ifTrue:[
726
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1716
                    value := nil
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1717
                ] ifFalse:[
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1718
                    value := Number readFrom:string onError:nil.
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1719
                    value isNil ifTrue:[
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1720
                        s := string withoutSeparators.
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1721
                        (s startsWith:'#') ifTrue:[
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1722
                            s := s copyFrom:2.
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1723
                            (s startsWith:$') ifTrue:[
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1724
                                s := s copyFrom:2 to:(s size - 1)
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1725
                            ].
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1726
                        ].
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1727
                        value := s asSymbol
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1728
                    ]
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1729
                ].
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1730
                model value:value]
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1731
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1732
        updateBlock: [:m :a :p | true]
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1733
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1734
    "Modified: / 26.10.1997 / 13:50:32 / cg"
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1735
    "Created: / 29.10.1997 / 15:49:26 / cg"
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1736
!
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1737
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1738
numberToText
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1739
    "setup the converter to convert from a string to a number
487
c7465591e41a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 486
diff changeset
  1740
     and vice versa."
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1741
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1742
    self
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1743
        getBlock:[:model |
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1744
                |numericValue|
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1745
726
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1746
                (numericValue := model value) isNumber ifFalse:[
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
  1747
                    ''
726
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1748
                ] ifTrue:[
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1749
                    numericValue printString
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1750
                ]]
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1751
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1752
        putBlock:
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1753
                [:model :string |
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1754
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1755
                |value|
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1756
2560
03c5e1535b9d isEmptyOrNil
sr
parents: 2559
diff changeset
  1757
                string isEmptyOrNil ifTrue:[
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1758
                    value := 0
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1759
                ] ifFalse:[
1000
70e95e4dca22 use #readFromString:onError: for string->number convertations
tz
parents: 997
diff changeset
  1760
                    value := Number readFromString: string onError:[0]
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1761
                ].
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1762
                model value:value]
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1763
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1764
        updateBlock: [:m :a :p | true]
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1765
726
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1766
    "Created: / 21.2.1997 / 18:57:05 / cg"
cdab756aebe4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 722
diff changeset
  1767
    "Modified: / 29.10.1997 / 15:49:21 / cg"
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1768
!
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1769
747
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1770
numberToText:numberOfPostDecimals
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1771
    "setup the converter to convert from a string to a number
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1772
     and vice versa."
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1773
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1774
    self
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1775
        getBlock:[:model |
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1776
                |numericValue|
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1777
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1778
                (numericValue := model value) isNumber ifFalse:[
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
  1779
                    ''
747
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1780
                ] ifTrue:[
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1781
                    (numericValue asFixedPoint:numberOfPostDecimals) printString
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1782
                ]]
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1783
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1784
        putBlock:
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1785
                [:model :string |
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1786
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1787
                |value|
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1788
2560
03c5e1535b9d isEmptyOrNil
sr
parents: 2559
diff changeset
  1789
                string isEmptyOrNil ifTrue:[
747
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1790
                    value := 0
1000
70e95e4dca22 use #readFromString:onError: for string->number convertations
tz
parents: 997
diff changeset
  1791
                ] ifFalse:[     
70e95e4dca22 use #readFromString:onError: for string->number convertations
tz
parents: 997
diff changeset
  1792
                    value := Number readFromString:string onError:[0]
747
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1793
                ].
1001
b1517a7164a3 update dependents for not valid inputs
tz
parents: 1000
diff changeset
  1794
                self setNumberValue: value inModel: model fromInput: string.
b1517a7164a3 update dependents for not valid inputs
tz
parents: 1000
diff changeset
  1795
                ]
747
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1796
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1797
        updateBlock: [:m :a :p | true]
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1798
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1799
    "Created: / 5.12.1997 / 02:54:13 / cg"
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1800
    "Modified: / 5.12.1997 / 18:21:04 / cg"
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1801
!
fe0360fb81ee added typeConverter for decimals with n digits after point
Claus Gittinger <cg@exept.de>
parents: 726
diff changeset
  1802
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1803
numberToTextFormattedBy:formatString
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1804
    "setup the converter to convert from a string to a number
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1805
     and vice versa, using formatString.
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1806
     The formatString is currently ignored when numbers are converted
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1807
     from a string."
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1808
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1809
    self
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1810
        getBlock:[:model |
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1811
                |numericValue|
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1812
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1813
                (numericValue := model value) isNil ifTrue:[
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
  1814
                    ''
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1815
                ] ifFalse:[
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1816
                    PrintConverter print:numericValue formattedBy:formatString
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1817
                ]]
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1818
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1819
        putBlock:
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1820
                [:model :string |
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1821
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1822
                |value|
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1823
2560
03c5e1535b9d isEmptyOrNil
sr
parents: 2559
diff changeset
  1824
                string isEmptyOrNil ifTrue:[
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1825
                    value := 0
1000
70e95e4dca22 use #readFromString:onError: for string->number convertations
tz
parents: 997
diff changeset
  1826
                ] ifFalse:[          
70e95e4dca22 use #readFromString:onError: for string->number convertations
tz
parents: 997
diff changeset
  1827
                    value := Number readFromString: string onError:[0]. "asNumberFromFormatString:formatString"
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1828
                ].
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1829
                model value:value]
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1830
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1831
        updateBlock: [:m :a :p | true]
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1832
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  1833
    "Modified: 21.2.1997 / 18:59:44 / cg"
446
e4a8087792d9 checkin from browser
ca
parents: 442
diff changeset
  1834
!
e4a8087792d9 checkin from browser
ca
parents: 442
diff changeset
  1835
1426
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1836
numberToTextLeftPaddedTo:aSize with:aCharacter
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1837
    "setup the converter to convert from a string to a number
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1838
     and vice versa, using formatString.
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1839
     The formatString is currently ignored when numbers are converted
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1840
     from a string."
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1841
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1842
    self
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1843
        getBlock:[:model |
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1844
                |numericValue|
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1845
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1846
                (numericValue := model value) isNil ifTrue:[
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
  1847
                    ''
1426
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1848
                ] ifFalse:[
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1849
                    numericValue printStringLeftPaddedTo:aSize with:aCharacter
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1850
                ]]
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1851
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1852
        putBlock:
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1853
                [:model :string |
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1854
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1855
                |value|
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1856
2560
03c5e1535b9d isEmptyOrNil
sr
parents: 2559
diff changeset
  1857
                string isEmptyOrNil ifTrue:[
1426
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1858
                    value := 0
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1859
                ] ifFalse:[          
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1860
                    value := Number readFromString: string onError:[0]. "asNumberFromFormatString:formatString"
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1861
                ].
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1862
                model value:value]
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1863
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1864
        updateBlock: [:m :a :p | true]
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1865
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1866
    "Modified: 21.2.1997 / 18:59:44 / cg"
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1867
!
6a5f5372fcc4 added: a converter for number - string, string lwftpaddedTo: with:
tm
parents: 1407
diff changeset
  1868
941
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
  1869
numberToTextMinValue:minVal maxValue:maxVal
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
  1870
    "setup the converter to convert from a string to a number
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
  1871
     and vice versa, but clamping the number into the range."
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
  1872
1974
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1873
    self numberToTextMinValue:minVal maxValue:maxVal format:nil
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1874
!
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1875
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1876
numberToTextMinValue:minVal maxValue:maxVal format:formatStringOrNil
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1877
    "setup the converter to convert from a string to a number
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1878
     and vice versa, but clamping the number into the range."
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1879
941
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
  1880
    self
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
  1881
        getBlock:[:model |
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
  1882
                |numericValue|
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
  1883
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
  1884
                (numericValue := model value) isNil ifTrue:[
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
  1885
                    ''
941
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
  1886
                ] ifFalse:[
1974
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1887
                    formatStringOrNil isNil ifTrue:[    
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1888
                        numericValue printString
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1889
                    ] ifFalse:[
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1890
                        numericValue printfPrintString:formatStringOrNil
025c3119062b converters with format and integerToText added
werner
parents: 1832
diff changeset
  1891
                    ]
941
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
  1892
                ]]
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
  1893
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
  1894
        putBlock:
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
  1895
                [:model :string |
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
  1896
1001
b1517a7164a3 update dependents for not valid inputs
tz
parents: 1000
diff changeset
  1897
                |value c|
941
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
  1898
2560
03c5e1535b9d isEmptyOrNil
sr
parents: 2559
diff changeset
  1899
                string isEmptyOrNil ifTrue:[
941
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
  1900
                    value := 0
1001
b1517a7164a3 update dependents for not valid inputs
tz
parents: 1000
diff changeset
  1901
                ] ifFalse:[
997
9871b863dc3a it does invoke a debugger for wrong inputs
tz
parents: 947
diff changeset
  1902
                    value := Number readFromString: string onError:[0]. 
1000
70e95e4dca22 use #readFromString:onError: for string->number convertations
tz
parents: 997
diff changeset
  1903
                ].               
942
54949af3f3c1 number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
  1904
                minVal notNil ifTrue:[
1001
b1517a7164a3 update dependents for not valid inputs
tz
parents: 1000
diff changeset
  1905
                    (value < minVal and: [string notEmpty]) ifTrue: [model setValue:nil].
942
54949af3f3c1 number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
  1906
                    value := value max:minVal.
54949af3f3c1 number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
  1907
                ].
54949af3f3c1 number-in-range may have nil-bounds
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
  1908
                maxVal notNil ifTrue:[
1001
b1517a7164a3 update dependents for not valid inputs
tz
parents: 1000
diff changeset
  1909
                    (value > maxVal and: [string notEmpty]) ifTrue: [model setValue:nil].
944
4ef99f8da24f checkin from browser
Claus Gittinger <cg@exept.de>
parents: 943
diff changeset
  1910
                    value := value min:maxVal.
1001
b1517a7164a3 update dependents for not valid inputs
tz
parents: 1000
diff changeset
  1911
                ].
b1517a7164a3 update dependents for not valid inputs
tz
parents: 1000
diff changeset
  1912
                self setNumberValue: value inModel: model fromInput: string.
b1517a7164a3 update dependents for not valid inputs
tz
parents: 1000
diff changeset
  1913
                ]
941
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
  1914
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
  1915
        updateBlock: [:m :a :p | true]
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
  1916
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
  1917
    "Modified: 21.2.1997 / 18:59:44 / cg"
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
  1918
!
ba196649eaec added converter for number-in-range
Claus Gittinger <cg@exept.de>
parents: 747
diff changeset
  1919
2613
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1920
numberWithOptionalScale
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1921
    "setup the converter to convert from a string to a number
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1922
     and vice versa. Invalid numbers are converted to nil.
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1923
     The number may be followed by one of m (for million) or
2620
7bd45a3ea825 Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents: 2613
diff changeset
  1924
     k (for thousand). E.g.: '1m2k55' "
2613
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1925
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1926
    |scaleDict|
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1927
2620
7bd45a3ea825 Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents: 2613
diff changeset
  1928
    scaleDict := Dictionary withKeysAndValues:#(
3214
d39b11efa0a6 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3103
diff changeset
  1929
            $g 1000000000
2620
7bd45a3ea825 Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents: 2613
diff changeset
  1930
            $m 1000000
7bd45a3ea825 Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents: 2613
diff changeset
  1931
            $k    1000
7bd45a3ea825 Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents: 2613
diff changeset
  1932
            $t    1000
7bd45a3ea825 Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents: 2613
diff changeset
  1933
        ).
2613
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1934
    self numberWithOptionalScales:scaleDict
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1935
!
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1936
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1937
numberWithOptionalScales:scaleDict
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1938
    "setup the converter to convert from a string to a number or nil
2620
7bd45a3ea825 Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents: 2613
diff changeset
  1939
     and vice versa; allow for scale characters (such as k for thousand).
7bd45a3ea825 Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents: 2613
diff changeset
  1940
7bd45a3ea825 Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents: 2613
diff changeset
  1941
     E.g. '1m2k55' "
2613
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1942
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1943
    self
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1944
        getBlock:[:model |
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1945
                    |numericValue|
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1946
2620
7bd45a3ea825 Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents: 2613
diff changeset
  1947
                    numericValue := model value.
7bd45a3ea825 Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents: 2613
diff changeset
  1948
                    numericValue isEmptyOrNil ifTrue:[
7bd45a3ea825 Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents: 2613
diff changeset
  1949
                        ''
2613
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1950
                    ] ifFalse:[
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1951
                        numericValue printString
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1952
                    ]
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1953
                ]
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1954
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1955
        putBlock:
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1956
                [:model :string |
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1957
2620
7bd45a3ea825 Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents: 2613
diff changeset
  1958
                    |value c stream scaleChar scale partValue|
2613
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1959
4178
57a7491ecadb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 3973
diff changeset
  1960
                    (string isNil or:[string isBlank]) ifTrue:[
2613
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1961
                        value := nil
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1962
                    ] ifFalse:[
2620
7bd45a3ea825 Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents: 2613
diff changeset
  1963
                        value := 0.
2613
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1964
                        stream := string readStream.
2620
7bd45a3ea825 Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents: 2613
diff changeset
  1965
                        [
7bd45a3ea825 Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents: 2613
diff changeset
  1966
                            partValue := Number readFrom:stream onError:[nil]. 
7bd45a3ea825 Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents: 2613
diff changeset
  1967
                            partValue notNil ifTrue:[
7bd45a3ea825 Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents: 2613
diff changeset
  1968
                                stream skipSeparators.
7bd45a3ea825 Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents: 2613
diff changeset
  1969
                                scaleChar := stream nextOrNil.
7bd45a3ea825 Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents: 2613
diff changeset
  1970
                                scale := scaleDict at:scaleChar ifAbsent:1.
7bd45a3ea825 Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents: 2613
diff changeset
  1971
                                value := value + (partValue * scale).
7bd45a3ea825 Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents: 2613
diff changeset
  1972
                            ].
7bd45a3ea825 Fix #numberWithOptionalScale to handle '1m2k55'
Stefan Vogel <sv@exept.de>
parents: 2613
diff changeset
  1973
                        ] doWhile:[partValue notNil].
2613
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1974
                    ].
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1975
                    self setNumberValue: value inModel: model fromInput: string.
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1976
                ]
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1977
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1978
        updateBlock: [:m :a :p | true]
4178
57a7491ecadb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 3973
diff changeset
  1979
57a7491ecadb #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 3973
diff changeset
  1980
    "Modified: / 14-09-2018 / 10:09:09 / Stefan Vogel"
2613
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1981
!
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1982
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1983
numberWithOptionalScales:scaleDict andThousandsSeparator:sep
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1984
    "setup the converter to convert from a string to a number with thousands separator
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1985
     and vice versa. Allow for scale characters (such as k for thousand) "
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1986
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1987
    self
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1988
        getBlock:[:model |
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1989
                    |numericValue|
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1990
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1991
                    (numericValue := model value) isNumber ifFalse:[
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
  1992
                        ''
2613
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1993
                    ] ifTrue:[
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1994
                        String streamContents:[:s | numericValue printOn:s thousandsSeparator:sep].
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1995
                    ]
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1996
                ]
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1997
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1998
        putBlock:
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  1999
                [:model :string |
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2000
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2001
                    |value c stream scaleChar scale s2|
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2002
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2003
                    string isEmptyOrNil ifTrue:[
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2004
                        value := 0
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2005
                    ] ifFalse:[
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2006
                        s2 := string reject:[:ch | ch = sep].    
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2007
                        stream := s2 readStream.
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2008
                        value := Number readFrom:stream onError:[nil]. 
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2009
                        value notNil ifTrue:[
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2010
                            stream skipSeparators.
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2011
                            scaleChar := stream peek.
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2012
                            scale := scaleDict at:scaleChar ifAbsent:1.
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2013
                            value := value * scale.
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2014
                        ].
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2015
                    ].
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2016
                    "/ model value:value
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2017
                    self setNumberValue: value inModel: model fromInput: string.
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2018
                ]
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2019
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2020
        updateBlock: [:m :a :p | true]
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2021
!
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2022
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2023
numberWithThousandsSeparator    
3779
dac60b42b4a8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3765
diff changeset
  2024
    "/ ^ self numberWithThousandsSeparator:$'
dac60b42b4a8 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 3765
diff changeset
  2025
    ^ self numberWithThousandsSeparator:(UserPreferences current thousandsSeparatorCharacter)
2613
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2026
!
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2027
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2028
numberWithThousandsSeparator:sep
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2029
    "setup the converter to convert from a string to a number with thousands separator
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2030
     and vice versa."
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2031
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2032
    self
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2033
        getBlock:[:model |
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2034
                |numericValue|
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2035
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2036
                (numericValue := model value) isNumber ifFalse:[
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
  2037
                    ''
2613
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2038
                ] ifTrue:[
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2039
                    String streamContents:[:s | numericValue printOn:s thousandsSeparator:sep].
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2040
                ]]
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2041
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2042
        putBlock:
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2043
                [:model :string |
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2044
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2045
                |value s2|
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2046
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2047
                string isEmptyOrNil ifTrue:[
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2048
                    value := 0
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2049
                ] ifFalse:[
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2050
                    s2 := string reject:[:ch | ch = sep].    
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2051
                    value := Number readFromString:s2 onError:[0]
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2052
                ].
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2053
                model value:value]
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2054
4c6bedf19f55 new typeConverter: numberWithOptionalScale
Claus Gittinger <cg@exept.de>
parents: 2607
diff changeset
  2055
        updateBlock: [:m :a :p | true]
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2056
! !
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2057
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2058
!TypeConverter class methodsFor:'documentation'!
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2059
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2060
version
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
  2061
    ^ '$Header$'
2868
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  2062
!
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  2063
Claus Gittinger <cg@exept.de>
parents: 2737
diff changeset
  2064
version_CVS
3486
dafab67a9be4 class: TypeConverter
Stefan Vogel <sv@exept.de>
parents: 3252
diff changeset
  2065
    ^ '$Header$'
442
2f5c72b7d46b intitial checkin
Claus Gittinger <cg@exept.de>
parents:
diff changeset
  2066
! !
3103
b2282e1a7b62 class: TypeConverter
Claus Gittinger <cg@exept.de>
parents: 3001
diff changeset
  2067