/*
* 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.jfreechart.xyplot;
import java.util.List;
import org.geoforge.lang.handler.IGfrHandlerLifeCycleObject;
import org.jfree.chart.axis.ValueAxis;
import org.jfree.chart.event.PlotChangeEvent;
import org.jfree.chart.event.RendererChangeEvent;
import org.jfree.chart.plot.CombinedDomainXYPlot;
import org.jfree.chart.plot.XYPlot;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.RectangleInsets;
/**
*
* @author robert
*/
abstract public class GfrCombinedDomainXYPlotAbs extends CombinedDomainXYPlot implements
IGfrHandlerLifeCycleObject
{
// beg tempo
public void updateSeriesNameChanged(
String strOldValue,
String strNewValue)
{
List<XYPlot> lstPlot = ((List<XYPlot>) super.getSubplots());
for (int i = 0; i < lstPlot.size(); i++)
{
XYPlot pltCur = (XYPlot) super.getSubplots().get(i);
XYDataset dst = pltCur.getDataset();
if (! (dst instanceof XYSeriesCollection))
continue;
XYSeriesCollection serCollection = (XYSeriesCollection) dst;
for (int intSer = 0; intSer < serCollection.getSeriesCount(); intSer++)
{
XYSeries ser = serCollection.getSeries(intSer);
String keyCur = (String) ser.getKey();
if(keyCur.compareTo(strOldValue) != 0)
continue;
ser.setKey(strNewValue);
//System.out.println(ser.getKey());
break;
}
}
}
public boolean contains(XYPlot plt)
{
for (Object objCur: super.subplots)
{
if (! (objCur instanceof XYPlot))
continue;
XYPlot pltCur = (XYPlot) objCur;
if (pltCur == plt)
return true;
}
return false;
}
public void insert(XYPlot subplot, int weight, int intIndex)
{
if (subplot == null)
{
throw new IllegalArgumentException("Null 'subplot' argument.");
}
if (weight <= 0)
{
throw new IllegalArgumentException("Require weight >= 1.");
}
// store the plot and its weight
subplot.setParent(this);
subplot.setWeight(weight);
subplot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0), false);
subplot.setDomainAxis(null);
subplot.addChangeListener(this);
super.subplots.add(intIndex, subplot);
ValueAxis axis = getDomainAxis();
if (axis != null)
{
axis.configure();
}
fireChangeEvent();
}
@Override
public void plotChanged(PlotChangeEvent event)
{
super.plotChanged(event);
}
@Override
public void rendererChanged(RendererChangeEvent event)
{
super.rendererChanged(event);
}
// end tempo
protected GfrCombinedDomainXYPlotAbs(ValueAxis domainAxis)
{
super(domainAxis);
super.setDomainAxisBoundariesShift(4.0);
}
@Override
public void destroy()
{
List<XYPlot> lstPlot = ((List<XYPlot>) super.getSubplots());
for (int i=0; i<lstPlot.size(); i++)
{
XYPlot pltCur = (XYPlot) super.getSubplots().get(i);
if (pltCur instanceof IGfrHandlerLifeCycleObject)
((IGfrHandlerLifeCycleObject)pltCur).destroy();
}
}
public boolean init()
{
return true;
}
}