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