/*
* 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.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.GfrMdlDatIdObjTloEclSct;
import org.geoforge.mdldspecl.render.wwd.GfrMdlDspRndWwdEarthShpDimTwoSct;
import org.geoforge.worldwind.awt.annotation.GfrCtrAnnCntImgs;
import org.geoforge.worldwind.handler.IGfrHandlerPhotoAlbumRender;
import org.geoforge.worldwind.render.GfrRndSurfaceSectorTloAbs;
import org.geoforge.wrpbasprssynecl.GfrWrpBasSynObjNameTloEclSct;
/**
*
* @author bgwilliams71
*
* email: bgwilliams71_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*/
public class GfrRndSurfaceSectorTloSct extends GfrRndSurfaceSectorTloAbs implements
IGfrHandlerPhotoAlbumRender
{
// ----
// begin: instantiate logger for this class
final private static Logger _LOGGER_ = Logger.getLogger(GfrRndSurfaceSectorTloSct.class.getName());
static
{
GfrRndSurfaceSectorTloSct._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
}
// end: instantiate logger for this class
// ----
public GfrRndSurfaceSectorTloSct(
PropertyChangeListener lstShouldRedraw,
String strId)
throws Exception
{
super(lstShouldRedraw,
strId,
GfrWrpBasSynObjNameTloEclSct.getInstance().getName(strId),
GfrWrpBasSynObjNameTloEclSct.getInstance().getGeometry(strId));
GfrMdlDatIdObjTloEclSct.getInstance().addObserver((Observer) this);
GfrMdlDspRndWwdEarthShpDimTwoSct.getInstance().addObserver((Observer) this);
// ---
List<String> lstPathAbsImages = GfrWrpBasSynObjNameTloEclSct.getInstance().getPathAbsoluteImages(strId);
HashMap<String, String> mapSourceToTitle = GfrWrpBasSynObjNameTloEclSct.getInstance().getMapPathAbsToNameImages(strId);
_updateImagesAnnotation(lstPathAbsImages, mapSourceToTitle);
}
@Override
public void destroy()
{
GfrMdlDatIdObjTloEclSct.getInstance().deleteObserver((Observer) this);
GfrMdlDspRndWwdEarthShpDimTwoSct.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(
GfrWrpBasSynObjNameTloEclSct.getInstance().getPathAbsoluteImages(super.getIdObjectGeoforgeWwdEarth()),
GfrWrpBasSynObjNameTloEclSct.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()";
GfrRndSurfaceSectorTloSct._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();
GfrRndSurfaceSectorTloSct._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();
GfrRndSurfaceSectorTloSct._LOGGER_.severe(strError);
//--
strError = GfrUtlString.s_formatExceptionMessageForDialog(strError);
JOptionPane.showMessageDialog(null, strError, "Exception caught", JOptionPane.ERROR_MESSAGE);
return null;
}
}
}