ImageSelectionBox.st
author Claus Gittinger <cg@exept.de>
Fri, 02 Aug 1996 21:03:37 +0200
changeset 233 4979c1304456
parent 202 e00b0bb1d439
child 3150 e3a55f15ef7e
permissions -rw-r--r--
changes for fixColors now being in device
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
64
claus
parents:
diff changeset
     1
"
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1995 by Claus Gittinger
claus
parents:
diff changeset
     3
	      All Rights Reserved
claus
parents:
diff changeset
     4
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
claus
parents:
diff changeset
    10
 hereby transferred.
claus
parents:
diff changeset
    11
"
claus
parents:
diff changeset
    12
claus
parents:
diff changeset
    13
FileSelectionBox subclass:#ImageSelectionBox
202
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    14
	instanceVariableNames:'previewField preview info'
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    15
	classVariableNames:''
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    16
	poolDictionaries:''
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
    17
	category:'Views-DialogBoxes'
64
claus
parents:
diff changeset
    18
!
claus
parents:
diff changeset
    19
233
4979c1304456 changes for fixColors now being in device
Claus Gittinger <cg@exept.de>
parents: 202
diff changeset
    20
!ImageSelectionBox  class methodsFor:'documentation'!
64
claus
parents:
diff changeset
    21
claus
parents:
diff changeset
    22
copyright
claus
parents:
diff changeset
    23
"
claus
parents:
diff changeset
    24
 COPYRIGHT (c) 1995 by Claus Gittinger
claus
parents:
diff changeset
    25
	      All Rights Reserved
claus
parents:
diff changeset
    26
claus
parents:
diff changeset
    27
 This software is furnished under a license and may be used
claus
parents:
diff changeset
    28
 only in accordance with the terms of that license and with the
claus
parents:
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
claus
parents:
diff changeset
    30
 be provided or otherwise made available to, or used by, any
claus
parents:
diff changeset
    31
 other person.  No title to or ownership of the software is
claus
parents:
diff changeset
    32
 hereby transferred.
claus
parents:
diff changeset
    33
"
claus
parents:
diff changeset
    34
!
claus
parents:
diff changeset
    35
claus
parents:
diff changeset
    36
documentation
claus
parents:
diff changeset
    37
"
claus
parents:
diff changeset
    38
    Like a fileSelectionBox, but adds a little preview field.
claus
parents:
diff changeset
    39
    Nice.
claus
parents:
diff changeset
    40
"
claus
parents:
diff changeset
    41
! !
claus
parents:
diff changeset
    42
claus
parents:
diff changeset
    43
!ImageSelectionBox methodsFor:'initialization'!
claus
parents:
diff changeset
    44
claus
parents:
diff changeset
    45
initialize
claus
parents:
diff changeset
    46
    |v check lw lh prefY frame previewSize|
claus
parents:
diff changeset
    47
claus
parents:
diff changeset
    48
    previewSize := 64@64.
claus
parents:
diff changeset
    49
claus
parents:
diff changeset
    50
    super initialize.
claus
parents:
diff changeset
    51
72
claus
parents: 64
diff changeset
    52
    label := (resources string:'Image dialog').
64
claus
parents:
diff changeset
    53
    labelField label:(resources string:'select an image file:').
claus
parents:
diff changeset
    54
claus
parents:
diff changeset
    55
    prefY := buttonPanel preferredExtent y.
claus
parents:
diff changeset
    56
claus
parents:
diff changeset
    57
    check := CheckBox label:(resources string:'preview') in:self.
claus
parents:
diff changeset
    58
    check model:(preview := false asValue).
claus
parents:
diff changeset
    59
    preview onChangeSend:#showPreview to:self.
claus
parents:
diff changeset
    60
    info := Label label:'' in:self.
claus
parents:
diff changeset
    61
    info adjust:#left.
claus
parents:
diff changeset
    62
claus
parents:
diff changeset
    63
    lh := check preferredExtent y.
claus
parents:
diff changeset
    64
    lw := check preferredExtent x.
claus
parents:
diff changeset
    65
claus
parents:
diff changeset
    66
    check
claus
parents:
diff changeset
    67
	origin:(0.0 @ 1.0)       
claus
parents:
diff changeset
    68
	corner:(0.0 @ 1.0).
claus
parents:
diff changeset
    69
    check
claus
parents:
diff changeset
    70
	topInset:(prefY + ViewSpacing + previewSize y) negated;
claus
parents:
diff changeset
    71
	bottomInset:(prefY + ViewSpacing + (previewSize y - check preferredExtent y)); 
claus
parents:
diff changeset
    72
	rightInset:(ViewSpacing + lw) negated.
claus
parents:
diff changeset
    73
claus
parents:
diff changeset
    74
    info
claus
parents:
diff changeset
    75
	origin:(0.0 @ 1.0)       
claus
parents:
diff changeset
    76
	corner:(1.0 @ 1.0).
claus
parents:
diff changeset
    77
    info
claus
parents:
diff changeset
    78
	topInset:(prefY + ViewSpacing + info preferredExtent y + ViewSpacing) negated;
claus
parents:
diff changeset
    79
	bottomInset:(prefY + ViewSpacing); 
claus
parents:
diff changeset
    80
	leftInset:ViewSpacing;
claus
parents:
diff changeset
    81
	rightInset:(ViewSpacing + previewSize x + ViewSpacing) negated.
claus
parents:
diff changeset
    82
