Embedding jReality in a Java Application

Have jReality programming problems or questions? Post them here.
Post Reply
karunaMaitri
Posts: 90
Joined: Sun 16. Nov 2008, 00:24

Embedding jReality in a Java Application

Post by karunaMaitri » Tue 25. Nov 2008, 22:58

I am new to jReality. I would like to use it to visualize the data my java application produces.
To make this embedding possible, I need to address three issues, which I describe below.

In order to embed jReality into my application,
I need to display jReality renderings in JInternalFrame. How can I do it? I have seen in some tutorials, ViewerApp.display() is used, which renders to a JFrame. Instead, can I use
JInternalFrame? How can I do it?

I would like the user to have a lot of interaction with my application. That means the data is updated and re-rendered. This can happen frequently and rapidly. As an important step of this interaction, I need to allow the user interact with the scene by picking and selection. I am assuming this is possible. Am I right?

Finally, I would like to set up multiple visualizations, each rendered into a different JInternalFrame and each rendering done on a different thread. Is this possible in jReality? Are there some examples illustrating this aspect?

I really appreciate any feedback on these issues.

Thanks,
Karuna

User avatar
steffen
Posts: 186
Joined: Fri 16. Jun 2006, 13:30
Location: TU Berlin
Contact:

Post by steffen » Thu 27. Nov 2008, 20:08

Instead, can I use JInternalFrame? How can I do it?
You can use ViewerApp to get everything set-up and then put the components where you like, but I have never tested JInternalFrames. Just use the constructor ViewerApp(SceneGraphNode n) and give it your SceneGraphComponent. Take a look at the javadoc of ViewerApp for more infos.
I need to allow the user interact with the scene by picking and selection. I am assuming this is possible. Am I right?
Yes, you are ;-) Please see the tutorials in the Wiki for a first introduction...
Finally, I would like to set up multiple visualizations, each rendered into a different JInternalFrame and each rendering done on a different thread...
It is no problem to create several ViewerApp instances with different content that is displayed. It is also possible to render different views from the same scene, but interacting with the same scene from different viewers will cause problems. Please give more details about what you want to do.

Good luck, Steffen.

karunaMaitri
Posts: 90
Joined: Sun 16. Nov 2008, 00:24

Post by karunaMaitri » Fri 5. Dec 2008, 08:58

Thanks Steffen, for the help, it worked for JFrame and JInternalFrame.

I have also extended the ViewerApp class by adding two constructors that take JFrame and JInternalFrame as arguments and then use the methods already present in ViewerApp.

"...but interacting with the same scene from different viewers will cause problems. Please give more details about what you want to do."

I am working on a Visualization research project that extensively uses surfaces and curves. This is an emerging research project. I will post messages as our work requires new visualizations.

Thanks,
Karuna

goose12
Posts: 11
Joined: Sun 24. Jul 2011, 03:08

Re: Embedding jReality in a Java Application

Post by goose12 » Sun 24. Jul 2011, 03:57

I am also trying to embed a viewer into a JInternalFrame, but have been unsuccessful thus far. Could you share some of the code that you used to add the viewer to the internal frame? Thanks

goose12
Posts: 11
Joined: Sun 24. Jul 2011, 03:08

Re: Embedding jReality in a Java Application

Post by goose12 » Mon 25. Jul 2011, 00:39

I have been able to add the viewing component to a JPanel "DrawPanel" within a JInternalFrame (see code below), but the ViewerApp is still displayed (see attached picture).

Code: Select all

public class DrawPanel extends JPanel {
	
	public DrawPanel(){
		//this.setBackground(Color.WHITE);
		//SceneGraphComponent sgc = SceneGraphUtility.createFullSceneGraphComponent("world");
		//sgc.setGeometry(createSurface(20));
		//Appearance ap = sgc.getAppearance();
		//ap.setAttribute(CommonAttributes.POLYGON_SHADER+"."+CommonAttributes.DIFFUSE_COLOR, Color.LIGHT_GRAY);
		ViewerApp v = new ViewerApp(new SceneGraphComponent());
		v.display(null);
		v.setCreateMenu(false);
		v.setBackgroundColor(Color.GREEN);
		v.update();
		this.add((Component)v.getContent());
	}
}
Also the ViewerApp is depreciated. Is there a way to add the viewing component of the JRViewer? Thanks in advance.
Attachments
Untitled.png
Untitled.png (80.1 KiB) Viewed 1205 times

goose12
Posts: 11
Joined: Sun 24. Jul 2011, 03:08

Re: Embedding jReality in a Java Application

Post by goose12 » Mon 25. Jul 2011, 04:08

For others browsing the forum, this is how you can add a viewer to an internal frame.

Code: Select all

/*
 * Created on Jan 12, 2010
 *
 */
package de.jreality.tutorial.plugin;

import java.awt.GridLayout;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JRootPane;

import de.jreality.plugin.JRViewer;
import de.jreality.plugin.JRViewer.ContentType;
import de.jreality.plugin.basic.Inspector;
import de.jreality.plugin.content.ContentLoader;
import de.jreality.plugin.content.ContentTools;
import de.jtem.jrworkspace.plugin.sidecontainer.template.ShrinkPanelPlugin;

public class InternalFrameTest {

   public static void main(String[] args) {
      JRViewer v = new JRViewer();
      v.addBasicUI();
      v.registerPlugin(new ContentLoader());
      v.registerPlugin(new ContentTools());
      v.getPlugin(Inspector.class).setInitialPosition(ShrinkPanelPlugin.SHRINKER_LEFT);
      v.addContentSupport(ContentType.CenteredAndScaled);
      v.setShowPanelSlots(true, false, false, false);

      // call this to avoid creating a Frame
      JRootPane rootPanel = v.startupLocal();
      // create your own frame, with a JInternalFrame, and
      // put the rootPanel into it.
      JFrame f = new JFrame("Internal Frame Test");
      JDesktopPane desktop = new JDesktopPane();
      JInternalFrame internalFrame1 = new JInternalFrame("Internal Frame");
      internalFrame1.setSize(600, 400);
      internalFrame1.setLayout(new GridLayout());
      internalFrame1.add(rootPanel);
      internalFrame1.setResizable(true);
      desktop.add(internalFrame1);
      internalFrame1.setVisible(true);
      f.setLayout(new GridLayout());
      f.add(desktop);
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      f.setSize(800, 600);
      f.setVisible(true);
   }
   
   
}

Andre
Posts: 226
Joined: Fri 18. Sep 2009, 11:30

Re: Embedding jReality in a Java Application

Post by Andre » Fri 19. Aug 2011, 21:38

Thx for this tutorial I've added this to the viewer Tutorials of jReality

Post Reply