[Newbies] SampleCode-ImageViewer

Edgar J. De Cleene edgardec2001 at yahoo.com.ar
Mon Jun 25 14:33:05 UTC 2007


Also you could do:

SelectedPictures new showThumbnails

Edgar

-------------- next part --------------
'From Squeak3.9alpha of 4 July 2005 [latest update: #6705] on 1 April 2005 at 9:24:38 am'!
"Change Set:		PobrePoint
Date:			1 April 2006
Author:			Edgar J. De Cleene

This is a adapted how to tutorial for El Marjani Raouane from my old stuff>"!

ImageMorph subclass: #MiFotoMiniatura
	instanceVariableNames: 'index'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'PobrePoint'!
Object subclass: #SelectedPictures
	instanceVariableNames: 'folder imagesList'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'PobrePoint'!
ImageMorph subclass: #SlideShowMorph
	instanceVariableNames: 'imagesList index'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'PobrePoint'!

!MiFotoMiniatura methodsFor: 'menus' stamp: 'edc 8/22/2002 11:30'!
addCustomMenuItems: aCustomMenu hand: aHandMorph 
	"Include our modest command set in the ctrl-menu"
	super addCustomMenuItems: aCustomMenu hand: aHandMorph.
	aCustomMenu addLine.
	self addMenuItemsTo: aCustomMenu hand: aHandMorph! !

!MiFotoMiniatura methodsFor: 'menus' stamp: 'edc 10/1/2003 10:22'!
addMenuItemsTo: aMenu hand: aHandMorph 
	| menu |
	menu _ MenuMorph new.
	menu
		color: (Color
				r: 0.4
				g: 0.4
				b: 0.4).
	menu
		color: (menu color alpha: 0.5).
	menu
		add: 'rotar contra reloj '
		target: self
		action: #rotarCCW.
	menu
		add: 'rotar sentido reloj '
		target: self
		action: #rotarCW.
menu
		add: 'ver Original '
		target: self
		action: #verOriginal.
	menu items
		do: [:i | i color: Color red;
				
				font: (StrikeFont
						familyName: 'Comic Bold'
						size: 12
						emphasized: 1)].
	menu invokeModal! !

!MiFotoMiniatura methodsFor: 'menus' stamp: 'edc 4/1/2005 08:18'!
initializarCon: unaImagen numero: unEntero 
	| rect text f frame |
	f := Form fromFileNamed: unaImagen.
	f := f scaledToSize: 80 @ 60.
	self image: f.
	self index: unEntero.
	rect := RectangleMorph roundRectPrototype
				color: (Color
						r: 0.4
						g: 0.4
						b: 0.4
						alpha: 0.5);
				 borderWidth: 2.
	text := TextMorph new contents: unEntero asString;
				 textColor: Color red;
				 fontName: #ComicBold size: 9.
	rect extent: text extent + (8 @ 6) asPoint.
	frame := LayoutFrame new.
	frame leftFraction: 0.5 offset: text width // -2.
	frame topFraction: 0 offset: 0.
	text layoutFrame: frame.
	rect layoutPolicy: ProportionalLayout new.
	rect addMorph: text.
	
	rect openInWorld.
	rect topLeft: self bottomLeft.
	self addMorph: rect.
	self openInWorld! !

!MiFotoMiniatura methodsFor: 'menus' stamp: 'edc 10/2/2003 08:49'!
redraw
	| m |
	m _ submorphs at: 1.
	self
		privateRemoveMorph: (submorphs at: 1).
	m topLeft: self bottomLeft.
	self addMorph: m.
	! !

!MiFotoMiniatura methodsFor: 'menus' stamp: 'edc 10/2/2003 08:51'!
rotarCW
	| f |
	f _ self image 	 rotateBy: #right centerAt: self center.
	self image: f.
	self redraw! !

!MiFotoMiniatura methodsFor: 'event handling' stamp: 'edc 10/1/2003 09:24'!
handlesMouseDown: anEvent 
	^ Smalltalk isMorphic not
		or: [anEvent yellowButtonPressed]! !

!MiFotoMiniatura methodsFor: 'event handling' stamp: 'edc 10/1/2003 10:21'!
mouseDown: evt 
	evt yellowButtonPressed
		ifTrue: [self processYellowButton: evt]
		ifFalse: [^ evt hand waitForClicksOrDrag: self event: evt]! !

!MiFotoMiniatura methodsFor: 'event handling' stamp: 'edc 10/1/2003 09:48'!
processYellowButton
	| s |
	s _ MiStack allInstances
		detect: [:each | each world == ActiveWorld].
s loadImage: self index! !

