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