package LocalNavigation;

import java.awt.Color;

import Carmen.*;

/**
 * <p>Base class for GUI messages.</p>
 * 
 * @author vona
 **/
public abstract class GUIMessage extends Message {

  /**
   * <p>Red color component in [0, 255] or negative if unset.</p>
   **/
  public int r;

  /**
   * <p>Green color component in [0, 255] or negative if unset.</p>
   **/
  public int g;

  /**
   * <p>Blue color component in [0, 255] or negative if unset.</p>
   **/
  public int b;
 
  /**
   * <p>Create a new GUIMessage.</p>
   *
   * @param r the red color component, negative to use current color
   * @param g the green color component, negative to use current color
   * @param b the blue color component, negative to use current color
   **/
  public GUIMessage(int r, int g, int b) {
    this.r = r;
    this.g = g;
    this.b = b;
    timestamp = Util.getTime();
    host = Util.getHostName();
  }
 
  /**
   * <p>Covers {@link #GUIMessage(int, int, int)}.</p>
   *
   * @param color the color, or null to use current
   **/
  public GUIMessage(Color color) {
    this((color != null) ? color.getRed() : -1,
         (color != null) ? color.getGreen() : -1,
         (color != null) ? color.getBlue() : -1);
  }

  /**
   * <p>Create a new GUIMessage.</p>
   *
   */
  public GUIMessage() {
    this(null);
  }

  /**
   * <p>Make a Java Color corresponding to {@link #r}, {@link #g}, {@link
   * #b}.</p>
   *
   * @return a Java color corresponding to <code>r</code>, <code>g</code>,
   * <code>b</code>, unless any of those are negative in which case null is
   * returned
   **/
  public Color makeColor() {

    if ((r < 0.0) || (g < 0.0) || (b < 0.0))
      return null;

    return new Color(r, g, b);
  }
}
