eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'Text':

Home

everywhere
www.exept.de
for:
[back]

Class: Text


Inheritance:

   Object
   |
   +--Collection
      |
      +--SequenceableCollection
         |
         +--ArrayedCollection
            |
            +--UninterpretedBytes
               |
               +--ByteArray
                  |
                  +--CharacterArray
                     |
                     +--Text

Package:
stx:libbasic2
Category:
Collections-Text
Version:
rev: 1.106 date: 2009/10/29 17:23:09
user: cg
file: Text.st directory: libbasic2
module: stx stc-classLibrary: libbasic2
Author:
Claus Gittinger

Description:


Texts add emphasis information to a string.
Texts and strings should behave interchanchably to the outside
world, except that texts keep per-character emphasis information.
(strings return nil, when asked for an elements emphasis).
Use #string, to get a texts underlying string without any emphasis
information.

Currently, the following attributes are supported:
    #bold     
    #italic  
    #underline  
    #underwave  
    #strikeout
    (#color -> aColor)
    (#backgroundColor -> aColor)
    (#underlineColor -> aColor)
    (#strikeoutColor -> aColor)

Attributes may be combined (pass an array of above) as emphasis.
See examples.

This class is not yet fully implemented - being constructed.


Related information:

    CharacterArray
    String
    RunArray

Class protocol:

emphasis constants
o  backgroundColorEmphasis

o  foregroundColorEmphasis

emphasis helper
o  addEmphasis: e1 to: e2
merge two emphasis's into one

o  emphasis: e1 includes: e2
return true, if e1 includes e2.
e2 should be a single emphasis.

o  extractEmphasis: key from: e
if key is included in the emphasis, e then return the key.
Otherwise, if a n association with that key is included, return the value.
Otherwise, return nil.

o  removeEmphasis: emToRemove from: emp
remove an emphasis; if it was not in e1, do nothing

initialization
o  initialize
initialize the class

instance creation
o  fromString: aString
create a Text instance, for the characters in aString,
without emphasis.

o  new
create a new empty Text instance.
Redefined for string-protocol compatibility

o  new: size
create a new empty Text instance.
Redefined for string-protocol compatibility

o  string: aString
create a Text instance, for the characters in aString,
without emphasis.

o  string: aString color: aColor
create a Text instance, for the characters in aString,
which are colored as aColor (only the foregroundColor is affected).
This is a shortCut for creating an emphasis of (#color->aColor)

o  string: aString emphasis: attribute
create a Text instance, for the characters in aString,
which are emphasized as described by attribute.

o  string: aString emphasisCollection: attributeCollection
create a Text instance, for the characters in aString,
which are individually emphasized as described by attributeCollection.

o  string: aString foregroundColor: fgColor backgroundColor: bgColor
create a Text instance, for the characters in aString,
which are colored in fgColor on bgColor.
This is a shortCut for creating an emphasis of
#( #color->fgColor) (#backgroundColor->bgColor)

o  string: aString runs: aRun
create a Text instance, for the characters in aString,
which are individually emphasized as described by attributeCollection.

o  uninitializedNew: size
for compatibility only

o  writeStream
answer the stream, that is best used with this class


Instance protocol:

accessing
o  at: characterIndex
return the plain character at characterIndex

o  at: characterIndex put: aCharacter
change the character at characterIndex to be aCharacter.
The emphasis (if any) of that character remains unchanged.

comparing
o  = aStringOrText
compare the receiver and the argument, ignoring emphasis

o  hash
return a suitable hashcode (req'd since = is redefined)

converting
o  asHtmlDocumentForRequest: request

o  asText
return a Text-object (string with emphasis) from myself.
I am already a text object.

o  writeStream
return a stream for writing onto the receiver.
Redefined to return a TextStream which deals with emphasis change messages

copying
o  , aStringOrText
concatenate the receivers characters with the arguments characters,
and return string or text object containing those characters.
If either the receiver or the argument contains emphasis information,
a text object will be returned. Otherwise, a string (i.e. without emphasis)
is returned.

o  concatenateFromString: aString
return the concatenation of aString and myself.
This may be a Text (if I have emphasis) or a string (if not).

o  copyFrom: start to: stop
return the subcollection starting at index start, anInteger and ending
at stop, anInteger.

o  postCopy

displaying
o  displayOn: aGC x: x0 y: y opaque: opaqueWanted
display the receiver on a GC

emphasis
o  actionForAll: aBlock
change the actionBlock of all characters.
Some widgets use this like a href if clicked onto the text.

o  allBold
make all characters bold

o  allBoldOverline
make all characters bold and overline

o  allItalic
make all characters italic

o  allOverline
make all characters overline

o  allStrikedOut
strikeOut all characters

o  allUnderlined
underline all characters

o  allUnderwaved
underwave all characters

o  backgroundColorizeAllWith: aColor
change the bc-color of all characters

o  colorizeAllWith: aColor
change the color of all characters

o  colorizeAllWith: fgColor on: bgColor
change the color and bg-color of all characters

o  emphasis
return the emphasis

o  emphasis: emArray

o  emphasisAllAdd: newEmphasis
add to the emphasis to all characters. return the receiver

o  emphasisAllRemove: anEmphasis
remove the emphasis from all characters. return the receiver

o  emphasisAt: characterIndex
return the emphasis at some index

o  emphasisAt: characterIndex add: newEmphasis
add to the emphasis at some index. return the receiver

o  emphasisAt: characterIndex put: emphasis
change the emphasis at some index. return the receiver

o  emphasisAt: characterIndex remove: emphasisToRemove
remove from the emphasis at some index. return the receiver

o  emphasisCollection
return the emphasis

o  emphasisFrom: start to: stop add: newEmphasis
add to the emphasis within some range. return the receiver

o  emphasisFrom: start to: stop remove: anEmphasis
remove from the emphasis within some range. return the receiver

o  emphasiseFrom: start to: stop with: newEmphasis
set to the emphasis within some range. return the receiver

o  emphasizeAllWith: emphasis
change the emphasis of all characters

o  emphasizeFrom: start count: count with: emphasis
change the emphasis of a range of characters, given startIndex and count.

o  emphasizeFrom: start to: stop with: emphasis
change the emphasis of a range of characters

o  emphasizeFrom: start with: emphasis
change the emphasis of some characters upTo the end

o  strikeoutAll
strikeout all characters

o  withoutAnyColorEmphasis

o  withoutBackgroundColorEmphasis

o  withoutEmphasis: emphasisToRemove

o  withoutForegroundColorEmphasis

inspecting
o  inspectorExtraAttributes
extra (pseudo instvar) entries to be shown in an inspector.

printing & storing
o  displayOn: aGCOrStream
append a printed representation from which the receiver can be reconstructed
to aStream.

o  displayString

o  printOn: aStream
print the receivers characters (including emphasis) on
aStream.
Notice, that some streams simply ignore the emphasis

o  storeOn: aStream
append a printed representation from which the receiver can be reconstructed
to aStream.

private-accessing
o  emphasisCollection: emphasisCollection
set the string and emphasis collection.
The emphasis collection contains per-character information.

o  setString: aString setRuns: anArray

o  string: aString emphasis: emphasis
set the string and emphasis. The emphasis is applied to all characters.

o  string: aString emphasisCollection: emphasisCollection
set the string and emphasis collection.
The emphasis collection contains per-character information.

queries
o  emphasisAtPoint: aPoint on: aGC
return the emphasis at a given point, or nil if there is none

o  encoding

o  hasChangeOfEmphasis
return true, if the receiver contains non-empty emphasis information

o  heightOn: aGC
return the number of device units, required on aGC's device

o  indexOf: aCharacter startingAt: index
search aCharacters index in the underlying string

o  isText
return true if this is a Text object - always true here

o  occurrencesOf: aCharacter
count & return the number of occurrences of aCharacter in the
underlying string

o  size
return the number of characters in the underlying string

o  string
return the receiver without any emphasis information
i.e. the underlying string.

o  widthFrom: startIndex to: endIndex on: aGC
return the number of device units, required on aGC's device

o  widthOn: aGC
return the number of device units, required on aGC's device

replacing
o  replaceFrom: start to: stop with: aCollection startingAt: startIndex
replace a range of characters, from another string or text object.
The corresponding characters' emphasis information is also copied.
Return the receiver.


Examples:


plain string (for comparison):


  Dialog
      warn:'hello'
emphasized strings as dialog titles:


  Dialog
      warn:((Text string:'hello') allBold)


  Dialog
      warn:(Text string:'hello' emphasis:#italic)


  Dialog
      warn:(Text string:'hello' emphasis:#(underline))


  Dialog
      warn:(Text string:'hello' emphasis:#(underwave))


  Dialog
      warn:(Text string:'hello' emphasis:#(bold underline))


  Dialog
      warn:(Text string:'hello' 
               emphasis:(Array with:#bold
                               with:#strikeout
                               with:(#color->Color red)))


  Dialog
      warn:(Text string:'hello' 
               emphasis:(Array with:(#color->Color black)
                               with:#underwave
                               with:(#underlineColor->Color red)))


  Dialog
      warn:(Text string:'hello' 
               emphasis:(Array with:#bold
                               with:#strikeout
                               with:(#color->Color red)
                               with:(#backgroundColor->Color yellow)))


  Dialog
      warn:(Text string:'hello' color:(Color red))
in an editTextView:


  |t v|

  t := 'The quick brown fox jumps over the lazy dog' asText.
  t emphasizeFrom:(t findString:'quick') count:5 with:#bold.
  t emphasizeFrom:(t findString:'brown') count:9 
                                       with:(Array with:#color->(Color name:'brown')
                                                   with:#bold).
  t emphasizeFrom:(t findString:'lazy') count:4 
                                        with:(Array with:#color->(Color red)
                                                    with:#italic).
  t emphasizeFrom:(t findString:'dog') count:3 with:#underline.

  v := HVScrollableView for:EditTextView.
  v contents:t.

  v width:450.
  v open.


ST/X 6.1.1; WebServer 1.620 at exept:8081; Wed, 23 May 2012 21:27:25 GMT