/*
* 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.worldwind.render;
import gov.nasa.worldwind.avlist.AVKey;
import gov.nasa.worldwind.geom.Position;
import gov.nasa.worldwind.render.Offset;
import gov.nasa.worldwind.render.PointPlacemarkAttributes;
import java.awt.geom.Point2D;
import java.beans.PropertyChangeListener;
import java.util.HashMap;
import java.util.List;
import java.util.Observable;
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.mdl.event.GfrEvtMdlIdAbs;
import org.geoforge.mdldat.event.*;
import org.geoforge.mdldsp.event.render.wwd.*;
import org.geoforge.worldwind.awt.annotation.GfrCtrAnnCntImgs;
import org.geoforge.worldwind.handler.IGfrHandlerPhotoAlbumRender;
import org.geoforge.wrpbasprsdsp.render.wwd.GfrWrpBasPrsDspPrjRndWwdEarthShpDimOnePushpin;
/**
*
* @author bgwilliams71
*
* email: bgwilliams71_AT_gmail.com
* ... please remove "_AT_" from the above string to get the right email address
*/
abstract public class GfrRndPointPlacemarkPushpinTloAbs extends GfrRndPointPlacemarkPushpinAbs implements
IGfrHandlerPhotoAlbumRender
{
// ----
// begin: instantiate logger for this class
final private static Logger _LOGGER_ = Logger.getLogger(GfrRndPointPlacemarkPushpinTloAbs.class.getName());
static
{
GfrRndPointPlacemarkPushpinTloAbs._LOGGER_.addHandler(FileHandlerLogger.s_getInstance());
}
// end: instantiate logger for this class
// ----
protected GfrRndPointPlacemarkPushpinTloAbs(
PropertyChangeListener lstShouldRedraw,
String strId,
String strName,
Position pos,
List<String> lstPathAbsImages,
HashMap<String, String> mapSourceToTitle)
throws Exception
{
super(lstShouldRedraw, strId, strName, pos);
setAttributesThis();
setEnabledTooltipThis();
_updateImagesAnnotation(lstPathAbsImages, mapSourceToTitle);
}
@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()";
GfrRndPointPlacemarkPushpinTloAbs._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 _clearImagesAnnotation_() throws Exception
{
super.setValue(AVKey.DATA_TYPE, "_void");
}
@Override
public void update(Observable obs, Object objEvt)
{
// beg display
// beg images
try
{
if (objEvt instanceof GfrEvtMdlIdDatRemovedLloVarImg)
{
GfrEvtMdlIdDatRemovedLloVarImg evt = (GfrEvtMdlIdDatRemovedLloVarImg) objEvt;
String strIdParent = evt.getIdParent();
if (strIdParent.compareTo(super._strId) != 0)
return;
_updateImagesAnnotation();
return;
}
if (objEvt instanceof GfrEvtMdlIdDatAddedLloVarImg)
{
GfrEvtMdlIdDatAddedLloVarImg evt = (GfrEvtMdlIdDatAddedLloVarImg) objEvt;
String strIdParent = evt.getIdParent();
if (strIdParent.compareTo(super._strId) != 0)
return;
_updateImagesAnnotation();
return;
}
if (objEvt instanceof GfrEvtMdlIdDatRenamedLloVar)
{
GfrEvtMdlIdDatRenamedLloVar evt = (GfrEvtMdlIdDatRenamedLloVar) objEvt;
String strIdParent = evt.getIdParent();
if (strIdParent.compareTo(super._strId) != 0)
return;
_updateImagesAnnotation();
return;
}
//
if (objEvt instanceof GfrEvtMdlIdDatRemovedAllLloImgs)
{
GfrEvtMdlIdDatRemovedAllLloImgs evt = (GfrEvtMdlIdDatRemovedAllLloImgs) objEvt;
String strIdParent = evt.getId();
if (strIdParent.compareTo(super._strId) != 0)
return;
_clearImagesAnnotation_();
return;
}
}
catch (Exception exc)
{
exc.printStackTrace();
String strError = exc.getMessage();
GfrRndPointPlacemarkPushpinTloAbs._LOGGER_.severe(strError);
//--
strError = GfrUtlString.s_formatExceptionMessageForDialog(strError);
JOptionPane.showMessageDialog(null, strError, "Dev coding error", JOptionPane.ERROR_MESSAGE);
return;
}
// end images
if (objEvt instanceof GfrEvtMdlIdDspRndWwdEarthShpDimOnePoint)
{
GfrEvtMdlIdDspRndWwdEarthShpDimOnePoint evt = (GfrEvtMdlIdDspRndWwdEarthShpDimOnePoint) objEvt;
String strId = evt.getId();
if (strId.compareTo(super._strId) != 0)
return;
Object objWhat = evt.getWhat();
if (objWhat == EnuEvtDspRndWwdEarthShpDimOnePushpin.VISIBLE_DISPLAY_PUSHPIN)
{
Boolean boo = (Boolean) evt.getValue();
if (boo.booleanValue())
{
String strLabel = (String) super.getValue(gov.nasa.worldwind.avlist.AVKey.DISPLAY_NAME);
super.setLabelText(strLabel);
}
else
{
super.setLabelText((String) null);
}
this.firePropertyChange(GfrShouldRedrawRnd.STR, null, null);
return;
}
if (objWhat == EnuEvtDspRndWwdEarthShpDimOnePoint.COLOR_PUSHPIN)
{
String strPathRelImage = (String) evt.getValue();
try
{
PointPlacemarkAttributes ppa = super.getAttributes();
ppa.setImageAddress(strPathRelImage);
this.firePropertyChange(GfrShouldRedrawRnd.STR, null, null);
return;
}
catch (Exception exc)
{
exc.printStackTrace();
String strError = exc.getMessage();
GfrRndPointPlacemarkPushpinTloAbs._LOGGER_.severe(strError);
//--
strError = GfrUtlString.s_formatExceptionMessageForDialog(strError);
JOptionPane.showMessageDialog(null, strError, "Dev coding error", JOptionPane.ERROR_MESSAGE);
return;
}
}
if (objWhat == EnuEvtDspRndWwdEarthShp.TOOLTIP)
{
Boolean boo = (Boolean) evt.getValue();
super.setValue(GfrKeysRnd.STR_HAS_TOOLTIP, boo.booleanValue());
// memo: no need to send event to redraw!
return;
}
if (objWhat == EnuEvtDspRndWwdEarthShpDimOne.COLOR)
{
throw new UnsupportedOperationException("Dev coding error, objWhat=" + objWhat.toString());
}
if (objWhat == EnuEvtDspRndWwdEarthShpDimOne.TRANSPARENCY)
{
throw new UnsupportedOperationException("Dev coding error, objWhat=" + objWhat.toString());
}
return;
}
// end display
// beg data
GfrEvtMdlIdAbs objId = (GfrEvtMdlIdAbs) objEvt;
String strIdEvt = objId.getId();
if (strIdEvt.compareTo(this._strId) != 0)
return;
if (objId instanceof GfrEvtMdlIdDatChangedGeometry)
{
GfrEvtMdlIdDatChangedGeometry evt = (GfrEvtMdlIdDatChangedGeometry) objEvt;
Point2D.Double p2d = (Point2D.Double) evt.getGeometry();
super.position = Position.fromDegrees(p2d.y, p2d.x);
this.firePropertyChange(GfrShouldRedrawRnd.STR, null, null);
return;
}
if (objId instanceof GfrEvtMdlIdDatRenamedTlo)
{
GfrEvtMdlIdDatRenamedTlo objRename = (GfrEvtMdlIdDatRenamedTlo) objId;
super.setValue(gov.nasa.worldwind.avlist.AVKey.DISPLAY_NAME, objRename.getValueNew());
super.setLabelText(objRename.getValueNew());
// memo: no need to redraw, coz of just handling toolTip
return;
}
// end data
}
/*
* trick in order to get label, not assigning to nil
* ... in progress
*/
@Override
protected boolean mustDrawLabel()
{
return super.mustDrawLabel();
}
@Override
public void setAttributesThis() throws Exception
{
boolean blnVisibleLabel = GfrWrpBasPrsDspPrjRndWwdEarthShpDimOnePushpin.getInstance().isVisibleLabel(super._strId);
if (blnVisibleLabel)
{
String strLabel = (String) super.getValue(gov.nasa.worldwind.avlist.AVKey.DISPLAY_NAME);
super.setLabelText(strLabel);
}
super.setLineEnabled(true);
PointPlacemarkAttributes ppa = new PointPlacemarkAttributes();
ppa.setScale(0.5);
//MEMO Amadeus
//!!!! Why those parameters??? I don't know, but if this line is commented
//placemarks have a display artefact : an offset from the real lat lon position
ppa.setImageOffset(new Offset(18.5d, 4d, AVKey.PIXELS, AVKey.PIXELS));
//!!!!!
String strPathRelImage = GfrWrpBasPrsDspPrjRndWwdEarthShpDimOnePushpin.getInstance().getKindColorPushpinValue(super._strId);
ppa.setImageAddress(strPathRelImage);
super.setAttributes(ppa);
}
@Override
public void setEnabledTooltipThis() throws Exception
{
boolean blnIsToolTip = GfrWrpBasPrsDspPrjRndWwdEarthShpDimOnePushpin.getInstance().isTooltip(this._strId);
super.setValue(GfrKeysRnd.STR_HAS_TOOLTIP, blnIsToolTip);
}
}