/*
* 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.worldwindecl.render;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.geom.Position;
import java.beans.PropertyChangeListener;
import java.util.HashMap;
import java.util.List;
import java.util.Observable;
import java.util.Observer;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import org.geoforge.java.util.logging.filehandler.FileHandlerLogger;
import org.geoforge.java.lang.string.GfrUtlString;
import org.geoforge.mdldat.event.GfrEvtMdlIdDatAddedLloVarImg;
import org.geoforge.mdldat.event.GfrEvtMdlIdDatRemovedAllLloImgs;
import org.geoforge.mdldat.event.GfrEvtMdlIdDatRemovedLloVarImg;
import org.geoforge.mdldat.event.GfrEvtMdlIdDatRenamedLloVar;
import org.geoforge.mdldatecl.GfrMdlDatIdObjTloEclSegWiseYes;
import org.geoforge.mdldspecl.render.wwd.GfrMdlDspRndWwdEarthShpDimOneSegWiseYesEcl;
import org.geoforge.worldwind.awt.annotation.GfrCtrAnnCntImgs;
import org.geoforge.worldwind.handler.IGfrHandlerPhotoAlbumRender;
import org.geoforge.worldwind.render.GfrRndSurfaceSegmentWiseYesTloAbs;
import org.geoforge.wrpbasprssynecl.GfrWrpBasSynObjNameTloEclSegWiseYes;
/**
*
* @author Amadeus.Sowerby
*
* email: Amadeus.Sowerby_AT_gmail.com ... please remove "_AT_" from the above
* string to get the right email address
*/
final public class GfrRndSurfaceSegmentWiseYesTloEcl extends GfrRndSurfaceSegmentWiseYesTloAbs implements
IGfrHandlerPhotoAlbumRender
{
// ----
// begin: instantiate logger for this class
final private static Logger _LOGGER_ = Logger.getLogger(GfrRndSurfaceSegmentWiseYesTloEcl.class.getName());
static
{
GfrRndSurfaceSegmentWiseYesTloEcl._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
}
// end: instantiate logger for this class
// ----
public GfrRndSurfaceSegmentWiseYesTloEcl(
PropertyChangeListener lstShouldRedraw,
String strId)
throws Exception
{
super(lstShouldRedraw,
strId,
GfrWrpBasSynObjNameTloEclSegWiseYes.getInstance().getName(strId),
GfrWrpBasSynObjNameTloEclSegWiseYes.getInstance().getPositions(strId));
GfrMdlDatIdObjTloEclSegWiseYes.getInstance().addObserver((Observer) this);
GfrMdlDspRndWwdEarthShpDimOneSegWiseYesEcl.getInstance().addObserver((Observer) this);
// ---
List<String> lstPathAbsImages = GfrWrpBasSynObjNameTloEclSegWiseYes.getInstance().getPathAbsoluteImages(strId);
HashMap<String, String> mapSourceToTitle = GfrWrpBasSynObjNameTloEclSegWiseYes.getInstance().getMapPathAbsToNameImages(strId);
_updateImagesAnnotation(lstPathAbsImages, mapSourceToTitle);
}
@Override
public void destroy()
{
GfrMdlDatIdObjTloEclSegWiseYes.getInstance().deleteObserver((Observer) this);
GfrMdlDspRndWwdEarthShpDimOneSegWiseYesEcl.getInstance().deleteObserver((Observer) this);
super.destroy();
}
@Override
public void _clearImagesAnnotation_() throws Exception
{
super.setValue(AVKey.DATA_TYPE, "_void");
}
@Override
public void _updateImagesAnnotation() throws Exception
{
_updateImagesAnnotation(
GfrWrpBasSynObjNameTloEclSegWiseYes.getInstance().getPathAbsoluteImages(super.getIdObjectGeoforgeWwdEarth()),
GfrWrpBasSynObjNameTloEclSegWiseYes.getInstance().getMapPathAbsToNameImages(super.getIdObjectGeoforgeWwdEarth()));
}
@Override
public void _updateImagesAnnotation(
List<String> lstPathAbsImages,
HashMap<String, String> mapSourceToTitle) throws Exception
{
if (lstPathAbsImages == null || lstPathAbsImages.isEmpty())
{
_clearImagesAnnotation_();
return;
}
if (mapSourceToTitle == null || mapSourceToTitle.isEmpty())
{
_clearImagesAnnotation_();
return;
}
if (mapSourceToTitle.size() != mapSourceToTitle.size())
{
String strError = "mapSourceToTitle.size() != mapSourceToTitle.size()";
GfrRndSurfaceSegmentWiseYesTloEcl._LOGGER_.severe(strError);
throw new Exception(strError);
}
String title = "dummy title";
super.setValue(AVKey.DATA_TYPE, GfrCtrAnnCntImgs.IMAGES);
super.setValue(AVKey.TITLE, title);
super.setValue(AVKey.URL, (Object) lstPathAbsImages);
super.setValue(GfrCtrAnnCntImgs.KEY_MAP_SOURCE_TO_TITLE, (Object) mapSourceToTitle);
}
@Override
public void update(Observable obs, Object objEvt)
{
// beg images
try
{
if (objEvt instanceof GfrEvtMdlIdDatRemovedLloVarImg)
{
GfrEvtMdlIdDatRemovedLloVarImg evt = (GfrEvtMdlIdDatRemovedLloVarImg) objEvt;
String strIdParent = evt.getIdParent();
if (strIdParent.compareTo(super.getIdObjectGeoforgeWwdEarth()) != 0)
return;
_updateImagesAnnotation();
return;
}
if (objEvt instanceof GfrEvtMdlIdDatAddedLloVarImg)
{
GfrEvtMdlIdDatAddedLloVarImg evt = (GfrEvtMdlIdDatAddedLloVarImg) objEvt;
String strIdParent = evt.getIdParent();
if (strIdParent.compareTo(super.getIdObjectGeoforgeWwdEarth()) != 0)
return;
_updateImagesAnnotation();
return;
}
if (objEvt instanceof GfrEvtMdlIdDatRenamedLloVar)
{
GfrEvtMdlIdDatRenamedLloVar evt = (GfrEvtMdlIdDatRenamedLloVar) objEvt;
String strIdParent = evt.getIdParent();
if (strIdParent.compareTo(super.getIdObjectGeoforgeWwdEarth()) != 0)
return;
_updateImagesAnnotation();
return;
}
//
if (objEvt instanceof GfrEvtMdlIdDatRemovedAllLloImgs)
{
GfrEvtMdlIdDatRemovedAllLloImgs evt = (GfrEvtMdlIdDatRemovedAllLloImgs) objEvt;
String strIdParent = evt.getId();
if (strIdParent.compareTo(super.getIdObjectGeoforgeWwdEarth()) != 0)
return;
_clearImagesAnnotation_();
return;
}
}
catch (Exception exc)
{
exc.printStackTrace();
String strError = exc.getMessage();
GfrRndSurfaceSegmentWiseYesTloEcl._LOGGER_.severe(strError);
//--
strError = GfrUtlString.s_formatExceptionMessageForDialog(strError);
JOptionPane.showMessageDialog(null, strError, "Dev coding error", JOptionPane.ERROR_MESSAGE);
return;
}
// end images
// ---
super.update(obs, objEvt);
}
@Override
public Position getPosition()
{
try
{
return super.getPositionBarycentricObjectGeoforgeWwdEarth();
}
catch (Exception exc)
{
exc.printStackTrace();
String strError = exc.getMessage();
GfrRndSurfaceSegmentWiseYesTloEcl._LOGGER_.severe(strError);
//--
strError = GfrUtlString.s_formatExceptionMessageForDialog(strError);
JOptionPane.showMessageDialog(null, strError, "Exception caught", JOptionPane.ERROR_MESSAGE);
return null;
}
}
}