Frame.java

/*
 * Created on 2005/08/05
 * Copyright (C) 2005 Koga Laboratory. All rights reserved.
 *
 */
package org.mklab.tool.graph.gnuplot.decoration;

/**
 * フレーム情報(原点のX座標、Y座標、幅、高さ)を表すクラスです。
 * 
 * @author koga
 * @version $Revision: 1.6 $, 2005/08/05
 */
public class Frame implements GnuplotComponent {


  /** 幅 */
  private double width;
  /** 高さ */
  private double height;
  /** 原点のx座標 */
  private double xOrigin;
  /** 原点のy座標 */
  private double yOrigin;

  /** 改行コード */
  private final String newLine = System.getProperty("line.separator"); //$NON-NLS-1$

  /**
   * コンストラクター
   * 
   */
  public Frame() {
    //
  }

  /**
   * コンストラクター
   * 
   * @param xOrigin 原点のX座標
   * @param yOrigin 原点のX座標
   * @param width 幅
   * @param height 高さ
   */
  public Frame(double xOrigin, double yOrigin, double width, double height) {
    this.xOrigin = xOrigin;
    this.yOrigin = yOrigin;
    this.width = width;
    this.height = height;
  }

  /**
   * 原点、幅、高さを設定します。
   * 
   * @param xOrigin 原点のX座標
   * @param yOrigin 原点のX座標
   * @param width 幅
   * @param height 高さ
   */
  public void setFrame(double xOrigin, double yOrigin, double width, double height) {
    this.xOrigin = xOrigin;
    this.yOrigin = yOrigin;
    this.width = width;
    this.height = height;
  }

  /**
   * @see org.mklab.tool.graph.gnuplot.decoration.GnuplotComponent#getCommand()
   */
  @SuppressWarnings("nls")
  public String getCommand() {
    return "set size " + this.width + "," + this.height + ";" + this.newLine + "set origin " + this.xOrigin + "," + this.yOrigin;
  }


  /**
   * {@inheritDoc}
   */
  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    long temp;
    temp = Double.doubleToLongBits(this.height);
    result = prime * result + (int)(temp ^ (temp >>> 32));
    result = prime * result + ((this.newLine == null) ? 0 : this.newLine.hashCode());
    temp = Double.doubleToLongBits(this.width);
    result = prime * result + (int)(temp ^ (temp >>> 32));
    temp = Double.doubleToLongBits(this.xOrigin);
    result = prime * result + (int)(temp ^ (temp >>> 32));
    temp = Double.doubleToLongBits(this.yOrigin);
    result = prime * result + (int)(temp ^ (temp >>> 32));
    return result;
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public boolean equals(Object obj) {
    if (this == obj) return true;
    if (obj == null) return false;
    if (getClass() != obj.getClass()) return false;
    Frame other = (Frame)obj;
    if (Double.doubleToLongBits(this.height) != Double.doubleToLongBits(other.height)) return false;
    if (this.newLine == null) {
      if (other.newLine != null) return false;
    } else if (!this.newLine.equals(other.newLine)) return false;
    if (Double.doubleToLongBits(this.width) != Double.doubleToLongBits(other.width)) return false;
    if (Double.doubleToLongBits(this.xOrigin) != Double.doubleToLongBits(other.xOrigin)) return false;
    if (Double.doubleToLongBits(this.yOrigin) != Double.doubleToLongBits(other.yOrigin)) return false;
    return true;
  }
}