SwingOSC – Java-based cross-platform replacements for Cocoa GUI classes


This class is meant as an emulation of SCTextView. last mod: 03-aug-08 sciss

Also refer to [JSCView] for different behaviour affecting all widgets


no-op / not working

different behaviour

string_ effective even when the view is made non-editable (in CocoaGUI, string_ doesn't work in this case)

enterInterpretsSelection uses Ctrl+Return instead

extended functionality

caretColor_ colour of the cursor (useful for dark backgrounds)

openURL loads a text file

action_ action function is called whenever text is entered, removed or caret moved

linkAction_ facility to implement hyperlink navigation


known issues / todo

textBounds not yet implemented

usesTabToFocusNextView not yet implemented

hyperlinks should add some action function to react to clicks on hyperlinks

mouseDownAction called with the regular arguments, not special cocoa clickPos

string_ doesn't clear previously used style, there should be a way to clear it

text transmission due to the trickery of the SuperCollider unicode support (a unicode

character can be reflected by more than one Char in a SuperCollider

String), there occurs a discrepency between the character count

(and hence cursor position) of the server (Swing) and the client

(SuperCollider). You'll get "Yukk" messages, indicating that

the text representation on the client (SuperCollider) might be wrong


JSCTextView a text editor


Note: please use the abstraction layer GUI.textView if possible! (see [GUI])


superclass: JSCView

see also: [Document]

*new(window, bounds);

string_ set the text

string get the text

setString(string, rangestart, rangesize)

set text into a range 


selectedString get the selected text only

selectionStart get the current position in the text

selectionSize get the current size of selection in the text

stringColor_ set the color of the whole text 

setStringColor(color, start, size)

set the color of a selection of text 


autoHideScrollers_

hasVerticalScroller_

hasHorizontalScroller_

textBounds_ NOT YET WORKING

don't know what this is for ...

font_ set the font of the whole text 

setFont( font, start, size )

set the font of a selection of text


usesTabToFocusNextView_

NOT YET WORKING

enterInterpretsSelection_

whether pressing enter should interprete the

selected text. default is 'on'. note that on SwingOSC,

since we cannot detect a difference between return and enter,

you will have to press Ctrl+Return!



//examples


(

var win;


win = JSCWindow.new;

t = JSCTextView( win, win.view.bounds.insetBy( 4, 4 ))

.resize_( 5 )

.hasVerticalScroller_( true )

.autohidesScrollers_( true )

.focus( true );

win.front;

)


t.enterInterpretsSelection_( true );


t.editable = false; // make it read-only

t.editable = true; // allow editing


t.autohidesScrollers = false; // always show the scrollbars


t.string = "Schoko";

// copy this help document into the view (style elements are not copied)

t.string = Document.current.string;


// well, we can style it afterwards...

t.setFont( JFont( "Times", 24, 1 ), 0, 8 );

t.setStringColor( Color.blue, 0, 8 );

t.setStringColor( Color( 0.5, 0.0, 0.7 ), 8, 68 );


// apply style to the whole document

t.font = JFont( "Times", 14 );

t.stringColor = Color.green( 0.4 );


t.background = Color.black;

t.caretColor = Color.white; // cursor colour (SwingOSC only)



// loading a text file (SwingOSC only). plain text, html and rtf should work

t.openURL( "file://" ++ "~/*/*.html".standardizePath.pathMatch.choose.absolutePath );

t.openURL( "http://swiki.hfbk-hamburg.de:8888/MusicTechnology/6" );

t.openURL( "file://" ++ Document.current.path ); // RTF is not properly loaded - why?

// TODO : clicking on links has no effect!


// listen for document changes

// possible states and parameters:

// \insert, <(Integer) pos>, <(Integer) length>, <(String) insertedText>

// \remove, <(Integer) pos>, <(Integer) length>

// \caret, <(Integer) pos1>, <(Integer) pos2>

// ; caret means the cursor was moved or the selection changed. with no text

// selected (cursor displayed) pos1 equals pos2, otherwise pos1 and pos2

// correspond to the selected range (pos1 may be both greater or less than pos2)!

t.action = { arg view, state ... params; ([ state ] ++ params).postcs };


// let's see what's been typed in

t.string;

t.selectedString; // just the part that's currently selected

t.selectionStart; // position of selection begins. starts at 0

t.selectionSize; // 0 means no text selected



// listen for hyperlink navigation

//   possible states: \entered, \exited, \activated

// NOTE: the linkAction only works when the document is read-only,

//   so the editable property needs to be set to false!

t.editable   = false;

t.linkAction = { arg view, state, url, description; [ state, url, description ].postln };

// a simple link-action to follow links

t.linkAction = { arg view, state, url; if( state === \activated, { view.openURL( url )})};