Package org.pentaho.reporting.engine.classic.core

Source Code of org.pentaho.reporting.engine.classic.core.ElementAlignment

/*
* This program is free software; you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License, version 2.1 as published by the Free Software
* Foundation.
*
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, you can obtain a copy at http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
* or from the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* 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.
*
* Copyright (c) 2001 - 2009 Object Refinery Ltd, Pentaho Corporation and Contributors..  All rights reserved.
*/

package org.pentaho.reporting.engine.classic.core;

import java.io.ObjectStreamException;
import java.io.Serializable;

import org.pentaho.reporting.engine.classic.core.util.ObjectStreamResolveException;

/**
* Represents the alignment of an element.
*
* @author Thomas Morgner
*/
public final class ElementAlignment implements Serializable
{
  /**
   * A constant for left alignment.
   */
  public static final ElementAlignment LEFT = new ElementAlignment("LEFT");

  /**
   * A constant for center alignment (horizontal).
   */
  public static final ElementAlignment CENTER = new ElementAlignment("CENTER");

  /**
   * A constant for right alignment.
   */
  public static final ElementAlignment RIGHT = new ElementAlignment("RIGHT");

  /**
   * A constant for top alignment.
   */
  public static final ElementAlignment TOP = new ElementAlignment("TOP");

  /**
   * A constant for middle alignment (vertical).
   */
  public static final ElementAlignment MIDDLE = new ElementAlignment("MIDDLE");

  /**
   * A constant for bottom alignment.
   */
  public static final ElementAlignment BOTTOM = new ElementAlignment("BOTTOM");

  /**
   * The alignment name.
   */
  private final String myName; // for debug only
  /**
   * A cached hashcode.
   */
  private final int hashCode;

  /**
   * Creates a new alignment object.  Since this constructor is private, you cannot create new alignment objects, you
   * can only use the predefined constants.
   *
   * @param name the alignment name.
   */
  private ElementAlignment(final String name)
  {
    myName = name;
    hashCode = myName.hashCode();
  }

  /**
   * Returns the alignment name.
   *
   * @return the alignment name.
   */
  public String toString()
  {
    return myName;
  }

  public boolean equals(final Object o)
  {
    if (this == o)
    {
      return true;
    }
    if (!(o instanceof ElementAlignment))
    {
      return false;
    }

    final ElementAlignment alignment = (ElementAlignment) o;
    if (!myName.equals(alignment.myName))
    {
      return false;
    }

    return true;
  }

  public int hashCode()
  {
    return hashCode;
  }

  /**
   * Replaces the automatically generated instance with one of the enumeration instances.
   *
   * @return the resolved element
   * @throws ObjectStreamException if the element could not be resolved.
   */
  private Object readResolve()
      throws ObjectStreamException
  {
    if (this.myName.equals(ElementAlignment.LEFT.myName))
    {
      return ElementAlignment.LEFT;
    }
    if (this.myName.equals(ElementAlignment.RIGHT.myName))
    {
      return ElementAlignment.RIGHT;
    }
    if (this.myName.equals(ElementAlignment.CENTER.myName))
    {
      return ElementAlignment.CENTER;
    }
    if (this.myName.equals(ElementAlignment.TOP.myName))
    {
      return ElementAlignment.TOP;
    }
    if (this.myName.equals(ElementAlignment.BOTTOM.myName))
    {
      return ElementAlignment.BOTTOM;
    }
    if (this.myName.equals(ElementAlignment.MIDDLE.myName))
    {
      return ElementAlignment.MIDDLE;
    }
    // unknown element alignment...
    throw new ObjectStreamResolveException();
  }
}
TOP

Related Classes of org.pentaho.reporting.engine.classic.core.ElementAlignment

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.