How to handle a HUD Frame close??

I want tocatch when a user clicks the close button on a Frame HUD widget so I can setVisibility and NOT have the widget destroyed. Using the following I can see
my override method called but the associated Frame is still destroyed. Note I am not calling any super() here so I expected to isolate myself from the default closing behavior. Thoughts???


public class JournalPageHUD extends Frame implements WidgetActionListener,
		WidgetStateListener, DialogListener, FrameListener{

public void onFrameClosed(Frame frame) {
		// TODO Auto-generated method stub
		System.out.println("fram close x");
	}


Hmm… 1st: I don’t know, where you override this method. It only exists in FrameListener. So it is not overridden, but implemented. But Maybe you mean that.
2nd: The Frame is not destroyed when it’s closed, but only removed from it’s parent (the HUD itself), which is nearly the same as setting it invisible. But only nearly. And this little difference is needed for frames. So just keep your Frame pointer stored and readd it to the HUD, when you want to re-show it. I guess this will solve your problems, does it?

Marvin

What am I doing wrong?? In this situation I have manually closed the Frame. I wish to redisplay it and have re-added the Frame to the HUD.

if(C.journalFrame.beenClosed)
{
C.hud.addWidget(C.journalFrame);
C.journalFrame.beenClosed=false;
}

Exception in thread “Thread-9” java.lang.IllegalArgumentException: This child already has a parent.
at com.xith3d.scenegraph.GroupNode.addChild(GroupNode.java:125)
at com.xith3d.scenegraph.Group.addChild(Group.java:69)
at org.xith3d.ui.hud.base.WidgetAssembler.addWidget(WidgetAssembler.java:138)
at org.xith3d.ui.hud.base.WidgetAssembler.addWidget(WidgetAssembler.java:167)
at org.xith3d.ui.hud.widgets.Frame.init(Frame.java:532)
at org.xith3d.ui.hud.base.WidgetBase.setContainer(WidgetBase.java:375)
at org.xith3d.ui.hud.widgets.Frame.setContainer(Frame.java:546)
at org.xith3d.ui.hud.HUD.addWidget(HUD.java:766)
at org.xith3d.ui.hud.HUD.addWidget(HUD.java:845)
at hawk.manager.GameUIManager.resolveDisplay(GameUIManager.java:755)
at hawk.jcd.Xith3DFrame.runx(Xith3DFrame.java:770)
at hawk.jcd.Xith3DFrame.loopIteration(Xith3DFrame.java:551)
at org.xith3d.render.loop.RenderLoop.run(RenderLoop.java:775)
at java.lang.Thread.run(Unknown Source)

quick workaround :


if(C.journalFrame.beenClosed)
         {
            C.journalFrame.getGroup().detach(); // not sure of this line, @marvin : is there a getGroup() method ? is there a detach() method for widgets ? it should be so
            C.hud.addWidget(C.journalFrame);
            C.journalFrame.beenClosed=false;
         }

The bug is fixed. And there is indeed such a method. Each Widget has a getSGNode() method, that returns the Node object, that is the root of the Widget in the scenegraph. Each WidgetContainer additionally has a method getSGGroup().

Marvin

And a detach() method, too ?

Were you talking about a HUD detach method? I assumed you were talking about the Node.detach() method. This one is of course accessable through


myWidget.getSGNode().detach();

Marvin

EDIT: A myWidget.detach() method is not needed. myWidget.getContainer().removeWidget( myWidget ) does the trick. But maybe it is convenient. I’ll add it soon.

Yeah that’s what I meant.

Done.

cool will validate

Cool, thanks.