Changing the properties of ViewerApp and JRViewer
-
- Posts: 90
- Joined: Sun 16. Nov 2008, 00:24
Changing the properties of ViewerApp and JRViewer
Hi,
For my application, I need to use viewers with different properties. Specifically, I need to stop some tools to be added to the ViewerApp and
JRViewer, while keeping the menu intact and being embedded in a Frame object I generate externally. I looked at the tutorial examples such as ViewerFromScratch. This does not meet my requirement fully. To give you an example, I would like the RotateTool not to be added to either ViewerApp or JRViewer (that is embedded in my frame object) while I am interacting with a curve. How can I do it?
Thanks,
Karuna
For my application, I need to use viewers with different properties. Specifically, I need to stop some tools to be added to the ViewerApp and
JRViewer, while keeping the menu intact and being embedded in a Frame object I generate externally. I looked at the tutorial examples such as ViewerFromScratch. This does not meet my requirement fully. To give you an example, I would like the RotateTool not to be added to either ViewerApp or JRViewer (that is embedded in my frame object) while I am interacting with a curve. How can I do it?
Thanks,
Karuna
-
- Posts: 90
- Joined: Sun 16. Nov 2008, 00:24
Re: Changing the properties of ViewerApp and JRViewer
I have made some progress in making JRViewer work for an external JFrame. But it is giving an error when I use the same code for a JInternalFrame. Here is the code I used for JIntenralFrame.
I get the following error.
Please see this.
http://bugs.sun.com/bugdatabase/view_bu ... id=6534718
I am afraid I do not know how to apply it to the JRViewer.
Please let me know how I can fix this problem.
Thanks,
Karuna
Code: Select all
SceneGraphComponent sgc = Primitives.wireframeSphere();
JRViewer v = new JRViewer();
v.setContent(sgc);
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 rootPane = v.startupLocal();
frame.add(rootPane);
frame.setVisible(true); // necessary as of 1.3
desktop.add(frame);
try {
frame.setSelected(true);
} catch (java.beans.PropertyVetoException e) {
}
I get the following error.
I have the following suggestion on the web about the error.Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.plaf.ColorUIResource cannot be cast to java.util.List
at javax.swing.plaf.metal.MetalUtils.drawGradient(Unknown Source)
at javax.swing.plaf.metal.MetalInternalFrameTitlePane.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
at java.awt.Container.paint(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
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)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.plaf.ColorUIResource cannot be cast to java.util.List
at javax.swing.plaf.metal.MetalUtils.drawGradient(Unknown Source)
at javax.swing.plaf.metal.MetalInternalFrameTitlePane.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
at java.awt.Container.paint(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
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)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.plaf.ColorUIResource cannot be cast to java.util.List
at javax.swing.plaf.metal.MetalUtils.drawGradient(Unknown Source)
at javax.swing.plaf.metal.MetalInternalFrameTitlePane.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
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)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.plaf.ColorUIResource cannot be cast to java.util.List
at javax.swing.plaf.metal.MetalUtils.drawGradient(Unknown Source)
at javax.swing.plaf.metal.MetalInternalFrameTitlePane.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
at java.awt.Container.paint(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
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)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.plaf.ColorUIResource cannot be cast to java.util.List
at javax.swing.plaf.metal.MetalUtils.drawGradient(Unknown Source)
at javax.swing.plaf.metal.MetalInternalFrameTitlePane.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
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)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.plaf.ColorUIResource cannot be cast to java.util.List
at javax.swing.plaf.metal.MetalUtils.drawGradient(Unknown Source)
at javax.swing.plaf.metal.MetalInternalFrameTitlePane.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
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)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.plaf.ColorUIResource cannot be cast to java.util.List
at javax.swing.plaf.metal.MetalUtils.drawGradient(Unknown Source)
at javax.swing.plaf.metal.MetalInternalFrameTitlePane.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
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)
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: javax.swing.plaf.ColorUIResource cannot be cast to java.util.List
at javax.swing.plaf.metal.MetalUtils.drawGradient(Unknown Source)
at javax.swing.plaf.metal.MetalInternalFrameTitlePane.paintComponent(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JLayeredPane.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
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)
Please see this.
http://bugs.sun.com/bugdatabase/view_bu ... id=6534718
I am afraid I do not know how to apply it to the JRViewer.
Please let me know how I can fix this problem.
Thanks,
Karuna
Re: Changing the properties of ViewerApp and JRViewer
It seems like there are really two different needs here. One is that you don't want the default tools to be added to the JRViewer class, and secondly you are having problems using packing a JRViewer into variants of the Frame class.
I can't help you with the second, but for the first, I think you should be able to achieve by deleting the following line:
You'll have to then provide all your own interactive tools, but that seems to be what you want, if I understand correctly. If you only want to temporarily remove the standard rotate tool, then you'll have to do something more clever, please post whether this is the case.
I can't help you with the second, but for the first, I think you should be able to achieve by deleting the following line:
Code: Select all
v.registerPlugin(new ContentTools());
jReality core developer
-
- Posts: 90
- Joined: Sun 16. Nov 2008, 00:24
Re: Changing the properties of ViewerApp and JRViewer
Thanks Charles!
You are right, there are two issues.
Regarding the first issue, there are two states in which my application can be used. The first state allows the user to experiment
with the geometry without modifying it. In the second state, the user modifies the geometry. The rotation tool seems to interfere with
the second state, but is essential for the first state. The way I thought I would do it is by making the user go to menu and disable/enable the
rotation tool. I know this is not very elegant. If there is a better way of doing it, it will really make things much better. Can you let me know.
About the second issue of using JInternalFrames to embed the rendered panel, let me tell you some things that have happened. Sometime back
I figured a way to use ViewerApp with JInternalFrame, while incorporating menus. As new versions of jReality have moved to JRViewer, I also
would like to move to JRViewer to use new features. Then I realized that to modify JRViewer to use JInternalFrame, I need to modify
SimpleController of jrworkspace. I understand it is an issue associated with jrworkspace. Unfortunately I do not know how to contact
jrworkspace people. If they have a simple solution, I would like to use it.
Thanks,
Karuna
You are right, there are two issues.
Regarding the first issue, there are two states in which my application can be used. The first state allows the user to experiment
with the geometry without modifying it. In the second state, the user modifies the geometry. The rotation tool seems to interfere with
the second state, but is essential for the first state. The way I thought I would do it is by making the user go to menu and disable/enable the
rotation tool. I know this is not very elegant. If there is a better way of doing it, it will really make things much better. Can you let me know.
About the second issue of using JInternalFrames to embed the rendered panel, let me tell you some things that have happened. Sometime back
I figured a way to use ViewerApp with JInternalFrame, while incorporating menus. As new versions of jReality have moved to JRViewer, I also
would like to move to JRViewer to use new features. Then I realized that to modify JRViewer to use JInternalFrame, I need to modify
SimpleController of jrworkspace. I understand it is an issue associated with jrworkspace. Unfortunately I do not know how to contact
jrworkspace people. If they have a simple solution, I would like to use it.
Thanks,
Karuna
Re: Changing the properties of ViewerApp and JRViewer
Regarding the tool question, I've written a new tutorial example and checked it in that shows how to replace one of the standard content tools (in this case the rotate tool) with another tool of your own choice, and also how to reverse the process and return to the rotate tool. It's in the class de.jreality.tutorial.plugin.ContentToolsExample.
Also, regarding your second question, can you be more specific about what what changes you need to make to SimpleController? You may have mentioned it in your previous posts but I don't find it right now.
Also, regarding your second question, can you be more specific about what what changes you need to make to SimpleController? You may have mentioned it in your previous posts but I don't find it right now.
jReality core developer
-
- Posts: 90
- Joined: Sun 16. Nov 2008, 00:24
Re: Changing the properties of ViewerApp and JRViewer
Thanks!
I have attached below the modified SimpleController and JRViewer classes. I made modifications as I see usable for externally supplied JFrame and JInternalFrame objects. I do not have success making them work. But they should tell you what I have been trying to do.
I am not in favor of modifying the jReality and jrworkspace classes as I have to keep up with the changes in future jReality versions.
I shall appreciate if you can let me know how I can solve this problem.
Since the code is long, I have only added the modifications I made
JRViewerInternalFrame
Field declarations
Code
The following are the modifications for SimpleController class
Field declarations
Other changes to SimpleController
I am sorry for sending you the long listing. I shall appreciate if you can let me know how to fix this external "Frame object" problem, especially
when the frame objects do not inherit from Frame class.
Thanks,
Karuna
I have attached below the modified SimpleController and JRViewer classes. I made modifications as I see usable for externally supplied JFrame and JInternalFrame objects. I do not have success making them work. But they should tell you what I have been trying to do.
I am not in favor of modifying the jReality and jrworkspace classes as I have to keep up with the changes in future jReality versions.
I shall appreciate if you can let me know how I can solve this problem.
Since the code is long, I have only added the modifications I made
JRViewerInternalFrame
Field declarations
Code: Select all
private SimpleControllerInternalFrame c;
private View view = new View();
private ViewPreferences viewPreferences = new ViewPreferences();
private JFrame frame;
private boolean rotate;
private JInternalFrame internalFrame;
private static WeakReference<JRViewerInternalFrame> lastViewer = new WeakReference<JRViewerInternalFrame>(
null);
Code: Select all
public JRViewerInternalFrame(JInternalFrame frame, boolean addLights,
JrScene s) {
this.internalFrame = frame;
c = new SimpleControllerInternalFrame(frame);
setShowPanelSlots(false, false, false, false);
c.setManageLookAndFeel(false);
c.registerPlugin(view);
c.registerPlugin(viewPreferences);
c.registerPlugin(new Scene(s));
c.registerPlugin(new ToolSystemPlugin());
lastViewer = new WeakReference<JRViewerInternalFrame>(this);
if (addLights) {
c.registerPlugin(new Lights());
}
}
public JRViewerInternalFrame(JFrame frame, boolean addLights, JrScene s) {
this.frame = frame;
c = new SimpleControllerInternalFrame(frame);
setShowPanelSlots(false, false, false, false);
c.setManageLookAndFeel(false);
c.registerPlugin(view);
c.registerPlugin(viewPreferences);
c.registerPlugin(new Scene(s));
c.registerPlugin(new ToolSystemPlugin());
lastViewer = new WeakReference<JRViewerInternalFrame>(this);
if (addLights) {
c.registerPlugin(new Lights());
}
}
public JRViewerInternalFrame() {
}
public Viewer display(SceneGraphComponent node, boolean rotate) {
this.rotate = rotate;
registerPlugin(new DirectContent());
registerPlugin(new ContentToolsInternalFrame(rotate));
if (node != null) {
registerPlugin(new ContentInjectionPlugin(node, true));
} else {
registerPlugin(new ContentLoader());
}
addBasicUI();
startup();
return getPlugin(View.class).getViewer();
}
Field declarations
Code: Select all
protected JFrame mainWindow = null;
protected JInternalFrame mainWindowInternalFrame = null;
protected boolean hasMainWindow = false,
hasMainWindowInternalFrame = false
private HelpWindowInternalFrame helpWindowInternalFrame;
private HelpWindowActionInternalFrame helpWindowActionInternalFrame;
private PreferencesWindowInternalFrame preferencesWindowInternalFrame;
private AboutDialogInternalFrame aboutDialogInternalFrame;
Code: Select all
public SimpleControllerInternalFrame(JFrame frame) {
mainWindow = frame;
frameType = "JFrame";
// get the default properties file path if the security manager allows
String filename = null;
try {
String userHome = System.getProperty("user.home");
filename = userHome + "/.jrworkspace/default_simple.xml";
} catch (SecurityException se) {
}
setPropertiesFile(filename == null ? null : new File(filename));
// init with user preferences associated with the controllers class, may
// be overridden by package specific properties
userPreferences = Preferences.userNodeForPackage(this.getClass());
}
public SimpleControllerInternalFrame(JInternalFrame frame) {
mainWindowInternalFrame = frame;
frameType = "JInternalFrame";
// get the default properties file path if the security manager allows
String filename = null;
try {
String userHome = System.getProperty("user.home");
filename = userHome + "/.jrworkspace/default_simple.xml";
} catch (SecurityException se) {
}
setPropertiesFile(filename == null ? null : new File(filename));
// init with user preferences associated with the controllers class, may
// be overridden by package specific properties
userPreferences = Preferences.userNodeForPackage(this.getClass());
}
public void startup(JFrame frame) {
mainWindow = frame;
frameType = "JFrame";
startup();
}
public void startup(JInternalFrame frame) {
mainWindowInternalFrame = frame;
frameType = "JInternalFrame";
startup();
}
public void startup() {
status = Status.Starting;
readUserPreferences();
loadProperties();
Runnable r = new Runnable() {
public void run() {
initializeComponents();
for (Plugin p : new LinkedList<Plugin>(plugins)) {
activatePlugin(p);
}
status = Status.Started;
if (hasToolBar || hasMenuBar) {
if (perspective == null) {
System.err
.println("SimpleControllerInternalFrame: No main perspective flavor found. Exit.");
System.exit(-1);
}
}
if (frameType.equals("JFrame")) {
if (mainWindow != null) {
if (!localStartup) {
mainWindow.setSize(perspective.getCenterComponent()
.getPreferredSize());
mainWindow.setVisible(true);
}
if (manageLookAndFeel) {
try {
String defaultLnF = "cross_platform_lnf_classname";
String lnfClass = getProperty(
SimpleControllerInternalFrame.class,
"lookAndFeelClass", defaultLnF);
flavorListener.installLookAndFeel(lnfClass);
flavorListener.updateFrontendUI();
} catch (Exception e) {
System.err
.println("Could not load look and feel.");
}
}
}
}
if (frameType.equals("JInternalFrame")) {
if (mainWindowInternalFrame != null) {
if (!localStartup) {
mainWindowInternalFrame.setSize(perspective
.getCenterComponent().getPreferredSize());
mainWindowInternalFrame.setVisible(true);
}
if (manageLookAndFeel) {
try {
String defaultLnF = "cross_platform_lnf_classname";
String lnfClass = getProperty(
SimpleControllerInternalFrame.class,
"lookAndFeelClass", defaultLnF);
flavorListener.installLookAndFeel(lnfClass);
flavorListener.updateFrontendUI();
} catch (Exception e) {
System.err
.println("Could not load look and feel.");
}
}
}
}
}
};
try {
if (isEventDispatchThread()) {
invokeLater(r);
} else {
invokeAndWait(r);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public JRootPane startupLocal() {
localStartup = true;
startup();
if (frameType.equals("JFrame")) {
if (mainWindow != null) {
return mainWindow.getRootPane();
} else {
return new JRootPane();
}
}
if (frameType.equals("JInternalFrame")) {
if (mainWindowInternalFrame != null) {
return mainWindowInternalFrame.getRootPane();
} else {
return new JRootPane();
}
}
return new JRootPane();
}
protected void initializeComponents() {
for (Plugin p : plugins) {
if (p instanceof PerspectiveFlavor) {
perspective = (PerspectiveFlavor) p;
if (frameType.equals("JFrame"))
hasMainWindow = true;
if (frameType.equals("JInternalFrame"))
hasMainWindowInternalFrame = true;
}
if (p instanceof HelpFlavor) {
hasHelpMenu = true;
hasMenuBar = true;
if (frameType.equals("JFrame"))
hasMainWindow = true;
if (frameType.equals("JInternalFrame"))
hasMainWindowInternalFrame = true;
}
if (p instanceof PreferencesFlavor) {
hasPreferencesMenu = true;
hasMenuBar = true;
if (frameType.equals("JFrame"))
hasMainWindow = true;
if (frameType.equals("JInternalFrame"))
hasMainWindowInternalFrame = true;
}
if (p instanceof ToolBarFlavor) {
hasToolBar = true;
if (frameType.equals("JFrame"))
hasMainWindow = true;
if (frameType.equals("JInternalFrame"))
hasMainWindowInternalFrame = true;
}
if (p instanceof MenuFlavor) {
hasMenuBar = true;
if (frameType.equals("JFrame"))
hasMainWindow = true;
if (frameType.equals("JInternalFrame"))
hasMainWindowInternalFrame = true;
}
if (p instanceof StatusFlavor) {
hasStatusBar = true;
if (frameType.equals("JFrame"))
hasMainWindow = true;
if (frameType.equals("JInternalFrame"))
hasMainWindowInternalFrame = true;
}
}
if (frameType.equals("JFrame")) {
if (hasMainWindow && mainWindow == null) {
// mainWindow = new JFrame();
mainWindow
.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
mainWindow.setLayout(new BorderLayout());
mainWindow.add(centerPanel, CENTER);
mainWindow.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
shutdown();
}
});
}
if (hasHelpMenu && helpWindow == null) {
helpWindow = new HelpWindow(mainWindow);
helpWindow.setLocationByPlatform(true);
helpWindowAction = new HelpWindowAction(helpWindow);
}
if (hasPreferencesMenu && preferencesWindow == null) {
preferencesWindow = new PreferencesWindow(mainWindow);
preferencesWindow.setLocationByPlatform(true);
}
if (hasToolBar && mainWindow != null) {
toolBarPanel.setLayout(new WrappingLayout(LEADING, 0, 0));
mainWindow.remove(toolBarPanel);
mainWindow.add(toolBarPanel, NORTH);
}
if (hasStatusBar && mainWindow != null) {
mainWindow.remove(statusLabel);
mainWindow.add(statusLabel, SOUTH);
}
}
if (frameType.equals("JInternalFrame")) {
if (hasMainWindowInternalFrame && mainWindowInternalFrame == null) {
// mainWindowInternalFrame = new JInternalFrame();
mainWindowInternalFrame
.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
mainWindowInternalFrame.setLayout(new BorderLayout());
mainWindowInternalFrame.add(centerPanel, CENTER);
mainWindowInternalFrame
.addInternalFrameListener(new InternalFrameListener() {
public void internalFrameClosing(
InternalFrameEvent e) {
shutdown();
}
public void internalFrameActivated(
InternalFrameEvent arg0) {
// TODO Auto-generated method stub
}
public void internalFrameClosed(InternalFrameEvent e) {
shutdown();
}
public void internalFrameDeactivated(
InternalFrameEvent e) {
// TODO Auto-generated method stub
}
public void internalFrameDeiconified(
InternalFrameEvent e) {
// TODO Auto-generated method stub
}
public void internalFrameIconified(
InternalFrameEvent e) {
// TODO Auto-generated method stub
}
public void internalFrameOpened(InternalFrameEvent e) {
// TODO Auto-generated method stub
}
});
}
if (hasHelpMenu && helpWindowInternalFrame == null) {
helpWindowInternalFrame = new HelpWindowInternalFrame(
mainWindowInternalFrame);
helpWindowInternalFrame.setLocationByPlatform(true);
helpWindowActionInternalFrame = new HelpWindowActionInternalFrame(
helpWindowInternalFrame);
}
if (hasPreferencesMenu && preferencesWindow == null) {
preferencesWindowInternalFrame = new PreferencesWindowInternalFrame(
mainWindowInternalFrame);
preferencesWindowInternalFrame.setLocationByPlatform(true);
}
if (hasToolBar && mainWindowInternalFrame != null) {
toolBarPanel.setLayout(new WrappingLayout(LEADING, 0, 0));
mainWindowInternalFrame.remove(toolBarPanel);
mainWindowInternalFrame.add(toolBarPanel, NORTH);
}
if (hasStatusBar && mainWindow != null) {
mainWindowInternalFrame.remove(statusLabel);
mainWindowInternalFrame.add(statusLabel, SOUTH);
}
}
}
protected void activatePlugin(Plugin p) {
if (isActive(p)) {
return;
} else {
installed.add(p.getClass());
}
dependencyStack.push(p);
try {
p.restoreStates(this);
} catch (Exception e) {
e.printStackTrace();
}
if (p instanceof FrontendFlavor) {
((FrontendFlavor) p).setFrontendListener(flavorListener);
}
if (p instanceof StatusFlavor) {
((StatusFlavor) p).setStatusListener(flavorListener);
}
if (p instanceof HelpFlavor) {
((HelpFlavor) p).setHelpListener(flavorListener);
}
if (p instanceof PropertiesFlavor) {
((PropertiesFlavor) p).setPropertiesListener(flavorListener);
}
if (p instanceof ShutdownFlavor) {
((ShutdownFlavor) p).setShutdownListener(flavorListener);
}
try {
p.install(this);
} catch (Exception e) {
e.printStackTrace();
}
dependencyStack.pop();
if (p instanceof PerspectiveFlavor) {
updateMainWindow();
}
if (p instanceof HelpFlavor) {
HelpFlavor hf = (HelpFlavor) p;
if (frameType.equals("JFrame"))
helpWindow.addHelpPlugin(hf);
if (frameType.equals("JInternalFrame"))
helpWindowInternalFrame.addHelpPlugin(hf);
updateMenuBarInternal();
}
if (p instanceof PreferencesFlavor) {
if (frameType.equals("JFrame"))
preferencesWindow.addPreferencesPlugin((PreferencesFlavor) p);
if (frameType.equals("JInternalFrame"))
preferencesWindowInternalFrame
.addPreferencesPlugin((PreferencesFlavor) p);
updateMenuBarInternal();
}
if (p instanceof ToolBarFlavor) {
updateToolBar();
}
if (p instanceof MenuFlavor) {
updateMenuBarInternal();
}
}
protected void updateMainWindow() {
if (frameType.equals("JFrame"))
if (!hasMainWindow) {
return;
}
if (frameType.equals("JInternalFrame"))
if (!hasMainWindowInternalFrame) {
return;
}
centerPanel.removeAll();
centerPanel.setLayout(new GridLayout());
if (perspective.getCenterComponent() == null) {
return;
}
centerPanel.add(perspective.getCenterComponent());
if (frameType.equals("JFrame")) {
mainWindow.setTitle(perspective.getTitle());
mainWindow
.setMinimumSize(mainWindow.getRootPane().getMinimumSize());
mainWindow
.setIconImage(ImageHook.renderIcon(perspective.getIcon()));
}
if (frameType.equals("JInternalFrame")) {
mainWindowInternalFrame.setTitle(perspective.getTitle());
mainWindowInternalFrame.setMinimumSize(mainWindowInternalFrame
.getRootPane().getMinimumSize());
ImageIcon icon = new ImageIcon(ImageHook.renderIcon(perspective
.getIcon()));
mainWindowInternalFrame.setFrameIcon(icon);
}
}
protected void updateMenuBarInternal() {
if (!hasMenuBar) {
return;
}
List<MenuFlavor> menuList = new LinkedList<MenuFlavor>();
for (Plugin mp : plugins) {
if (mp instanceof MenuFlavor) {
MenuFlavor mf = (MenuFlavor) mp;
if (mf.getPerspective().equals(perspective.getClass())) {
menuList.add(mf);
}
}
}
Collections.sort(menuList, new MenuFlavorComparator());
JMenuBar mBar = new JMenuBar();
for (MenuFlavor mf : menuList) {
for (JMenu m : mf.getMenus()) {
mBar.add(m);
}
}
JMenu helpMenu = new JMenu("Help");
helpMenu.setMnemonic('H');
if (hasPreferencesMenu) {
helpMenu.add(new PreferencesWindowAction(preferencesWindow));
}
if (hasHelpMenu) {
helpMenu.add(helpWindowAction);
}
if (aboutDialog == null) {
if (frameType.equals("JFrame"))
aboutDialog = new AboutDialog(mainWindow, true);
if (frameType.equals("JInternalFrame"))
aboutDialogInternalFrame = new AboutDialogInternalFrame(
mainWindowInternalFrame, true);
}
helpMenu.add(new JPopupMenu.Separator());
helpMenu.add(new AboutAction(aboutDialog));
mBar.add(helpMenu);
mainWindow.setJMenuBar(mBar);
}
protected void updateToolBar() {
if (!hasToolBar) {
return;
}
toolBarPanel.removeAll();
List<ToolBarFlavor> toolList = new LinkedList<ToolBarFlavor>();
for (Plugin p : plugins) {
if (isActive(p) && p instanceof ToolBarFlavor) {
ToolBarFlavor tbf = (ToolBarFlavor) p;
if (tbf.getPerspective().equals(perspective.getClass())) {
toolList.add(tbf);
}
}
}
Collections.sort(toolList, new ToolBarFlavorComparator());
for (ToolBarFlavor tbf : toolList) {
toolBarPanel.add(tbf.getToolBarComponent());
}
if (frameType.equals("JFrame"))
mainWindow.doLayout();
if (frameType.equals("JInternalFrame"))
mainWindowInternalFrame.doLayout();
}
public void updateFrontend() {
if (frameType.equals("JFrame")) {
if (mainWindow != null) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
updateMainWindow();
updateMenuBar();
mainWindow.doLayout();
if (preferencesWindow != null) {
preferencesWindow.doLayout();
}
if (helpWindow != null) {
helpWindow.doLayout();
}
}
});
}
}
if (frameType.equals("JInternalFrame")) {
if (mainWindowInternalFrame != null) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
updateMainWindow();
updateMenuBar();
mainWindowInternalFrame.doLayout();
if (preferencesWindowInternalFrame != null) {
preferencesWindowInternalFrame.doLayout();
}
if (helpWindow != null) {
helpWindow.doLayout();
}
}
});
}
}
}
public void updateContent() {
if (frameType.equals("JFrame")) {
if (mainWindow != null) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
updateMainWindow();
mainWindow.doLayout();
if (fullScreenFrame != null) {
fullScreenFrame.doLayout();
}
}
});
}
}
if (frameType.equals("JInternalFrame")) {
if (mainWindowInternalFrame != null) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
updateMainWindow();
mainWindowInternalFrame.doLayout();
if (fullScreenFrame != null) {
fullScreenFrame.doLayout();
}
}
});
}
}
}
/**
* Updates the menu bar of this controller
*/
public void updateMenuBar() {
if (frameType.equals("JFrame")) {
if (mainWindow != null) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
SimpleControllerInternalFrame.this
.updateMenuBarInternal();
mainWindow.doLayout();
if (fullScreenFrame != null) {
fullScreenFrame.doLayout();
}
}
});
}
}
if (frameType.equals("JInternalFrame")) {
if (mainWindowInternalFrame != null) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
SimpleControllerInternalFrame.this
.updateMenuBarInternal();
mainWindowInternalFrame.doLayout();
if (fullScreenFrame != null) {
fullScreenFrame.doLayout();
}
}
});
}
}
}
public void updateFrontendUI() {
if (frameType.equals("JFrame")) {
if (status == Started && mainWindow != null
&& mainWindow.isShowing()) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
SwingUtilities.updateComponentTreeUI(mainWindow);
if (fullScreenFrame != null) {
SwingUtilities
.updateComponentTreeUI(fullScreenFrame);
}
if (preferencesWindow != null) {
SwingUtilities
.updateComponentTreeUI(preferencesWindow);
}
if (helpWindow != null) {
SwingUtilities
.updateComponentTreeUI(helpWindow);
}
}
});
}
}
if (frameType.equals("JInternalFrame")) {
if (status == Started && mainWindowInternalFrame != null
&& mainWindowInternalFrame.isShowing()) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
SwingUtilities
.updateComponentTreeUI(mainWindowInternalFrame);
if (fullScreenFrame != null) {
SwingUtilities
.updateComponentTreeUI(fullScreenFrame);
}
if (preferencesWindowInternalFrame != null) {
SwingUtilities
.updateComponentTreeUI(preferencesWindowInternalFrame);
}
if (helpWindowInternalFrame != null) {
SwingUtilities
.updateComponentTreeUI(helpWindowInternalFrame);
}
}
});
}
}
}
public void setFullscreen(boolean fs) {
if (frameType.equals("JInternalFrame"))
return;
if (mainWindow == null) {
return;
}
GraphicsDevice gd = mainWindow.getGraphicsConfiguration()
.getDevice();
if (!gd.isFullScreenSupported()) {
return;
}
if (fs) {
Container content = mainWindow.getContentPane();
JMenuBar menuBar = mainWindow.getJMenuBar();
mainWindow.setVisible(false);
fullScreenFrame = new Frame(mainWindow.getTitle());
setIconImage(fullScreenFrame, mainWindow.getIconImage());
fullScreenFrame.setUndecorated(true);
fullScreenFrame.setLayout(new BorderLayout());
fullScreenFrame.add(content, CENTER);
if (menuBar != null) {
menuBar.setPreferredSize(new Dimension(10, 0));
fullScreenFrame.add(menuBar, NORTH);
}
mainWindow.dispose();
gd.setFullScreenWindow(fullScreenFrame);
} else {
Component[] c = fullScreenFrame.getComponents();
mainWindow.setContentPane((Container) c[0]);
if (c.length > 1) {
mainWindow.setJMenuBar((JMenuBar) c[1]);
}
gd.setFullScreenWindow(null);
fullScreenFrame.dispose();
mainWindow.setVisible(true);
mainWindow.requestFocus();
}
}
public void setShowMenuBar(final boolean show) {
if (frameType.equals("JFrame")) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (mainWindow.getJMenuBar() != null) {
Dimension d = show ? null : new Dimension(10, 0);
mainWindow.getJMenuBar().setPreferredSize(d);
mainWindow.getJMenuBar().revalidate();
}
}
});
}
if (frameType.equals("JInternalFrame")) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
if (mainWindowInternalFrame.getJMenuBar() != null) {
Dimension d = show ? null : new Dimension(10, 0);
mainWindowInternalFrame.getJMenuBar()
.setPreferredSize(d);
mainWindowInternalFrame.getJMenuBar().revalidate();
}
}
});
}
}
public void showHelpPage(HelpFlavor hf) {
if (frameType.equals("JFrame")) {
if (helpWindow != null) {
helpWindow.activateHelpPage(hf);
helpWindowAction.actionPerformed(null);
}
}
if (frameType.equals("JInternalFrame")) {
if (helpWindowInternalFrame != null) {
helpWindowInternalFrame.activateHelpPage(hf);
helpWindowActionInternalFrame.actionPerformed(null);
}
}
}
public String getUserPropertyFile() {
return SimpleControllerInternalFrame.this.getUserPropertyFile();
}
public boolean isAskBeforeSaveOnExit() {
return SimpleControllerInternalFrame.this.isAskBeforeSaveOnExit();
}
public boolean isLoadFromUserPropertyFile() {
return SimpleControllerInternalFrame.this
.isLoadFromUserPropertyFile();
}
public boolean isSaveOnExit() {
return SimpleControllerInternalFrame.this.isSaveOnExit();
}
public void setAskBeforeSaveOnExit(boolean askBeforeSaveOnExit) {
SimpleControllerInternalFrame.this
.setAskBeforeSaveOnExit(askBeforeSaveOnExit);
}
public void setLoadFromUserPropertyFile(boolean loadFromUserPropertyFile) {
SimpleControllerInternalFrame.this
.setLoadFromUserPropertyFile(loadFromUserPropertyFile);
}
public void setSaveOnExit(boolean saveOnExit) {
SimpleControllerInternalFrame.this.setSaveOnExit(saveOnExit);
}
public void setUserPropertyFile(String userPropertyFile) {
SimpleControllerInternalFrame.this
.setUserPropertyFile(userPropertyFile);
}
public void shutdown() {
SimpleControllerInternalFrame.this.shutdown();
}
protected boolean savePropertiesOnExit() {
if (!propertiesAreSafe || (!askBeforeSaveOnExit && !saveOnExit))
return true;
for (Plugin p : plugins) {
try {
p.storeStates(SimpleControllerInternalFrame.this);
} catch (Exception e) {
System.out.println("could not store states of plugin " + p
+ ": " + e.getMessage());
}
}
File file = null;
if (userPropertyFile != null) {
file = new File(userPropertyFile);
}
if (file == null) {
file = propFile;
}
SaveOnExitDialogInternalFrame dialog = new SaveOnExitDialogInternalFrame(
file, new JFrame(), this);
if (frameType.equals("JFrame"))
dialog = new SaveOnExitDialogInternalFrame(file, mainWindow, this);
if (frameType.equals("JInternalFrame"))
dialog = new SaveOnExitDialogInternalFrame(file,
mainWindowInternalFrame, this);
OutputStream out;
if (askBeforeSaveOnExit) {
boolean canceled = !dialog.show();
if (canceled)
return false;
out = dialog.getOutputStream();
} else {
try {
if (file != null && file.getParentFile() != null
&& !file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
out = new FileOutputStream(file);
} catch (Exception e) {
assert saveOnExit;
boolean canceled = !dialog.show();
if (canceled)
return false;
out = dialog.getOutputStream();
}
}
if (out != null) {
try {
String xml = propertyxStream.toXML(properties);
OutputStreamWriter writer = new OutputStreamWriter(out);
writer.write(xml);
writer.flush();
out.flush();
out.close();
} catch (IOException e) {
System.out.println("could not write properties: "
+ e.getMessage());
}
}
try {
userPreferences.flush();
} catch (BackingStoreException e) {
System.err.println("could not persist user preferences: "
+ e.getMessage());
}
return true;
}
public void setShowPreferencesWindow(boolean show) {
if (frameType.equals("JFrame")) {
if (preferencesWindow == null) {
return;
}
if (preferencesWindow.isShowing()) {
preferencesWindow.toFront();
return;
}
preferencesWindow.setLocationByPlatform(true);
preferencesWindow.setLocationRelativeTo(preferencesWindow
.getParent());
preferencesWindow.updateData();
preferencesWindow.setVisible(true);
}
if (frameType.equals("JInternalFrame")) {
if (preferencesWindowInternalFrame == null) {
return;
}
if (preferencesWindowInternalFrame.isShowing()) {
preferencesWindowInternalFrame.toFront();
return;
}
preferencesWindowInternalFrame.setLocationByPlatform(true);
preferencesWindowInternalFrame
.setLocationRelativeTo(preferencesWindowInternalFrame
.getParent());
preferencesWindowInternalFrame.updateData();
preferencesWindowInternalFrame.setVisible(true);
}
}
when the frame objects do not inherit from Frame class.
Thanks,
Karuna
Re: Changing the properties of ViewerApp and JRViewer
The code listing is a bit daunting. I recommend that you make another post in which you describe in two or three sentences what problems you had with the existing classes that led you to make the changes that you made, and then another couple of sentences to describe the changes themselves.
jReality core developer
-
- Posts: 90
- Joined: Sun 16. Nov 2008, 00:24
Re: Changing the properties of ViewerApp and JRViewer
Hi Charles,
In response to your suggestions, I will try to summarize my experiences. It has three parts: goals, problems and modifications,
organized into three different paragraphs.
First let me tell you my objectives. I need to get the jReality suplied panel to be embedded in a JInternalFrame object.
This panel needs to show menu that is normally shown in JRViewer. The user enables/disables RotateTool in order to
modify the geometry through interaction.
About the problems I faced: I have not succeeded in producing a JFrameObject that embeds JInternalFrame containing a rendered
geometry. I get the error - "javax.swing.plaf.ColorUIResource cannot be cast to java.util.List". I added the modifications suggested
on sun forum. But the error persists. It actually sets up multiple windows. With the creation of each JInternalFrame object,
it sets up two more windows. The windows have poor control.
I tried to trace the execution in order to localize the problem. I found the problem arising in SimpleController (jrworkspace).
It uses JFrame to embed the rendered panel. A number of methods are involved that do not take into consideration the
differences between JFrame and JInternalFrame. These differences exist primarily because JFrame extends Frame and Window,
whereas JInternalFrame extends JComponent. The modifications I made (and I think are required, if my code already does
not reflect them) include: (i) JInternalFrame has addInternlFrameListener(), and JFrame has addWindowListener(), (ii) JFrame can
be placed anywhere on the window and hence its dimensions are computed accordingly, whereas JInternalFrame needs to take
care of the JDesktop dimensions. The changes I made to JRViewer or SimpleController have not helped with the situation.
Please let me know if you need any additional information. I shall really appreciate if you can help me with this problem.
Thanks!
Karuna
In response to your suggestions, I will try to summarize my experiences. It has three parts: goals, problems and modifications,
organized into three different paragraphs.
First let me tell you my objectives. I need to get the jReality suplied panel to be embedded in a JInternalFrame object.
This panel needs to show menu that is normally shown in JRViewer. The user enables/disables RotateTool in order to
modify the geometry through interaction.
About the problems I faced: I have not succeeded in producing a JFrameObject that embeds JInternalFrame containing a rendered
geometry. I get the error - "javax.swing.plaf.ColorUIResource cannot be cast to java.util.List". I added the modifications suggested
on sun forum. But the error persists. It actually sets up multiple windows. With the creation of each JInternalFrame object,
it sets up two more windows. The windows have poor control.
I tried to trace the execution in order to localize the problem. I found the problem arising in SimpleController (jrworkspace).
It uses JFrame to embed the rendered panel. A number of methods are involved that do not take into consideration the
differences between JFrame and JInternalFrame. These differences exist primarily because JFrame extends Frame and Window,
whereas JInternalFrame extends JComponent. The modifications I made (and I think are required, if my code already does
not reflect them) include: (i) JInternalFrame has addInternlFrameListener(), and JFrame has addWindowListener(), (ii) JFrame can
be placed anywhere on the window and hence its dimensions are computed accordingly, whereas JInternalFrame needs to take
care of the JDesktop dimensions. The changes I made to JRViewer or SimpleController have not helped with the situation.
Please let me know if you need any additional information. I shall really appreciate if you can help me with this problem.
Thanks!
Karuna
Re: Changing the properties of ViewerApp and JRViewer
Thanks for the description of your problem.
Regarding the main issue with the SimpleController and JInternalFrame, that indeed lies outside my domain. I hope that the author of the jrworkspace package will be able to take a look at the post before too long. I will email him a link to this thread.
Regarding the smaller issue with deactivating/activating the standard rotate tool: I hope that my previous post (including the new tutorial example) convinces you that this change does not need to be included in the revised JRViewer class, but can be handled without changing any existing code, just by using the setRotationEnabled() method on the ContentTools class.
Regarding the main issue with the SimpleController and JInternalFrame, that indeed lies outside my domain. I hope that the author of the jrworkspace package will be able to take a look at the post before too long. I will email him a link to this thread.
Regarding the smaller issue with deactivating/activating the standard rotate tool: I hope that my previous post (including the new tutorial example) convinces you that this change does not need to be included in the revised JRViewer class, but can be handled without changing any existing code, just by using the setRotationEnabled() method on the ContentTools class.
jReality core developer
-
- Posts: 90
- Joined: Sun 16. Nov 2008, 00:24
Re: Changing the properties of ViewerApp and JRViewer
Thanks Charles, for offering to send an email to the author of jrworkspace. It is very helpful.
I have looked at the example ContentToolsExample. It is very good. Yes, it convinced me that RotateTool can be enabled/disabled without
changing the JRViewer code.
Thanks Again!
Karuna
I have looked at the example ContentToolsExample. It is very good. Yes, it convinced me that RotateTool can be enabled/disabled without
changing the JRViewer code.
Thanks Again!
Karuna
Re: Changing the properties of ViewerApp and JRViewer
Hi karunaMaitri,
the method
public JRootPane startupLocal()
is meant to be used in your sittuation. The JRootPane that is beeing returned by the method can be added to whatever Frame, JFrame, or JInternalFrame you want.
Best
Sechel
the method
public JRootPane startupLocal()
is meant to be used in your sittuation. The JRootPane that is beeing returned by the method can be added to whatever Frame, JFrame, or JInternalFrame you want.
Best
Sechel
-
- Posts: 90
- Joined: Sun 16. Nov 2008, 00:24
Re: Changing the properties of ViewerApp and JRViewer
Hi Sechel,
Thanks for the post.
I tried the method you suggested - please see my second post in this "topic" ("thread"). I tried it again today just to make sure that I got it right.
It is not working. I attach below the specific code I used.
[code]
JRViewer v = new JRViewer();
v.setContent(world);
v.setPropertiesFile("JRViewer.xml");
v.setPropertiesResource(JRViewer.class, "JRViewer.xml");
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);
v.startup();
frame.getContentPane().add((Component) v.startupLocal());
[/code]
In the code, "frame" is a JInternalFrame object. I get the same error message as I posted in my second post. The JInternalFrame object is shown
but it does not have the menu and it is frozen.
Thanks,
Karuna
Thanks for the post.
I tried the method you suggested - please see my second post in this "topic" ("thread"). I tried it again today just to make sure that I got it right.
It is not working. I attach below the specific code I used.
[code]
JRViewer v = new JRViewer();
v.setContent(world);
v.setPropertiesFile("JRViewer.xml");
v.setPropertiesResource(JRViewer.class, "JRViewer.xml");
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);
v.startup();
frame.getContentPane().add((Component) v.startupLocal());
[/code]
In the code, "frame" is a JInternalFrame object. I get the same error message as I posted in my second post. The JInternalFrame object is shown
but it does not have the menu and it is frozen.
Thanks,
Karuna
Re: Changing the properties of ViewerApp and JRViewer
Hi,
you must not use startup() and startupLocal() at the same time. Use either startup() if you want the Controller to open a frame for you or startupLocal() if you have your own Container for the content to be displayed. So in your case simply removing the v.startup() should do the job. The issue you have seems to have something to do with the Look and feel of the Swing widgets. I will check that.
Sechel
you must not use startup() and startupLocal() at the same time. Use either startup() if you want the Controller to open a frame for you or startupLocal() if you have your own Container for the content to be displayed. So in your case simply removing the v.startup() should do the job. The issue you have seems to have something to do with the Look and feel of the Swing widgets. I will check that.
Sechel
-
- Posts: 90
- Joined: Sun 16. Nov 2008, 00:24
Re: Changing the properties of ViewerApp and JRViewer
Thanks Sechel for pointing out how to use startup().
I made the correction and still I do not have success making it work.
Karuna.
I made the correction and still I do not have success making it work.
Karuna.
Re: Changing the properties of ViewerApp and JRViewer
Please have a look at this example. It should do what you want.
The output is attached.
Code: Select all
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.setPropertiesFile("JRViewer.xml");
v.setPropertiesResource(JRViewer.class, "JRViewer.xml");
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();
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);
}
}
- Attachments
-
- internalFrametest.png (89.88 KiB) Viewed 2979 times