/*
* 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.data.xy;
import java.beans.PropertyChangeListener;
import java.util.Observable;
import java.util.Observer;
import org.geoforge.java.lang.string.GfrUtlString;
import org.geoforge.mdl.event.GfrEvtMdlIdAbs;
import org.geoforge.mdldat.event.GfrEvtMdlIdDatRenamedAbs;
import org.geoforge.mdldat.event.GfrEvtMdlIdDatRenamedLloVar;
import org.jfree.chart.util.ParamChecks;
/**
*
* @author robert
*
* trick to fix-up renable xyseries, displayed in legends
==> comparable should be unique
prepend a unique ID with an hard-coded separator
*/
abstract public class GfrXYSeriesDepVarAbs extends GfrXYSeriesDepAbs implements
Observer
{
final static private String _STR_TRICK_DELIMITER_ = "_trick_delimiter_id_versus_label_";
static private String _s_getUniqueIdThisSeries_(Comparable cmp)
{
String str = cmp.toString();
int intEndIndex = str.indexOf(_STR_TRICK_DELIMITER_);
String strUniqueIdThisSeries = str.substring(0, intEndIndex);
return strUniqueIdThisSeries;
}
static public boolean s_isRenable(Comparable cmp)
{
String str = cmp.toString();
if (str==null || str.length()<1)
return false;
int intIndexDelimiter = str.indexOf(_STR_TRICK_DELIMITER_);
if (intIndexDelimiter == -1)
return false;
return true;
}
static public String s_getLabel(Comparable cmp)
{
String str = cmp.toString();
int intBegIndex = str.indexOf(_STR_TRICK_DELIMITER_);
intBegIndex += _STR_TRICK_DELIMITER_.length();
String strLabel = str.substring(intBegIndex);
return strLabel;
}
static private String _s_setUniqueNameThisSeries_(String strNameObject)
{
String str = GfrUtlString.s_getUniqueId();
str += _STR_TRICK_DELIMITER_;
str += strNameObject;
return str;
}
// ---
protected GfrXYSeriesDepVarAbs(
String strIdThis,
String strNameThis,
boolean blnUnitDepthMeter,
PropertyChangeListener lstPropertyChange) throws Exception
{
super(
strIdThis,
_s_setUniqueNameThisSeries_(strNameThis),
(String) null, // strNameTlo
blnUnitDepthMeter);
if (lstPropertyChange != null)
super.addPropertyChangeListener(lstPropertyChange);
}
/*
* fixing up bug on rename log
* bantchao:
* Overriding this method coz of bug
*/
@Override
public void setKey(Comparable key)
{
ParamChecks.nullNotPermitted(key, "key");
Comparable old = super.key;
super.key = key;
//super.setKey(key);
super.propertyChangeSupport.firePropertyChange("Key", old, key);
}
@Override
public void update(Observable obs, Object objEvt)
{
// just handling markers
if (objEvt instanceof GfrEvtMdlIdDatRenamedLloVar)
{
GfrEvtMdlIdAbs evtId = (GfrEvtMdlIdAbs) objEvt;
String strId = evtId.getId();
if (strId.compareTo(this.getUniqueId()) != 0)
return;
// do job
GfrEvtMdlIdDatRenamedAbs evtRenamed = (GfrEvtMdlIdDatRenamedAbs) evtId;
String strNameNew = evtRenamed.getValueNew();
_updateRenamed(strNameNew);
return;
}
}
protected void _updateRenamed(String strNameNew)
{
String strUniqueIdThisSeries = _s_getUniqueIdThisSeries_(super.key);
String strTrick = strUniqueIdThisSeries;
strTrick += _STR_TRICK_DELIMITER_;
strTrick += strNameNew;
// ATTN overriding method coz of bug in JFreeChart
this.setKey(strTrick// + " " + this._strSuffix_
);
}
}