Integration with Swing in Mac OS

60 views
Skip to first unread message

Massimiliano

unread,
Jan 22, 2010, 4:40:52 PM1/22/10
to Jzy3d
Hello!

I am trying to integrate jzy3d into my swing application. Basically I
want to have a JInternalFrame that shows graphs with jzy3d.
An example of code could be the following:

public class JZY3DFrame extends JInternalFrame implements Observer
{
public JZY3DFrame (Chart chart, Rectangle bounds, String title)
{
this (chart, title);
setBounds (bounds);
}

public JZY3DFrame (Chart chart, String title)
{
_chart = chart;
addInternalFrameListener(new JZY3DFrameInternalFrameAdapter
());
setDefaultCloseOperation (EXIT_ON_CLOSE);
getContentPane().setLayout(new BorderLayout());
getContentPane().add((Component)_chart.getCanvas());
setTitle (title);
}

public void update(Observable o, Object arg) {
throw new UnsupportedOperationException("Not supported yet.");
}

private Chart _chart;

private class JZY3DFrameInternalFrameAdapter extends
InternalFrameAdapter
{
@Override
public void internalFrameClosing (InternalFrameEvent e)
{
remove ((Component) _chart.getCanvas());
_chart.dispose();
_chart = null;
dispose();
}
}

public static Chart getTestChart() {
// Define a function to plot
Mapper mapper = new Mapper() {

public double f(double x, double y) {
return 10 * Math.sin(x / 10) * Math.cos(y / 20) * x;
}
};

// Define range and precision for the function to plot
Range range = new Range(-150, 150);
int steps = 50;

surface = (Shape)Builder.buildOrthonormal(new OrthonormalGrid
(range, steps, range, steps), mapper);
surface.setColorMapper(new ColorMapper(new ColorMapRainbow(),
surface.getBounds().getZmin(), surface.getBounds().getZmax(), new Color
(1,1,1,.5f)));

surface.setFaceDisplayed(true);
surface.setWireframeDisplayed(true);
surface.setWireframeColor(Color.BLACK);
surface.setFace(new ColorbarFace(surface));
surface.setFace2dDisplayed(true); // opens a colorbar on the
right part of the display

Chart c = new Chart() {
@Override
public void setScale(Scale scale) {
super.setScale(scale);
ColorMapper cm = surface.getColorMapper();
cm.setScale(scale);
surface.setColorMapper(cm);

//surface.setFaceDisplayed(true);
}
};
c.getScene().getGraph().add (surface);

return c;
}

static Shape surface;
}

With Windows everything is working fine (http://dl.dropbox.com/u/
234787/Stuff/windows.png) but with Mac OS (Leopard, Java 1.6, 64bit)
the canvas where the graph is rendered is always on top of everything,
no matter if the JInternalFrame is the one with focus or not (http://
dl.dropbox.com/u/234787/Stuff/osx.png).

Just a note: Since I had troubles recompiling JOGL for 64bit myself I
am using the one distributed together with worldwind.

Hope somebody has a clue about what's going on.

Thanks,
Max

Massimiliano

unread,
Jan 22, 2010, 4:42:22 PM1/22/10
to Jzy3d
Hummm... the links to the pics are messed up. Let me try again.

Windows: http://dl.dropbox.com/u/234787/Stuff/windows.png
Mac OSx: http://dl.dropbox.com/u/234787/Stuff/osx.png

Martin Pernollet

unread,
Jan 23, 2010, 6:58:19 AM1/23/10
to jz...@googlegroups.com
Hi Massimiliano
That's weird it worked on windows, because I fear you are actually using the heavywight CanvasAWT component in Swing.
The Chart object relies on a Canvas, either CanvasAWT or CanvasSwing. Its default behaviour is to use a CanvasAWT but you may force a Swing one this way:

Chart c = new Chart(){
   @Override
   public Canvas initializeCanvas(Scene scene, Quality quality){
return new CanvasSwing(scene, quality);
   }
}

