ImageSelBox.st
changeset 202 e00b0bb1d439
parent 86 4d7dbb5f1719
child 233 4979c1304456
equal deleted inserted replaced
201:0aadc66e6134 202:e00b0bb1d439
     8  be provided or otherwise made available to, or used by, any
     8  be provided or otherwise made available to, or used by, any
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
    12 
    13 'From Smalltalk/X, Version:2.10.5 on 28-jun-1995 at 6:45:45 am'!
       
    14 
       
    15 FileSelectionBox subclass:#ImageSelectionBox
    13 FileSelectionBox subclass:#ImageSelectionBox
    16 	 instanceVariableNames:'previewField preview info'
    14 	instanceVariableNames:'previewField preview info'
    17 	 classVariableNames:''
    15 	classVariableNames:''
    18 	 poolDictionaries:''
    16 	poolDictionaries:''
    19 	 category:'Views-DialogBoxes'
    17 	category:'Views-DialogBoxes'
    20 !
    18 !
    21 
    19 
    22 !ImageSelectionBox class methodsFor:'documentation'!
    20 !ImageSelectionBox class methodsFor:'documentation'!
    23 
    21 
    24 copyright
    22 copyright
    38 documentation
    36 documentation
    39 "
    37 "
    40     Like a fileSelectionBox, but adds a little preview field.
    38     Like a fileSelectionBox, but adds a little preview field.
    41     Nice.
    39     Nice.
    42 "
    40 "
    43 !
       
    44 
       
    45 version
       
    46     ^ '$Header: /cvs/stx/stx/libwidg2/Attic/ImageSelBox.st,v 1.3 1995-11-11 16:29:01 cg Exp $'
       
    47 ! !
       
    48 
       
    49 !ImageSelectionBox methodsFor:'user actions'!
       
    50 
       
    51 selectionChanged
       
    52     "selections in list show the image"
       
    53 
       
    54     super selectionChanged.
       
    55     self showPreview
       
    56 !
       
    57 
       
    58 showPreview
       
    59     "show the image as thumbNail"
       
    60 
       
    61     |fileNameString fileName image|
       
    62 
       
    63     previewField label:nil.
       
    64     info label:nil.
       
    65 
       
    66     preview value ifFalse:[
       
    67 	^ self
       
    68     ].
       
    69 
       
    70     "
       
    71      show the image in the previewLabel
       
    72     "
       
    73     fileNameString := self contents.
       
    74     (fileNameString notNil and:[fileNameString notEmpty]) ifTrue:[
       
    75 	fileName := fileNameString asFilename.    
       
    76 	(fileName exists 
       
    77 	and:[fileName isDirectory not
       
    78 	and:[fileName isReadable]]) ifTrue:[
       
    79 
       
    80 	    self topView withWaitCursorDo:[
       
    81 		image := Image fromFile:fileNameString.
       
    82 		image notNil ifTrue:[
       
    83 		    info label:(resources string:'Size: %1 x %2' 
       
    84 					  with:image width printString
       
    85 					  with:image height printString),
       
    86 			       (resources string:' Depth: %1' 
       
    87 					    with:image depth printString).
       
    88 
       
    89 		    (image width <= 64 and:[image height <= 64]) ifFalse:[
       
    90 			image := image magnifiedPreservingRatioTo:64@64.
       
    91 		    ].
       
    92 		    "
       
    93 		     for the thumbNail picture,
       
    94 		     we can temporarily switch to a rough dither.
       
    95 		     (this speeds up the thing quite a bit
       
    96 		    "
       
    97 		    (image depth > 2 
       
    98 		    and:[Color fixColors isNil]) ifTrue:[
       
    99 			"temporarily go to a 3x3x2 colormap ..."
       
   100 			Object errorSignal handle:[:ex |
       
   101 			    'very low resolution colors' infoPrintNL.
       
   102 			    Object errorSignal handle:[:ex |
       
   103 				'cannot allocate dither colors' infoPrintNL.
       
   104 				ex return
       
   105 			    ] do:[
       
   106 				Color getColorsRed:2 green:2 blue:2.
       
   107 			    ]
       
   108 			] do:[
       
   109 			    Color getColorsRed:5 green:5 blue:3.
       
   110 			].
       
   111 			previewField label:image.
       
   112 			Color releaseDitherColors.
       
   113 		    ] ifFalse:[
       
   114 			previewField label:image.
       
   115 		    ]
       
   116 		]
       
   117 	    ]
       
   118 	]
       
   119     ]
       
   120 ! !
    41 ! !
   121 
    42 
   122 !ImageSelectionBox methodsFor:'initialization'!
    43 !ImageSelectionBox methodsFor:'initialization'!
   123 
    44 
   124 initialize
    45 initialize
   181 
   102 
   182     selectionList superView
   103     selectionList superView
   183 	bottomInset:(prefY + ViewSpacing + previewSize y + (frame borderWidth * 2) + ViewSpacing).
   104 	bottomInset:(prefY + ViewSpacing + previewSize y + (frame borderWidth * 2) + ViewSpacing).
   184 ! !
   105 ! !
   185 
   106 
       
   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 
       
   158                     and:[Color fixColors isNil]) ifTrue:[
       
   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:[
       
   166                                 Color getColorsRed:2 green:2 blue:2.
       
   167                             ]
       
   168                         ] do:[
       
   169                             Color getColorsRed:5 green:5 blue:3.
       
   170                         ].
       
   171                         previewField label:image.
       
   172                         Color releaseDitherColors.
       
   173                     ] ifFalse:[
       
   174                         previewField label:image.
       
   175                     ]
       
   176                 ]
       
   177             ]
       
   178         ]
       
   179     ]
       
   180 
       
   181     "Modified: 7.6.1996 / 12:25:19 / cg"
       
   182 ! !
       
   183 
       
   184 !ImageSelectionBox class methodsFor:'documentation'!
       
   185 
       
   186 version
       
   187     ^ '$Header: /cvs/stx/stx/libwidg2/Attic/ImageSelBox.st,v 1.4 1996-06-07 16:35:50 cg Exp $'
       
   188 ! !