/*
* 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.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.logging.Logger;
import org.geoforge.guillc.optionpane.GfrOptionPaneAbs;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.mdl.event.GfrEvtMdlIdAbs;
import org.geoforge.mdldat.event.GfrEvtMdlIdDatAddedTlo;
import org.geoforge.mdldat.event.GfrEvtMdlIdDatClonedTlo;
import org.geoforge.worldwind.layer.GfrRlrObjTloAbs;
/**
*
* @author bantchao
*/
abstract public class GfrSetRlrTopSecLclAbs extends GfrSetRlrTopSecAbs
{
// ----
// begin: instantiate logger for this class
final private static Logger _LOGGER_ = Logger.getLogger(GfrSetRlrTopSecLclAbs.class.getName());
static
{
GfrSetRlrTopSecLclAbs._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
}
// end: instantiate logger for this class
// ----
protected GfrSetRlrTopSecLclAbs(WorldWindowGLCanvas cnv, String strIdViewer)
{
super(cnv, strIdViewer);
}
@Override
public void update(Observable obs, Object objEvt)
{
try
{
if (objEvt instanceof GfrEvtMdlIdDatAddedTlo ||
objEvt instanceof GfrEvtMdlIdDatClonedTlo)
{
GfrEvtMdlIdAbs evt = (GfrEvtMdlIdAbs) objEvt;
String strId = evt.getId();
addObjectVariable(strId);
// ending
return;
}
}
catch (Exception exc)
{
exc.printStackTrace();
String str = exc.getMessage();
GfrSetRlrTopSecLclAbs._LOGGER_.severe(str);
GfrOptionPaneAbs.s_showDialogError(null, str);
System.exit(1);
}
super.update(obs, objEvt);
}
@Override
public boolean removeObjectVariable(String strId) throws Exception
{
LayerList llt = super._cnv.getModel().getLayers();
for (Layer lyrCur: llt)
{
if (! (lyrCur instanceof GfrRlrObjTloAbs))
continue;
GfrRlrObjTloAbs rlrCur = (GfrRlrObjTloAbs) lyrCur;
String strIdCur = rlrCur.getIdObjectGeoforgeWwdEarth();
if (strIdCur.compareTo(strId) != 0)
continue;
llt.remove(lyrCur);
rlrCur.removeAllRenderables();
rlrCur.destroy();
return true;
}
return false;
}
@Override
protected boolean _selectObject(String strIdObjectTlo, boolean bln) throws Exception
{
LayerList llt = super._cnv.getModel().getLayers();
for (Layer lyrCur: llt)
{
if (! (lyrCur instanceof GfrRlrObjTloAbs))
continue;
String strIdCur = ((GfrRlrObjTloAbs) lyrCur).getIdObjectGeoforgeWwdEarth();
if (strIdCur.compareTo(strIdObjectTlo) != 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;
}
}