Switch viewer in example "ViewerFromScratch.java"

Have jReality programming problems or questions? Post them here.
Post Reply
Joe
Posts: 61
Joined: Fri 11. Jul 2008, 19:29

Switch viewer in example "ViewerFromScratch.java"

Post by Joe » Thu 8. Apr 2010, 20:34

Hello,
because ViewerApp has been set to deprecated a long time ago, I tried to update my code and started playing around with http://www3.math.tu-berlin.de/jreality/ ... ratch.java

If I would like to switch the viewer (JOGL or softviewer) at runtime, I did this like this with ViewerApp:

Code: Select all

ViewerSwitch viewerSwitch = _viewerApp.getViewerSwitch();
viewerSwitch.selectViewer(viewerIndex);
viewerSwitch.getCurrentViewer().renderAsync();
How can this be achieved with the "ViewerFromScratch.java" example?

Thanks and best regards, Joe

sechel
Posts: 69
Joined: Tue 2. Oct 2007, 09:20

Re: Switch viewer in example "ViewerFromScratch.java"

Post by sechel » Fri 9. Apr 2010, 08:05

Hi Joe,
have you tried the replacement of ViewerApp, which is JRViewer from the plugin source folder? It uses the ViewerSwitch like ViewerApp did. You find the code in de.jreality.plugin.basic.View.

Joe
Posts: 61
Joined: Fri 11. Jul 2008, 19:29

Re: Switch viewer in example "ViewerFromScratch.java"

Post by Joe » Sun 11. Apr 2010, 11:59

Hi Stefan,
thanks for your answer. I tried to use JRViewer, but I got a new problem. Every time when I run the code below, a new JRViewer window pops up. But I would like to integrate only the viewing component into my own viewer.

Here's my code:

Code: Select all

JRViewer jrViewer = new JRViewer();

// Add the View-Plugin for getting a ViewerSwitch
jrViewer.registerPlugin(new View());
jrViewer.startup();

// Add this into the JPanel of my viewer
Viewer viewer = jrViewer.getViewer();
viewer.getViewingComponent();
Best regards, Joe

sechel
Posts: 69
Joined: Tue 2. Oct 2007, 09:20

Re: Switch viewer in example "ViewerFromScratch.java"

Post by sechel » Sun 11. Apr 2010, 14:29

Hi Joe,
try using the startupLocal() method from the JRViewer. It's basically the same as startup() but instead of opening the window it returns the root pane. So you can add this to whatever component you like. There is a thread about adding such a root pane to an internal swing frame:
http://www3.math.tu-berlin.de/jreality/ ... ?f=3&t=436
Please note also the main method from JRViewer to get started with the plugin configuration.
You don't need to add the View plug-in, it's added by default along with a set of other default plug-ins.

Joe
Posts: 61
Joined: Fri 11. Jul 2008, 19:29

Re: Switch viewer in example "ViewerFromScratch.java"

Post by Joe » Sun 18. Apr 2010, 07:41

Hi Stefan,
thanks. I was able to switch from ViewerApp to JRViewer. But one bug reappears, which has already been solved here: http://www3.math.tu-berlin.de/jreality/ ... p?f=3&t=78

The VieweApp class provides a method "dispose()", which allows to clean up the memory. JRViewer doesn't have this method, so I got the memory leaks again.

What is the official way to clean up the memory with the JRViewer?

Thanks and best regards, Joe

sechel
Posts: 69
Joined: Tue 2. Oct 2007, 09:20

Re: Switch viewer in example "ViewerFromScratch.java"

Post by sechel » Thu 22. Apr 2010, 00:08

Hi Joe,
please check out the svn. There is a dispose method in the JRViewer now.
It should do similar things as ViewerApp.dispose(). Memory profiling however
showed that the swing components are somehow not beeing collected.
Stefan

Post Reply