## SwingOSC – Java-based GUI classes

This class is meant as an emulation of SCCompositeView. last mod: 17-jul-09 sciss
Also refer to JSCView for different behaviour affecting all widgets

different behaviour
clipping | child components whose bounds transgress the container's bounds are painted in a clipped way as expected. this is not true for cocoa gui.
known issues / todo
gradient | HiliteGradient is painted as regular Gradient
moving | moving the view using bounds_ moves along child components (in accordance with cocoa GUI they should remain at their absolute positions)

# JSCCompositeView

Note: please use the abstraction layer CompositeView if possible!

A composite view is a container that contains other views. This allows you for example to show and hide all children of that composite view or to attach a certain resize behaviour to the composite view.

Examples:

### grouping by background color

    (
    w = JSCWindow.new;

    c = JSCCompositeView( w, Rect( 20, 20, 300, 300 ));

    a = JSC2DSlider( c, Rect( 20, 20, 100, 100 ));
    b = JSC2DSlider( c, Rect( 120, 120, 100, 100 ));

    c.background = Gradient( Color.rand, Color.rand );

    w.front;
    )

Coordinates are always relative to the top-left corner of the parent view, unless you set `relativeOrigin` to `true`.

### overlapping children

If children are placed in a way that their bounding boxes overlap, a child that was created after another child will appear in front of that other child:

    (
    b.bounds = b.bounds.moveBy( -50, -50 );
    a.background = Color.red;
    b.background = Color.blue;  // this appears in front of the red one
    )

### keydown bubbling

Note that the `keyDown` action is assigned to the composite view. If c and d do not have `keyDown` actions themselves, the event is passed to `b`, the parent.

    (
    w = JSCWindow.new;

    c = JSCCompositeView( w, Rect( 0, 0, 500, 500 ));

    a = JSC2DSlider( c, Rect( 0, 0, 100, 100 ));
    b = JSC2DSlider( c, Rect( 100, 100, 100, 100 ));

    w.front;

    c.keyDownAction = { "keydown bubbled up to me".postln };

    // d is on window w, not on composite view c, so pressing keys when d is focussed won't call c.keyDownAction
    d = JSC2DSlider( w, Rect( 200, 200, 100, 100 ));
    )

click on the different views and hit keys on the keyboard.

### decorators

a 'decorator' object can be set to handle layout management. all views added to the composite view will now be placed by the decorator.

    (
    a = JSCWindow.new;

    b = JSCCompositeView( a, Rect( 0, 0, 500, 500 ));
    b.decorator = FlowLayout( b.bounds );

    // adding views to b automatically use the decorator
    // no need to use parent.decorator.place
    c = JSC2DSlider( b, Rect( 0, 0, 100, 100 ));   // size matters
    d = JSC2DSlider( b, Rect( 0, 0, 100, 100 ));   // origin doesn't

    a.front;
    )

### hiding / swapping

    (
    a = JSCWindow.new;
    q = 3;

    e = JSCButton( a, Rect( 6, 6, 160, 20 ));

    e.states = Array.fill( q, { arg i; [ i.asString, Color.black, Color.white ]});

    e.action = { arg butt;
        p.visible = false;
        p = c.at( butt.value );
        p.visible = true;
    };

    c = Array.fill( q, { arg i;
        b = JSCCompositeView( a, Rect( 2, 32, 300, 300 ));
        b.decorator = FlowLayout( b.bounds );
        b.background = Color.rand( 0.6 );
        c = JSC2DSlider( b, Rect( 0, 0, 100, 100 ));
        c.x = 1.0.rand;
        d = JSC2DSlider( b, Rect( 0, 0, 100, 100 ));
        d.y = 1.0.rand;
        b.visible = false;
        b;
    });

    p = c.at( 0 ); // previous
    p.visible = true; // show first one

    a.front;
    )

See also JSCTabbedPane

### removing

    (
        w = JSCWindow.new;
        c = JSCCompositeView( w, Rect( 0, 0, 300, 300 ));
        a = JSC2DSlider( c, Rect( 0, 0, 100, 100 ));
        b = JSC2DSlider( c, Rect( 100, 100, 100, 100 ));
        c.background = Gradient( Color.rand, Color.rand );
        w.front;
    )

    a.remove;

### resize constraints

resize the window to see how the contents behave

    (
    w = JSCWindow.new;

    c = JSCCompositeView( w, Rect( 0, 0, 300, 300 ));
    //c.background = Gradient(Color.rand,Color.rand);
    c.background = Gradient( Color( rrand( 0.3, 0.9 ), rrand( 0.3, 0.9 ), rrand( 0.3, 0.9 ), rrand( 0.3, 0.9 )), Color.rand );

    c.resize = 5; // elastic

    a = JSC2DSlider( c, Rect( 0, 0, 100, 100 ));
    a.resize = 1; // fixed

    b = JSC2DSlider( c, Rect( 100, 100, 100, 100));
    b.resize = 2; // x elastic
    b.setProperty( \minWidth, 30 ); // up to a point
    b.setProperty( \maxWidth, 200 );
    w.front;
    )

Bug in Cocoa-GUI (doesn't apply to SwingOSC): composite view should get limited by it's contents' limitations.