Package org.geoforge.guillcogc.wwd.rlrs

Source Code of org.geoforge.guillcogc.wwd.rlrs.GfrSetRlrTopMainOgcWmssSel

/*
*  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.guillcogc.wwd.rlrs;

import gov.nasa.worldwind.avlist.AVList;
import gov.nasa.worldwind.awt.WorldWindowGLCanvas;
import gov.nasa.worldwind.layers.Layer;
import gov.nasa.worldwind.layers.LayerList;
import java.util.Observable;
import java.util.Observer;
import java.util.logging.Logger;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.mdldsp.event.state.singleton.wwd.GfrEvtMdlSttSngGlbSel;
import org.geoforge.mdldsp.state.singleton.wwd.GfrMdlSttSngGlbSel;
import org.geoforge.worldwindogc.capabilities.GfrWMSCapabilities;
import org.geoforge.worldwindogc.factory.GfrBasicLayerFactory;
import org.geoforge.worldwindogc.layer.GfrLyrWMSTiledImageLayer;
import org.geoforge.wrpbasprsdsp.state.singleton.wwd.GfrWrpObjSttSngGlbSel;

/**
*
* @author bantchao
*/
public class GfrSetRlrTopMainOgcWmssSel extends GfrSetRlrTopMainOgcWmssAbs
{
   // ----
    // begin: instantiate logger for this class
    final private static Logger _LOGGER_ = Logger.getLogger(GfrSetRlrTopMainOgcWmssSel.class.getName());

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

    // end: instantiate logger for this class
    // ----
   
   public GfrSetRlrTopMainOgcWmssSel(WorldWindowGLCanvas cnv)
           throws Exception
   {
      super(cnv, "selector");
     
      GfrMdlSttSngGlbSel.getInstance().addObserver((Observer) this);
   }
  
   @Override
    public void destroy()
    {
       super.destroy();
      
     
      GfrMdlSttSngGlbSel.getInstance().deleteObserver((Observer) this);
    }
  
   @Override
   public void update(Observable obs, Object objEvt)
   {
      if (objEvt instanceof GfrEvtMdlSttSngGlbSel)
      {
         GfrEvtMdlSttSngGlbSel evt = (GfrEvtMdlSttSngGlbSel) objEvt;
     
         String strId = evt.getKey();
         boolean bln = evt.getValue();
     
         _update_(strId, bln);
     
         return;
      }
     
      super.update(obs, objEvt);
   }
  
   private void _update_(String strId, boolean bln)
   {
      boolean blnGotIt = false;
     
      blnGotIt = _updateLayer_(strId, bln);
     
      // TODO terrain
     
      if (! blnGotIt)
         return;
     
      javax.swing.SwingUtilities.invokeLater(new Runnable()
      {
          @Override
          public void run()
          {
             if (_cnv != null)
                _cnv.redraw();
          }
      });
   }
  
  
   private boolean _updateLayer_(String strId, boolean bln)
   {
      LayerList llt = super._cnv.getModel().getLayers();
       
      for (Layer lyrCur: llt)
      {
         if (! (lyrCur instanceof GfrLyrWMSTiledImageLayer))
             continue;

         GfrLyrWMSTiledImageLayer rlrCur = (GfrLyrWMSTiledImageLayer) lyrCur;
        
         String strIdCur = rlrCur.getIdObjectGeoforgeWwdEarth();
        
         if (strIdCur.compareTo(strId) != 0)
            continue;
        
         rlrCur.setEnabled(bln);
         return true;
      }
    
      return false;
   }
  
   @Override
   protected Object _addObjectLloLayer(String strId, String strIdParent,
           GfrWMSCapabilities caps, AVList params) throws Exception
   {     
        Object obj = GfrBasicLayerFactory.s_createComponent(caps, params);
       
        if (obj == null)
           return null;
       
        GfrLyrWMSTiledImageLayer objLayer = (GfrLyrWMSTiledImageLayer) obj;
       
        String strErrorCheck = objLayer.getErrorCheck();
       
        if (strErrorCheck != null)
        {
           GfrSetRlrTopMainOgcWmssSel._LOGGER_.warning(strErrorCheck);
           // TODO: send event to registered listeners
           return null;
        }
       
        LayerList llt = super._cnv.getModel().getLayers();
        llt.add(objLayer);
        objLayer.setIdParent(strIdParent);
        objLayer.setUniqueIdGtr(strId);
       
        boolean bln = GfrWrpObjSttSngGlbSel.getInstance().isEnabled(strId);
        objLayer.setEnabled(bln);
       
        return obj;
   }


}
TOP

Related Classes of org.geoforge.guillcogc.wwd.rlrs.GfrSetRlrTopMainOgcWmssSel

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.