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