Package org.geoforge.guillc.action

Source Code of org.geoforge.guillc.action.GfrScreenShotActionWwdEarth

/*
Copyright (C) 2001, 2009 United States Government
as represented by the Administrator of the
National Aeronautics and Space Administration.
All Rights Reserved.
*/

package org.geoforge.guillc.action;

import com.jogamp.opengl.util.awt.Screenshot;
import gov.nasa.worldwind.WorldWindow;
import gov.nasa.worldwind.event.RenderingEvent;
import gov.nasa.worldwind.event.RenderingListener;
import java.awt.Component;
import java.io.File;
import java.io.IOException;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import org.geoforge.guillc.filechooser.GfrUtilFileChooserSerSave;

/**
* @author tag
* @version $Id: ScreenShotAction.java 1 2011-07-16 23:22:47Z dcollins $
*
* modified by bantchao
*/
public class GfrScreenShotActionWwdEarth extends
        Object //AbstractAction
        implements RenderingListener
{
   final static private String _STR_NAME_BASE_ = "snapshot";
   final static private String _STR_NAME_EXTENSION_ = ".png";
   final static private String _STR_TITLE_DIALOG_ = "Take snapshot";
  
  
    transient private WorldWindow _wwd_;
    transient private File _fle_;
   
    transient private Component _cmpOwner_ = null;

    public GfrScreenShotActionWwdEarth(WorldWindow wwd)
    {
        super();

        this._wwd_ = wwd;

        // TBRL with serialization
        // this._cmpOwner_ = wwd instanceof Component ? ((Component) wwd).getParent() : null;

        GfrUtilFileChooserSerSave fcr = new GfrUtilFileChooserSerSave(
                this._cmpOwner_ , _STR_TITLE_DIALOG_, _STR_NAME_BASE_, _STR_NAME_EXTENSION_);
       
        this._fle_ = fcr.doJob();
                //FileChooserGfr.s_chooseFile(frame, _STR_TITLE_DIALOG_, _STR_NAME_BASE_, _STR_NAME_EXTENSION_);
       
        this._wwd_.removeRenderingListener(this); // ensure not to add a duplicate
        this._wwd_.addRenderingListener(this);
    }


   

   @Override
    public void stageChanged(RenderingEvent evt)
    {
       if (this._fle_ == null)
          return;
      
        if (! evt.getStage().equals(RenderingEvent.AFTER_BUFFER_SWAP))
           return;
       
         try
         {
            GLAutoDrawable glad = (GLAutoDrawable) evt.getSource();
            int[] viewport = new int[4];
            glad.getGL().glGetIntegerv(GL.GL_VIEWPORT, viewport, 0);
            Screenshot.writeToFile(this._fle_, viewport[2] + 10, viewport[3], false);
            glad.getGL().glViewport(0, 0, glad.getWidth(), glad.getHeight());
         }
        
         catch (IOException e)
         {
            e.printStackTrace();
         }

         finally
         {
            this._fle_ = null;
            this._wwd_.removeRenderingListener(this);
         }
       
    }

   
}
TOP

Related Classes of org.geoforge.guillc.action.GfrScreenShotActionWwdEarth

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.