Changing the properties of ViewerApp and JRViewer

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

Re: Changing the properties of ViewerApp and JRViewer

Post by karunaMaitri » Mon 18. Jan 2010, 05:30

Thanks Sechel, for the code. I am sorry for delayed reply as I have been trying to explore various scenarios in which your code works. My conclusion, so far, is that
if we add a few other things to your code, your code does not work. The things I need to add are event listeners and a menu bar. These become necessary as several internal frames need to be generated and organized in Desktop pane.

I tested your code with some standard code from Sun Java tutorials and other well tested code. I get the same error. I could not post this question on other forums (not jReality) as the question involves knowledge of jReality and jrworkspace.

I put below one of the modifications to the code.

I shall really appreciate your help in this.

Code: Select all

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JRootPane;

import MyInternalFrameTests.LinesRectsOvalsJPanel;

import de.jreality.geometry.Primitives;
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_jReality2 {
	private int index = 0; 

   public static void main(String[] args) {
	   InternalFrameTest_jReality2 test = new InternalFrameTest_jReality2();
   }
   
   public JRootPane createJRealityObject(){
      JRViewer v = new JRViewer();
      v.setPropertiesFile("JRViewer.xml");
      v.setPropertiesResource(JRViewer.class, "JRViewer.xml");
      v.setContent(Primitives.sharedIcosahedron);
      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);

      JRootPane rootPanel = v.startupLocal();
   
    return rootPanel; 
   }
   
   public  InternalFrameTest_jReality2(){	
		  JFrame f = new JFrame("Internal Frame Test");
	      final JDesktopPane desktop = new JDesktopPane();      
	      f.setLayout(new GridLayout());
	      f.add(desktop);
	      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	      f.setSize(800, 600);
	      f.setVisible(true);
		JMenuBar bar = new JMenuBar(); // create menu bar
		JMenu addMenu = new JMenu( "Add" ); // create Add menu
		JMenuItem newFrame = new JMenuItem( "Internal Frame" );
		addMenu.add( newFrame ); // add new frame item to Add menu
		bar.add( addMenu ); // add Add menu to menu bar
		f.setJMenuBar( bar ); // set menu bar for this application
		//final JDesktopPane theDesktop = new JDesktopPane(); // create desktop pane
	    //f.add( desktop ); // add desktop pane to frame
	      // set up listener for newFrame menu item
	    newFrame.addActionListener(
	    		new ActionListener() // anonymous inner class
	         {  
	            // display new internal window
	            public void actionPerformed( ActionEvent event ) 
	            {
	            	JInternalFrame internalFrame1 = new JInternalFrame("Internal Frame" + index);
	      	      internalFrame1.setSize(600, 400);
	      	      internalFrame1.setOpaque(true);
	      	      internalFrame1.setLayout(new GridLayout());
	      	      JRootPane rootPanel = createJRealityObject();
	      	      internalFrame1.add(rootPanel);
	      	      internalFrame1.setResizable(true);
	      	      desktop.add(internalFrame1);
	      	      internalFrame1.setVisible(true);
	      	      index++;
	            }
	         });
	}
}
Thanks,
Karuna

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

Re: Changing the properties of ViewerApp and JRViewer

Post by karunaMaitri » Mon 18. Jan 2010, 06:54

I did one more experiment and proves my point. I took a very complex program (See Topley's Core JFC, 2nd ed, GraphicsDemo 3, Chapter 13). I created JRootPane from it and added it to JInternalFrames (see code in my previous post). It works! I could create several instances of JInternalFrame objects without a problem.

Can you let me know how we can solve the problem, please!

Thanks,
Karuna

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

Re: Changing the properties of ViewerApp and JRViewer

Post by karunaMaitri » Mon 25. Jan 2010, 20:25

Hi,

Could you let me know if there is some development with respect to the question I raised.

Thank you!
Karuna

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

Re: Changing the properties of ViewerApp and JRViewer

Post by sechel » Fri 5. Feb 2010, 17:08

Sorry for not responing for a long time. Here is my analysis:
1) First thing is a jreality problem and that is fixed now. If you created a viewer from the Eventqueue thread
youll get an empty JRootPane. Please update your jreality from the svn.
2) This is a look and feel problem: If you start your first JRViewer when hitting a button, then
it will probably have a different look and feel than the host application. You can avoid this problem by simply using
the same look and feel as the JRViewer which is the system lnf:

