home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / awt / font / Highlight.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  2.7 KB  |  111 lines

  1. /*
  2.  * @(#)Highlight.java    1.5 98/03/18
  3.  *
  4.  * Copyright 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. /*
  16.  * (C) Copyright Taligent, Inc. 1996 - 1997, All Rights Reserved
  17.  * (C) Copyright IBM Corp. 1996 - 1998, All Rights Reserved
  18.  *
  19.  * The original version of this source code and documentation is
  20.  * copyrighted and owned by Taligent, Inc., a wholly-owned subsidiary
  21.  * of IBM. These materials are provided under terms of a License
  22.  * Agreement between Taligent and Sun. This technology is protected
  23.  * by multiple US and International patents.
  24.  *
  25.  * This notice and attribution to Taligent may not be removed.
  26.  * Taligent is a registered trademark of Taligent, Inc.
  27.  *
  28.  */
  29.  
  30. package java.awt.font;
  31.  
  32. import java.awt.geom.GeneralPath;
  33. import java.awt.geom.AffineTransform;
  34. import java.awt.geom.Rectangle2D;
  35. import java.awt.Graphics;
  36. import java.awt.Shape;
  37. import java.awt.Rectangle;
  38. import java.awt.Graphics2D;
  39.  
  40. final class Highlight {
  41.  
  42.     private GeneralPath fPath;
  43.     private boolean fStroke;
  44.  
  45.     // Package-only constructor.  For performance,
  46.     // it doesn't clone so be nice.
  47.     Highlight(GeneralPath path, boolean stroke) {
  48.  
  49.         fPath = path;
  50.         fStroke = stroke;
  51.     }
  52.  
  53.     public void draw(Graphics2D g2d) {
  54.  
  55.         /*Graphics2D g2d = new Graphics2D(g);*/
  56.         if (fStroke) {
  57.             g2d.draw(fPath);
  58.         }
  59.         else {
  60.             g2d.fill(fPath);
  61.         }
  62.     }
  63.  
  64.     public void translate(double dx, double dy) {
  65.  
  66.         AffineTransform t = new AffineTransform();
  67.         t.setToTranslation(dx, dy);
  68.         fPath = (GeneralPath) fPath.createTransformedShape(t);
  69.     }
  70.  
  71.     public void add(Highlight h) {
  72.  
  73.         fPath.append(h.fPath, false);
  74.     }
  75.  
  76.     public Rectangle2D getBounds2D() {
  77.  
  78.         return fPath.getBounds2D();
  79.     }
  80.  
  81.     public Rectangle getBounds() {
  82.  
  83.         return fPath.getBounds();
  84.     }
  85.  
  86.     public boolean equals(Object rhs) {
  87.  
  88.         try {
  89.             return equals((Highlight) rhs);
  90.         }
  91.         catch(ClassCastException e) {
  92.             return false;
  93.         }
  94.     }
  95.  
  96.     public boolean equals(Highlight rhs) {
  97.  
  98.         return fPath.equals(rhs.fPath) && fStroke == rhs.fStroke;
  99.     }
  100.  
  101.     public Shape createPath() {
  102.  
  103.         // clone would be better...
  104.         AffineTransform t = new AffineTransform();
  105.         t.setToTranslation(0, 0);
  106.         return fPath.createTransformedShape(t);
  107.     }
  108. }
  109.  
  110.  
  111.