Package org.geoforge.guillc.panel

Source Code of org.geoforge.guillc.panel.GfrPnlStatusBarWwd

/*
*  Copyright (C) 2011-2014 GeoForge Project
*
*  This program is free software: you can redistribute it and/or modify
*  it under the terms of the GNU Lesser General Public License as published by
*  the Free Software Foundation, either version 3 of the License, or
*  (at your option) any later version.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU Lesser General Public License for more details.
*
*  You should have received a copy of the GNU Lesser General Public License
*  along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package org.geoforge.guillc.panel;

import gov.nasa.worldwind.event.PositionEvent;
import gov.nasa.worldwind.geom.Position;
import gov.nasa.worldwind.geom.coords.MGRSCoord;
import gov.nasa.worldwind.geom.coords.UTMCoord;
import gov.nasa.worldwind.util.StatusBar;
import org.geoforge.guillc.togglebutton.GfrTbnPositionUtmVsMgrsWwdEarth;
import org.geoforge.lang.handler.IGfrHandlerLifeCycleObject;
import org.geoforge.worldwind.awt.GfrWorldWindowGLCanvas;

/**
*
* @author bantchao
*/
public class GfrPnlStatusBarWwd extends StatusBar implements IGfrHandlerLifeCycleObject
{
   private boolean _blnIsUtm_ = GfrTbnPositionUtmVsMgrsWwdEarth.BLN_IS_SELECTED_DEFAULT;
  
   public void setUtm(boolean bln) { this._blnIsUtm_ = bln; }
  
   public GfrPnlStatusBarWwd(GfrWorldWindowGLCanvas cnv)
   {
      super();
     
      super.setEventSource(cnv);
   }

   @Override
   public boolean init()
   {
      return true;
   }

   @Override
   public void destroy()
   {     
      if (super.downloadTimer != null)
      {
         if (super.downloadTimer.isRunning())
            super.downloadTimer.stop();
        
         super.downloadTimer = null;
      }
     
      if (super.eventSource != null)
        {
            super.eventSource.removePositionListener(this);
            super.eventSource.removeRenderingListener(this);
        }
   }
  
   @Override
    protected void handleCursorPositionChange(PositionEvent event)
   {
      // beg tempo
      if (true)
      {
         super.handleCursorPositionChange(event);
         return;
      }
      // end tempo
     
      Position newPos = event.getPosition();
     
      if (newPos == null)
      {
         latDisplay.setText("");
         lonDisplay.setText("Off globe");
         eleDisplay.setText("");
        
         return;
      }
     
      if (this._blnIsUtm_)
         _handleCursorPositionChangeUTM_(newPos);
      else
         _handleCursorPositionChangeMgrs_(newPos);
   }
  
   private void _handleCursorPositionChangeUTM_(Position newPos)
   {

      String las = String.format("%7.4f\u00B0 %7.4f\u00B0", newPos.getLatitude().getDegrees(), newPos.getLongitude().getDegrees());
      String els = makeCursorElevationDescription(
            getEventSource().getModel().getGlobe().getElevation(newPos.getLatitude(), newPos.getLongitude()));
      String los = "";

      try
      {
            UTMCoord UTM = UTMCoord.fromLatLon(newPos.getLatitude(), newPos.getLongitude(), getEventSource().getModel().getGlobe());
            los = UTM.toString();
      }
      catch (Exception e)
      {
            los = "";
      }

      latDisplay.setText(las);
      lonDisplay.setText(los);
      eleDisplay.setText(els);

   }

   private void _handleCursorPositionChangeMgrs_(Position newPos)
   {

      String las = String.format("%7.4f\u00B0 %7.4f\u00B0", newPos.getLatitude().getDegrees(), newPos.getLongitude().getDegrees());
      String els = makeCursorElevationDescription(
            getEventSource().getModel().getGlobe().getElevation(newPos.getLatitude(), newPos.getLongitude()));
      String los = "";
     
      try
      {
            MGRSCoord MGRS = MGRSCoord.fromLatLon(newPos.getLatitude(), newPos.getLongitude(),
                  getEventSource().getModel().getGlobe());
           
            los = MGRS.toString();
      }
     
      catch (Exception e)
      {
            los = "";
      }
     
      latDisplay.setText(las);
      lonDisplay.setText(los);
      eleDisplay.setText(els);
       
    }
}
TOP

Related Classes of org.geoforge.guillc.panel.GfrPnlStatusBarWwd

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.