Code: Select all

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JRootPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import de.jreality.geometry.Primitives;
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_jReality2 {
	private int index = 0;

	public static void main(String[] args) {
		try {
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		} catch (Exception e) {
			e.printStackTrace();
		}
		new InternalFrameTest_jReality2();
	}

	public JRootPane createJRealityObject() {
		JRViewer v = new JRViewer();
		v.setPropertiesFile("JRViewer.xml");
		v.setPropertiesResource(JRViewer.class, "JRViewer.xml");
		v.setContent(Primitives.sharedIcosahedron);
		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);

		JRootPane rootPanel = v.startupLocal();

		return rootPanel;
	}

	public InternalFrameTest_jReality2() {
		JFrame f = new JFrame("Internal Frame Test");
		final JDesktopPane desktop = new JDesktopPane();
		f.setLayout(new GridLayout());
		f.add(desktop);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setSize(800, 600);
		f.setVisible(true);
		JMenuBar bar = new JMenuBar(); // create menu bar
		JMenu addMenu = new JMenu("Add"); // create Add menu
		JMenuItem newFrame = new JMenuItem("Internal Frame");
		addMenu.add(newFrame); // add new frame item to Add menu
		bar.add(addMenu); // add Add menu to menu bar
		f.setJMenuBar(bar); // set menu bar for this application
		newFrame.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				SwingUtilities.invokeLater(new Runnable() {
					@Override
					public void run() {
						JInternalFrame internalFrame1 = new JInternalFrame(
								"Internal Frame" + index);
						internalFrame1.setSize(600, 400);
						internalFrame1.setOpaque(true);
						internalFrame1.setLayout(new GridLayout());
						JRootPane rootPanel = createJRealityObject();
						internalFrame1.add(rootPanel);
						internalFrame1.setResizable(true);
						desktop.add(internalFrame1);
						internalFrame1.setVisible(true);
						index++;
					}
				});
			}
		});
	}
}

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

Re: Changing the properties of ViewerApp and JRViewer

Post by karunaMaitri » Sat 6. Feb 2010, 07:05

Thank you very much! It is working now!

Prabhakar

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

Re: Changing the properties of ViewerApp and JRViewer

Post by karunaMaitri » Thu 11. Feb 2010, 10:16

Hello,

I have a new problem related to JRViewer JRootPane object. I need to embed "it" (or its contents) into a container/component such as a JPanel. Then I need to add the JPanel to my JInternalFrame. One example of this gui construction is a panel that has several subpanels in it, and JRViewer becomes one of the subpanels. I looked at the tutorials and I cannot find any examples. I have tried to do it in a simple way - since JRootPane is a component, I added the JRootPane object from JRViewer to a JPanel object. I get the following error when I press "add new internal frame" menu item from the main frame (see your code from previous post).

Code: Select all

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
	at org.dyno.visual.swing.layouts.GroupLayout.checkPreferredSize(GroupLayout.java:59)
	at org.dyno.visual.swing.layouts.GroupLayout.addLayoutComponent(GroupLayout.java:53)
	at java.awt.Container.addImpl(Unknown Source)
	at java.awt.Container.add(Unknown Source)
	at javax.swing.JInternalFrame.addImpl(Unknown Source)
	at java.awt.Container.add(Unknown Source)
	at INTERNAL_FRAME_TESTS.InternalFrameTests.IFrameForConstraintsAndImage.initComponents(IFrameForConstraintsAndImage.java:57)
	at INTERNAL_FRAME_TESTS.InternalFrameTests.IFrameForConstraintsAndImage.<init>(IFrameForConstraintsAndImage.java:39)
	at INTERNAL_FRAME_TESTS.InternalFrameTests.InternalFrameWithGUISetUp$1$1.run(InternalFrameWithGUISetUp.java:74)
	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
I am not sure this is even the right way to do it as JRootPane has several layers and a menubar, which should not be added to JPanel as a component. Then I tried to get menubar, content pane from JRootPane and then added them to JPanel. I get the same error.

Is there an example to suggest how to do this? Are plugins helpful in this situation?
How can we solve this problem?

If you are wondering why this gui necessary, let me give you a user interaction scenario. The user may not only need to be able to select some geometries or coordinates (such as points outside the geometries) but also may need to give some description of what he/she intends to do there. One specific example is "Constraint-based Shape Modification", in which the user provides a set of constraints to be applied at the selected geometries. Hence, the user should have access to tools (mouse, etc), as well as means to input some information. I can think of various scenarios in which this kind of interaction becomes very useful.

Can you suggest me how I can solve the problem.

Thank you!
Prabhakar

User avatar
gunn
Posts: 323
Joined: Thu 14. Dec 2006, 09:56
Location: TU Berlin
Contact:

Re: Changing the properties of ViewerApp and JRViewer

Post by gunn » Thu 11. Feb 2010, 12:19

It's hard to know exactly what the problem is without seeing the code which is being run.

I've adapted the code provided by sechel to use a JPanel as you've indicated, and I get no exception. There is a problem however, in the sizing of the JOGL canvas. It doesn't resize properly. Debugging reveals that the JOGL Viewer is not receiving any resize() events. Perhaps someone can suggest a quick fix so the JPanel passes on resize events properly? Here's the code change:

Code: Select all

                 JPanel jpanel = new JPanel();
                  jpanel.add(rootPanel);
                  internalFrame1.add(jpanel);
And here's the picture: Image

There's another JOGL Viewer class that might interest you. It's a so-called lightweight drawable since it's a subclass of JPanel. The full class name is de.jreality.jogl.GLJPanelViewer. There's a tutorial demo in de.jreality.tutorial.viewer.GLJPanelViewerExample. The tutorial shows how you can mix jReality graphics with standard 2D Java code in this class.

