SmallSense__ClassPO.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 20 May 2014 11:01:39 +0100
changeset 229 c82a22d2153d
parent 176 df6d3225d1e4
child 230 2c12395f8108
permissions -rw-r--r--
PO refactoring: get rid of subject instvar. The meaning of subject instvar was ambiguous and confusing. Some PO don't even use it to store anything meaningful. Now each PO should define its own instvars with meaningfull names to store information they need.

"{ Package: 'jv:smallsense' }"

"{ NameSpace: SmallSense }"

PO subclass:#ClassPO
	instanceVariableNames:'showPrefix klass'
	classVariableNames:''
	poolDictionaries:''
	category:'SmallSense-Core-Interface-PO'
!


!ClassPO methodsFor:'accessing'!

icon

    icon ifNil:[icon := SystemBrowser iconForClass: klass].
    ^icon

    "Created: / 06-04-2011 / 23:36:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

klass
    ^ klass

    "Created: / 25-08-2013 / 13:07:10 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

klass: aClass
    ^ klass := aClass

    "Created: / 25-08-2013 / 13:07:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 20-05-2014 / 10:05:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

name

    | nm |

    showPrefix ifTrue:[
        nm := klass name.
        (context notNil and:[klass isJavaClass]) ifTrue:[
            context language isJava ifTrue:[
                nm := klass javaName
            ] ifFalse:[
                context language isSmalltalk ifTrue:[
                   nm := 'JAVA ' , (klass  binaryName copyReplaceAll: $/ with: Character space)
                 ]
            ]
        ].
    ] ifFalse:[
        nm := klass nameWithoutPrefix.
    ].
    ^nm

    "Created: / 26-08-2013 / 10:26:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 17-12-2013 / 22:16:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

showPrefix
    ^ showPrefix
!

showPrefix:something
    showPrefix := something.
!

stringAlreadyWritten
    "Answers a string already written in the textview"    

    (klass isJavaClass and:[context language isSmalltalk]) ifTrue:[
        | rec |

        rec := context node .
        [ rec isUnaryMessage ] whileTrue:[
            rec := rec receiver.
        ].
        (rec isVariableNode and:['JAVA' startsWith: rec name]) ifTrue:[
            ^ context codeView contents asString copyFrom: rec startPosition to: context node endPosition
        ].
    ].
    ^ super stringAlreadyWritten

    "Created: / 20-10-2013 / 02:46:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

stringToCompleteForLanguage: language
    ^ (klass isJavaClass and:[language isSmalltalk]) ifTrue:[
        'JAVA ', (klass binaryName copyReplaceAll: $/ with: Character space)
    ] ifFalse:[
        super stringToCompleteForLanguage: language
    ].

    "Created: / 03-10-2013 / 16:42:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 20-10-2013 / 02:35:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!ClassPO methodsFor:'converting'!

asString
    ^klass isJavaClass ifTrue:[
        klass javaName
    ] ifFalse:[
        klass name
    ].

    "Created: / 04-04-2012 / 13:00:58 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 26-08-2013 / 10:27:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!ClassPO methodsFor:'displaying'!

displayLabel:aLabel h:lH on:aGC x:x y:y h:h
    | namespace y0 lw cnw fg |

    super displayLabel:aLabel h:lH on:aGC x:x y:y h:h.

    showPrefix ifFalse:[
        namespace := klass isJavaClass 
                        ifFalse:[klass  nameSpace name]
                        ifTrue:[klass javaPackage].
        (namespace notNil and:[namespace ~~ #Smalltalk]) ifTrue:[
            namespace := 'in ', namespace.
            lw :=  x + IconWidth + (aLabel widthOn: aGC).
            y0 := y - (lH + 1 - h // 2).
            y0 := y0 + (namespace ascentOn:aGC). 
            cnw := aGC widthOfString: namespace.

            (aGC width > (lw + cnw + 5)) ifTrue:[
                fg := aGC paint.
                aGC paint: (Color gray: 40).
                namespace displayOn:aGC x: aGC width - cnw - 5 y:y0.
                aGC paint: fg.
            ]
        ]
    ]

    "Created: / 18-09-2013 / 00:17:20 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

displayString
    ^ self name

    "Created: / 20-04-2012 / 18:19:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
    "Modified: / 26-08-2013 / 10:27:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!ClassPO methodsFor:'initialization'!

initialize
    "Invoked when a new instance is created."

    "/ please change as required (and remove this comment)
    "/ showPrefix := nil.

    super initialize.  
    showPrefix := false.

    "Modified: / 20-10-2013 / 02:38:05 / Jan Vrany <jan.vrany@fit.cvut.cz>"
!

initializeWithClass: aClass

    klass := aClass.
    showPrefix := false.

    "Created: / 20-05-2014 / 09:56:44 / Jan Vrany <jan.vrany@fit.cvut.cz>"
! !

!ClassPO methodsFor:'testing'!

isSmallSenseClassPO
    ^ true
! !

!ClassPO class methodsFor:'documentation'!

version_HG

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

version_SVN
    ^ '$Id: SmallSense__ClassPO.st,v 1.2 2014/02/12 14:49:29 sr Exp $'
! !