/*=========================================================================

  Program:   Orbit Visualization Tool
  Source:    $Source: /stor/devel/ovt2g/ovt/object/ClusterSats.java,v $
  Date:      $Date: 2001/04/13 17:34:29 $
  Version:   $Revision: 1.8 $


Copyright (c) 2000 OVT Team (Kristof Stasiewicz, Mykola Khotyaintsev, 
Yuri Khotyaintsev)
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification is permitted provided that the following conditions are met:

 * No part of the software can be included in any commercial package without
written consent from the OVT team.

 * Redistributions of the source or binary code must retain the above
copyright notice, this list of conditions and the following disclaimer.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT OR
INDIRECT DAMAGES  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE.

OVT Team (http://ovt.irfu.se)   K. Stasiewicz, M. Khotyaintsev, Y.
Khotyaintsev

=========================================================================*/

/*
 * ClusterSats.java
 *
 * Created on den 9 april 2000, 17:03
 */
 
package ovt.object;

import ovt.*;
import ovt.gui.*;
import ovt.util.*;
import ovt.beans.*;
import ovt.event.*;
import ovt.datatype.*;
import ovt.interfaces.*;

import java.beans.*;

/** 
 *
 * @author  mykola
 * @version 
 */
public class ClusterSats extends VisualObject implements TimeChangeListener, 
  CoordinateSystemChangeListener, MagPropsChangeListener, PropertyChangeListener {

/** Holds value of property configurationWindowVisible. */
  private boolean configurationWindowVisible = false;
  protected ClusterConfigurationPanel configurationPanel;
  public String clusterConfOutFileName;

  /** Creates new ClusterSats */
  public ClusterSats(Sats sats) {
    super(sats.getCore(), "Cluster", OVTCore.getImagesDir()+"cluster.gif", true);
    Log.log("ClusterSats :: init ...", 3);
    clusterConfOutFileName = OVTCore.getUserdataDir()+"clusters.conf";
    setParent(sats);
    setChildren(new Children());
    try {
      BasicPropertyDescriptor pd = new BasicPropertyDescriptor("configurationWindowVisible", this);
      pd.setDisplayName("Cluster configuration");
      WindowPropertyEditor editor = new WindowPropertyEditor(pd, new String[]{"show configuration", "hide configuration"});
      editor.setModal(false);
      
      if (!OVTCore.isServer()) {
        configurationPanel = new ClusterConfigurationPanel(this, editor);
        editor.setComponent(configurationPanel);
      }
      
      pd.setPropertyEditor(editor);
      addPropertyChangeListener(editor);
      getDescriptors().put(pd);
    } catch (IntrospectionException e2) {}
  }
  
  public void add(Sat sat) {
    addPropertyChangeListener(sat);
    sat.addPropertyChangeListener(this);
    sat.setParent(this);
    if (!sat.isEnabled()) setEnabled(sat.isEnabled());
    addChild(sat);
  }
  /** Returns ClusterSat by it's number */
  public ClusterSat get(int number) {
    if (number>4 || number<1) throw new IllegalArgumentException("Invalid number of Cluster Satellite - "+number);
    return get("Cluster"+number);
  }
  
  public ClusterSat get(String satName) {
    return (ClusterSat)(getChildren().get(satName));
  }

  public void timeChanged(TimeEvent evt) {
    Children children = getChildren();
    if (children != null) TimeChangeSupport.fireTimeChange(evt, children.elements());
    if (!OVTCore.isServer()) configurationPanel.timeChanged(evt);
  }
  public void coordinateSystemChanged(CoordinateSystemEvent evt) {
    Children children = getChildren();
    if (children != null) 
      CoordinateSystemChangeSupport.fireCoordinateSystemChange(evt, children.elements());
  }
  public void magPropsChanged(MagPropsEvent evt) {
    Children children = getChildren();
    if (children != null) 
      MagPropsChangeSupport.fireMagPropsChange(evt, children.elements());
  }
  
  /** Getter for property configurationWindowVisible.
   * @return Value of property configurationWindowVisible.
   */
  public boolean isConfigurationWindowVisible() {
    return configurationWindowVisible;
  }
  /** Setter for property configurationWindowVisible.
   * @param configurationWindowVisible New value of property configurationWindowVisible.
   */
  public void setConfigurationWindowVisible(boolean configurationWindowVisible) {
    boolean oldConfigurationWindowVisible = this.configurationWindowVisible;
    this.configurationWindowVisible = configurationWindowVisible;
    propertyChangeSupport.firePropertyChange ("configurationWindowVisible", new Boolean (oldConfigurationWindowVisible), new Boolean (configurationWindowVisible));
  }
  
  
  public void propertyChange(PropertyChangeEvent evt) {
    if (evt.getPropertyName().equals("enabled")) {
      boolean enabled = ((Boolean)evt.getNewValue()).booleanValue();
      setEnabled(enabled);
    }
  }
}