Package org.geoforge.guillcogcecl.wwd.rlrs

Source Code of org.geoforge.guillcogcecl.wwd.rlrs.GfrSetRlrTopMainPthsAbs

/*
*  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 2
*  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, write to the Free Software
*  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package org.geoforge.guillcogcecl.wwd.rlrs;

import gov.nasa.worldwind.awt.WorldWindowGLCanvas;
import gov.nasa.worldwind.layers.Layer;
import gov.nasa.worldwind.layers.LayerList;
import java.beans.PropertyChangeListener;
import java.util.Observer;
import java.util.logging.Logger;
import org.geoforge.guillc.wwd.rlrs.GfrSetRlrTopMainLclAbs;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.mdldatecl.GfrMdlDatSetTlosEclPth;
import org.geoforge.worldwind.layer.GfrRlrObjTloAbs;
import org.geoforge.worldwindecl.layer.GfrRlrObjTloRndSngSurfacePolylinePth;
import org.geoforge.wrpbasprssynecl.GfrWrpBasTopSynEclPths;

/**
*
* @author bantchao
*
* email: bantchao_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*
*/
abstract public class GfrSetRlrTopMainPthsAbs extends GfrSetRlrTopMainLclAbs
{
   // ----
    // begin: instantiate logger for this class
    final private static Logger _LOGGER_ = Logger.getLogger(GfrSetRlrTopMainPthsAbs.class.getName());

    static
    {
        GfrSetRlrTopMainPthsAbs._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
    }

    // end: instantiate logger for this class
    // ----
   
   protected GfrSetRlrTopMainPthsAbs(WorldWindowGLCanvas cnv)
   {
      super(cnv);
     
      GfrMdlDatSetTlosEclPth.getInstance().addObserver((Observer) this);
   }
  
   @Override
   public void addAllObjects() throws Exception
   {
      String[] strsUniqueId = GfrWrpBasTopSynEclPths.getInstance().getIdsTlo();

      if (strsUniqueId == null || strsUniqueId.length < 1)
         return;
     
      for (int i=0; i<strsUniqueId.length; i++)
      {
         addObjectVariable(strsUniqueId[i]);
      }
     
      javax.swing.SwingUtilities.invokeLater(new Runnable()
      {
            @Override
            public void run()
            {
               if (_cnv != null)
                  _cnv.redraw();
            }
      });
   }
  
  
   @Override
   public void removeAllObjects() throws Exception
   {
      LayerList llt = super._cnv.getModel().getLayers();
      boolean blnGotIt = false;
       
      for (Layer lyrCur: llt)
      {
         if (! (lyrCur instanceof GfrRlrObjTloRndSngSurfacePolylinePth))
             continue;

         GfrRlrObjTloAbs rlrCur = (GfrRlrObjTloAbs) lyrCur;
         llt.remove(rlrCur);
         rlrCur.removeAllRenderables();
         rlrCur.destroy();
          blnGotIt = true;
      }
    
      if (! blnGotIt)
         return;
     
      javax.swing.SwingUtilities.invokeLater(new Runnable()
      {
            @Override
            public void run()
            {
               if (_cnv != null)
                  _cnv.redraw();
            }
      });
   }

   @Override
   public Object addObjectVariable(String strId) throws Exception
   {     
      LayerList llt = super._cnv.getModel().getLayers();
       
        for (Layer lyrCur: llt)
        {
            if (! (lyrCur instanceof GfrRlrObjTloRndSngSurfacePolylinePth))
                continue;
           
            String strIdCur = ((GfrRlrObjTloAbs) lyrCur).getIdObjectGeoforgeWwdEarth();

           
            if (strIdCur.compareTo(strId) != 0)
                continue;
           
            // bug
            String str = "already loaded: " + strId;
            GfrSetRlrTopMainPthsAbs._LOGGER_.warning(str);
            return null;
        }

        // ----
        GfrRlrObjTloAbs lyr = new GfrRlrObjTloRndSngSurfacePolylinePth(
                (PropertyChangeListener) this,
                strId);
       
        if (! lyr.init())
        {
           String str = "! lyr.init()";
            GfrSetRlrTopMainPthsAbs._LOGGER_.severe(str);
            throw new Exception(str);
        }
       
        llt.add(lyr);
       
        javax.swing.SwingUtilities.invokeLater(new Runnable()
            {
                @Override
                public void run()
                {
                   if (_cnv != null)
                      _cnv.redraw();
                }
            });
       
       
        return lyr;
   }

  

   @Override
    public void destroy()
    {
       GfrMdlDatSetTlosEclPth.getInstance().deleteObserver((Observer) this);
       super.destroy();
    }
}
TOP

Related Classes of org.geoforge.guillcogcecl.wwd.rlrs.GfrSetRlrTopMainPthsAbs

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.