ImageSelBox.st
changeset 64 10910b8b003a
child 72 f17df5ea35ed
equal deleted inserted replaced
63:e560d8279473 64:10910b8b003a
       
     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 'From Smalltalk/X, Version:2.10.5 on 28-jun-1995 at 6:45:45 am'!
       
    14 
       
    15 FileSelectionBox subclass:#ImageSelectionBox
       
    16 	 instanceVariableNames:'previewField preview info'
       
    17 	 classVariableNames:''
       
    18 	 poolDictionaries:''
       
    19 	 category:'Views-DialogBoxes'
       
    20 !
       
    21 
       
    22 !ImageSelectionBox class methodsFor:'documentation'!
       
    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:'user actions'!
       
    46 
       
    47 selectionChanged
       
    48     "selections in list show the image"
       
    49 
       
    50     super selectionChanged.
       
    51     self showPreview
       
    52 !
       
    53 
       
    54 showPreview
       
    55     "show the image as thumbNail"
       
    56 
       
    57     |fileNameString fileName image|
       
    58 
       
    59     previewField label:nil.
       
    60     info label:nil.
       
    61 
       
    62     preview value ifFalse:[
       
    63 	^ self
       
    64     ].
       
    65 
       
    66     "
       
    67      show the image in the previewLabel
       
    68     "
       
    69     fileNameString := self contents.
       
    70     (fileNameString notNil and:[fileNameString notEmpty]) ifTrue:[
       
    71 	fileName := fileNameString asFilename.    
       
    72 	(fileName exists 
       
    73 	and:[fileName isDirectory not
       
    74 	and:[fileName isReadable]]) ifTrue:[
       
    75 
       
    76 	    self topView withWaitCursorDo:[
       
    77 		image := Image fromFile:fileNameString.
       
    78 		image notNil ifTrue:[
       
    79 		    info label:'Size: ' ,
       
    80 			       (image width printString , ' x ' , image height printString),
       
    81 			       ' Depth: ' , image depth printString.
       
    82 
       
    83 		    (image width <= 64 and:[image height <= 64]) ifFalse:[
       
    84 			image := image magnifiedPreservingRatioTo:64@64.
       
    85 		    ].
       
    86 		    "
       
    87 		     for the thumbNail picture,
       
    88 		     we can temporarily switch to a rough dither.
       
    89 		     (this speeds up the thing quite a bit
       
    90 		    "
       
    91 		    (image depth > 2 
       
    92 		    and:[Color fixColors isNil]) ifTrue:[
       
    93 			"temporarily go to a 3x3x2 colormap ..."
       
    94 			Object errorSignal handle:[:ex |
       
    95 			    'very low resolution colors' infoPrintNL.
       
    96 			    Object errorSignal handle:[:ex |
       
    97 				'cannot allocate dither colors' infoPrintNL.
       
    98 				ex return
       
    99 			    ] do:[
       
   100 				Color getColorsRed:2 green:2 blue:2.
       
   101 			    ]
       
   102 			] do:[
       
   103 			    Color getColorsRed:5 green:5 blue:3.
       
   104 			].
       
   105 			previewField label:image.
       
   106 			Color releaseDitherColors.
       
   107 		    ] ifFalse:[
       
   108 			previewField label:image.
       
   109 		    ]
       
   110 		]
       
   111 	    ]
       
   112 	]
       
   113     ]
       
   114 ! !
       
   115 
       
   116 !ImageSelectionBox methodsFor:'initialization'!
       
   117 
       
   118 initialize
       
   119     |v check lw lh prefY frame previewSize|
       
   120 
       
   121     previewSize := 64@64.
       
   122 
       
   123     super initialize.
       
   124 
       
   125     label := 'Image dialog'.
       
   126     labelField label:(resources string:'select an image file:').
       
   127 
       
   128     prefY := buttonPanel preferredExtent y.
       
   129 
       
   130     check := CheckBox label:(resources string:'preview') in:self.
       
   131     check model:(preview := false asValue).
       
   132     preview onChangeSend:#showPreview to:self.
       
   133     info := Label label:'' in:self.
       
   134     info adjust:#left.
       
   135 
       
   136     lh := check preferredExtent y.
       
   137     lw := check preferredExtent x.
       
   138 
       
   139     check
       
   140 	origin:(0.0 @ 1.0)       
       
   141 	corner:(0.0 @ 1.0).
       
   142     check
       
   143 	topInset:(prefY + ViewSpacing + previewSize y) negated;
       
   144 	bottomInset:(prefY + ViewSpacing + (previewSize y - check preferredExtent y)); 
       
   145 	rightInset:(ViewSpacing + lw) negated.
       
   146 
       
   147     info
       
   148 	origin:(0.0 @ 1.0)       
       
   149 	corner:(1.0 @ 1.0).
       
   150     info
       
   151 	topInset:(prefY + ViewSpacing + info preferredExtent y + ViewSpacing) negated;
       
   152 	bottomInset:(prefY + ViewSpacing); 
       
   153 	leftInset:ViewSpacing;
       
   154 	rightInset:(ViewSpacing + previewSize x + ViewSpacing) negated.
       
   155 
       
   156     StyleSheet is3D ifTrue:[
       
   157 	v := View in:self.
       
   158 	previewField := Label origin:0.0@0.0 corner:1.0@1.0 in:v.
       
   159 	previewField allInset:ViewSpacing//2.
       
   160 	frame := v.
       
   161 	previewField level:-1.
       
   162 	frame level:1.
       
   163     ] ifFalse:[
       
   164 	previewField := frame := Label in:self.
       
   165     ].
       
   166     frame
       
   167 	origin:(1.0 @ 1.0)       
       
   168 	corner:(1.0 @ 1.0).
       
   169     frame
       
   170 	topInset:(prefY + ViewSpacing + previewSize y + (frame borderWidth * 2)) negated;
       
   171 	bottomInset:(prefY + frame borderWidth + ViewSpacing); 
       
   172 	leftInset:(ViewSpacing + previewSize x + ViewSpacing) negated;
       
   173 	rightInset:ViewSpacing.
       
   174     previewField sizeFixed:true.
       
   175 
       
   176     selectionList superView
       
   177 	bottomInset:(prefY + ViewSpacing + previewSize y + (frame borderWidth * 2) + ViewSpacing).
       
   178 ! !
       
   179