Could it make sense for your application to consider using GLJPanelViewer, whether you want to mix in 2D Java or not? I tried this using the code provided by sechel, in the unchanged version and also in the version I changed above to use the JPanel as intermediary container. To use this class, add the following line at the beginning of your code:

Code: Select all

	  System.setProperty(SystemProperties.VIEWER, "de.jreality.jogl.GLJPanelViewer");
  
The results were:

Without the GLJPanelViewer, sechel's code gives a window that can't be resized (on my MacBook Pro). That is, the lower right hand corner isn't active and can't be dragged. When I use the JLGViewer, however, it is active and does resize (within the JInternalFrame) correctly, although it does appear that you lose the hardware anti-aliasing with this option.

Inserting the JRootPane into a JPanel (the change made above) while using the GLJPanelViewer, gives slightly better results than with a standard JOGL Viewer. There is still a resize problem but the JOGL graphics is clipped to the proper boundaries:
Image
Again, no resizing events are reaching the JOGL Viewer so it's natural that the sizing is wrong.

In any case, the situation would be much improved if one could get the resize events to get passed down to the JOGL Viewer. Whether the GLJPanelViewer is the right choice is probably a separate decision.

Please post specific code when you post exception traces -- preferably code which has been minimized to illustrate just one particular problem. The trace you've posted doesn't have any jReality classes so it's hard to know what jReality might be contributing to the problem.
jReality core developer

User avatar
gunn
Posts: 323
Joined: Thu 14. Dec 2006, 09:56
Location: TU Berlin
Contact:

Re: Changing the properties of ViewerApp and JRViewer

Post by gunn » Thu 11. Feb 2010, 12:44

Just a quick followup to the previous post. I've figured out how to force the JPanel to pass on resize() events to its children. The inserted code should look like this:

Code: Select all

                                  JPanel jpanel = new JPanel();
                  // force resizing to be passed on to children
                  jpanel.setLayout(new java.awt.BorderLayout());
                  jpanel.setMaximumSize(new java.awt.Dimension(32768,32768));
                  jpanel.setMinimumSize(new java.awt.Dimension(10,10));
                  jpanel.add(rootPanel);
                  internalFrame1.add(jpanel);
Using the GLJPanelViewer (as in previous post) the example code now runs correctly and resizes correctly. But notice that there is no anti-aliasing!

Image
jReality core developer

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

Re: Changing the properties of ViewerApp and JRViewer

Post by karunaMaitri » Sun 14. Feb 2010, 09:45

Thanks for the code and all the suggestions.

I did not put the code in my previous message because I thought my explanation was sufficient. Sorry about that. In future I will try to put "minimized" code as you suggested. As to the "exception" I posted, the problem is resolved now. It was due to GroupLayout. I thought it was interfering jReality objects. After I removed it, I am not getting the exception message anymore.

As you pointed out, I have added (JRViewer) JRootPane object to JPanel, then added the JPanel object to JInternalFrame. In my code, I have two JPanels inside JPanel. The left JPanel has several Swing components. The right JPanel has JRootPane object. It shows the left panel completely. But I cannot make the right panel show the complete JRootPane object of the jReality (as you pointed out).

I am still trying to make GLJPanelViewer work as you suggested. The tutorial uses ViewerApp. I would like to use JRViewer and get the JRootPane object to be used by GLJPanelViewer (I need menubar).I still have not figured out how to do it. Any suggestions are most welcome.

Thanks,
Prabhakar

User avatar
gunn
Posts: 323
Joined: Thu 14. Dec 2006, 09:56
Location: TU Berlin
Contact:

Re: Changing the properties of ViewerApp and JRViewer

Post by gunn » Sun 14. Feb 2010, 15:00

In the tutorial, the GLJPanelViewerExample is now updated to use JRViewer, and has been checked into the repository. I've also improved the way the preRender() and postRender() methods are defined to give a better idea what's actually going on, should you want to mix Java2D code with JOGL code.

The example code which I posted on this thread also uses a GLJPanelViewer and perhaps is closer to what you want. Once you set the System property as indicated in that post, you'll get instances of GLJPanelViewer when you use JRViewer. It appears to work correctly (actually better than with the default JOGL viewer as indicated in the post -- see posting for details).
jReality core developer

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

Re: Changing the properties of ViewerApp and JRViewer

Post by karunaMaitri » Mon 15. Feb 2010, 09:36

Thank you! It is a nice example showing how to bring Java2D rendering and JRViewer together.

Thanks,
Prabhakar

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

Re: Changing the properties of ViewerApp and JRViewer

Post by karunaMaitri » Mon 15. Feb 2010, 11:03

I have just figured out a way to get two panels rendered inside JInternalFrame. The right panel contains the JRViewer's JRootPane object. By using GridBagLayout and by forcing only the right panel (containing the JRViewer' JRootPane object) to grow when the JInternalFrame is elongated, I could get the complete JRViewer view visible.

Prabhakar

Post Reply