claus
parents:
diff changeset
    83
    StyleSheet is3D ifTrue:[
claus
parents:
diff changeset
    84
	v := View in:self.
claus
parents:
diff changeset
    85
	previewField := Label origin:0.0@0.0 corner:1.0@1.0 in:v.
claus
parents:
diff changeset
    86
	previewField allInset:ViewSpacing//2.
claus
parents:
diff changeset
    87
	frame := v.
claus
parents:
diff changeset
    88
	previewField level:-1.
claus
parents:
diff changeset
    89
	frame level:1.
claus
parents:
diff changeset
    90
    ] ifFalse:[
claus
parents:
diff changeset
    91
	previewField := frame := Label in:self.
claus
parents:
diff changeset
    92
    ].
claus
parents:
diff changeset
    93
    frame
claus
parents:
diff changeset
    94
	origin:(1.0 @ 1.0)       
claus
parents:
diff changeset
    95
	corner:(1.0 @ 1.0).
claus
parents:
diff changeset
    96
    frame
claus
parents:
diff changeset
    97
	topInset:(prefY + ViewSpacing + previewSize y + (frame borderWidth * 2)) negated;
claus
parents:
diff changeset
    98
	bottomInset:(prefY + frame borderWidth + ViewSpacing); 
claus
parents:
diff changeset
    99
	leftInset:(ViewSpacing + previewSize x + ViewSpacing) negated;
claus
parents:
diff changeset
   100
	rightInset:ViewSpacing.
claus
parents:
diff changeset
   101
    previewField sizeFixed:true.
claus
parents:
diff changeset
   102
claus
parents:
diff changeset
   103
    selectionList superView
claus
parents:
diff changeset
   104
	bottomInset:(prefY + ViewSpacing + previewSize y + (frame borderWidth * 2) + ViewSpacing).
claus
parents:
diff changeset
   105
! !
claus
parents:
diff changeset
   106
202
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   107
!ImageSelectionBox methodsFor:'user actions'!
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   108
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   109
selectionChanged
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   110
    "selections in list show the image"
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   111
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   112
    super selectionChanged.
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   113
    self showPreview
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   114
!
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   115
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   116
showPreview
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   117
    "show the image as thumbNail"
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   118
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   119
    |fileNameString fileName image|
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   120
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   121
    previewField label:nil.
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   122
    info label:nil.
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   123
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   124
    preview value ifFalse:[
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   125
        ^ self
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   126
    ].
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   127
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   128
    "
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   129
     show the image in the previewLabel
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   130
    "
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   131
    fileNameString := self contents.
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   132
    (fileNameString notNil and:[fileNameString notEmpty]) ifTrue:[
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   133
        fileName := fileNameString asFilename.    
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   134
        (fileName exists 
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   135
        and:[fileName isDirectory not
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   136
        and:[fileName isReadable]]) ifTrue:[
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   137
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   138
            self topView withWaitCursorDo:[
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   139
                image := Image fromFile:fileNameString.
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   140
                image notNil ifTrue:[
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   141
                    info label:(resources string:'%1 x %2' 
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   142
                                          with:image width printString
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   143
                                          with:image height printString),
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   144
                               (resources string:' Depth:%1' 
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   145
                                            with:image depth printString),
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   146
                               (resources string:' (%1)' 
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   147
                                            with:image photometric printString).
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   148
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   149
                    (image width <= 64 and:[image height <= 64]) ifFalse:[
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   150
                        image := image magnifiedPreservingRatioTo:64@64.
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   151
                    ].
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   152
                    "
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   153
                     for the thumbNail picture,
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   154
                     we can temporarily switch to a rough dither.
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   155
                     (this speeds up the thing quite a bit
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   156
                    "
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   157
                    (image depth > 2 
233
4979c1304456 changes for fixColors now being in device
Claus Gittinger <cg@exept.de>
parents: 202
diff changeset
   158
                    and:[device fixColors isNil]) ifTrue:[
202
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   159
                        "temporarily go to a 3x3x2 colormap ..."
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   160
                        Object errorSignal handle:[:ex |
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   161
                            'very low resolution colors' infoPrintNL.
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   162
                            Object errorSignal handle:[:ex |
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   163
                                'cannot allocate dither colors' infoPrintNL.
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   164
                                ex return
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   165
                            ] do:[
233
4979c1304456 changes for fixColors now being in device
Claus Gittinger <cg@exept.de>
parents: 202
diff changeset
   166
                                Color getColorsRed:2 green:2 blue:2 on:device.
202
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   167
                            ]
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   168
                        ] do:[
233
4979c1304456 changes for fixColors now being in device
Claus Gittinger <cg@exept.de>
parents: 202
diff changeset
   169
                            Color getColorsRed:5 green:5 blue:3 on:device.
202
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   170
                        ].
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   171
                        previewField label:image.
233
4979c1304456 changes for fixColors now being in device
Claus Gittinger <cg@exept.de>
parents: 202
diff changeset
   172
                        device releaseFixColors.
202
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   173
                    ] ifFalse:[
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   174
                        previewField label:image.
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   175
                    ]
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   176
                ]
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   177
            ]
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   178
        ]
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   179
    ]
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   180
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   181
    "Modified: 7.6.1996 / 12:25:19 / cg"
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   182
! !
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   183
233
4979c1304456 changes for fixColors now being in device
Claus Gittinger <cg@exept.de>
parents: 202
diff changeset
   184
!ImageSelectionBox  class methodsFor:'documentation'!
202
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   185
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   186
version
233
4979c1304456 changes for fixColors now being in device
Claus Gittinger <cg@exept.de>
parents: 202
diff changeset
   187
    ^ '$Header: /cvs/stx/stx/libwidg2/ImageSelectionBox.st,v 1.5 1996-08-02 19:03:37 cg Exp $'
202
e00b0bb1d439 show photometric
Claus Gittinger <cg@exept.de>
parents: 86
diff changeset
   188
! !