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. * (C) Copyright Taligent, Inc. 1996 - 1997, All Rights Reserved
  9. * (C) Copyright IBM Corp. 1996 - 1998, All Rights Reserved
  10. *
  11. * The original version of this source code and documentation is
  12. * copyrighted and owned by Taligent, Inc., a wholly-owned subsidiary
  13. * of IBM. These materials are provided under terms of a License
  14. * Agreement between Taligent and Sun. This technology is protected
  15. * by multiple US and International patents.
  16. *
  17. * This notice and attribution to Taligent may not be removed.
  18. * Taligent is a registered trademark of Taligent, Inc.
  19. *
  20. */
  21. package java.awt.font;
  22. import java.awt.geom.AffineTransform;
  23. import java.io.Serializable;
  24. /**
  25. * The <code>TransformAttribute</code> class provides an immutable
  26. * wrapper for a transform so that it is safe to use as an attribute.
  27. */
  28. public final class TransformAttribute implements Serializable {
  29. /**
  30. * The <code>AffineTransform</code> for this
  31. * <code>TransformAttribute</code>, or <code>null</code>
  32. * if <code>AffineTransform</code> is the identity transform.
  33. */
  34. private AffineTransform transform;
  35. /**
  36. * Wraps the specified transform. The transform is cloned and a
  37. * reference to the clone is kept. The original transform is unchanged.
  38. * @param transform the specified {@link AffineTransform} to be wrapped
  39. */
  40. public TransformAttribute(AffineTransform transform) {
  41. if (transform == null) {
  42. throw new IllegalArgumentException("transform may not be null");
  43. }
  44. if (!transform.isIdentity()) {
  45. this.transform = new AffineTransform(transform);
  46. }
  47. }
  48. /**
  49. * Returns a copy of the wrapped transform.
  50. * @return a <code>AffineTransform</code> that is a copy of the wrapped
  51. * transform of this <code>TransformAttribute</code>.
  52. */
  53. public AffineTransform getTransform() {
  54. AffineTransform at = transform;
  55. return (at == null) ? new AffineTransform() : new AffineTransform(at);
  56. }
  57. /**
  58. * Returns <code>true</code> if the wrapped transform is
  59. * an identity transform.
  60. * @return <code>true</code> if the wrapped transform is
  61. * an identity transform; <code>false</code> otherwise.
  62. * @since 1.4
  63. */
  64. public boolean isIdentity() {
  65. return (transform == null);
  66. }
  67. private void writeObject(java.io.ObjectOutputStream s)
  68. throws java.lang.ClassNotFoundException,
  69. java.io.IOException
  70. {
  71. // sigh -- 1.3 expects transform is never null, so we need to always write one out
  72. if (this.transform == null) {
  73. this.transform = new AffineTransform();
  74. }
  75. s.defaultWriteObject();
  76. }
  77. // Added for serial backwards compatability (4348425)
  78. static final long serialVersionUID = 3356247357827709530L;
  79. }