/* ========================
* JSynoptic : a free Synoptic editor
* ========================
*
* Project Info: http://jsynoptic.sourceforge.net/index.html
*
* 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 2.1 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, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307, USA.
*
* (C) Copyright 2003, by :
* Corporate:
* Astrium SAS
* EADS CRC
* Individual:
* Nicolas Brodu
*
* $Id: DataSourceAnimatorProvider.java,v 1.3 2007/09/04 13:55:33 ogor Exp $
*
* Changes
* -------
* 29-Jan-2004 : Creation date (NB);
*
*/
package jsynoptic.data;
import simtools.data.DataSource;
import simtools.data.DataSourcePool;
import simtools.data.DefaultEmptyDataSource;
import simtools.data.EmptyDataSource;
import simtools.data.EmptyDataSourcePool;
/**
* Override of simtools provider to include popups by registering jsynoptic
* version of the animator
*/
public class DataSourceAnimatorProvider extends simtools.data.DataSourceAnimatorProvider {
public DataSource provide(String id, String dscId, Object optionalInformation, DataSourcePool pool) {
if (!(optionalInformation instanceof Object[])) {
return null;
}
if (!((Object[]) optionalInformation)[0].equals(simtools.data.DataSourceAnimator.MARKER)) {
return null;
}
if (!id.startsWith(simtools.data.DataSourceAnimator.MARKER)) {
return null;
}
id = id.substring(simtools.data.DataSourceAnimator.MARKER.length());
long period = ((Long) (((Object[]) optionalInformation)[1])).longValue();
boolean autostop = ((Boolean) (((Object[]) optionalInformation)[2])).booleanValue();
int delay = ((Integer) (((Object[]) optionalInformation)[3])).intValue();
Object realOption = ((Object[]) optionalInformation)[4];
DataSourcePool poolToSearch = pool;
if (pool == null) {
poolToSearch = DataSourcePool.global;
}
// Do not add the result in the datapool yet, but rather add this object
// on success
DataSource ds = poolToSearch.provide(id, dscId, realOption, false);
if (ds == null) {
return null;
}
if (ds instanceof EmptyDataSource) {
DefaultEmptyDataSource emptyDs = new DefaultEmptyDataSource(id, simtools.data.DataSourceAnimator.MARKER
+ dscId, optionalInformation);
EmptyDataSourcePool.global.addEmptyDaSource(id, emptyDs);
return emptyDs;
}
DataSourceAnimator dsa = new DataSourceAnimator(ds, delay, period);
dsa.setAutoStop(autostop);
if (pool != null) {
pool.addDataSource(dsa);
}
return dsa;
}
}