home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / ed8n1t2i / caption.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  3.7 KB  |  99 lines

  1. //****************************************************************************
  2. // ---- version information ----
  3. //
  4. // Caption.java          v 1.00 b1
  5. // Written by:           I. van Rienen / E-mail ivr@bart.nl
  6. // URL:                  http://www/bart.nl/~ivr
  7. // Initial release:
  8. // Released in public domain:
  9. //
  10. // ---- Description ----
  11. // Java class containing methods for creating a caption in the schematic
  12. //
  13. // This program and the Java source is in the public domain.
  14. // Permission to use, copy, modify, and distribute this software
  15. // and its documentation for NON-COMMERCIAL purposes and
  16. // without fee is hereby granted.
  17. //
  18. //    Copyright 1996
  19. //
  20. //    Iwan van Rienen
  21. //    Joan Maetsuyckerstr. 145
  22. //    2593 ZG  The Hague
  23. //    The Netherlands
  24. //
  25. // I am not responsible for any bugs in this program and
  26. // possible damage to hard- or software when using this program.
  27. //****************************************************************************
  28. import java.awt.*;
  29. import java.io.PrintStream;
  30.  
  31. class Caption extends ElectronicComponent {
  32.     static final Color CaptionColor = Color.white;
  33.     public String Text;
  34.     public Font CaptionFont;
  35.  
  36. //----------------------------------------------------------------------------
  37. // The constructor of a new Caption.
  38. //----------------------------------------------------------------------------
  39.     public Caption (int x, int y, String text) {
  40.         super (x, y, 1, 1, 0, 1, 1, 1, 0, 0);      // x,y,w,h HitBox x,y,w,h,I,O
  41.         Text = text;
  42.         ComponentName = "Text";
  43.         ClassName = "Caption";
  44.         CaptionFont = new Font("TimesRoman",Font.PLAIN, 16);
  45.     }
  46.  
  47. //----------------------------------------------------------------------------
  48. // The constructor of a new Caption, which is a copy of CompToCopy
  49. //----------------------------------------------------------------------------
  50.     public Caption (ElectronicComponent CompToCopy, int xo, int yo) {
  51.         super (CompToCopy, xo, yo);
  52.     }
  53.  
  54. //----------------------------------------------------------------------------
  55. // Method for copying this component.
  56. //----------------------------------------------------------------------------
  57.     public ElectronicComponent Copy(int xo, int yo) {
  58.         Caption NewComponent = new Caption(this, xo, yo);
  59.         NewComponent.Text = Text;
  60.         NewComponent.CaptionFont = CaptionFont;
  61.         return NewComponent;
  62.     }
  63.  
  64. //----------------------------------------------------------------------------
  65. // Draw the caption.
  66. //----------------------------------------------------------------------------
  67.     public void draw(Graphics g, int xp, int yp, int gs) {
  68.         FontMetrics CaptionFontMetrics;
  69.         int x = Pos.x - xp;
  70.         int y = Pos.y - yp;
  71.  
  72.         g.setFont (CaptionFont);
  73.         CaptionFontMetrics = g.getFontMetrics();
  74.         int FontHeight = CaptionFontMetrics.getHeight();
  75.         int FontWidth = CaptionFontMetrics.stringWidth(Text);
  76.         HitBoxSize.width = Dim.width = FontWidth / gs + 1;
  77.         HitBoxSize.height = Dim.height = FontHeight / gs;
  78.  
  79.         super.draw (g, xp, yp, gs);
  80.  
  81.         // Draw HitBox
  82.         // DrawHitBox(g, x, y, gs);
  83.  
  84.         g.setColor (CaptionColor);
  85.         g.drawString (Text, x * gs, y * gs + FontHeight);
  86.     }
  87.  
  88. //----------------------------------------------------------------------------
  89. // Save this caption
  90. //----------------------------------------------------------------------------
  91.    public void Save (PrintStream myPrintStream) {
  92.         myPrintStream.println ("describe component Caption");
  93.         myPrintStream.println (" pos " + Pos.x + " " + Pos.y);
  94.         myPrintStream.println (" Text " + Text);
  95.         myPrintStream.println ("end describe");
  96.     }
  97.  
  98.  
  99. }