/*
* 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.util.Observable;
import java.util.Observer;
import java.util.logging.Logger;
import org.geoforge.guillc.frame.GfrFrmAbs;
import org.geoforge.guillc.optionpane.GfrOptionPaneAbs;
import org.geoforge.guillc.panel.GfrPnlStatusBarMain;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.mdldsp.event.state.singleton.selecttlo.GfrEvtMdlSttSngSelTlo;
import org.geoforge.mdldsp.state.singleton.selecttlo.GfrMdlSttSngSelTlo;
import org.geoforge.worldwind.layer.GfrRlrObjTloAbs;
import org.geoforge.worldwindecl.layer.GfrRlrObjTloRndSngPntPnt;
import org.geoforge.wrpbasprsdsp.state.singleton.selecttlo.GfrWrpObjSttSngSelTlo;
/**
*
* @author bantchao
*
* email: bantchao_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*
*/
public class GfrSetRlrTopMainPntsSel extends GfrSetRlrTopMainPntsAbs
{
// ----
// begin: instantiate logger for this class
final private static Logger _LOGGER_ = Logger.getLogger(GfrSetRlrTopMainPntsSel.class.getName());
static
{
GfrSetRlrTopMainPntsSel._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
}
// end: instantiate logger for this class
// ----
public GfrSetRlrTopMainPntsSel(WorldWindowGLCanvas cnv)
{
super(cnv);
GfrMdlSttSngSelTlo.getInstance().addObserver((Observer) this);
}
@Override
public void destroy()
{
GfrMdlSttSngSelTlo.getInstance().deleteObserver((Observer) this);
super.destroy();
}
@Override
public void update(Observable obs, Object objEvt)
{
try
{
if (objEvt instanceof GfrEvtMdlSttSngSelTlo)
{
GfrEvtMdlSttSngSelTlo evt = (GfrEvtMdlSttSngSelTlo) objEvt;
String strId = evt.getKey();
boolean bln = evt.getValue();
_selectObject_(strId, bln);
// ending
return;
}
}
catch (Exception exc)
{
exc.printStackTrace();
String str = exc.getMessage();
GfrSetRlrTopMainPntsSel._LOGGER_.severe(str);
GfrOptionPaneAbs.s_showDialogError(GfrFrmAbs.s_getFrameOwner(GfrPnlStatusBarMain.s_getInstance()), str);
return;
}
super.update(obs, objEvt);
}
@Override
public Object addObjectVariable(String strId) throws Exception
{
Object obj = super.addObjectVariable(strId);
if (obj == null)
return null;
boolean bln = GfrWrpObjSttSngSelTlo.getInstance().isEnabled(strId);
if (bln)
return obj;
GfrRlrObjTloAbs lyr = (GfrRlrObjTloAbs) obj;
lyr.setEnabled(false);
return obj;
}
private boolean _selectObject_(String strId, boolean bln) throws Exception
{
LayerList llt = super._cnv.getModel().getLayers();
for (Layer lyrCur: llt)
{
if (! (lyrCur instanceof GfrRlrObjTloRndSngPntPnt))
continue;
String strIdCur = ((GfrRlrObjTloAbs) lyrCur).getIdObjectGeoforgeWwdEarth();
if (strIdCur.compareTo(strId) != 0)
continue;
if (bln && lyrCur.isEnabled())
return false;
if (!bln && !lyrCur.isEnabled())
return false;
lyrCur.setEnabled(bln);
if (_cnv != null)
_cnv.redraw();
return true;
}
return false;
}
}