395
|
1 |
Object subclass:#DropObject
|
|
2 |
instanceVariableNames:'theObject'
|
|
3 |
classVariableNames:''
|
|
4 |
poolDictionaries:''
|
|
5 |
category:'Interface-Support'
|
|
6 |
!
|
|
7 |
|
403
|
8 |
DropObject class instanceVariableNames:'DisplayObject'
|
|
9 |
|
|
10 |
"
|
|
11 |
The following class instance variables are inherited by this class:
|
|
12 |
|
|
13 |
Object -
|
|
14 |
"
|
|
15 |
!
|
|
16 |
|
|
17 |
DropObject subclass:#File
|
|
18 |
instanceVariableNames:'info isHtmlFile isImageFile isPrintable'
|
395
|
19 |
classVariableNames:''
|
|
20 |
poolDictionaries:''
|
|
21 |
privateIn:DropObject
|
|
22 |
!
|
|
23 |
|
403
|
24 |
DropObject subclass:#Color
|
395
|
25 |
instanceVariableNames:''
|
|
26 |
classVariableNames:''
|
|
27 |
poolDictionaries:''
|
|
28 |
privateIn:DropObject
|
|
29 |
!
|
|
30 |
|
|
31 |
DropObject subclass:#Image
|
|
32 |
instanceVariableNames:''
|
|
33 |
classVariableNames:''
|
|
34 |
poolDictionaries:''
|
|
35 |
privateIn:DropObject
|
|
36 |
!
|
|
37 |
|
403
|
38 |
DropObject subclass:#Text
|
|
39 |
instanceVariableNames:''
|
395
|
40 |
classVariableNames:''
|
|
41 |
poolDictionaries:''
|
|
42 |
privateIn:DropObject
|
|
43 |
!
|
|
44 |
|
|
45 |
|
|
46 |
!DropObject class methodsFor:'instance creation'!
|
|
47 |
|
|
48 |
new:someThing
|
|
49 |
"create an instance dependant on something
|
|
50 |
"
|
|
51 |
|cls|
|
|
52 |
|
|
53 |
someThing isColor ifTrue:[cls := Color
|
|
54 |
] ifFalse:[someThing isImageOrForm ifTrue:[cls := Image
|
|
55 |
] ifFalse:[(someThing isKindOf:Filename) ifTrue:[cls := File
|
|
56 |
] ifFalse:[cls isString ifTrue:[cls := Text
|
|
57 |
] ifFalse:[
|
|
58 |
cls := DropObject
|
|
59 |
]]]].
|
|
60 |
|
|
61 |
^ cls new theObject:someThing
|
|
62 |
!
|
|
63 |
|
|
64 |
newColor:aColor
|
|
65 |
^ Color new theObject:aColor
|
|
66 |
!
|
|
67 |
|
|
68 |
newFile:aFilename
|
|
69 |
^ File new theObject:aFilename
|
|
70 |
!
|
|
71 |
|
|
72 |
newImage:anImageOrForm
|
|
73 |
^ Image new theObject:anImageOrForm
|
|
74 |
!
|
|
75 |
|
|
76 |
newText:aTextOrString
|
|
77 |
^ Text new theObject:aTextOrString
|
|
78 |
! !
|
|
79 |
|
403
|
80 |
!DropObject class methodsFor:'defaults'!
|
|
81 |
|
|
82 |
displayObject
|
|
83 |
|
|
84 |
DisplayObject notNil ifTrue:[
|
|
85 |
^ DisplayObject
|
|
86 |
].
|
|
87 |
DisplayObject := Smalltalk::Image fromFile:(self displayObjectName).
|
|
88 |
^ DisplayObject
|
|
89 |
!
|
|
90 |
|
|
91 |
displayObjectName
|
|
92 |
^ 'bitmaps/xpmBitmaps/plain_pixmaps/balloon3.xpm'
|
|
93 |
|
|
94 |
! !
|
|
95 |
|
395
|
96 |
!DropObject methodsFor:'accessing'!
|
|
97 |
|
|
98 |
theObject
|
|
99 |
"return the value of the instance variable 'theObject' (automatically generated)"
|
|
100 |
|
|
101 |
^ theObject!
|
|
102 |
|
|
103 |
theObject:something
|
|
104 |
"set the value of the instance variable 'theObject' (automatically generated)"
|
|
105 |
|
|
106 |
theObject := something.! !
|
|
107 |
|
396
|
108 |
!DropObject methodsFor:'queries'!
|
|
109 |
|
|
110 |
displayObject
|
|
111 |
"return my graphical representation - here a default is returned"
|
403
|
112 |
^ self class displayObject
|
396
|
113 |
! !
|
|
114 |
|
395
|
115 |
!DropObject methodsFor:'testing'!
|
|
116 |
|
|
117 |
isColorObject
|
|
118 |
^ false
|
|
119 |
!
|
|
120 |
|
|
121 |
isFileObject
|
|
122 |
^ false
|
|
123 |
!
|
|
124 |
|
|
125 |
isImageObject
|
|
126 |
^ false
|
|
127 |
!
|
|
128 |
|
|
129 |
isTextObject
|
|
130 |
^ false
|
|
131 |
! !
|
|
132 |
|
403
|
133 |
!DropObject::File class methodsFor:'defaults'!
|
|
134 |
|
|
135 |
displayObjectName
|
|
136 |
^ 'bitmaps/xpmBitmaps/plain_pixmaps/xfm_file.xpm'
|
|
137 |
|
|
138 |
|
|
139 |
! !
|
|
140 |
|
|
141 |
!DropObject::File methodsFor:'accessing'!
|
|
142 |
|
|
143 |
theObject:aPathname
|
|
144 |
|path|
|
|
145 |
|
|
146 |
path := OperatingSystem pathNameOf:(aPathname asString).
|
|
147 |
info := OperatingSystem infoOf:path.
|
|
148 |
|
|
149 |
super theObject:(path asFilename)
|
|
150 |
! !
|
|
151 |
|
|
152 |
!DropObject::File methodsFor:'queries'!
|
|
153 |
|
|
154 |
exists
|
|
155 |
"returns true if file exists
|
|
156 |
"
|
|
157 |
^ info notNil
|
|
158 |
!
|
|
159 |
|
|
160 |
isDirectory
|
|
161 |
"checks whether file is a directory
|
|
162 |
"
|
|
163 |
^ (info notNil and:[info type == #directory])
|
|
164 |
!
|
|
165 |
|
|
166 |
isHtmlFile
|
|
167 |
"checks whether file is a html file
|
|
168 |
"
|
|
169 |
|suffixes pathName|
|
|
170 |
|
|
171 |
isHtmlFile isNil ifTrue:[
|
|
172 |
(info isNil or:[self isDirectory]) ifTrue:[
|
|
173 |
isHtmlFile := false
|
|
174 |
] ifFalse:[
|
|
175 |
pathName := theObject asString.
|
|
176 |
suffixes := #( '.html' '.htm' '.HTML' '.HTM' ).
|
|
177 |
isHtmlFile := (suffixes findFirst:[:el|pathName endsWith:el]) ~~ 0
|
|
178 |
]
|
|
179 |
].
|
|
180 |
^ isHtmlFile
|
|
181 |
!
|
|
182 |
|
|
183 |
isImageFile
|
|
184 |
"returns true if file is assigned to an image
|
|
185 |
"
|
|
186 |
|suffixes pathName|
|
|
187 |
|
|
188 |
isImageFile isNil ifTrue:[
|
|
189 |
(info isNil or:[self isDirectory]) ifTrue:[
|
|
190 |
isImageFile := false
|
|
191 |
] ifFalse:[
|
|
192 |
pathName := theObject asString.
|
|
193 |
suffixes := #( '.xpm' '.xbm' '.tiff' '.gif' '.bmp' '.ico' '.icon' ).
|
|
194 |
isImageFile := (suffixes findFirst:[:el|pathName endsWith:el]) ~~ 0
|
|
195 |
]
|
|
196 |
].
|
|
197 |
^ isImageFile
|
|
198 |
|
|
199 |
!
|
|
200 |
|
|
201 |
isPrintable
|
|
202 |
"returns false if file contains non printable characters
|
|
203 |
"
|
|
204 |
|stream buff size|
|
|
205 |
|
|
206 |
isPrintable isNil ifTrue:[
|
|
207 |
isPrintable := false.
|
|
208 |
|
|
209 |
(info isNil or:[self isDirectory]) ifFalse:[
|
|
210 |
stream := FileStream readonlyFileNamed:(theObject pathName).
|
|
211 |
|
|
212 |
stream isNil ifFalse:[
|
|
213 |
buff := String new:300.
|
|
214 |
size := stream nextBytes:300 into:buff.
|
|
215 |
stream close.
|
|
216 |
].
|
|
217 |
1 to:size do:[:i|
|
|
218 |
(buff at:i) isPrintable ifFalse:[
|
|
219 |
^ isPrintable
|
|
220 |
]
|
|
221 |
].
|
|
222 |
isPrintable := true
|
|
223 |
]
|
|
224 |
].
|
|
225 |
^ isPrintable
|
|
226 |
! !
|
|
227 |
|
|
228 |
!DropObject::File methodsFor:'testing'!
|
|
229 |
|
|
230 |
isFileObject
|
|
231 |
^ true
|
|
232 |
! !
|
|
233 |
|
|
234 |
!DropObject::Color class methodsFor:'defaults'!
|
|
235 |
|
|
236 |
displayObjectName
|
|
237 |
^ 'bitmaps/xpmBitmaps/plain_pixmaps/paint2.xpm'
|
|
238 |
|
|
239 |
|
|
240 |
|
|
241 |
|
|
242 |
|
|
243 |
! !
|
|
244 |
|
396
|
245 |
!DropObject::Color methodsFor:'testing'!
|
|
246 |
|
|
247 |
isColorObject
|
|
248 |
^ true
|
|
249 |
! !
|
|
250 |
|
403
|
251 |
!DropObject::Image class methodsFor:'defaults'!
|
396
|
252 |
|
403
|
253 |
displayObjectName
|
|
254 |
^ 'bitmaps/xpmBitmaps/plain_pixmaps/hobbes.xpm'
|
396
|
255 |
|
|
256 |
|
|
257 |
! !
|
|
258 |
|
|
259 |
!DropObject::Image methodsFor:'testing'!
|
|
260 |
|
|
261 |
isImageObject
|
|
262 |
^ true
|
|
263 |
|
|
264 |
|
|
265 |
! !
|
|
266 |
|
403
|
267 |
!DropObject::Text class methodsFor:'defaults'!
|
395
|
268 |
|
403
|
269 |
displayObjectName
|
|
270 |
^ 'bitmaps/xpmBitmaps/plain_pixmaps/xfm_text.xpm'
|
|
271 |
|
|
272 |
|
|
273 |
|
395
|
274 |
! !
|
|
275 |
|
403
|
276 |
!DropObject::Text methodsFor:'testing'!
|
395
|
277 |
|
403
|
278 |
isTextObject
|
|
279 |
^ true
|
395
|
280 |
|
403
|
281 |
|
395
|
282 |
! !
|
|
283 |
|
|
284 |
!DropObject class methodsFor:'documentation'!
|
|
285 |
|
|
286 |
version
|
403
|
287 |
^ '$Header: /cvs/stx/stx/libview2/DropObject.st,v 1.3 1997-02-03 09:12:22 ca Exp $'
|
395
|
288 |
! !
|