001/* =========================================================== 002 * JFreeChart : a free chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C) Copyright 2000-2020, by Object Refinery Limited and Contributors. 006 * 007 * Project Info: http://www.jfree.org/jfreechart/index.html 008 * 009 * This library is free software; you can redistribute it and/or modify it 010 * under the terms of the GNU Lesser General Public License as published by 011 * the Free Software Foundation; either version 2.1 of the License, or 012 * (at your option) any later version. 013 * 014 * This library is distributed in the hope that it will be useful, but 015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 017 * License for more details. 018 * 019 * You should have received a copy of the GNU Lesser General Public 020 * License along with this library; if not, write to the Free Software 021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 022 * USA. 023 * 024 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 025 * Other names may be trademarks of their respective owners.] 026 * 027 */ 028 029package org.jfree.chart.ui; 030 031import java.io.ObjectStreamException; 032import java.io.Serializable; 033 034/** 035 * Represents a type of transform for a {@code GradientPaint}. 036 */ 037public final class GradientPaintTransformType implements Serializable { 038 039 /** For serialization. */ 040 private static final long serialVersionUID = 8331561784933982450L; 041 042 /** Vertical. */ 043 public static final GradientPaintTransformType VERTICAL 044 = new GradientPaintTransformType("GradientPaintTransformType.VERTICAL"); 045 046 /** Horizontal. */ 047 public static final GradientPaintTransformType HORIZONTAL 048 = new GradientPaintTransformType( 049 "GradientPaintTransformType.HORIZONTAL"); 050 051 /** Center/vertical. */ 052 public static final GradientPaintTransformType CENTER_VERTICAL 053 = new GradientPaintTransformType( 054 "GradientPaintTransformType.CENTER_VERTICAL"); 055 056 /** Center/horizontal. */ 057 public static final GradientPaintTransformType CENTER_HORIZONTAL 058 = new GradientPaintTransformType( 059 "GradientPaintTransformType.CENTER_HORIZONTAL"); 060 061 /** The name. */ 062 private String name; 063 064 /** 065 * Private constructor. 066 * 067 * @param name the name. 068 */ 069 private GradientPaintTransformType(String name) { 070 this.name = name; 071 } 072 073 /** 074 * Returns a string representing the object. 075 * 076 * @return The string. 077 */ 078 @Override 079 public String toString() { 080 return this.name; 081 } 082 083 /** 084 * Returns {@code true} if this object is equal to the specified 085 * object, and {@code false} otherwise. 086 * 087 * @param o the other object. 088 * 089 * @return A boolean. 090 */ 091 @Override 092 public boolean equals(Object o) { 093 094 if (this == o) { 095 return true; 096 } 097 if (!(o instanceof GradientPaintTransformType)) { 098 return false; 099 } 100 101 final GradientPaintTransformType t = (GradientPaintTransformType) o; 102 if (!this.name.equals(t.name)) { 103 return false; 104 } 105 106 return true; 107 } 108 109 /** 110 * Returns a hash code value for the object. 111 * 112 * @return the hashcode 113 */ 114 @Override 115 public int hashCode() { 116 return this.name.hashCode(); 117 } 118 119 /** 120 * Ensures that serialization returns the unique instances. 121 * 122 * @return The object. 123 * 124 * @throws ObjectStreamException if there is a problem. 125 */ 126 private Object readResolve() throws ObjectStreamException { 127 GradientPaintTransformType result = null; 128 if (this.equals(GradientPaintTransformType.HORIZONTAL)) { 129 result = GradientPaintTransformType.HORIZONTAL; 130 } 131 else if (this.equals(GradientPaintTransformType.VERTICAL)) { 132 result = GradientPaintTransformType.VERTICAL; 133 } 134 else if (this.equals(GradientPaintTransformType.CENTER_HORIZONTAL)) { 135 result = GradientPaintTransformType.CENTER_HORIZONTAL; 136 } 137 else if (this.equals(GradientPaintTransformType.CENTER_VERTICAL)) { 138 result = GradientPaintTransformType.CENTER_VERTICAL; 139 } 140 return result; 141 } 142 143} 144 145