/*
* 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.jfree.chart;
import java.awt.event.MouseListener;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import javax.swing.JPopupMenu;
import org.geoforge.guillc.handler.IGfrHandlerDisplayChartMarkersLegends;
import org.geoforge.guillc.menuitem.GfrMimTrsAlrNewChildMrkPikAbs;
import org.geoforge.jfreechart.chartpanel.GfrChartPanelDstAbs;
import org.geoforge.jfreechart.handler.IHandlerContainerVariableLayer;
import org.geoforge.jfreechart.handler.IHandlerContainerVariableMarkersTlo;
import org.geoforge.lang.handler.IGfrHandlerTransitoryObject;
import org.jfree.chart.ChartMouseListener;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.plot.XYPlot;
/**
*
* @author robert
*/
abstract public class GfrChartPanelDstColLyrAbs extends GfrChartPanelDstAbs implements
IGfrHandlerTransitoryObject,
IHandlerContainerVariableLayer,
IHandlerContainerVariableMarkersTlo,
IGfrHandlerDisplayChartMarkersLegends
{
protected String _strIdTlo = null;
protected GfrMimTrsAlrNewChildMrkPikAbs _mimPicked = null;
abstract protected void _displayMenuItemPickedMarker(double dblDepth);
@Override
public void setVisibleMarkersLegendsChart(boolean bln)
{
((IGfrHandlerDisplayChartMarkersLegends) super.getChart()).setVisibleMarkersLegendsChart(bln);
}
@Override
public boolean addVariableMarkerTlo(String strId) throws Exception
{
return ((IHandlerContainerVariableMarkersTlo) super.getChart()).addVariableMarkerTlo(strId);
}
@Override
public boolean removeAllMarkersTlo() throws Exception
{
return ((IHandlerContainerVariableMarkersTlo) super.getChart()).removeAllMarkersTlo();
}
@Override
public boolean removeVariableMarkerTlo(String strId) throws Exception
{
return ((IHandlerContainerVariableMarkersTlo) super.getChart()).removeVariableMarkerTlo(strId);
}
@Override
public boolean addVariableLayer(String strId) throws Exception
{
return ((IHandlerContainerVariableLayer) super.getChart()).addVariableLayer(strId);
}
@Override
public boolean removeAllLayers() throws Exception
{
return ((IHandlerContainerVariableLayer) super.getChart()).removeAllLayers();
}
@Override
public boolean removeVariableLayer(String strId) throws Exception
{
return ((IHandlerContainerVariableLayer) super.getChart()).removeVariableLayer(strId);
}
protected GfrChartPanelDstColLyrAbs(
GfrJFreeChartDepColLyrAbs jfc,
ChartMouseListener lstChartMouse,
MouseListener lstMouse,
String strIdTlo)
{
super(jfc, lstChartMouse, lstMouse);
this._strIdTlo = strIdTlo;
}
@Override
public boolean init()
{
if (! super.init())
return false;
if (! this._mimPicked.init())
return false;
JPopupMenu pop = super.getPopupMenu();
pop.add(this._mimPicked, 0);
pop.add(new JPopupMenu.Separator(), 1);
return true;
}
@Override
public void destroy()
{
super.destroy();
if (this._mimPicked != null)
{
this._mimPicked.destroy();
this._mimPicked = null;
}
}
@Override
public void loadTransient() throws Exception
{
this._mimPicked.loadTransient();
}
@Override
public void releaseTransient() throws Exception
{
this._mimPicked.releaseTransient();
}
@Override
protected void displayPopupMenu(int x, int y)
{
JPopupMenu pop = super.getPopupMenu();
if (pop != null)
{
if (this._mimPicked != null)
{
Point2D p = super.translateScreenToJava2D(new java.awt.Point(x, y));
ChartRenderingInfo info = super.getChartRenderingInfo();
Rectangle2D dataArea = info.getPlotInfo().getDataArea();
XYPlot plt = (XYPlot) super.getPlot();
double dblDepth = plt.getDomainAxis().java2DToValue(p.getY(), dataArea,
plt.getDomainAxisEdge());
_displayMenuItemPickedMarker(dblDepth);
}
}
super.displayPopupMenu(x, y);
}
}