/* ========================
* 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 2001-2005, by :
* Corporate:
* Astrium SAS
* Individual:
* Ronan Ogor
*
* $Id: PropertiesTransformGroupNode.java,v 1.8 2007/03/09 18:04:57 ogor Exp $
*
* Changes
* -------
* 29 juin 2005 : Creation date (RO);
*
*/
package syn3d.nodes;
import java.awt.Color;
import java.io.Serializable;
import javax.swing.JDialog;
import simtools.data.DataSource;
import simtools.data.DataSourcePool;
import simtools.data.EndNotificationListener;
import simtools.ui.ColorMapper;
import syn3d.base.ActiveNode;
import syn3d.data.PropertyData;
import syn3d.ui.PropertiesTransformDataUI;
/**
* A multi stamped transform group node holds a tramsform and a several attributes related to the node
* @author ogor
*/
public abstract class PropertiesTransformGroupNode extends TransformGroupNode implements Serializable{
static final long serialVersionUID = -5642925151407657526L;
protected PropertyData properties[];
protected ColorMapperManager colorMapperManager;
public PropertiesTransformGroupNode(ActiveNode parent) {
super(parent);
colorMapperManager = null;
name = NodeResourcesManager.getNodeName("PropertiesTransformGroup") + ((anonymousNodeNumber == 1) ? "" : String.valueOf(anonymousNodeNumber));
}
protected void initData() {
// Add the universe this node belongs to as the unique en notification listener
// See notes in the UniverseNode class
super.initData();
universe = SceneNode.getScene(parent);
for(int i=0; i< properties.length;i++)
properties[i].setDelegateListener(universe);
}
/* (non-Javadoc)
* @see syn3d.builtin.DirtyNode#cleanup()
*/
public void cleanup() {
super.cleanup();
for(int i=0; i< properties.length;i++)
properties[i].updateValues();
}
public void doAction(Object action) {
if (action==null) return;
if (action.equals(NodeResourcesManager.resources.getString("Properties"))) {
PropertiesTransformDataUI dui = new PropertiesTransformDataUI(this, data, properties, true, colorMapperManager);
JDialog dialog = dui.createDialog(null, NodeResourcesManager.resources.getString("Properties"));
dialog.show();
}
}
/*
* Sub classes have to restore the transform data
*/
public void restoreReferences(ActiveNode parent) {
super.restoreReferences(parent);
}
/* (non-Javadoc)
* @see syn3d.base.ActiveNode#remove()
*/
public void remove() {
super.remove();
for(int i=0; i< properties.length;i++)
properties[i].removeSceneGraphData();
}
public class ColorMapperManager implements Serializable, EndNotificationListener{
/**<b>(long)</b> serialVersionUID: The serialVersionUID.*/
private static final long serialVersionUID = -6030017005754136421L;
protected Color color;
protected transient DataSource colorMapperSource;
protected ColorMapper colorMapper;
protected PropertyData colorProperty;
protected boolean colorMapperEnabled;
/** Factory for subclasses */
public ColorMapperManager(PropertyData colorProperty, boolean colorMapperEnabled){
this.colorProperty = colorProperty;
this.colorMapperEnabled = false;
color = new Color( (float)colorProperty.getValue(0), (float)colorProperty.getValue(1), (float)colorProperty.getValue(2));
}
public void notificationEnd(Object referer){
Color c = null;
if (colorMapper!=null) {
c = (Color)colorMapper.getPaint(colorMapperSource);
if ( (c!=null) && !(c.equals(color))){
color = c;
float floatValues[] = new float[3];
color.getRGBColorComponents(floatValues);
double values[] = { (double)floatValues[0], (double)floatValues[1], (double)floatValues[2]};
colorProperty.set(values, null);
setDirty();
getScene().notificationEnd(null);
}
}
}
/**
* @return Returns the color.
*/
public Color getColor() {
return color;
}
/**
* @param color The color to set.
*/
public void setColor(Color color) {
this.color = color;
}
/**
* @return Returns the colorMapper.
*/
public ColorMapper getColorMapper() {
return colorMapper;
}
/**
* @param colorMapper The colorMapper to set.
*/
public void setColorMapper(ColorMapper colorMapper) {
this.colorMapper = colorMapper;
}
/**
* @return Returns the colorMapperSource.
*/
public DataSource getColorMapperSource() {
return colorMapperSource;
}
/**
* @param colorMapperSource The colorMapperSource to set.
*/
public void setColorMapperSource(DataSource colorMapperSource) {
this.colorMapperSource = colorMapperSource;
}
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
out.defaultWriteObject();
DataSourcePool.global.writeDataSource(out, colorMapperSource);
}
private void readObject(java.io.ObjectInputStream in) throws java.lang.ClassNotFoundException, java.io.IOException {
in.defaultReadObject();
colorMapperSource = DataSourcePool.global.readDataSource(in);
if (colorMapper != null) {
colorMapper = ColorMapper.updateColorMapper(colorMapper);
}
if ((colorMapperSource!=null) && (isColorMapperEnabled())){
colorMapperSource.addEndNotificationListener(this);
}
}
/**
* @return Returns the colorMapperEnabled.
*/
public boolean isColorMapperEnabled() {
return colorMapperEnabled;
}
/**
* @param colorMapperEnabled The colorMapperEnabled to set.
*/
public void setColorMapperEnabled(boolean colorMapperEnabled) {
this.colorMapperEnabled = colorMapperEnabled;
}
}
}