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