Forums > Java

JitterGUI Family Documentation

March 13, 2007 | 12:16 am

I’m hoping for any tips on how to write a peer to jitterGUISlider which utilizes the available classes. If I don’t have to reinvent the wheel, I don’t want to. BUT just reading the .java files is really making my brain explode.

is there something akin to api documentation?


March 17, 2007 | 5:59 am

Hi Matthew,

There is nothing akin to API documentation for these example java
classes (or the javascript code that inspired them.) But I don’t
think it will be as hard as you think it will be to understand the
code. JitterGuiSlider is a really simple wrapper around
JitterGuiSliderElement which extends JitterGuiElement. Go through the
methods carefully and feel free to post any specific questions you
have to the forum.

Ben



jbm
June 2, 2007 | 2:15 pm

Hello Ben,

I’ve been trying to wrap my head around gui stuff for the last couple of weeks, and it’s giving me a really hard time. I’m sure most of this is simply due to the fact that graphics programming is *very* different from audio/midi – at least to my mind… Anyway, in poking around with your java-jitter gui stuff, I think I’ve managed to kind of get a sense of what’s going on, but I’m still really unclear on how to do the things I need to do. What I want to do is "add" new objects to existing objects, and have those new objects "stick" to the existing (parent) objects, while maintaining the functionality of both child and parent.
In messing around with this, I’ve been trying to add a "nested" slider to one of your JitterGuiSliders, to make a kind of "bank".
I’ve done some hacking, but it’s really not working:

// Created on 3-Sep-2005
import com.cycling74.max.*;
import java.util.*;

/**
* @author bbn, @destroyed_by jbm
*
* Max object container for a single slider
*/
public class JitterGuiSliderBank extends MaxObject {

private JitterGuiSliderElement s = null;
private ArrayList Sliders = null;
private String context;

public JitterGuiSliderBank(Atom args[]) // initialize with one slider
{
if (args.length == 0)
bail("gui.slider: need a context argument");
context = args[0].toString();
Sliders = new ArrayList();
s = new JitterGuiSliderElement(this, new Callback(this, "out"));
s.init(context);
Sliders.add(s);
declareAttribute("color", null, "setColor");
declareAttribute("rotate", null, "setRotate");
declareAttribute("position", null, "setPosition");
declareAttribute("scale", null, "setScale");
}

public void nestSlider()
{
JitterGuiSliderElement sliderOne = Sliders.get(0);
float homePositionX = sliderOne.position[0];
float homePositionY = sliderOne.position[1];
float homePositionZ = sliderOne.position[2];
post("home position x: " +homePositionX);
JitterGuiSliderElement slider = new JitterGuiSliderElement(this, new Callback(this, "out"));
Atom[] setup = new Atom[]{Atom.newAtom((float)homePositionX + 0.4f),
Atom.newAtom((float)homePositionY + 0.6f), Atom.newAtom((float)homePositionZ)};
slider.init(context);
slider.setPosition(setup);
Sliders.add(slider);
}

public void out()
{
for(int i=0;i < Sliders.size();i++)
{
JitterGuiSliderElement slider = Sliders.get(i);
outlet(0, slider.val);
}
}

public void notifyDeleted()
{
for(int i=0;i < Sliders.size();i++)
{
JitterGuiSliderElement slider = Sliders.get(i);
slider.free();
}
}

public void setColor(Atom a[]) {s.setColor(a);}
public void setRotate(Atom a[]) {s.setRotate(a);}
public void setPosition(Atom a[]) {s.setPosition(a);}
public void setScale(Atom a[]) {s.setScale(a);}
}

It does create a new, functioning slider. But it then loses the ability to detect the old one with the mouse. Also, the nested slider doesn’t move with the initial one. Is there any chance you could give me a quick run-down of how to best manage this? I’d thought about perhaps adding code to JitterGuiElement which would allow the creation of nested objects, but I’m not at all sure how I’d go about doing that. Even if you could outline for me how your js-based sliderrow would work with your java gui classes, that would be awesome. This is doing my head in right now, but I’m sure once I can get a model of it in my head, I’ll be able to go from there.

Thanks in advance,

J.



jbm
June 2, 2007 | 3:14 pm

okay, so with a little observation I got them to move together (just x, y at the moment, but that’s fine for now). Just added some offsets:

