0N/A/*
2362N/A * Copyright (c) 1998, 2005, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * (C) Copyright Taligent, Inc. 1996 - 1997, All Rights Reserved
0N/A * (C) Copyright IBM Corp. 1996 - 1998, All Rights Reserved
0N/A *
0N/A * The original version of this source code and documentation is
0N/A * copyrighted and owned by Taligent, Inc., a wholly-owned subsidiary
0N/A * of IBM. These materials are provided under terms of a License
0N/A * Agreement between Taligent and Sun. This technology is protected
0N/A * by multiple US and International patents.
0N/A *
0N/A * This notice and attribution to Taligent may not be removed.
0N/A * Taligent is a registered trademark of Taligent, Inc.
0N/A *
0N/A */
0N/A
0N/Apackage java.awt.font;
0N/A
0N/Aimport java.awt.geom.AffineTransform;
0N/Aimport java.io.Serializable;
0N/Aimport java.io.ObjectStreamException;
0N/A
0N/A/**
0N/A * The <code>TransformAttribute</code> class provides an immutable
0N/A * wrapper for a transform so that it is safe to use as an attribute.
0N/A */
0N/Apublic final class TransformAttribute implements Serializable {
0N/A
0N/A /**
0N/A * The <code>AffineTransform</code> for this
0N/A * <code>TransformAttribute</code>, or <code>null</code>
0N/A * if <code>AffineTransform</code> is the identity transform.
0N/A */
0N/A private AffineTransform transform;
0N/A
0N/A /**
0N/A * Wraps the specified transform. The transform is cloned and a
0N/A * reference to the clone is kept. The original transform is unchanged.
0N/A * If null is passed as the argument, this constructor behaves as though
0N/A * it were the identity transform. (Note that it is preferable to use
0N/A * {@link #IDENTITY} in this case.)
0N/A * @param transform the specified {@link AffineTransform} to be wrapped,
0N/A * or null.
0N/A */
0N/A public TransformAttribute(AffineTransform transform) {
0N/A if (transform != null && !transform.isIdentity()) {
0N/A this.transform = new AffineTransform(transform);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Returns a copy of the wrapped transform.
0N/A * @return a <code>AffineTransform</code> that is a copy of the wrapped
0N/A * transform of this <code>TransformAttribute</code>.
0N/A */
0N/A public AffineTransform getTransform() {
0N/A AffineTransform at = transform;
0N/A return (at == null) ? new AffineTransform() : new AffineTransform(at);
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>true</code> if the wrapped transform is
0N/A * an identity transform.
0N/A * @return <code>true</code> if the wrapped transform is
0N/A * an identity transform; <code>false</code> otherwise.
0N/A * @since 1.4
0N/A */
0N/A public boolean isIdentity() {
0N/A return transform == null;
0N/A }
0N/A
0N/A /**
0N/A * A <code>TransformAttribute</code> representing the identity transform.
0N/A * @since 1.6
0N/A */
0N/A public static final TransformAttribute IDENTITY = new TransformAttribute(null);
0N/A
0N/A private void writeObject(java.io.ObjectOutputStream s)
0N/A throws java.lang.ClassNotFoundException,
0N/A java.io.IOException
0N/A {
0N/A // sigh -- 1.3 expects transform is never null, so we need to always write one out
0N/A if (this.transform == null) {
0N/A this.transform = new AffineTransform();
0N/A }
0N/A s.defaultWriteObject();
0N/A }
0N/A
0N/A /*
0N/A * @since 1.6
0N/A */
0N/A private Object readResolve() throws ObjectStreamException {
0N/A if (transform == null || transform.isIdentity()) {
0N/A return IDENTITY;
0N/A }
0N/A return this;
0N/A }
0N/A
0N/A // Added for serial backwards compatability (4348425)
0N/A static final long serialVersionUID = 3356247357827709530L;
0N/A
0N/A /**
0N/A * @since 1.6
0N/A */
0N/A public int hashCode() {
0N/A return transform == null ? 0 : transform.hashCode();
0N/A }
0N/A
0N/A /**
0N/A * Returns <code>true</code> if rhs is a <code>TransformAttribute</code>
0N/A * whose transform is equal to this <code>TransformAttribute</code>'s
0N/A * transform.
0N/A * @param rhs the object to compare to
0N/A * @return <code>true</code> if the argument is a <code>TransformAttribute</code>
0N/A * whose transform is equal to this <code>TransformAttribute</code>'s
0N/A * transform.
0N/A * @since 1.6
0N/A */
0N/A public boolean equals(Object rhs) {
0N/A try {
0N/A TransformAttribute that = (TransformAttribute)rhs;
0N/A if (transform == null) {
0N/A return that.transform == null;
0N/A }
0N/A return transform.equals(that.transform);
0N/A }
0N/A catch (ClassCastException e) {
0N/A }
0N/A return false;
0N/A }
0N/A}