ImageInspectorView.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 08 Aug 2013 11:08:29 +0100
branchjv
changeset 13330 02d6c2d848a0
parent 13178 c9bf900fe729
parent 13297 ea807c25ceb9
child 15566 184cea584be5
permissions -rw-r--r--
Merged c574d5af6621 and c248680c1ebf (branch default - CVS HEAD)

"
 COPYRIGHT (c) 1993 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
"{ Package: 'stx:libtool' }"

InspectorView subclass:#ImageInspectorView
	instanceVariableNames:'imageView'
	classVariableNames:'LastRatio LastExtent'
	poolDictionaries:''
	category:'Interface-Inspector'
!

!ImageInspectorView class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1993 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    this class allows better inspection of images,
    by adding another subView, which displays the image.
"
! !

!ImageInspectorView class methodsFor:'defaults'!

defaultTopViewExtent
    ^ LastExtent ? super defaultExtent

    "Created: / 23-10-2007 / 18:58:18 / cg"
!

rememberLastExtent:anExtent
    LastExtent := anExtent

    "Created: / 23-10-2007 / 19:09:34 / cg"
! !

!ImageInspectorView class methodsFor:'menu specs'!

imageMenu
    "This resource specification was automatically generated
     by the MenuEditor of ST/X."

    "Do not manually edit this!! If it is corrupted,
     the MenuEditor may not be able to read the specification."

    "
     MenuEditor new openOnClass:ImageInspectorView andSelector:#imageMenu
     (Menu new fromLiteralArrayEncoding:(ImageInspectorView imageMenu)) startUp
    "

    <resource: #menu>

    ^ 
     #(Menu
        (
         (MenuItem
            label: 'Edit'
            itemValue: menuEdit
            translateLabel: true
          )
         (MenuItem
            label: 'File Browser'
            itemValue: menuFileBrowser
            translateLabel: true
            enabled: filenameOfImageKnown
          )
         (MenuItem
            label: '-'
          )
         (MenuItem
            label: 'Magnification...'
            itemValue: menuMagnification
            translateLabel: true
          )
         (MenuItem
            label: 'Background'
            translateLabel: true
            submenu: 
           (Menu
              (
               (MenuItem
                  label: 'White'
                  itemValue: menuSetBackgroundColor:
                  translateLabel: true
                  argument: white
                )
               (MenuItem
                  label: 'Grey'
                  itemValue: menuSetBackgroundColor:
                  translateLabel: true
                  argument: grey
                )
               (MenuItem
                  label: 'Black'
                  itemValue: menuSetBackgroundColor:
                  translateLabel: true
                  argument: black
                )
               (MenuItem
                  label: '-'
                )
               (MenuItem
                  label: 'Red'
                  itemValue: menuSetBackgroundColor:
                  translateLabel: true
                  argument: red
                )
               (MenuItem
                  label: 'Green'
                  itemValue: menuSetBackgroundColor:
                  translateLabel: true
                  argument: green
                )
               (MenuItem
                  label: 'Blue'
                  itemValue: menuSetBackgroundColor:
                  translateLabel: true
                  argument: blue
                )
               )
              nil
              nil
            )
          )
         )
        nil
        nil
      )
! !

!ImageInspectorView methodsFor:'accessing'!

inspect:anObject
    "set the object to be inspected"

    super inspect:anObject.
    imageView image:anObject.

    "
     ImageInspectorView inspect:(Image fromScreen:(0@0 corner:800@800))
    "
! !

!ImageInspectorView methodsFor:'initialization'!

destroy
    |imageViewsSuperView|

    imageViewsSuperView := imageView superView.
    imageViewsSuperView notNil ifTrue:[
        LastRatio := 1.0 - 
                     (imageViewsSuperView relativeCorner y - imageViewsSuperView relativeOrigin y).
    ].
    super destroy

    "Created: / 07-09-1998 / 13:13:43 / cg"
    "Modified: / 23-10-2007 / 19:10:48 / cg"
!

initialize
    |v newPanel sub|

    super initialize.

    LastRatio isNil ifTrue:[
        LastRatio := 0.3
    ].

    newPanel := VariableVerticalPanel in:self.
    newPanel origin:0.0 @ 0.0 corner:1.0 @ 1.0.
    newPanel snapMode:#both.

    "
     wrap my existing subview into the new
     variable panel
    "
    sub := self subViews first.
    self removeSubView:sub.
    sub origin:0.0@0.0 corner:1.0@LastRatio.
    newPanel addSubView:sub.

    v := HVScrollableView for:ImageView in:newPanel.
    v origin:(0.0 @ LastRatio) corner:(1.0 @ 1.0).
    imageView := v scrolledView.
    imageView menuHolder:self; menuMessage:#imageMenu; menuPerformer:self.

    LastExtent notNil ifTrue:[
        self extent:LastExtent
    ].

    "
     ImageInspectorView new realize
     ImageInspectorView inspect:(Image fromFile:'bitmaps/claus.gif')
    "

    "Modified: / 28-05-2007 / 15:15:32 / cg"
! !

!ImageInspectorView methodsFor:'menu'!

imageMenu
    ^ self class imageMenu

    "Created: / 28-05-2007 / 15:12:56 / cg"
!

menuEdit
    inspectedObject edit
!

menuFileBrowser
    UserPreferences current fileBrowserClass
        openOn:inspectedObject fileName
!

menuMagnification
    |mag|

    mag := Dialog 
            request:'Magnify by:' 
            initialAnswer:1 
            list:#('0.5' '1' '2' '4' '8').
    mag := Number readFrom:mag onError:[nil].
    mag notNil ifTrue:[
        imageView image:(inspectedObject magnifiedBy:mag).
    ]

    "Created: / 28-05-2007 / 15:14:35 / cg"
    "Modified: / 30-10-2007 / 16:49:16 / cg"
!

menuSetBackgroundColor:colorNameSymbol
    imageView backgroundColor:(Color name:colorNameSymbol)
! !

!ImageInspectorView methodsFor:'queries'!

filenameOfImageKnown
    ^ [ inspectedObject fileName notNil ]
!

labelFor:anObject
    |l fn|

    l := super labelFor:anObject.
    (anObject notNil and:[(fn := anObject fileName) notNil]) ifTrue:[
        l := l , ' (''' , fn asFilename baseName, ''')'
    ].
    ^ l

    "Modified: / 25-07-2012 / 12:53:13 / cg"
! !

!ImageInspectorView class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libtool/ImageInspectorView.st,v 1.28 2013-08-06 08:38:10 cg Exp $'
!

version_CVS
    ^ '$Header: /cvs/stx/stx/libtool/ImageInspectorView.st,v 1.28 2013-08-06 08:38:10 cg Exp $'
!

version_HG

    ^ '$Changeset: <not expanded> $'
!

version_SVN
    ^ '$Id: ImageInspectorView.st 8026 2012-07-26 16:09:41Z vranyj1 $'
! !