ImageEditor.st
changeset 1353 701e41f8ff9f
parent 1345 218b7fcff239
child 1376 ce3cf26e201e
equal deleted inserted replaced
1352:73f656cea457 1353:701e41f8ff9f
    11 "
    11 "
    12 
    12 
    13 ToolApplicationModel subclass:#ImageEditor
    13 ToolApplicationModel subclass:#ImageEditor
    14 	instanceVariableNames:'imageEditView colorMapMode editMode mouseKeyColorMode
    14 	instanceVariableNames:'imageEditView colorMapMode editMode mouseKeyColorMode
    15 		selectedColorIndex postOpenAction'
    15 		selectedColorIndex postOpenAction'
    16 	classVariableNames:''
    16 	classVariableNames:'LastDirectory'
    17 	poolDictionaries:''
    17 	poolDictionaries:''
    18 	category:'Interface-UIPainter'
    18 	category:'Interface-UIPainter'
    19 !
    19 !
    20 
    20 
    21 !ImageEditor class methodsFor:'documentation'!
    21 !ImageEditor class methodsFor:'documentation'!
  1220             #translateLabel: true
  1220             #translateLabel: true
  1221             #submenu: 
  1221             #submenu: 
  1222            #(#Menu
  1222            #(#Menu
  1223               #(
  1223               #(
  1224                #(#MenuItem
  1224                #(#MenuItem
  1225                   #label: 'Grid Magnification...'
  1225                   #label: 'Grid Magnification Limit...'
  1226                   #translateLabel: true
  1226                   #translateLabel: true
  1227                   #value: #doChangeGridMagnification
  1227                   #value: #doChangeGridMagnification
  1228                   #activeHelpKey: #settingsGridMagnification
  1228                   #activeHelpKey: #settingsGridMagnification
  1229                 )
  1229                 )
  1230                )
  1230                )
  2523         selector:(imageEditView resourceSelector)
  2523         selector:(imageEditView resourceSelector)
  2524 
  2524 
  2525     "Modified: / 31.7.1998 / 02:01:15 / cg"
  2525     "Modified: / 31.7.1998 / 02:01:15 / cg"
  2526 !
  2526 !
  2527 
  2527 
  2528 doChangeGridMagnification
       
  2529     "change grid magnification"
       
  2530 
       
  2531     imageEditView changeGridMagnification
       
  2532 !
       
  2533 
       
  2534 doCropAll
  2528 doCropAll
  2535     "find all borders and cut them off"
  2529     "find all borders and cut them off"
  2536 
  2530 
  2537     imageEditView cropLeft:true right:true top:true bottom:true.   
  2531     imageEditView cropLeft:true right:true top:true bottom:true.   
  2538     self updateInfoLabel
  2532     self updateInfoLabel
  2634 !
  2628 !
  2635 
  2629 
  2636 doMagnifyImage
  2630 doMagnifyImage
  2637     "magnifies current image"
  2631     "magnifies current image"
  2638 
  2632 
  2639     imageEditView magnifyImage.   
  2633     |box newSize image|
       
  2634 
       
  2635     image := imageEditView image.
       
  2636 
       
  2637     box := EnterBox new.
       
  2638     box title:(resources string:'Images new size:').
       
  2639     box okText:(resources string:'OK').
       
  2640     box abortText:(resources string:'Cancel').
       
  2641     box initialText:image extent printString.
       
  2642     box showAtPointer.
       
  2643     (box accepted 
       
  2644     and: [(newSize := Object readFromString:(box contents) onError:nil) notNil])
       
  2645     ifTrue:[
       
  2646         imageEditView magnifyImageTo:newSize.
       
  2647     ].
       
  2648 
  2640     self updateInfoLabel
  2649     self updateInfoLabel
  2641 !
  2650 !
  2642 
  2651 
  2643 doMagnifyUp
  2652 doMagnifyUp
  2644     "magnifies current image one step up"
  2653     "magnifies current image one step up"
  2661     self findColorMapMode.     
  2670     self findColorMapMode.     
  2662     imageEditView undoImages removeLast
  2671     imageEditView undoImages removeLast
  2663 !
  2672 !
  2664 
  2673 
  2665 doResizeImage
  2674 doResizeImage
  2666     "resizes current image"
  2675     "resizes the current image"
  2667 
  2676 
  2668     imageEditView resizeImage.   
  2677     |box newSize image|
  2669     self updateInfoLabel
  2678 
       
  2679     image := imageEditView image.
       
  2680 
       
  2681     box := EnterBox new.
       
  2682     box title:(resources string:'Images new size:').
       
  2683     box okText:(resources string:'OK').
       
  2684     box abortText:(resources string:'Cancel').
       
  2685     box initialText:image extent printString.
       
  2686     box showAtPointer.
       
  2687     (box accepted 
       
  2688     and: [(newSize := Object readFromString:(box contents) onError:nil) notNil])
       
  2689     ifTrue:[
       
  2690         imageEditView resizeImageTo:newSize.
       
  2691     ].
       
  2692 
  2670 !
  2693 !
  2671 
  2694 
  2672 doRotateImage
  2695 doRotateImage
  2673     "rotates current image"
  2696     "rotates current image"
  2674 
  2697 
  2675     imageEditView rotateImage.
  2698     |box rotation|
  2676     self updateInfoLabel
  2699 
       
  2700     box := EnterBox new.
       
  2701     box title:(resources string:'Rotate by (degrees, clockwise):').
       
  2702     box okText:(resources string:'OK').
       
  2703     box abortText:(resources string:'Cancel').
       
  2704     box initialText: '0'.
       
  2705     box showAtPointer.
       
  2706     (box accepted and: [(rotation := Object readFromString: box contents onError:nil) notNil])
       
  2707     ifTrue:[
       
  2708         imageEditView rotateImageBy:rotation.
       
  2709         self updateInfoLabel
       
  2710     ].
  2677 !
  2711 !
  2678 
  2712 
  2679 doUndo
  2713 doUndo
  2680     "reverses last edit action"
  2714     "reverses last edit action"
  2681 
  2715 
  2701 !
  2735 !
  2702 
  2736 
  2703 doLoadFromFile
  2737 doLoadFromFile
  2704     "opens a dialog for loading an image from a file"
  2738     "opens a dialog for loading an image from a file"
  2705 
  2739 
  2706     |img|
  2740     |img file dir filters|
  2707 
  2741 
  2708     self loadFromFile:
  2742     img := self image.
  2709         (FileSelectionBrowser
  2743     img notNil ifTrue: [
  2710             request: 'Load Image From'
  2744         file := img fileName
  2711             fileName: ((img := self image) notNil ifTrue: [img fileName] ifFalse: [nil])
  2745     ] ifFalse:[
  2712             withFileFilters: FileSelectionBrowser loadImageFileNameFilters)
  2746         dir := LastDirectory
       
  2747     ].
       
  2748 
       
  2749     filters := FileSelectionBrowser loadImageFileNameFilters.
       
  2750 
       
  2751     file notNil ifTrue:[
       
  2752         file := FileSelectionBrowser
       
  2753                     request:'Load Image From'
       
  2754                     fileName:file
       
  2755                     withFileFilters:filters.
       
  2756     ] ifFalse:[
       
  2757         file := FileSelectionBrowser
       
  2758                     request:'Load Image From'
       
  2759                     inDirectory:dir
       
  2760                     withFileFilters:filters.
       
  2761     ].
       
  2762     file notNil ifTrue:[
       
  2763         LastDirectory := file asFilename directoryName.
       
  2764         self loadFromFile:file
       
  2765     ]
  2713 !
  2766 !
  2714 
  2767 
  2715 doNewImage
  2768 doNewImage
  2716     "opens a dialog with choices of size and color map for creating a new image"
  2769     "opens a dialog with choices of size and color map for creating a new image"
  2717 
  2770 
  2845 
  2898 
  2846     img := imageEditView image.
  2899     img := imageEditView image.
  2847     TextBox openOn:img storeString
  2900     TextBox openOn:img storeString
  2848 ! !
  2901 ! !
  2849 
  2902 
       
  2903 !ImageEditor methodsFor:'user actions - settings'!
       
  2904 
       
  2905 doChangeGridMagnification
       
  2906     "change grid magnification"
       
  2907 
       
  2908     |box oldGridLimit newGridLimit|
       
  2909 
       
  2910     oldGridLimit := imageEditView class gridMagnificationLimit asPoint.
       
  2911 
       
  2912     box := EnterBox new.
       
  2913     box title:(resources string:'Grid Magnification Limit:').
       
  2914     box okText:(resources string:'OK').
       
  2915     box abortText:(resources string:'Cancel').
       
  2916     box initialText:(oldGridLimit x printString).
       
  2917     box showAtPointer.
       
  2918 
       
  2919     (box accepted 
       
  2920     and: [(newGridLimit := Number readFromString:(box contents) onError:[2]) notNil]
       
  2921     ) ifTrue:[
       
  2922         newGridLimit := (99 min: (2 max:newGridLimit)) asPoint.
       
  2923         imageEditView class gridMagnificationLimit:newGridLimit.
       
  2924         imageEditView invalidate
       
  2925     ]
       
  2926 
       
  2927 ! !
       
  2928 
  2850 !ImageEditor class methodsFor:'documentation'!
  2929 !ImageEditor class methodsFor:'documentation'!
  2851 
  2930 
  2852 version
  2931 version
  2853     ^ '$Header$'
  2932     ^ '$Header$'
  2854 ! !
  2933 ! !