/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.geoforge.plg3danimatedshapes.swing.thread;
import com.jogamp.opengl.util.FPSAnimator;
import java.awt.Container;
import java.awt.event.ActionListener;
import java.util.logging.Logger;
import javax.media.opengl.awt.GLCanvas;
import javax.swing.SwingUtilities;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;
import org.geoforge.appogcecl.lang.thread.GfrThrNewViewerFrmIntVolPlgAbs;
import org.geoforge.guillc.internalframe.GfrIfrWinViewRunAbs;
import org.geoforge.guillc.internalframe.GfrIfrWinViewRunSimplestVolPlg;
import org.geoforge.guillc.optionpane.GfrOptionPaneAbs;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.plg3danimatedshapes.media.opengl.awt.GfrGLCanvasPlgViewerVolShps3dAni;
import org.geoforge.plg3danimatedshapes.media.opengl.util.GfrFPSAnimatorPlgViewerVolShps3dAni;
/**
*
* @author bantchao
*/
public class GfrThrNewViewerFrmIntVolPlgShps3dAni extends GfrThrNewViewerFrmIntVolPlgAbs
{
final static public String STR_WHAT = "Animated 3D shapes in volatile frame";
// ----
// begin: instantiate logger for this class
final private static Logger _LOGGER_ = Logger.getLogger(GfrThrNewViewerFrmIntVolPlgShps3dAni.class.getName());
static
{
GfrThrNewViewerFrmIntVolPlgShps3dAni._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
}
// end: instantiate logger for this class
// ----
public GfrThrNewViewerFrmIntVolPlgShps3dAni(
InternalFrameListener iflPlgRun,
Container cntDesktopPane
)
{
super(iflPlgRun,
(ActionListener) null, // alrPlgRun
(ActionListener) null, // alrPlgThis
cntDesktopPane
);
}
@Override
public void run()
{
try
{
super._ifr_ = new GfrIfrWinViewRunSimplestVolPlg(
super._iflPlgRun,
GfrThrNewViewerFrmIntVolPlgShps3dAni.STR_WHAT);
_addContents_(super._ifr_);
super._run(super._ifr_);
}
catch(Exception exc)
{
exc.printStackTrace();
String strError = exc.getMessage();
GfrThrNewViewerFrmIntVolPlgShps3dAni._LOGGER_.warning(strError);
GfrOptionPaneAbs.s_showDialogWarning(null, strError);
}
}
private void _addContents_(final GfrIfrWinViewRunAbs ifr)
{
// Run the GUI codes in the event-dispatching thread for thread safety
SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run() {
// Create the OpenGL rendering canvas
GLCanvas canvas = new GfrGLCanvasPlgViewerVolShps3dAni();
// Create a animator that drives canvas' display() at the specified FPS.
final FPSAnimator animator = new GfrFPSAnimatorPlgViewerVolShps3dAni(canvas);
// Create the top-level container
ifr.getContentPane().add(canvas);
ifr.addInternalFrameListener(new InternalFrameAdapter()
{
@Override
public void internalFrameClosing(InternalFrameEvent e)
{
// Use a dedicate thread to run the stop() to ensure that the
// animator stops before program exits.
new Thread()
{
@Override
public void run()
{
try
{
if (animator.isStarted()) animator.stop();
}
catch(Exception exc) // ie. java.lang.Exception: Stack trace,
{
// don't care
}
}
}.start();
}
});
animator.start(); // start the animation loop
}
});
}
}