Page 1 of 1

Switch viewer in example "ViewerFromScratch.java"

Posted: Thu 8. Apr 2010, 20:34
by Joe
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

Re: Switch viewer in example "ViewerFromScratch.java"

Posted: Fri 9. Apr 2010, 08:05
by sechel
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.

Re: Switch viewer in example "ViewerFromScratch.java"

Posted: Sun 11. Apr 2010, 11:59
by Joe
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

Re: Switch viewer in example "ViewerFromScratch.java"

Posted: Sun 11. Apr 2010, 14:29
by sechel
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.

Re: Switch viewer in example "ViewerFromScratch.java"

Posted: Sun 18. Apr 2010, 07:41
by Joe
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

Re: Switch viewer in example "ViewerFromScratch.java"

Posted: Thu 22. Apr 2010, 00:08
by sechel
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