KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > font > TransformAttribute


1 /*
2  * @(#)TransformAttribute.java 1.17 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 /*
9  * (C) Copyright Taligent, Inc. 1996 - 1997, All Rights Reserved
10  * (C) Copyright IBM Corp. 1996 - 1998, All Rights Reserved
11  *
12  * The original version of this source code and documentation is
13  * copyrighted and owned by Taligent, Inc., a wholly-owned subsidiary
14  * of IBM. These materials are provided under terms of a License
15  * Agreement between Taligent and Sun. This technology is protected
16  * by multiple US and International patents.
17  *
18  * This notice and attribution to Taligent may not be removed.
19  * Taligent is a registered trademark of Taligent, Inc.
20  *
21  */

22
23 package java.awt.font;
24
25 import java.awt.geom.AffineTransform JavaDoc;
26 import java.io.Serializable JavaDoc;
27
28 /**
29  * The <code>TransformAttribute</code> class provides an immutable
30  * wrapper for a transform so that it is safe to use as an attribute.
31  */

32 public final class TransformAttribute implements Serializable JavaDoc {
33
34     /**
35      * The <code>AffineTransform</code> for this
36      * <code>TransformAttribute</code>, or <code>null</code>
37      * if <code>AffineTransform</code> is the identity transform.
38      */

39     private AffineTransform JavaDoc transform;
40
41     /**
42    * Wraps the specified transform. The transform is cloned and a
43    * reference to the clone is kept. The original transform is unchanged.
44    * @param transform the specified {@link AffineTransform} to be wrapped
45      */

46     public TransformAttribute(AffineTransform JavaDoc transform) {
47     if (transform == null) {
48         throw new IllegalArgumentException JavaDoc("transform may not be null");
49     }
50
51     if (!transform.isIdentity()) {
52         this.transform = new AffineTransform JavaDoc(transform);
53     }
54     }
55
56     /**
57      * Returns a copy of the wrapped transform.
58      * @return a <code>AffineTransform</code> that is a copy of the wrapped
59      * transform of this <code>TransformAttribute</code>.
60      */

61     public AffineTransform JavaDoc getTransform() {
62     AffineTransform JavaDoc at = transform;
63     return (at == null) ? new AffineTransform JavaDoc() : new AffineTransform JavaDoc(at);
64     }
65
66     /**
67      * Returns <code>true</code> if the wrapped transform is
68      * an identity transform.
69      * @return <code>true</code> if the wrapped transform is
70      * an identity transform; <code>false</code> otherwise.
71      * @since 1.4
72      */

73     public boolean isIdentity() {
74     return (transform == null);
75     }
76
77     private void writeObject(java.io.ObjectOutputStream JavaDoc s)
78       throws java.lang.ClassNotFoundException JavaDoc,
79          java.io.IOException JavaDoc
80     {
81         // sigh -- 1.3 expects transform is never null, so we need to always write one out
82
if (this.transform == null) {
83         this.transform = new AffineTransform JavaDoc();
84     }
85     s.defaultWriteObject();
86     }
87     
88     // Added for serial backwards compatability (4348425)
89
static final long serialVersionUID = 3356247357827709530L;
90
91 }
92
Popular Tags