--- a/ImageEditor.st Sat Apr 04 13:34:35 1998 +0200
+++ b/ImageEditor.st Wed Apr 08 01:25:23 1998 +0200
@@ -1,5 +1,5 @@
"
- COPYRIGHT (c) 1997 by eXept Software AG
+ COPYRIGHT (c) 1997-1998 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
@@ -21,7 +21,7 @@
copyright
"
- COPYRIGHT (c) 1997 by eXept Software AG
+ COPYRIGHT (c) 1997-1998 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
@@ -47,30 +47,28 @@
[author:]
Thomas Zwick, eXept Software AG
"
-!
-
-listOfColors
-
- ^List new
-
! !
!ImageEditor class methodsFor:'instance creation'!
openModalOnClass: aClass andSelector: aSelector
-
- "self openModalOnClass: self andSelector: #leftMouseKeyIcon"
+ "opens modal the Image Editor on aClass and aSelector"
+ "
+ self openModalOnClass: self andSelector: #leftMouseKeyIcon
+ "
- |imageEditor imageEditView className resourceClassName resourceSelector|
+ |imageEditor imageEditView className resourceClassName resourceSelector|
+
imageEditor := self new.
+
aClass isClass ifTrue: [className := aClass name].
- aClass isString ifTrue: [className := aClass].
+ aClass isString ifTrue:[className := aClass].
imageEditor postOpenAction: [imageEditView := imageEditor imageEditView. imageEditor loadFromOrPrepareForMessage: className, ' ', aSelector].
imageEditor openModal.
resourceClassName := imageEditView resourceClass.
- resourceSelector := imageEditView resourceSelector.
+ resourceSelector := imageEditView resourceSelector.
(className asString ~= resourceClassName) | (aSelector asString ~= resourceSelector)
ifTrue: [^resourceClassName, ' ', resourceSelector]
@@ -78,29 +76,36 @@
!
openOnClass: aClass andSelector: aSelector
-
- "self openOnClass: self andSelector: #leftMouseKeyIcon"
+ "opens the Image Editor on aClass and aSelector"
+ "
+ self openOnClass: self andSelector: #leftMouseKeyIcon
+ "
^self open loadFromMessage: aClass name, ' ', aSelector
!
-openOnFile: image
+openOnFile: aFileName
+ "opens the Image Editor on aFileName"
+ "
+ self openOnFile: 'bitmaps/SmalltalkX.xbm'
+ "
- "self openOnFile: 'bitmaps/SmalltalkX.xbm'"
-
- ^self open loadFromFile: image
+ ^self open loadFromFile: aFileName
!
-openOnImage: image
+openOnImage: anImage
+ "opens the Image Editor on anImage"
+ "
+ self openOnImage: self stxIcon
+ "
- "self openOnImage: self stxIcon"
-
- ^self open loadFromImage: image
+ ^self open loadFromImage: anImage
! !
!ImageEditor class methodsFor:'accessing'!
listOfColorMaps
+ "returns the list of default color maps for a new image"
|colorMap|
(colorMap := OrderedCollection new)
@@ -149,8 +154,9 @@
!
listOfDefaultSizes
+ "returns the list of default sizes for a new image"
- ^#('24x24' '16x16' '32x32')
+ ^#('22x22' '16x16' '32x32')
! !
!ImageEditor class methodsFor:'help specs'!
@@ -292,7 +298,7 @@
!ImageEditor class methodsFor:'interface specs'!
-windowSpec
+dialogSpecForNewImage
"This resource specification was automatically generated
by the UIPainter of ST/X."
@@ -300,205 +306,8 @@
the UIPainter may not be able to read the specification."
"
- UIPainter new openOnClass:ImageEditor andSelector:#windowSpec
- ImageEditor new openInterface:#windowSpec
- ImageEditor open
- "
-
- <resource: #canvas>
-
- ^
-
- #(#FullSpec
- #window:
- #(#WindowSpec
- #name: 'Image Editor'
- #layout: #(#LayoutFrame 188 0 318 0 687 0 663 0)
- #label: 'Image Editor'
- #min: #(#Point 400 320)
- #max: #(#Point 1152 900)
- #bounds: #(#Rectangle 188 318 688 664)
- #menu: #menu
- #usePreferredExtent: false
- )
- #component:
- #(#SpecCollection
- #collection:
- #(
- #(#MenuPanelSpec
- #name: 'menuToolbarView'
- #layout: #(#LayoutFrame 0 0.0 0 0 0 1.0 32 0)
- #menu: #menuToolbar
- #style: #(#FontDescription #helvetica #medium #roman 10)
- #showSeparatingLines: true
- )
- #(#VariableHorizontalPanelSpec
- #name: 'variableHorizontalPanel1'
- #layout: #(#LayoutFrame 0 0.0 34 0.0 0 1.0 -26 1.0)
- #component:
- #(#SpecCollection
- #collection:
- #(
- #(#ViewSpec
- #name: 'view1'
- #component:
- #(#SpecCollection
- #collection:
- #(
- #(#VariableVerticalPanelSpec
- #name: 'VariableVerticalPanel1'
- #layout: #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
- #component:
- #(#SpecCollection
- #collection:
- #(
- #(#ViewSpec
- #name: 'View1'
- #component:
- #(#SpecCollection
- #collection:
- #(
- #(#MenuPanelSpec
- #name: 'MouseButtonColorToolBar'
- #layout: #(#LayoutFrame 0 0.0 0 0 0 1.0 24 0)
- #menu: #menuMouseButtonColors
- )
- #(#DataSetSpec
- #name: 'colorDataSetView'
- #layout: #(#LayoutFrame 0 0.0 26 0.0 0 1.0 0 1.0)
- #activeHelpKey: #colorMapTable
- #model: #selectionOfColor
- #style: #(#FontDescription #helvetica #medium #roman 10)
- #hasHorizontalScrollBar: true
- #hasVerticalScrollBar: true
- #miniScrollerHorizontal: true
- #miniScrollerVertical: true
- #level: -1
- #dataList: #listOfColors
- #has3Dsepartors: true
- #verticalSpacing: 1
- #columns:
- #(
- #(#DataSetColumnSpec
- #rendererType: #rowSelector
- #backgroundSelector: #yourself
- )
- #(#DataSetColumnSpec
- #label: 'R'
- #model: #rowRedByte
- #canSelect: false
- )
- #(#DataSetColumnSpec
- #label: 'G'
- #model: #rowGreenByte
- #canSelect: false
- )
- #(#DataSetColumnSpec
- #label: 'B'
- #model: #rowBlueByte
- #canSelect: false
- )
- )
- )
- )
- )
- )
- #(#ArbitraryComponentSpec
- #name: 'imagePreView'
- #activeHelpKey: #previewView
- #hasHorizontalScrollBar: true
- #hasVerticalScrollBar: true
- #miniScrollerHorizontal: true
- #miniScrollerVertical: true
- #component: #ImageView
- #hasBorder: false
- )
- )
- )
- #handles: #(#Any 0.723776 1.0)
- )
- )
- )
- )
- #(#ViewSpec
- #name: 'view2'
- #component:
- #(#SpecCollection
- #collection:
- #(
- #(#ArbitraryComponentSpec
- #name: 'imageEditView'
- #layout: #(#LayoutFrame 2 0.0 2 0.0 -2 1.0 -24 1.0)
- #hasHorizontalScrollBar: true
- #hasVerticalScrollBar: true
- #component: #ImageEditView
- #hasBorder: false
- )
- #(#LabelSpec
- #name: 'coordLabel'
- #layout: #(#LayoutFrame 2 0.0 -22 1 -83 1.0 0 1.0)
- #level: -1
- #adjust: #left
- #resizeForLabel: false
- )
- #(#ArrowButtonSpec
- #name: 'magnifyDownButton'
- #layout: #(#LayoutFrame -80 1 -22 1 -58 1 0 1)
- #activeHelpKey: #magnifyImageDown
- #model: #magnifyDown
- #enableChannel: #imageIsLoaded
- #isTriggerOnDown: true
- #direction: #left
- )
- #(#ArrowButtonSpec
- #name: 'magnifyUpButton'
- #layout: #(#LayoutFrame -24 1 -22 1 -2 1 0 1)
- #activeHelpKey: #magnifyImageUp
- #model: #magnifyUp
- #enableChannel: #imageIsLoaded
- #isTriggerOnDown: true
- #direction: #right
- )
- #(#InputFieldSpec
- #name: 'magnificationInputField'
- #layout: #(#LayoutFrame -57 1 -22 1 -26 1 0 1)
- #activeHelpKey: #magnificationNumber
- #enableChannel: #imageIsLoaded
- #model: #valueOfMagnification
- #type: #number
- #acceptOnReturn: false
- #acceptOnTab: false
- #numChars: 2
- )
- )
- )
- #level: -1
- )
- )
- )
- #handles: #(#Any 0.276 1.0)
- )
- #(#UISubSpecification
- #name: 'infoBarSubSpec'
- #layout: #(#LayoutFrame 0 0.0 -24 1 0 1.0 0 1.0)
- #majorKey: #ToolApplicationModel
- #minorKey: #windowSpecForInfoBar
- )
- )
- )
- )
-!
-
-windowSpecForNewImage
- "This resource specification was automatically generated
- by the UIPainter of ST/X."
-
- "Do not manually edit this!! If it is corrupted,
- the UIPainter may not be able to read the specification."
-
- "
- UIPainter new openOnClass:ImageEditor andSelector:#windowSpecForNewImage
- ImageEditor new openInterface:#windowSpecForNewImage
+ UIPainter new openOnClass:ImageEditor andSelector:#dialogSpecForNewImage
+ ImageEditor new openInterface:#dialogSpecForNewImage
"
<resource: #canvas>
@@ -580,6 +389,206 @@
)
)
)
+!
+
+windowSpec
+ "This resource specification was automatically generated
+ by the UIPainter of ST/X."
+
+ "Do not manually edit this!! If it is corrupted,
+ the UIPainter may not be able to read the specification."
+
+ "
+ UIPainter new openOnClass:ImageEditor andSelector:#windowSpec
+ ImageEditor new openInterface:#windowSpec
+ ImageEditor open
+ "
+
+ <resource: #canvas>
+
+ ^
+
+ #(#FullSpec
+ #window:
+ #(#WindowSpec
+ #name: 'Image Editor'
+ #layout: #(#LayoutFrame 167 0 330 0 666 0 675 0)
+ #label: 'Image Editor'
+ #min: #(#Point 400 320)
+ #max: #(#Point 1152 900)
+ #bounds: #(#Rectangle 167 330 667 676)
+ #menu: #menu
+ #usePreferredExtent: false
+ )
+ #component:
+ #(#SpecCollection
+ #collection:
+ #(
+ #(#MenuPanelSpec
+ #name: 'menuToolbarView'
+ #layout: #(#LayoutFrame 0 0.0 0 0 0 1.0 32 0)
+ #menu: #menuToolbar
+ #style: #(#FontDescription #helvetica #medium #roman 10)
+ #showSeparatingLines: true
+ )
+ #(#VariableHorizontalPanelSpec
+ #name: 'variableHorizontalPanel1'
+ #layout: #(#LayoutFrame 0 0.0 34 0.0 0 1.0 -26 1.0)
+ #component:
+ #(#SpecCollection
+ #collection:
+ #(
+ #(#ViewSpec
+ #name: 'view1'
+ #component:
+ #(#SpecCollection
+ #collection:
+ #(
+ #(#VariableVerticalPanelSpec
+ #name: 'VariableVerticalPanel1'
+ #layout: #(#LayoutFrame 0 0.0 0 0.0 0 1.0 0 1.0)
+ #component:
+ #(#SpecCollection
+ #collection:
+ #(
+ #(#ViewSpec
+ #name: 'View1'
+ #component:
+ #(#SpecCollection
+ #collection:
+ #(
+ #(#MenuPanelSpec
+ #name: 'MouseButtonColorToolBar'
+ #layout: #(#LayoutFrame 0 0.0 0 0 0 1.0 24 0)
+ #menu: #menuMouseButtonColors
+ )
+ #(#DataSetSpec
+ #name: 'colorDataSetView'
+ #layout: #(#LayoutFrame 0 0.0 26 0.0 0 1.0 0 1.0)
+ #activeHelpKey: #colorMapTable
+ #model: #selectionOfColor
+ #style: #(#FontDescription #helvetica #medium #roman 10)
+ #hasHorizontalScrollBar: true
+ #hasVerticalScrollBar: true
+ #miniScrollerHorizontal: true
+ #miniScrollerVertical: true
+ #level: -1
+ #dataList: #listOfColors
+ #has3Dsepartors: true
+ #verticalSpacing: 1
+ #columns:
+ #(
+ #(#DataSetColumnSpec
+ #rendererType: #rowSelector
+ #backgroundSelector: #yourself
+ )
+ #(#DataSetColumnSpec
+ #label: 'R'
+ #labelAlignment: #left
+ #model: #rowRedByte
+ #canSelect: false
+ )
+ #(#DataSetColumnSpec
+ #label: 'G'
+ #labelAlignment: #left
+ #model: #rowGreenByte
+ #canSelect: false
+ )
+ #(#DataSetColumnSpec
+ #label: 'B'
+ #labelAlignment: #left
+ #model: #rowBlueByte
+ #canSelect: false
+ )
+ )
+ )
+ )
+ )
+ )
+ #(#ArbitraryComponentSpec
+ #name: 'imagePreView'
+ #activeHelpKey: #previewView
+ #hasHorizontalScrollBar: true
+ #hasVerticalScrollBar: true
+ #miniScrollerHorizontal: true
+ #miniScrollerVertical: true
+ #component: #ImageView
+ #hasBorder: false
+ )
+ )
+ )
+ #handles: #(#Any 0.723776 1.0)
+ )
+ )
+ )
+ )
+ #(#ViewSpec
+ #name: 'view2'
+ #component:
+ #(#SpecCollection
+ #collection:
+ #(
+ #(#ArbitraryComponentSpec
+ #name: 'imageEditView'
+ #layout: #(#LayoutFrame 2 0.0 2 0.0 -2 1.0 -24 1.0)
+ #hasHorizontalScrollBar: true
+ #hasVerticalScrollBar: true
+ #component: #ImageEditView
+ #hasBorder: false
+ )
+ #(#LabelSpec
+ #name: 'coordLabel'
+ #layout: #(#LayoutFrame 2 0.0 -22 1 -83 1.0 0 1.0)
+ #level: -1
+ #adjust: #left
+ #resizeForLabel: false
+ )
+ #(#ArrowButtonSpec
+ #name: 'magnifyDownButton'
+ #layout: #(#LayoutFrame -80 1 -22 1 -58 1 0 1)
+ #activeHelpKey: #magnifyImageDown
+ #model: #doMagnifyDown
+ #enableChannel: #imageIsLoaded
+ #isTriggerOnDown: true
+ #direction: #left
+ )
+ #(#ArrowButtonSpec
+ #name: 'magnifyUpButton'
+ #layout: #(#LayoutFrame -24 1 -22 1 -2 1 0 1)
+ #activeHelpKey: #magnifyImageUp
+ #model: #doMagnifyUp
+ #enableChannel: #imageIsLoaded
+ #isTriggerOnDown: true
+ #direction: #right
+ )
+ #(#InputFieldSpec
+ #name: 'magnificationInputField'
+ #layout: #(#LayoutFrame -57 1 -22 1 -26 1 0 1)
+ #activeHelpKey: #magnificationNumber
+ #enableChannel: #imageIsLoaded
+ #model: #valueOfMagnification
+ #type: #number
+ #acceptOnReturn: false
+ #acceptOnTab: false
+ #numChars: 2
+ )
+ )
+ )
+ #level: -1
+ )
+ )
+ )
+ #handles: #(#Any 0.276 1.0)
+ )
+ #(#UISubSpecification
+ #name: 'infoBarSubSpec'
+ #layout: #(#LayoutFrame 0 0.0 -24 1 0 1.0 0 1.0)
+ #majorKey: #ToolApplicationModel
+ #minorKey: #windowSpecForInfoBar
+ )
+ )
+ )
+ )
! !
!ImageEditor class methodsFor:'menu specs'!
@@ -619,7 +628,7 @@
#(
#(#MenuItem
#label: 'New...'
- #value: #newImage
+ #value: #doNewImage
#activeHelpKey: #fileNewImage
)
#(#MenuItem
@@ -627,12 +636,12 @@
)
#(#MenuItem
#label: 'Load...'
- #value: #loadFromClass
+ #value: #doLoadFromClass
#activeHelpKey: #fileLoadFromClass
)
#(#MenuItem
#label: 'Load From File...'
- #value: #loadFromFile
+ #value: #doLoadFromFile
#activeHelpKey: #fileLoadFromFile
)
#(#MenuItem
@@ -640,13 +649,13 @@
)
#(#MenuItem
#label: 'Save'
- #value: #saveMethod
+ #value: #doSaveMethod
#activeHelpKey: #fileSaveMethod
#enabled: #imageIsLoaded
)
#(#MenuItem
#label: 'Save As...'
- #value: #saveMethodAs
+ #value: #doSaveMethodAs
#activeHelpKey: #fileSaveMethodAs
#enabled: #imageIsLoaded
)
@@ -655,13 +664,13 @@
)
#(#MenuItem
#label: 'Save To File...'
- #value: #saveImageFileAs
+ #value: #doSaveImageFileAs
#activeHelpKey: #fileSaveAs
#enabled: #imageIsLoaded
)
#(#MenuItem
#label: 'Save Mask To File...'
- #value: #saveImageMaskFileAs
+ #value: #doSaveImageMaskFileAs
#activeHelpKey: #fileSaveMaskAs
#enabled: #imageIsLoaded
)
@@ -670,7 +679,7 @@
)
#(#MenuItem
#label: 'Print'
- #value: #print
+ #value: #doPrint
#activeHelpKey: #filePrint
#enabled: #imageIsLoaded
)
@@ -679,7 +688,7 @@
)
#(#MenuItem
#label: 'Browse Class'
- #value: #browseClass
+ #value: #doBrowseClass
#activeHelpKey: #fileBrowseClass
#enabled: #imageIsLoaded
)
@@ -706,7 +715,7 @@
#(
#(#MenuItem
#label: 'Undo'
- #value: #undo
+ #value: #doUndo
#activeHelpKey: #editUndo
#enabled: #valueOfCanUndo
)
@@ -715,12 +724,12 @@
)
#(#MenuItem
#label: 'Flip - Vertical'
- #value: #flipVertical
+ #value: #doFlipVertical
#activeHelpKey: #editFlipVertical
)
#(#MenuItem
#label: 'Flip - Horizontal'
- #value: #flipHorizontal
+ #value: #doFlipHorizontal
#activeHelpKey: #editFlipHorizontal
)
#(#MenuItem
@@ -728,17 +737,17 @@
)
#(#MenuItem
#label: 'Resize...'
- #value: #resizeImage
+ #value: #doResizeImage
#activeHelpKey: #editResize
)
#(#MenuItem
#label: 'Magnify...'
- #value: #magnifyImage
+ #value: #doMagnifyImage
#activeHelpKey: #editMagnifyImage
)
#(#MenuItem
#label: 'Rotate...'
- #value: #rotateImage
+ #value: #doRotateImage
#activeHelpKey: #editRotate
)
#(#MenuItem
@@ -746,7 +755,7 @@
)
#(#MenuItem
#label: 'Negative'
- #value: #negativeImage
+ #value: #doNegativeImage
#activeHelpKey: #editNegate
)
) nil
@@ -908,21 +917,21 @@
#(#MenuItem
#label: 'newImage'
#isButton: true
- #value: #newImage
+ #value: #doNewImage
#activeHelpKey: #fileNewImage
#labelImage: #(#ResourceRetriever nil #newIcon)
)
#(#MenuItem
#label: 'loadFromClass'
#isButton: true
- #value: #loadFromClass
+ #value: #doLoadFromClass
#activeHelpKey: #fileLoadFromClass
#labelImage: #(#ResourceRetriever nil #loadIcon)
)
#(#MenuItem
#label: 'saveMethod'
#isButton: true
- #value: #saveMethod
+ #value: #doSaveMethod
#activeHelpKey: #fileSaveMethod
#enabled: #imageIsLoaded
#labelImage: #(#ResourceRetriever nil #saveIcon)
@@ -989,11 +998,13 @@
!ImageEditor methodsFor:'accessing'!
image
+ "returns the current editing image"
^self imageEditView image
!
postOpenAction: anAction
+ "sets an action which is evaluated after opening"
postOpenAction := anAction
! !
@@ -1001,16 +1012,19 @@
!ImageEditor methodsFor:'accessing - views'!
coordLabel
+ "returns the view the coord label"
^builder componentAt: #coordLabel
!
imageEditView
+ "returns the image editing view"
^(builder componentAt: #imageEditView) subViews first
!
imagePreView
+ "returns the preview of the image"
^(builder componentAt: #imagePreView) subViews first
! !
@@ -1018,6 +1032,7 @@
!ImageEditor methodsFor:'aspects'!
imageIsLoaded
+ "returns whether an image is loaded as value holder"
|holder|
(holder := builder bindingAt:#imageIsLoaded) isNil ifTrue:[
@@ -1027,6 +1042,7 @@
!
listOfColors
+ "returns the list of colors in a List"
|holder|
(holder := builder bindingAt:#listOfColors) isNil ifTrue:[
@@ -1036,6 +1052,7 @@
!
selectionOfColor
+ "returns current selection of the edit color as an AspectAdaptor"
|holder|
(holder := builder bindingAt:#selectionOfColor) isNil ifTrue:[
@@ -1046,6 +1063,7 @@
!
valueOfMagnification
+ "returns current magnification of the image as an AspectAdaptor"
|holder|
(holder := builder bindingAt:#valueOfMagnification) isNil ifTrue:[
@@ -1055,32 +1073,184 @@
^ holder
! !
+!ImageEditor methodsFor:'change & update'!
+
+findColorMapMode
+ "finds the colorMapMode for an new image"
+
+ self image depth > 8 ifTrue: [colorMapMode := ''. self listOfColors removeAll. ^nil].
+ colorMapMode := self image depth printString, '-plane'.
+ self listOfColors isEmpty
+ ifTrue:
+ [
+ self colorMapMode: colorMapMode value: nil
+ ].
+ self imageEditView selectColors: (Array with: (self listOfColors at: 1) with: (self listOfColors at: 2 ifAbsent: [self listOfColors at: 1])).
+ (self image mask notNil and: [(self listOfColors includes: (Color basicNew setColorId:0)) not])
+ ifTrue:
+ [
+ colorMapMode := colorMapMode, ' + mask'.
+ self listOfColors addFirst: (Color basicNew setColorId:0).
+ self imageEditView selectColors: (Array with: (self listOfColors at: 2 ifAbsent: [self listOfColors at: 1]) with: (self listOfColors at: 1)).
+ ].
+ self selectionOfColor value: 0.
+ self selectionOfColor value: (self listOfColors indexOf: self imageEditView selectedColor).
+!
+
+updateForNoneImage
+ "updates channels and view, if image is loaded"
+
+ self imageIsLoaded value: false.
+ self listOfColors removeAll.
+ self imagePreView image: nil
+
+
+
+
+!
+
+updateLabelsAndHistory
+ "updates labels and history, if something has changed"
+
+ self imageIsLoaded value: self image notNil.
+
+ self image isNil ifTrue: [^nil].
+
+ self updateInfoLabel.
+
+ self imageEditView resourceMessage asCollectionOfWords size = 2
+ ifTrue: [self addToHistory: self imageEditView resourceMessage -> #loadFromMessage:].
+
+ self image fileName notNil
+ ifTrue: [self addToHistory: self image fileName -> #loadFromFile:].
+
+
+
+! !
+
!ImageEditor methodsFor:'help'!
defaultInfoLabel
+ "returns the default info label"
(self imageEditView resourceClass isSymbol and: [(Smalltalk at: self imageEditView resourceClass) isClass])
ifTrue:
[
^self imageEditView resourceClass, ' >> ', self imageEditView resourceSelector
].
- ^'No class defined'
+ ^'No class and selector defined.'
!
openDocumentation
+ "opens the documentation file of the Image Editor"
self openHTMLDocument: 'tools/uipainter/ImageEditor.html'
! !
+!ImageEditor methodsFor:'loading'!
+
+loadFromFile: aFileName
+ "loads an image from aFileName and sets up color map list and other info labels"
+
+ (self imageEditView loadFromFile: aFileName) notNil
+ ifTrue:
+ [
+ self image notNil
+ ifTrue:
+ [
+ self image colorMap notNil
+ ifTrue:
+ [
+ self listOfColors contents: self image usedColors asSet.
+ ]
+ ifFalse:
+ [
+ self listOfColors removeAll.
+ ].
+ self findColorMapMode.
+ self updateLabelsAndHistory.
+ ]
+ ifFalse:
+ [
+ self updateForNoneImage
+ ]
+ ]
+!
+
+loadFromImage: anImage
+ "loads an image from anImage and sets up color map list and other info labels"
+
+ self imageEditView image: anImage.
+ self image notNil
+ ifTrue:
+ [
+ self image colorMap notNil
+ ifTrue:
+ [
+ self listOfColors contents: self image usedColors asSet asOrderedCollection.
+ ]
+ ifFalse:
+ [
+ self listOfColors removeAll.
+ ].
+ self findColorMapMode.
+ self updateLabelsAndHistory.
+ ]
+ ifFalse:
+ [
+ self updateForNoneImage
+ ]
+!
+
+loadFromMessage: aMessage
+ "loads an image by evaluating aMessage and sets up color map list and other info labels"
+
+ (self imageEditView loadFromMessage: aMessage) notNil
+ ifTrue:
+ [
+ self image notNil
+ ifTrue:
+ [
+ self listOfColors contents: self image usedColors asSet asOrderedCollection.
+ self findColorMapMode.
+ self updateLabelsAndHistory.
+ ]
+ ifFalse:
+ [
+ self updateForNoneImage
+ ]
+ ]
+!
+
+loadFromOrPrepareForMessage: aMessage
+ "loads an image by evaluating aMessage;
+ if no image could extract from aMessage; do set the class and the selector from
+ the aMessage for a saving at the end of editing"
+
+ (self imageEditView loadFromMessage: aMessage) notNil
+ ifTrue:
+ [
+ self listOfColors contents: self image usedColors asSet asOrderedCollection.
+ self findColorMapMode.
+ ]
+ ifFalse:
+ [
+ self imageEditView resourceMessage: aMessage.
+ ].
+ self updateLabelsAndHistory.
+! !
+
!ImageEditor methodsFor:'menu modes'!
colorMapMode: aMode
+ "returns whether colorMapMode is equal to aMode"
^colorMapMode = aMode
!
colorMapMode: aMode value: aValue
+ "calculates a new color map for the image from aMode"
|depth newColorMap newImage image newColors realColorMap oldFileName|
@@ -1149,82 +1319,35 @@
!
editMode: aMode
+ "returns whether editMode is equal to aMode"
^self imageEditView editMode = aMode
!
editMode: aMode value: aValue
+ "sets the editMode to aMode"
self imageEditView editMode: aMode
!
mouseKeyColorMode: aMode
+ "sets the mouseKeyColorMode to aMode"
^self imageEditView mouseKeyColorMode = aMode
!
mouseKeyColorMode: aMode value: aValue
+ "sets the mouseKeyColorMode to aMode"
self imageEditView mouseKeyColorMode: aMode.
self selectionOfColor value: (self listOfColors indexOf: self imageEditView selectedColor).
! !
-!ImageEditor methodsFor:'private'!
-
-findColorMapMode
-
- self image depth > 8 ifTrue: [colorMapMode := ''. self listOfColors removeAll. ^nil].
- colorMapMode := self image depth printString, '-plane'.
- self listOfColors isEmpty
- ifTrue:
- [
- self colorMapMode: colorMapMode value: nil
- ].
- self imageEditView selectColor: (Array with: (self listOfColors at: 1) with: (self listOfColors at: 2 ifAbsent: [self listOfColors at: 1])).
- self image mask notNil
- ifTrue:
- [
- colorMapMode := colorMapMode, ' + mask'.
- self listOfColors addFirst: (Color basicNew setColorId:0).
- self imageEditView selectColor: (Array with: (self listOfColors at: 1 ifAbsent: [self listOfColors at: 2]) with: (self listOfColors at: 1)).
- ].
- self selectionOfColor value: 0.
- self selectionOfColor value: (self listOfColors indexOf: self imageEditView selectedColor).
-!
-
-updateForNoneImage
-
- self imageIsLoaded value: false.
- self listOfColors removeAll.
- self imagePreView image: nil
-
-
-
-
-!
-
-updateLabelsAndHistory
-
- self imageIsLoaded value: self image notNil.
-
- self image isNil ifTrue: [^nil].
-
- self updateInfoLabel.
-
- self imageEditView resourceMessage asCollectionOfWords size = 2
- ifTrue: [self addToHistory: self imageEditView resourceMessage -> #loadFromMessage:].
-
- self image fileName notNil
- ifTrue: [self addToHistory: self image fileName -> #loadFromFile:].
-
-
-
-! !
-
!ImageEditor methodsFor:'queries'!
preferredExtent
+ "returns the preferred extent"
^super preferredExtent max: (Screen current width//3)@(Screen current height//3.5)
@@ -1234,25 +1357,29 @@
!ImageEditor methodsFor:'selection'!
magnification
+ "returns the magnification of the image"
(builder componentAt: #imageEditView) isNil ifTrue: [^1].
^self imageEditView magnification x
!
magnification: aValue
+ "sets the magnification of the image"
|magnification|
magnification := aValue asInteger asPoint.
- (magnification = self imageEditView magnification) | (magnification = (0@0)) ifTrue: [^nil].
+ (magnification = self imageEditView magnification or: [magnification = (0@0)]) ifTrue: [^nil].
self imageEditView magnification: magnification
!
selectedColorIndex
+ "returns the index of the selected color"
^selectedColorIndex
!
selectedColorIndex: anIndex
+ "sets the index of the selected color"
selectedColorIndex := anIndex.
self imageEditView selectedColor: (self listOfColors at: anIndex ifAbsent: [^nil])
@@ -1262,12 +1389,14 @@
!ImageEditor methodsFor:'startup / release'!
closeRequest
+ "close request"
self imageEditView checkModified ifTrue:[super closeRequest]
!
open
+ "after opening, sets the masterApplication of the imageEditView to self"
super open.
@@ -1275,36 +1404,37 @@
!
postOpenWith:aBuilder
+ "after opening, sets the masterApplication of the imageEditView to self;
+ evaluate the postOpenAction"
self imageEditView masterApplication: self.
postOpenAction notNil ifTrue: [postOpenAction value].
- super postOpenWith:aBuilder.
-!
-reOpen
-
- self imageEditView checkModified ifTrue:[super reOpen]
-
+ super postOpenWith:aBuilder
! !
!ImageEditor methodsFor:'user actions - editing'!
-browseClass
+doBrowseClass
+ "opens a System Browser on the resourceClass and the resourceSelector"
SystemBrowser openInClass: (Smalltalk at: self imageEditView resourceClass ifAbsent: [^nil]) class selector: self imageEditView resourceSelector
!
-flipHorizontal
+doFlipHorizontal
+ "flips horizontally current image"
self imageEditView flipHorizontal
!
-flipVertical
+doFlipVertical
+ "flips vertically current image"
self imageEditView flipVertical
!
-magnifyDown
+doMagnifyDown
+ "magnifies current image one step down"
self valueOfMagnification value > 1
ifTrue:
@@ -1313,13 +1443,15 @@
]
!
-magnifyImage
+doMagnifyImage
+ "magnifies current image"
self imageEditView magnifyImage.
self updateInfoLabel
!
-magnifyUp
+doMagnifyUp
+ "magnifies current image one step up"
self valueOfMagnification value < 99
ifTrue:
@@ -1328,33 +1460,38 @@
]
!
-negativeImage
+doNegativeImage
+ "negates current image by negating the color map"
self imageEditView negativeImage.
self listOfColors removeAll.
- self findColorMapMode.
+ self findColorMapMode
!
-resizeImage
+doResizeImage
+ "resizes current image"
self imageEditView resizeImage.
self updateInfoLabel
!
-rotateImage
+doRotateImage
+ "rotates current image"
self imageEditView rotateImage.
self updateInfoLabel
!
-undo
+doUndo
+ "reverses last edit action"
self imageEditView undo
! !
!ImageEditor methodsFor:'user actions - loading'!
-loadFromClass
+doLoadFromClass
+ "opens a dialog for loading an image from class and a (resource-) selector"
(self imageEditView loadFromClass) notNil
ifTrue:
@@ -1364,43 +1501,7 @@
[
self listOfColors contents: self image usedColors asSet asOrderedCollection.
self findColorMapMode.
- self updateLabelsAndHistory.
- ]
- ifFalse:
- [
- self updateForNoneImage
- ]
- ]
-!
-
-loadFromFile
-
- self loadFromFile:
- (FileSelectionBrowser
- request: 'Load Image From'
- fileName: (self image notNil ifTrue: [self image fileName] ifFalse: [nil])
- withFileFilters: FileSelectionBrowser loadImageFileNameFilters)
-!
-
-loadFromFile: aFileName
-
- (self imageEditView loadFromFile: aFileName) notNil
- ifTrue:
- [
- self image notNil
- ifTrue:
- [
- self image colorMap notNil
- ifTrue:
- [
- self listOfColors contents: self image usedColors asSet.
- ]
- ifFalse:
- [
- self listOfColors removeAll.
- ].
- self findColorMapMode.
- self updateLabelsAndHistory.
+ self updateLabelsAndHistory
]
ifFalse:
[
@@ -1409,89 +1510,44 @@
]
!
-loadFromImage: image
+doLoadFromFile
+ "opens a dialog for loading an image from a file"
- self imageEditView image: image.
- self image notNil
- ifTrue:
- [
- self image colorMap notNil
- ifTrue:
- [
- self listOfColors contents: self image usedColors asSet asOrderedCollection.
- ]
- ifFalse:
- [
- self listOfColors removeAll.
- ].
- self findColorMapMode.
- self updateLabelsAndHistory.
- ]
- ifFalse:
- [
- self updateForNoneImage
- ]
+ self loadFromFile:
+ (FileSelectionBrowser
+ request: 'Load Image From'
+ fileName: (self image notNil ifTrue: [self image fileName] ifFalse: [nil])
+ withFileFilters: FileSelectionBrowser loadImageFileNameFilters)
!
-loadFromMessage: aMessage
-
- (self imageEditView loadFromMessage: aMessage) notNil
- ifTrue:
- [
- self image notNil
- ifTrue:
- [
- self listOfColors contents: self image usedColors asSet asOrderedCollection.
- self findColorMapMode.
- self updateLabelsAndHistory.
- ]
- ifFalse:
- [
- self updateForNoneImage
- ]
- ]
-!
-
-loadFromOrPrepareForMessage: aMessage
-
- (self imageEditView loadFromMessage: aMessage) notNil
- ifTrue:
- [
- self listOfColors contents: self image usedColors asSet asOrderedCollection.
- self findColorMapMode.
- ]
- ifFalse:
- [
- self imageEditView resourceMessage: aMessage.
- ].
- self updateLabelsAndHistory.
-!
-
-newImage
+doNewImage
+ "opens a dialog with choices of size and color map for creating a new image"
|aspects|
+
aspects := IdentityDictionary new
- at:#listOfSizes put: self class listOfDefaultSizes asValue;
- at:#listOfColorMaps put: self class listOfColorMaps keys asSortedCollection asValue;
- at:#selectionOfSize put: self class listOfDefaultSizes first copy asValue;
+ at:#listOfSizes put: self class listOfDefaultSizes asValue;
+ at:#listOfColorMaps put: self class listOfColorMaps keys asSortedCollection asValue;
+ at:#selectionOfSize put: self class listOfDefaultSizes first copy asValue;
at:#selectionOfColorMap put: self class listOfColorMaps keys asSortedCollection first asValue;
yourself.
- (self openDialogInterface:#windowSpecForNewImage withBindings:aspects)
+ (self openDialogInterface:#dialogSpecForNewImage withBindings:aspects)
ifTrue:
[
|width height cMap imageClass image|
- width := 128 min: (Integer readFromString: ((aspects at:#selectionOfSize) value upTo: $x) onError:[24]).
+
+ width := 128 min: (Integer readFromString: ((aspects at:#selectionOfSize) value upTo: $x) onError:[24]).
height := 128 min: (Integer readFromString: ((aspects at:#selectionOfSize) value copy reverse upTo: $x) reverse onError:[24]).
- cMap := (self class listOfColorMaps at: (colorMapMode := (aspects at:#selectionOfColorMap) value)).
+ cMap := (self class listOfColorMaps at: (colorMapMode := (aspects at:#selectionOfColorMap) value)).
imageClass := Image implementorForDepth: ((cMap size log: 2) asInteger).
- image := imageClass width: width height: height fromArray: (ByteArray new: width*height).
+ image := imageClass width: width height: height fromArray: (ByteArray new: width*height).
(colorMapMode copy reverse readStream nextWord reverse = 'mask')
ifTrue:
[
- image mask: (Depth1Image width: width height: height depth: 1 fromArray: (ByteArray new: width*height)) clearMaskedPixels.
+ image mask: (Depth1Image width: width height: height depth: 1 fromArray: (ByteArray new: width*height)) clearMaskedPixels
].
image colorMap: cMap.
image fillRectangleX:0 y:0 width:width height:height with:Color white.
@@ -1502,33 +1558,38 @@
self findColorMapMode.
self updateLabelsAndHistory
]
- ].
+ ]
! !
!ImageEditor methodsFor:'user actions - saving'!
-print
+doPrint
+ "prints current image on the current printer"
self imageEditView print
!
-saveImageFile
+doSaveImageFile
+ "saves current image to current file"
self imageEditView save
!
-saveImageFileAs
+doSaveImageFileAs
+ "opens a dialog for saving current image to a file"
self imageEditView saveImageFileAs.
self updateLabelsAndHistory
!
-saveImageMaskFileAs
+doSaveImageMaskFileAs
+ "opens a dialog for saving mask of current image to a file"
self imageEditView saveImageMaskFileAs
!
-saveMethod
+doSaveMethod
+ "saves current image on current class and selector"
self imageEditView saveMethod notNil
ifTrue:
@@ -1537,7 +1598,8 @@
]
!
-saveMethodAs
+doSaveMethodAs
+ "opens a dialog for saving current image on a class and a selector"
self imageEditView saveMethodAs notNil
ifTrue: