'From Squeak3.5 of ''11 April 2003'' [latest update: #5180] on 27 April 2003 at 6:13:10 pm'! "Change Set: PatternLoader-sbw Date: 30 September 2002 Author: Stephan B. Wessels SM Name: Background Loader with Preview Provides a previewer for images that can be loaded as the desktop. Opens up from the Appearance menu, via 'set desktop image...'. New capability from previous version of this change set includes a few options for how the desktop image is placed. NOTE: This change set requires Dialogs-sbw and AppearanceMenuReg-sbw. Date Update ------------- ----------------------------------------------------------------------- 20-apr-2003 Added prerequisite change set checking to preamble. 15-apr-2003 update for Squeak 3.5 22-Nov-2002 Modified to work with Squeak 3.4. 30-sep-200 initial file release. " | prereqSMName continue cs prereqCSName prereqRevDateRqd | prereqCSName _ 'AppearanceMenuReg-sbw'. prereqSMName _ 'Appearance Menu Registry'. prereqRevDateRqd _ '15-apr-2003' asDate. continue _ (ChangeSorter respondsTo: #assurePrerequisiteChangeSetNamed:withSqueakMapName:revisionDate:) ifTrue: [ChangeSorter assurePrerequisiteChangeSetNamed: prereqCSName withSqueakMapName: prereqSMName revisionDate: prereqRevDateRqd] ifFalse: [cs _ ChangeSorter changeSetNamed: prereqCSName. cs isNil ifTrue: [(Object confirm: 'The package "' , prereqSMName , '" is not installed in your image. Do you want me to install it for you?. Please note that "' , prereqSMName , '" is required for the package you are about to install.') and: []. (Smalltalk at: #SMSqueakMap ifAbsent: []) ifNil: [Object error: 'You don''t have installed Squeakmap in your image']. Utilities informUser: 'Installing "' , prereqSMName , '"...' during: [(Smalltalk at: #SMSqueakMap) default installPackageNamed: prereqSMName]. true] ifFalse: [true]]. continue ifFalse: [Object error: 'Unable to load prerequisite package.']. prereqCSName _ 'Dialogs-sbw'. prereqSMName _ 'FileList2 Dialogs Enhancement'. prereqRevDateRqd _ '15-apr-2003' asDate. continue _ (ChangeSorter respondsTo: #assurePrerequisiteChangeSetNamed:withSqueakMapName:revisionDate:) ifTrue: [ChangeSorter assurePrerequisiteChangeSetNamed: prereqCSName withSqueakMapName: prereqSMName revisionDate: prereqRevDateRqd] ifFalse: [cs _ ChangeSorter changeSetNamed: prereqCSName. cs isNil ifTrue: [(Object confirm: 'The package "' , prereqSMName , '" is not installed in your image. Do you want me to install it for you?. Please note that "' , prereqSMName , '" is required for the package you are about to install.') and: []. (Smalltalk at: #SMSqueakMap ifAbsent: []) ifNil: [Object error: 'You don''t have installed Squeakmap in your image']. Utilities informUser: 'Installing "' , prereqSMName , '"...' during: [(Smalltalk at: #SMSqueakMap) default installPackageNamed: prereqSMName]. true] ifFalse: [true]]. continue ifFalse: [Object error: 'Unable to load prerequisite package.']. ! !FileList2 methodsFor: '*patternLoader' stamp: 'sbw 1/30/2002 00:55'! fileListIndex: anInteger super fileListIndex: anInteger. self changed: #imageDimensionContents. self updateImageMorph! ! !FileList2 methodsFor: '*patternLoader' stamp: 'sbw 3/8/2002 11:45'! imageDimensionContents | fName frm ext dpth strm label | label _ 'Dimensions: '. listIndex = 0 ifFalse: [fName _ self fullName. fName isNil ifFalse: [frm _ Form fromFileNamed: fName. frm isNil ifFalse: [ext _ frm extent. dpth _ frm depth. strm _ ReadWriteStream on: ''. strm nextPutAll: ' ' , ext x printString; nextPutAll: ' x ' , ext y printString; nextPutAll: ' x ' , dpth printString. ^ label, strm contents]]]. ^ label! ! !FileList2 methodsFor: '*patternLoader' stamp: 'sbw 3/8/2002 10:59'! imageMorph | win | win _ self topView. win isNil ifTrue: [^ nil]. ^ win submorphNamed: #image! ! !FileList2 methodsFor: '*patternLoader' stamp: 'sbw 3/8/2002 10:44'! morphicImageDimensionsPane | pane | pane _ PluggableTextMorph on: self text: #imageDimensionContents accept: nil readSelection: nil menu: nil. pane hideScrollBarIndefinitely; color: Color white. ^ pane! ! !FileList2 methodsFor: '*patternLoader' stamp: 'sbw 3/8/2002 11:09'! morphicImagePreviewPane | alignMorph | alignMorph _ AlignmentMorph newColumn beSticky. alignMorph borderWidth: 0; color: Color white; clipSubmorphs: true; layoutPolicy: ProportionalLayout new. alignMorph addMorphBack: (ImageMorph new name: #image; image: self whiteFormPreviewPane; yourself). ^alignMorph! ! !FileList2 methodsFor: '*patternLoader' stamp: 'sbw 3/8/2002 11:56'! optionalButtonRow | row | row _ super optionalButtonRow. Preferences alternativeWindowLook ifTrue: [row color: Color transparent. row submorphsDo: [:m | m borderWidth: 2; borderColor: #raised]]. ^row! ! !FileList2 methodsFor: '*patternLoader' stamp: 'sbw 1/30/2002 00:55'! preview ^Form fromFileNamed: self fullName! ! !FileList2 methodsFor: '*patternLoader' stamp: 'sbw 11/22/2002 04:53'! servicesForImageViewPreviewer "Answer the services to show in the button pane for the project loader" ^ {self serviceSortByName. self serviceSortByDate. self serviceSortBySize}! ! !FileList2 methodsFor: '*patternLoader' stamp: 'sbw 1/9/2003 17:45'! setSelectedDirectoryTo: aFileDirectoryWrapper currentDirectorySelected _ aFileDirectoryWrapper. self directory: aFileDirectoryWrapper withoutListWrapper. brevityState _ #FileList. "self addPath: path." self changed: #fileList. self changed: #contents. self changed: #currentDirectorySelected. self changed: #imageDimensionContents. self updateImageMorph! ! !FileList2 methodsFor: '*patternLoader' stamp: 'sbw 3/8/2002 11:43'! updateImageMorph | morph form preview limits ratio ext fName | morph _ self imageMorph. morph isNil ifTrue: [^ nil]. listIndex = 0 ifTrue: [preview _ self whiteFormPreviewPane] ifFalse: [fName _ self fullName. fName isNil ifFalse: [form _ self preview. limits _ morph owner extent - (2*(self class previewWhiteSpace@self class previewWhiteSpace)). (form width <= limits x and: [form height <= limits y]) ifTrue: [preview _ form] ifFalse: [form width > form height ifTrue: [ratio _ limits x / form width] ifFalse: [ratio _ limits y / form height]. ext _ (form extent * ratio) rounded. preview _ form scaledToSize: ext]]]. morph newForm: preview. morph layoutChanged! ! !FileList2 methodsFor: '*patternLoader' stamp: 'sbw 3/8/2002 11:07'! whiteFormPreviewPane | whiteForm extent iMorph | extent _ 1 @ 1. self topView isNil ifFalse: [iMorph _ self imageMorph. iMorph isNil ifFalse: [extent _ iMorph extent]]. whiteForm _ Form extent: extent depth: 32. whiteForm fill: whiteForm boundingBox fillColor: self defaultBackgroundColor. ^ whiteForm! ! !FileList2 class methodsFor: '*patternLoader' stamp: 'sbw 3/8/2002 11:41'! buildPreviewerPane: aFileList | alignMorph listHeight dimHeight space | listHeight _ 70. dimHeight _ 16. space _ self previewWhiteSpace. alignMorph _ AlignmentMorph newColumn beSticky. alignMorph borderWidth: 0; color: Color white; clipSubmorphs: true; layoutPolicy: ProportionalLayout new. alignMorph addMorph: aFileList morphicFileListPane fullFrame: (LayoutFrame fractions: (0 @ 0 corner: 1 @ 0) offsets: (16 @ 0 corner: 0 @ listHeight)). alignMorph addMorph: aFileList morphicImageDimensionsPane fullFrame: (LayoutFrame fractions: (0 @ 0 corner: 1 @ 0) offsets: (16 @ (listHeight + space) corner: 0 @ (listHeight + space + dimHeight))). alignMorph addMorph: aFileList morphicImagePreviewPane fullFrame: (LayoutFrame fractions: (0 @ 0 corner: 1 @ 1) offsets: (space @ (listHeight + space + dimHeight + space) corner: space negated @ space negated)). ^ alignMorph! ! !FileList2 class methodsFor: '*patternLoader' stamp: 'sbw 11/22/2002 16:31'! morphicViewImageViewerWithPreview | dir aFileList window firstLine fixedSize | dir _ FileDirectory default. aFileList _ self new directory: dir. aFileList optionalButtonSpecs: aFileList servicesForImageViewPreviewer. window _ (SystemWindow labelled: 'Select image for desktop') model: aFileList. fixedSize _ 25. firstLine _ 0.4. self addFullPanesTo: window from: { {aFileList optionalButtonRow. 0 @ 0 corner: 1 @ 0. 0 @ 0 corner: 0 @ fixedSize}. {aFileList morphicDirectoryTreePane. 0 @ 0 corner: firstLine @ 1. 0 @ fixedSize corner: 0 @ 0}. {self buildPreviewerPane: aFileList. firstLine @ 0 corner: 1 @ 1. 0 @ fixedSize corner: 0 @ 0}}. aFileList postOpen. ^ window! ! !FileList2 class methodsFor: '*patternLoader' stamp: 'sbw 1/30/2002 01:04'! openMorphicViewWithPreviewInWorld "FileList2 openMorphicViewWithPreviewInWorld" ^ self morphicViewImageViewerWithPreview openInWorld! ! !FileList2 class methodsFor: '*patternLoader' stamp: 'sbw 3/8/2002 11:41'! previewWhiteSpace ^3! ! !FileList2 class methodsFor: '*patternLoader' stamp: 'sbw 11/22/2002 18:34'! registerPatternLoaderWithAppearanceMenu "FileList2 registerPatternLoaderWithAppearanceMenu" TheWorldMenu registerAppearanceCommand: {'set desktop image...'. {FileList2. #openMorphicViewWithPreviewInWorld}. 'open up an image browser to choose a new desktop background'}! ! !Form methodsFor: '*patternLoader' stamp: 'sbw 11/16/2002 11:24'! scaledToSizeUsingMaximum: newExtent | scale | newExtent = self extent ifTrue: [^ self]. scale _ newExtent x / self width max: newExtent y / self height. ^ self magnify: self boundingBox by: scale smoothing: 2! ! !Form class methodsFor: '*patternLoader' stamp: 'sbw 11/22/2002 16:50'! fileReaderServicesForFile: fullName suffix: suffix ^(suffix = 'bmp') | (suffix = 'gif') | (suffix = 'jpg') | (suffix = 'jpeg') | (suffix = 'form') | (suffix = '*') | (suffix = 'png') ifTrue: [ self services ] ifFalse: [#()] ! ! !Form class methodsFor: '*patternLoader' stamp: 'sbw 11/22/2002 16:48'! openAsBackgroundWithOptions: fullName | theForm choices actions response | theForm _ self fromFileNamed: fullName. Smalltalk isMorphic ifFalse: [^ theForm setAsBackground]. choices _ #('Tile the image' 'Scale the image full' 'Scale the image keep aspect' 'Center the image' ). actions _ #(#tile #scale #aspect #center ). response _ (SelectionMenu labelList: choices selections: actions) startUpWithCaption: 'Set in background with option...'. response = #tile ifTrue: [^ theForm setAsBackground]. response = #scale ifTrue: [^ (theForm scaledToSizeUsingMaximum: self currentWorld extent) setAsBackground]. response = #aspect ifTrue: [^ self openImageCenteredOnBackground: (theForm scaledToSizeUsingMaximum: self currentWorld extent)]. response = #center ifTrue: [^ self openImageCenteredOnBackground: theForm]! ! !Form class methodsFor: '*patternLoader' stamp: 'sbw 11/22/2002 16:52'! openImageCenteredOnBackground: image | sketch previous | sketch _ SketchMorph withForm: image. sketch setToAdhereToEdge: #center; name: 'worldBackgroundImage'; lock. previous _ self currentWorld submorphNamed: 'worldBackgroundImage'. previous isNil ifFalse: [previous delete]. sketch openInWorld. sketch goBehind! ! !Form class methodsFor: '*patternLoader' stamp: 'sbw 11/22/2002 16:45'! serviceImageAsBackground "Answer a service for setting the desktop background from a given graphical file's contents" ^ SimpleServiceEntry provider: self label: 'use graphic as background' selector: #openAsBackgroundWithOptions: description: 'use the graphic as the background for the desktop (with placement options)' buttonLabel: 'background'! ! "Postscript: Add a hook to the appearance menu." FileList2 registerPatternLoaderWithAppearanceMenu. !