public void nestSlider()
{
JitterGuiSliderElement sliderOne = Sliders.get(0);
float homePositionX = sliderOne.position[0];
float homePositionY = sliderOne.position[1];
float homePositionZ = sliderOne.position[2];
post("home position x: " +homePositionX);
JitterGuiSliderElement slider = new JitterGuiSliderElement(this, new Callback(this, "out"));
Atom[] setup = new Atom[]{Atom.newAtom((float)homePositionX + 0.4f),
Atom.newAtom((float)homePositionY + 0.6f), Atom.newAtom((float)homePositionZ)};
slider.init(context);
slider.setUniqueIndex(Sliders.size());
slider.setPosition(setup);
Sliders.add(slider);
// set up offsets for positioning later
sX = s.position[0];
sY = s.position[1];
float sliderX = slider.position[0];
xoffset = sliderX – sX;
float sliderY = slider.position[1];
yoffset = sliderY – sY;
}

then looped through the children in setPosition():

public void setPosition(Atom a[])
{
s.setPosition(a);
sX = s.position[0];
sY = s.position[1];
for(int i=1;i < Sliders.size();i++)
{
float sliderZ = Sliders.get(i).position[2];
JitterGuiSliderElement slider = Sliders.get(i);
Atom[] shift = new Atom[]{Atom.newAtom((float)sX + xoffset), Atom.newAtom((float)sY + yoffset),
Atom.newAtom((float)sliderZ)};
slider.setPosition(shift);
}
}

The focus/selection thing is more mysterious to me, though…

J.



jbm
June 2, 2007 | 3:19 pm

oh! I just noticed that if I add more than one nested slider, the two children are able to negotiate focus/selection properly. hmm. This may put me closer than I thought I was…

apologies to all those who still use the mailing list. I’m strictly forum-based these days, so I don’t get spammy posts by goofballs like myself. ;-)

J.



jbm
June 2, 2007 | 3:29 pm

aha! Got it. setUniqueIndex on the parent can’t be zero (which I’d set it to before)…

Here’s the current code. Ben, if you find this laughably goofy, please point out where, and why.

// Created on 3-Sep-2005
import com.cycling74.max.*;
import java.util.*;

/**
* @author bbn
*
* Max object container for a single slider
*/
public class JitterGuiSliderBank extends MaxObject {

private JitterGuiSliderElement s = null;
private ArrayList Sliders = null;
private String context;
private float sX, sY, xoffset, yoffset;
public JitterGuiSliderBank(Atom args[]) // initialize with one slider
{
if (args.length == 0)
bail("gui.slider: need a context argument");
context = args[0].toString();
Sliders = new ArrayList
();
s = new JitterGuiSliderElement(this, new Callback(this, "out"));
s.init(context);
s.setUniqueIndex(1);
Sliders.add(s);
declareAttribute("color", null, "setColor");
declareAttribute("rotate", null, "setRotate");
declareAttribute("position", null, "setPosition");
declareAttribute("scale", null, "setScale");
}

public void nestSlider()
{
JitterGuiSliderElement sliderOne = Sliders.get(0);
float homePositionX = sliderOne.position[0];
float homePositionY = sliderOne.position[1];
float homePositionZ = sliderOne.position[2];
post("home position x: " +homePositionX);
JitterGuiSliderElement slider = new JitterGuiSliderElement(this, new Callback(this, "out"));
Atom[] setup = new Atom[]{Atom.newAtom((float)homePositionX + 0.4f),
Atom.newAtom((float)homePositionY + 0.6f), Atom.newAtom((float)homePositionZ)};
slider.init(context);
slider.setUniqueIndex(Sliders.size() + 1);
slider.setPosition(setup);
Sliders.add(slider);
// set up offsets for positioning later
sX = s.position[0];
sY = s.position[1];
float sliderX = slider.position[0];
xoffset = sliderX – sX;
float sliderY = slider.position[1];
yoffset = sliderY – sY;
}

public void out()
{
for(int i=0;i < Sliders.size();i++)
{
JitterGuiSliderElement slider = Sliders.get(i);
outlet(0, slider.val);
}
}

public void notifyDeleted()
{
for(int i=0;i < Sliders.size();i++)
{
JitterGuiSliderElement slider = Sliders.get(i);
slider.free();
}
}

public void setColor(Atom a[]) {s.setColor(a);}
public void setRotate(Atom a[]) {s.setRotate(a);}
public void setPosition(Atom a[])
{
s.setPosition(a);
sX = s.position[0];
sY = s.position[1];
for(int i=1;i < Sliders.size();i++)
{
float sliderZ = Sliders.get(i).position[2];
JitterGuiSliderElement slider = Sliders.get(i);
Atom[] shift = new Atom[]{Atom.newAtom((float)sX + xoffset), Atom.newAtom((float)sY + yoffset),
Atom.newAtom((float)sliderZ)};
slider.setPosition(shift);
}
}
public void setScale(Atom a[]) {s.setScale(a);}
}

cheers,

J.


Viewing 6 posts - 1 through 6 (of 6 total)