/*
* 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.GfrMdlDatSetTlosEclSpn;
import org.geoforge.worldwind.layer.GfrRlrObjTloAbs;
import org.geoforge.worldwindecl.layer.GfrRlrObjTloRndMltPntCircleSpn;
import org.geoforge.wrpbasprssynecl.GfrWrpBasTopSynEclSpns;
/**
*
* @author bantchao
*
* email: bantchao_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*
*/
abstract public class GfrSetRlrTopMainSpnsAbs extends GfrSetRlrTopMainLclAbs
{
// ----
// begin: instantiate logger for this class
final private static Logger _LOGGER_ = Logger.getLogger(GfrSetRlrTopMainSpnsAbs.class.getName());
static
{
GfrSetRlrTopMainSpnsAbs._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
}
// end: instantiate logger for this class
// ----
protected GfrSetRlrTopMainSpnsAbs(WorldWindowGLCanvas cnv)
{
super(cnv);
GfrMdlDatSetTlosEclSpn.getInstance().addObserver((Observer) this);
}
@Override
public void addAllObjects() throws Exception
{
String[] strsUniqueId = GfrWrpBasTopSynEclSpns.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 GfrRlrObjTloRndMltPntCircleSpn))
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 GfrRlrObjTloRndMltPntCircleSpn))
continue;
String strIdCur = ((GfrRlrObjTloAbs) lyrCur).getIdObjectGeoforgeWwdEarth();
if (strIdCur.compareTo(strId) != 0)
continue;
// bug
String str = "already loaded: " + strId;
GfrSetRlrTopMainSpnsAbs._LOGGER_.warning(str);
return null;
}
// ----
GfrRlrObjTloAbs lyr = new GfrRlrObjTloRndMltPntCircleSpn(
(PropertyChangeListener) this,
strId);
if (! lyr.init())
{
String str = "! lyr.init()";
GfrSetRlrTopMainSpnsAbs._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()
{
GfrMdlDatSetTlosEclSpn.getInstance().deleteObserver((Observer) this);
super.destroy();
}
}