Package views

Source Code of views.Star

package views;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;

import models.Coordinates;
import models.coordinates.EquatorialCoordinates;
import models.coordinates.LocalHorizontalCoordinates;
import models.coordinates.UserCoordinates;
import models.distances.IDistance;
import controllers.Front;


/**
* @author francois
* @version 23 avr. 2013
*/
public class Star extends Astre {

 
  //Coordonnées fournies dans le système de coordonnées équatoriales.

  private String name, spectralType;

  private double magnitude;      //Irradiance ou éclairement énergétrique.

  private Point point;

  /**
   *
   * @param name
   *            the name of the star
   * @param c
   *            the coordinates of the star expressed in the local horizontal
   *            coordinates
   * @param magnitude
   *            the magnitude of the star
   * @param spectralType
   *            the spectral type of the star
   */
  public Star(String name, EquatorialCoordinates c, double magnitude, String spectralType) {
    this.name = name;
    this.coordinates = c;
    this.magnitude = magnitude;
    this.spectralType = spectralType;
    this.color = color(magnitude, spectralType);
  }

  public Star(String name, EquatorialCoordinates c, double magnitude,
      Color color) {
    this(name, c, magnitude, "");
    this.color = color;
  }

  @Override
  public String toString(){
    return name+" : "+coordinates+" "+magnitude+", "+spectralType;
  }

  /**
   *
   * @param magnitude
   * @param spectralType
   * @return the color of a star
   */
  public static Color color(double magnitude, String spectralType) {
    if(spectralType == "" || spectralType == null) return null;
    double r, g, b, factor;
    //Détermination du r
    if (spectralType.charAt(0) == 'O')
      r = 0.8;
    if(spectralType.charAt(0) == 'B')
      r = 0.9;
    else
      r = 1.0;
    //Détermination du g
    if (spectralType.charAt(0) == 'O')
      g = 0.8;
    if (spectralType.charAt(0) == 'B' || spectralType.charAt(0) == 'K')
      g = 0.9;

    if(spectralType.charAt(0) == 'M' || spectralType.charAt(0) == 'C' || spectralType.charAt(0) == 'S')
      g = 0.6;
    else
      g = 1.0;
    //Déternimation du b
    if (spectralType.charAt(0) == 'F' || spectralType.charAt(0) == 'K')
      b = 0.8;
    if (spectralType.charAt(0) == 'G')
      b = 0.7;
    if(spectralType.charAt(0) == 'M' || spectralType.charAt(0) == 'C' || spectralType.charAt(0) == 'S')
      b = 0.6;
    else
      b = 1.0;
    //Multiplication par le facteur
    //Formule issue du sujet, étrange, on peut directement faire la simplification par 2.42
    factor = Math.min(1, (3.0 * 2.42) / ((2.46 + magnitude) * 2.42));
    r *= factor;
    g *= factor;
    b *= factor;
    return new Color( (float) r, (float) g, (float) b);
  }

  @Override
  public void draw(Graphics g, UserCoordinates userCoordinates, Circle mapBounds) {
    LocalHorizontalCoordinates lhc = Coordinates.equatorialToLocalHorizontal(coordinates, userCoordinates);
    if (lhc.isVisible()) {
      point = getProjection(lhc, mapBounds);
      g.setColor(getColor().darker());
      g.drawOval(point.x - paintWidth / 2, point.y - paintHeight / 2, paintWidth-1, paintHeight-1);
      g.setColor(getColor().brighter());
      g.fillRect(point.x - (paintWidth-2) / 2, point.y - (paintHeight-2) / 2, paintWidth - 2, paintHeight-2);
    }
  }

  /**
   *
   * @return tells where the star is drawn (in pixels)
   */
  public Point getPoint() {
    return point;
  }

  /**
   *
   * @return the name of the Star
   */
  public String getName(){
    return this.name;
  }

  /**
   *
   * @return the magnitude of the star
   */
  public double getMagnitude(){
    return this.magnitude;
  }

  /**
   *
   * @return the spectral type of the star
   */
  public String getSpectralType(){
    return this.spectralType;
  }
 
  public Color getColor(){
    return color;
  }
 
  public double[] getCoodinates(IDistance d){
    double[] result = new double[d.getDimension()];
    switch(d.getName()){
    case "ColorDistance":
    case "EuclidianColorDistance":
    case "EuclideanColorDistance":
      result[0] = getColor().getRed();
      result[1] = getColor().getGreen();
      result[2] = getColor().getBlue();
      break;
    case "Distance2D":
    case "Euclidienne":
    case "Simple2D":
    case "Euclidian":
    case "Euclidean":
    case "EuclidianSimple2D":
    case "EuclideanSimple2D":
      result[0] = getCoodinates().getDeclinaison();
      result[1] = getCoodinates().getAscention();
      break;
    case "Magnitude":
      result[0] = getMagnitude();
      break;
    case "Visible":
      LocalHorizontalCoordinates lhc = Coordinates.equatorialToLocalHorizontal(getCoodinates(), ((SkyMap) Front.userInterface.getSkyMap()).getUserCoordinates());
      result[0] = lhc.getAzimut();
      result[1] = lhc.getHauteur();
      break;
    }
    return result;
  }
 
  public boolean isBrighterThan(double maxMagnitude) {
    //brightness is greater when magnitude is negative
    return (this.getMagnitude() <= maxMagnitude);
  }
  private static final String datFormatSeparator = ",";
  public String toDatFormat() {
    return this.getName()+datFormatSeparator+
        this.coordinates.getAscention()+datFormatSeparator+
        this.coordinates.getDeclinaison()+datFormatSeparator+
        this.getMagnitude()+datFormatSeparator+
        this.getSpectralType()+"\n";
  }

}
TOP

Related Classes of views.Star

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.