!MiFotoMiniatura methodsFor: 'event handling' stamp: 'edc 10/1/2003 10:21'!
processYellowButton: evt
| menu |
menu _ MenuMorph new defaultTarget: self.
			self addMenuItemsTo: menu hand: evt hand.
			menu popUpEvent: evt in: self world.! !

!MiFotoMiniatura methodsFor: 'accessing' stamp: 'edc 9/29/2003 09:34'!
index
	"Answer the value of index"

	^ index! !

!MiFotoMiniatura methodsFor: 'accessing' stamp: 'edc 9/29/2003 09:34'!
index: anObject
	"Set the value of index"

	index _ anObject! !

!MiFotoMiniatura methodsFor: 'menu commands' stamp: 'edc 10/2/2003 08:48'!
rotarCCW
	| f |
	f _ self image rotateBy: #left centerAt: self center.
	self image: f.
	self redraw! !

!MiFotoMiniatura methodsFor: 'menu commands' stamp: 'edc 3/25/2004 10:36'!
verOriginal
	| s |
	s _ MiStack allInstances last.
	
	s isInWorld
		ifTrue: [s loadImage: self index]! !


!SelectedPictures methodsFor: 'accessing' stamp: 'edc 3/18/2004 10:22'!
folder
	"Answer the value of folder"

	^ folder! !

!SelectedPictures methodsFor: 'accessing' stamp: 'edc 3/18/2004 10:22'!
folder: anObject
	"Set the value of folder"

	folder _ anObject! !

!SelectedPictures methodsFor: 'accessing' stamp: 'edc 3/18/2004 10:22'!
imagesList
	"Answer the value of imagesList"

	^ imagesList! !

!SelectedPictures methodsFor: 'accessing' stamp: 'edc 3/18/2004 10:22'!
imagesList: anObject
	"Set the value of imagesList"

	imagesList _ anObject! !

!SelectedPictures methodsFor: 'actions' stamp: 'edc 4/1/2005 08:42'!
showThumbnails
	| fondo number thumb |
	fondo := PasteUpMorph new.
	fondo becomeLikeAHolder.
	number := 1.
	self imagesList
		do: [:pict | 
thumb:= MiFotoMiniatura new .
thumb initializarCon: folder pathName, FileDirectory slash,pict numero: number.

			
			number := number + 1.
			fondo addMorphBack: thumb].
	fondo extent: World extent * 0.9.
	fondo openCenteredInWorld! !

!SelectedPictures methodsFor: 'actions' stamp: 'edc 4/1/2005 09:13'!
slideShow
|fullpathNames|
fullpathNames := OrderedCollection new.
self imagesList
		do: [:pict | fullpathNames add: 
(folder pathName, FileDirectory slash,pict)].
^ SlideShowMorph new imagesList: fullpathNames
! !

!SelectedPictures methodsFor: 'initialize-release' stamp: 'edc 4/1/2005 08:37'!
initialize
	| aSuffixList   |
	
	folder := FileDirectory on: (FileList2 modalFolderSelector) pathName.
	
aSuffixList :=#('.gif' '.jpg' '.png' ).


	imagesList := OrderedCollection new.
	aSuffixList do:
		[:aSuffix | imagesList addAll: (folder  fileNamesMatching: '*', aSuffix)].
	self inspect
! !


!SlideShowMorph methodsFor: 'accessing' stamp: 'edc 4/1/2005 08:59'!
imagesList
	"Answer the value of imagesList"

	^ imagesList! !

!SlideShowMorph methodsFor: 'accessing' stamp: 'edc 4/1/2005 08:59'!
imagesList: anObject
	"Set the value of imagesList"

	imagesList := anObject! !

!SlideShowMorph methodsFor: 'initialization' stamp: 'edc 4/1/2005 09:08'!
initialize
super initialize.
index:= 0.
self openCenteredInWorld! !

!SlideShowMorph methodsFor: 'stepping and presenter' stamp: 'edc 4/1/2005 09:19'!
step
(index < imagesList  size) ifTrue:[index := index  + 1.
	self image:( Form fromFileNamed: (imagesList at: index))]
ifFalse:[PopUpMenu inform: 'End of know picts'] .
! !

!SlideShowMorph methodsFor: 'stepping and presenter' stamp: 'edc 4/1/2005 09:08'!
stepTime
^1000! !


!SlideShowMorph reorganize!
('accessing' imagesList imagesList:)
('initialization' initialize)
('stepping and presenter' step stepTime)
!

SelectedPictures class removeSelector: #new!
SelectedPictures removeSelector: #resetFolder!

!SelectedPictures reorganize!
('accessing' folder folder: imagesList imagesList:)
('actions' showThumbnails slideShow)
('initialize-release' initialize)
!



More information about the Beginners mailing list