--- a/DataSetLabel.st Wed Aug 21 11:44:57 2002 +0200
+++ b/DataSetLabel.st Wed Aug 21 12:09:15 2002 +0200
@@ -90,7 +90,9 @@
redrawX:xLeft w:width h:height inset:inset on:aGC
"redraw the label; the background is cleared and the paint is set
"
- |y0 margin x y ascent gcFont prevClip mustUndoClip|
+ |y0 x y ascent gcFont labelWidth
+ shortenedLabel shownLabel wDots wRest prevClip mustUndoClip
+ netWidth|
label isNil ifTrue:[ ^ self ].
@@ -104,12 +106,30 @@
].
y0 := height - preferredHeight // 2.
+ netWidth := width-inset-inset.
+
label do:[:aLabel|
+ shownLabel := aLabel.
+
mustUndoClip := false.
+ labelWidth := shownLabel widthOn:aGC.
+ labelWidth > netWidth ifTrue:[
+ shownLabel isString ifTrue:[
+ wDots := '...' widthOn:aGC.
+ shortenedLabel := shownLabel copyWithoutLast:1.
+ [ shortenedLabel size > 0
+ and:[(wRest := shortenedLabel widthOn:aGC) > (netWidth-wDots)]] whileTrue:[
+ shortenedLabel := shortenedLabel copyWithoutLast:1.
+ ].
+ shownLabel := shortenedLabel , '...'.
+ labelWidth := shownLabel widthOn:aGC.
+ ].
+ ].
+
adjust == #left ifTrue:[
x := xLeft + inset.
] ifFalse:[
- x := width - (aLabel widthOn:aGC).
+ x := width - labelWidth.
adjust == #right ifTrue:[x := x - inset]
ifFalse:[x := x // 2].
@@ -125,9 +145,9 @@
width:width height:height).
].
].
- y := aLabel isImageOrForm ifTrue:[y0] ifFalse:[y0 + ascent].
- aLabel displayOn:aGC x:x y:y.
- y0 := y0 + (aLabel heightOn:aGC).
+ y := shownLabel isImageOrForm ifTrue:[y0] ifFalse:[y0 + ascent].
+ shownLabel displayOn:aGC x:x y:y.
+ y0 := y0 + (shownLabel heightOn:aGC).
mustUndoClip == true ifTrue:[
aGC clippingRectangle:prevClip
@@ -287,5 +307,5 @@
!DataSetLabel class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libwidg2/DataSetLabel.st,v 1.11 2001-12-14 10:51:02 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg2/DataSetLabel.st,v 1.12 2002-08-21 10:09:15 penk Exp $'
! !