as CanvasSwing is just an extention of the JOGL GLJPanel (http://savior.awardspace.com/javax/media/opengl/GLJPanel.html) you should have something that doesn't mess up when having other swing components on top. I however have no clue on why the colorbar doesn't render properly in your Swing case.

Regards
Martin

2010/1/22 Massimiliano <email...@gmail.com>

Massimiliano

unread,
Jan 23, 2010, 8:12:32 AM1/23/10
to Jzy3d
Thanks Martin,

I will try this as soon as I can and let you know!

On Jan 23, 6:58 am, Martin Pernollet <martin.pernol...@gmail.com>
wrote:


> Hi Massimiliano
> That's weird it worked on windows, because I fear you are actually using the
> heavywight CanvasAWT component in Swing.
> The Chart object relies on a Canvas, either CanvasAWT or CanvasSwing. Its
> default behaviour is to use a CanvasAWT but you may force a Swing one this
> way:
>
> Chart c = new Chart(){
>    @Override
>    public Canvas initializeCanvas(Scene scene, Quality quality){
> return new CanvasSwing(scene, quality);
>    }
>
> }
>
> as CanvasSwing is just an extention of the JOGL GLJPanel (http://savior.awardspace.com/javax/media/opengl/GLJPanel.html) you should
> have something that doesn't mess up when having other swing components on
> top. I however have no clue on why the colorbar doesn't render properly in
> your Swing case.
>
> Regards
> Martin
>

> 2010/1/22 Massimiliano <emaildel...@gmail.com>

Massimiliano

unread,
Jan 25, 2010, 9:55:40 AM1/25/10
to Jzy3d
Ok, that worked :)

I have also seen the other post where you say you added the parameter
swing/awt in the constructor, thanks, I will checkout the latest code
from SVN and test it out.
Unfortunately the color bar on the right still doesn't render
properly.

Never mind, my final objective is essentially the following: I need to
draw points in a 3d canvas, I don't need any graph (at least for now)
I want to be able to show essentially spheres, each sphere represents
a point and I want to be able to control the radius of the sphere, the
color and maybe the opacity and of course the coordinates of the
center. It'd be great if I could also click on such spheres and show
related information somewhere, a separate window would be fine.
Is this doable with jzy3d?
Before reading the documentation I wanted to make sure I could easily
integrate it into my project, and now that I was able to make it work
I need to see if I can do what I need. There aren't many libraries
that enable 3d visualization in java, so I hope I can do what I need
with this one.

Thanks,
Massimiliano

On Jan 23, 6:58 am, Martin Pernollet <martin.pernol...@gmail.com>
wrote:

> Hi Massimiliano
> That's weird it worked on windows, because I fear you are actually using the
> heavywight CanvasAWT component in Swing.
> The Chart object relies on a Canvas, either CanvasAWT or CanvasSwing. Its
> default behaviour is to use a CanvasAWT but you may force a Swing one this
> way:
>
> Chart c = new Chart(){
>    @Override
>    public Canvas initializeCanvas(Scene scene, Quality quality){
> return new CanvasSwing(scene, quality);
>    }
>
> }
>
> as CanvasSwing is just an extention of the JOGL GLJPanel (http://savior.awardspace.com/javax/media/opengl/GLJPanel.html) you should
> have something that doesn't mess up when having other swing components on
> top. I however have no clue on why the colorbar doesn't render properly in
> your Swing case.
>
> Regards
> Martin
>

> 2010/1/22 Massimiliano <emaildel...@gmail.com>

Martin Pernollet

unread,
Jan 26, 2010, 10:30:21 AM1/26/10
to jz...@googlegroups.com


2010/1/25 Massimiliano <email...@gmail.com>

Ok, that worked :)

I have also seen the other post where you say you added the parameter
swing/awt in the constructor, thanks, I will checkout the latest code
from SVN and test it out.
Unfortunately the color bar on the right still doesn't render
properly.


Strange. You may post a bug on the repository issue manager. If you post a file to reproduce it, I can try to understand.
 

Never mind, my final objective is essentially the following: I need to
draw points in a 3d canvas, I don't need any graph (at least for now)
I want to be able to show essentially spheres, each sphere represents
a point and I want to be able to control the radius of the sphere, the
color and maybe the opacity and of course the coordinates of the
center.

there's a trial on light that's using sphere. You may find it in src/trials and look at the sphere object from there.
You should be able to call setVolume(radius) on a sphere while it is allready displayed, and chart.render() to update the graph.
 
It'd be great if I could also click on such spheres and show
related information somewhere, a separate window would be fine.
Is this doable with jzy3d?

Implementing object selection when clicking with the mouse is not supported, but it is possible to add it to jzy if you feel like diving a bit in open gl? I won't have time to do it for you, but I could help in finding ressources.
 
Before reading the documentation I wanted to make sure I could easily
integrate it into my project, and now that I was able to make it work
I need to see if I can do what I need. There aren't many libraries
that enable 3d visualization in java, so I hope I can do what I need
with this one.

if you plan to do things that go further than ploting, do not use jzy. jzy's cool for doing simple things. I think there are more robust and complete libraries (LGWGL, aviatrix, etc) that could help you as well.

 

Martin Pernollet

unread,
Jan 26, 2010, 11:26:58 AM1/26/10
to jz...@googlegroups.com


2010/1/26 Martin Pernollet <martin.p...@gmail.com>

Martin Pernollet

unread,
Jan 26, 2010, 5:39:57 PM1/26/10
to jz...@googlegroups.com
Hi,
Selecting objects seems to be easy to do with Gleem (http://alumni.media.mit.edu/~kbrussel/gleem/). Although the lib home page is old, it seems to have been integrated to JOGL.
I let you check :)
Martin


2010/1/26 Martin Pernollet <martin.p...@gmail.com>

Massimiliano

unread,
Jan 26, 2010, 5:50:12 PM1/26/10
to Jzy3d
I took a closer look at the code... those classes I said are
definitely not subclassable!

On Jan 26, 5:39 pm, Martin Pernollet <martin.pernol...@gmail.com>
wrote:


> Hi,
> Selecting objects seems to be easy to do with Gleem (http://alumni.media.mit.edu/~kbrussel/gleem/). Although the lib home page is
> old, it seems to have been integrated to JOGL.
> I let you check :)
> Martin
>

> 2010/1/26 Martin Pernollet <martin.pernol...@gmail.com>
>
>
>
>
>
> > 2010/1/26 Martin Pernollet <martin.pernol...@gmail.com>
>
> >> 2010/1/25 Massimiliano <emaildel...@gmail.com>

> > *jMonkeyEngine <http://www.jmonkeyengine.com/>, lwjgl <http://lwjgl.org/>,
> > Xith3D <http://xith.org/>, Aviatrix3D <http://aviatrix3d.j3d.org/>*

Martin Pernollet

unread,
Jan 26, 2010, 6:00:25 PM1/26/10
to jz...@googlegroups.com
Which classes?

2010/1/26 Massimiliano <email...@gmail.com>

Massimiliano

unread,
Jan 26, 2010, 7:00:14 PM1/26/10
to Jzy3d

Hummm... One of my posts seems to be missing, it was a looong post :(
well, I guess I'll try to rewrite it tomorrow, or maybe it'll
magically appear in the meanwhile.
On Jan 26, 6:00 pm, Martin Pernollet <martin.pernol...@gmail.com>
wrote:
> Which classes?
>
> 2010/1/26 Massimiliano <emaildel...@gmail.com>

Massimiliano

unread,
Jan 26, 2010, 5:41:30 PM1/26/10
to Jzy3d
Thanks for all the resources you linked me. I don't think what I have
to do is that complicated, for now I will stay with jzy3d.
What I have been able to do so far is implementing a class called
MultidimensionalScatter, which is very similar to Scatter but it draws
a list of MultidimensionalPoint (a particular data structure I have in
my project). I render the points with x, y , z as the first 3
dimensions and point width, point alpha and point color as additional
coordinates (I haven't moved to spheres yet)... yes I know a bit of
OpenGL, it was pretty easy for me to implement that.

What I am trying to do now is having the ability of customize the axis
labels and scale. For instance, I would like to do the following:
let's say I want to visually plot a netflow-like dataset, e.g. source-
ip, dest-ip, port, number-of-packets.
What I will do is assigning a numeric value for each of the fields,
i.e. the IPs will be 0 to 100, port will stay as it is (and these are
x, y and z) and number-of-packets will be the alpha value, normalized
between 0 and 1. This I have already done.

Now I would like to have the possibility to label the x-axes as source-
IP the y as dest-IP and the z port (BTW, Z never shows up in the
graph). Moreover, I'd like to have rather than numbers on the axes
(0-100 for instance) the corresponding IPs (using a look-up-table for
instance). I started to look into this, at least at the axes labels,
however there is some problem with jzy's source code:

- The only way I found would be extending AxeBox and reimplementing
drawTicks. Unfortunately AxeBox has a number of private fields which I
cannot use in my subclass. So I just created my own class, copy
pasting basically all the AxeBox + adding methods and variables to set
the labels. BUT:
- My plan was to extend View as well, and set my own axebox in the
constructor. However the attribute in View for the axebox is of type
AxeBox and not Axe (the interface) as I expected. I could cast of
course, but before writing messy code I'd like to know if there are
other ways to do what I am trying to do.

Thanks for your help with this,
Massimiliano

On Jan 26, 11:26 am, Martin Pernollet <martin.pernol...@gmail.com>
wrote:


> 2010/1/26 Martin Pernollet <martin.pernol...@gmail.com>
>
>
>
>
>
>
>
> > 2010/1/25 Massimiliano <emaildel...@gmail.com>
>

> *jMonkeyEngine <http://www.jmonkeyengine.com/>, lwjgl <http://lwjgl.org/>,
> Xith3D <http://xith.org/>, Aviatrix3D <http://aviatrix3d.j3d.org/>*
>
>
>
>
>

Martin Pernollet

unread,
Jan 27, 2010, 4:02:35 AM1/27/10
to jz...@googlegroups.com
Don't know why when you post something it appears in a spam list and I have to validate your mail;
welle, that's done, and I'll read it.

2010/1/27 Massimiliano <email...@gmail.com>

Martin Pernollet

unread,
Jan 27, 2010, 4:08:40 AM1/27/10
to jz...@googlegroups.com
You are right, there are number of classes with private fields / methods which is stupid. I'll change that as soon as possible to allow subclassing  the AxeBox and View. Maybe I'll think the Axe labeling differently since you provide a use case.
More generally, I sometime had to write code fast. So do not hesitate to tell about things you don't like in the code!
Thanks for all your remarks,
Martin


 
2010/1/26 Massimiliano <email...@gmail.com>
Reply all
Reply to author
Forward
0 new messages