SwingOSC – Java-based GUI classes

This class is meant as an emulation of the Knob class by blackrain. last mod: 17-jul-09 sciss
Also refer to JSCView and JSCUserView.

different behaviour
modifiersdrag-n-drop uses control modifier (as in all dnd ops). for vert mode, use shift key

 

JKnob

Note: please use the abstraction layer Knob if possible!

JKnob is a gui control with round, horizontal or vertical action.

Instantiation

	JKnob.new( <parent>, <bounds> )
	

Instance methods

 

Behavior

 

Default Keyboard Mappings

Keys work like on JSCSlider when the Knob gains focus:

csr up/right or ]increment value by keystep
csr down/left or [decrement value by keystep
xset value to 1.0
cset value to 0.5
nset value to 0.0

 

Examples

(
var window, size = 32; // try different sizes - from 15 to 200 or more!
window = JSCWindow.new("Knob", Rect(300,300,270,100)).front;
k = JKnob.new(window, Rect(20, 10, size, size));
k.action_({|v,x,y,m| ["action func", v.value].postln; });
//k.color[1] = Color.gray(alpha:0);
)
k.value
k.value = 0.25
k.valueAction = 0.125

// modes
k.mode = \vert;
k.mode = \horiz;
k.mode = \round; // default

k.visible
k.visible = false
k.visible = true
k.enabled_(false)
k.enabled_(true)
k.canFocus = false
k.canFocus = true

// centered mode - a pan control
(
var window, spec;
spec = ControlSpec(-1, 1, default: 0);
window = JSCWindow.new("Pan Knob", Rect(350,400,270,70)).front;
k = JKnob.new(window, Rect(20,10,28,28));
k.action_({|v,x,y,m| spec.map(v.value).postln; })
// .mode_(\horiz)
	.centered_(true)
	.value_(spec.unmap(0)); // 0.5
//k.color[1] = Color.gray(alpha:0);
)

k.centered
k.centered = false
k.centered = true

k.refresh

// mouseOverAction
(
var size = 28;
w = JSCWindow.new("Knobs", Rect(250,500,270,70));
w.acceptsMouseOver=true; // true in parent window!
w.view.decorator = FlowLayout(w.view.bounds);
h = JSCStaticText(w, 150 @ 20);
w.view.decorator.nextLine;
k = Array(8);
8.do({|item, i|
	var knob;
	knob = JKnob.new(w, size @ size)
	// .canFocus_(false)
		.action_({|v,x,y,m| h.string = "val: " ++ v.value.asString; })
		.mouseOverAction_({|v,x,y| h.string = "val: " ++ v.value.asString; });
	
	knob.color[0] = [Color.blue(0.7, 0.4), Color.red(0.7, 0.7), Color.green(0.3, 0.6),
		Color.black.alpha_(0.3)].choose;
	k = k.add(knob);
});
w.front
)
k[4].value

// drag and drop
// in SwingOSC : ctrl+press+move initiated drag!
(
var w, txt, size = 36;
w = JSCWindow.new("knobs", Rect(400,400,250,100)).front;
w.acceptsMouseOver=true;
w.view.decorator = FlowLayout(w.view.bounds).gap_(10 @ 10).margin_(10 @10);
txt = JSCStaticText(w, 200 @ 14);
w.view.decorator.nextLine;

k = JKnob(w, size @ size);
k.action = {arg v,x,y;  v.value.postln; txt.string_("value: " ++ v.value); };
k.mouseOverAction = {|v| txt.string_("value: " ++ v.value); };

j = JKnob(w, size @ size);
j.action = {arg v,x,y;  j.value.postln; txt.string_("value: " ++ v.value); };
j.mouseOverAction = { txt.string_("value: " ++ j.value); };

n = JSCNumberBox(w, 100 @ 20);
//n.setProperty(\boxColor,Color.grey(alpha:0.0));
n.value = 0.0;
)

// customize drag and drop methods
k.canReceiveDragHandler
k.canReceiveDragHandler = false; // don't accept drops

k.canReceiveDragHandler = { JSCView.currentDrag.isFloat }; // accept only if drag is float

k.receiveDragHandler = { ("value droped in: " ++ JSCView.currentDrag).postln }

k.receiveDragHandler = { k.valueAction = JSCView.currentDrag.clip(0.0, 1.0); }

k.beginDragAction = { ("drag out -> " ++ k.value).postln; }

k.beginDragAction = { k.value.asFloat; }