ImageSelectionBox.st
changeset 3150 e3a55f15ef7e
parent 233 4979c1304456
child 4770 6634b540fea2
equal deleted inserted replaced
3149:66df7168e377 3150:e3a55f15ef7e
     7  inclusion of the above copyright notice.   This software may not
     7  inclusion of the above copyright notice.   This software may not
     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 
       
    13 "{ Package: 'stx:libwidg2' }"
    12 
    14 
    13 FileSelectionBox subclass:#ImageSelectionBox
    15 FileSelectionBox subclass:#ImageSelectionBox
    14 	instanceVariableNames:'previewField preview info'
    16 	instanceVariableNames:'previewField preview info'
    15 	classVariableNames:''
    17 	classVariableNames:''
    16 	poolDictionaries:''
    18 	poolDictionaries:''
    62 
    64 
    63     lh := check preferredExtent y.
    65     lh := check preferredExtent y.
    64     lw := check preferredExtent x.
    66     lw := check preferredExtent x.
    65 
    67 
    66     check
    68     check
    67 	origin:(0.0 @ 1.0)       
    69 	origin:(0.0 @ 1.0)
    68 	corner:(0.0 @ 1.0).
    70 	corner:(0.0 @ 1.0).
    69     check
    71     check
    70 	topInset:(prefY + ViewSpacing + previewSize y) negated;
    72 	topInset:(prefY + ViewSpacing + previewSize y) negated;
    71 	bottomInset:(prefY + ViewSpacing + (previewSize y - check preferredExtent y)); 
    73 	bottomInset:(prefY + ViewSpacing + (previewSize y - check preferredExtent y));
    72 	rightInset:(ViewSpacing + lw) negated.
    74 	rightInset:(ViewSpacing + lw) negated.
    73 
    75 
    74     info
    76     info
    75 	origin:(0.0 @ 1.0)       
    77 	origin:(0.0 @ 1.0)
    76 	corner:(1.0 @ 1.0).
    78 	corner:(1.0 @ 1.0).
    77     info
    79     info
    78 	topInset:(prefY + ViewSpacing + info preferredExtent y + ViewSpacing) negated;
    80 	topInset:(prefY + ViewSpacing + info preferredExtent y + ViewSpacing) negated;
    79 	bottomInset:(prefY + ViewSpacing); 
    81 	bottomInset:(prefY + ViewSpacing);
    80 	leftInset:ViewSpacing;
    82 	leftInset:ViewSpacing;
    81 	rightInset:(ViewSpacing + previewSize x + ViewSpacing) negated.
    83 	rightInset:(ViewSpacing + previewSize x + ViewSpacing) negated.
    82 
    84 
    83     StyleSheet is3D ifTrue:[
    85     StyleSheet is3D ifTrue:[
    84 	v := View in:self.
    86 	v := View in:self.
    89 	frame level:1.
    91 	frame level:1.
    90     ] ifFalse:[
    92     ] ifFalse:[
    91 	previewField := frame := Label in:self.
    93 	previewField := frame := Label in:self.
    92     ].
    94     ].
    93     frame
    95     frame
    94 	origin:(1.0 @ 1.0)       
    96 	origin:(1.0 @ 1.0)
    95 	corner:(1.0 @ 1.0).
    97 	corner:(1.0 @ 1.0).
    96     frame
    98     frame
    97 	topInset:(prefY + ViewSpacing + previewSize y + (frame borderWidth * 2)) negated;
    99 	topInset:(prefY + ViewSpacing + previewSize y + (frame borderWidth * 2)) negated;
    98 	bottomInset:(prefY + frame borderWidth + ViewSpacing); 
   100 	bottomInset:(prefY + frame borderWidth + ViewSpacing);
    99 	leftInset:(ViewSpacing + previewSize x + ViewSpacing) negated;
   101 	leftInset:(ViewSpacing + previewSize x + ViewSpacing) negated;
   100 	rightInset:ViewSpacing.
   102 	rightInset:ViewSpacing.
   101     previewField sizeFixed:true.
   103     previewField sizeFixed:true.
   102 
   104 
   103     selectionList superView
   105     selectionList superView
   120 
   122 
   121     previewField label:nil.
   123     previewField label:nil.
   122     info label:nil.
   124     info label:nil.
   123 
   125 
   124     preview value ifFalse:[
   126     preview value ifFalse:[
   125         ^ self
   127 	^ self
   126     ].
   128     ].
   127 
   129 
   128     "
   130     "
   129      show the image in the previewLabel
   131      show the image in the previewLabel
   130     "
   132     "
   131     fileNameString := self contents.
   133     fileNameString := self contents.
   132     (fileNameString notNil and:[fileNameString notEmpty]) ifTrue:[
   134     (fileNameString notNil and:[fileNameString notEmpty]) ifTrue:[
   133         fileName := fileNameString asFilename.    
   135 	fileName := fileNameString asFilename.
   134         (fileName exists 
   136 	(fileName exists
   135         and:[fileName isDirectory not
   137 	and:[fileName isDirectory not
   136         and:[fileName isReadable]]) ifTrue:[
   138 	and:[fileName isReadable]]) ifTrue:[
   137 
   139 
   138             self topView withWaitCursorDo:[
   140 	    self topView withWaitCursorDo:[
   139                 image := Image fromFile:fileNameString.
   141 		image := Image fromFile:fileNameString.
   140                 image notNil ifTrue:[
   142 		image notNil ifTrue:[
   141                     info label:(resources string:'%1 x %2' 
   143 		    info label:(resources string:'%1 x %2'
   142                                           with:image width printString
   144 					  with:image width printString
   143                                           with:image height printString),
   145 					  with:image height printString),
   144                                (resources string:' Depth:%1' 
   146 			       (resources string:' Depth:%1'
   145                                             with:image depth printString),
   147 					    with:image depth printString),
   146                                (resources string:' (%1)' 
   148 			       (resources string:' (%1)'
   147                                             with:image photometric printString).
   149 					    with:image photometric printString).
   148 
   150 
   149                     (image width <= 64 and:[image height <= 64]) ifFalse:[
   151 		    (image width <= 64 and:[image height <= 64]) ifFalse:[
   150                         image := image magnifiedPreservingRatioTo:64@64.
   152 			image := image magnifiedPreservingRatioTo:64@64.
   151                     ].
   153 		    ].
   152                     "
   154 		    "
   153                      for the thumbNail picture,
   155 		     for the thumbNail picture,
   154                      we can temporarily switch to a rough dither.
   156 		     we can temporarily switch to a rough dither.
   155                      (this speeds up the thing quite a bit
   157 		     (this speeds up the thing quite a bit
   156                     "
   158 		    "
   157                     (image depth > 2 
   159 		    (image depth > 2
   158                     and:[device fixColors isNil]) ifTrue:[
   160 		    and:[device fixColors isNil]) ifTrue:[
   159                         "temporarily go to a 3x3x2 colormap ..."
   161 			"temporarily go to a 3x3x2 colormap ..."
   160                         Object errorSignal handle:[:ex |
   162 			Object errorSignal handle:[:ex |
   161                             'very low resolution colors' infoPrintNL.
   163 			    'very low resolution colors' infoPrintNL.
   162                             Object errorSignal handle:[:ex |
   164 			    Object errorSignal handle:[:ex |
   163                                 'cannot allocate dither colors' infoPrintNL.
   165 				'cannot allocate dither colors' infoPrintNL.
   164                                 ex return
   166 				ex return
   165                             ] do:[
   167 			    ] do:[
   166                                 Color getColorsRed:2 green:2 blue:2 on:device.
   168 				Color getColorsRed:2 green:2 blue:2 on:device.
   167                             ]
   169 			    ]
   168                         ] do:[
   170 			] do:[
   169                             Color getColorsRed:5 green:5 blue:3 on:device.
   171 			    Color getColorsRed:5 green:5 blue:3 on:device.
   170                         ].
   172 			].
   171                         previewField label:image.
   173 			previewField label:image.
   172                         device releaseFixColors.
   174 			device releaseFixColors.
   173                     ] ifFalse:[
   175 		    ] ifFalse:[
   174                         previewField label:image.
   176 			previewField label:image.
   175                     ]
   177 		    ]
   176                 ]
   178 		]
   177             ]
   179 	    ]
   178         ]
   180 	]
   179     ]
   181     ]
   180 
   182 
   181     "Modified: 7.6.1996 / 12:25:19 / cg"
   183     "Modified: 7.6.1996 / 12:25:19 / cg"
   182 ! !
   184 ! !
   183 
   185 
   184 !ImageSelectionBox  class methodsFor:'documentation'!
   186 !ImageSelectionBox  class methodsFor:'documentation'!
   185 
   187 
   186 version
   188 version
   187     ^ '$Header: /cvs/stx/stx/libwidg2/ImageSelectionBox.st,v 1.5 1996-08-02 19:03:37 cg Exp $'
   189     ^ '$Header: /cvs/stx/stx/libwidg2/ImageSelectionBox.st,v 1.6 2006-11-13 16:11:30 cg Exp $'
   188 ! !
   190 ! !