home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Extras / ODesign / SetupPSE.exe / data.z / OSImageFile.java < prev    next >
Encoding:
Java Source  |  1997-01-24  |  3.1 KB  |  152 lines

  1. package COM.odi.demo.OSDraw;
  2.  
  3. /**
  4.  *      <H3>Copyright (C) Object Design Inc. 1996, 1997</H3>
  5.  */
  6.  
  7. import COM.odi.*;
  8. import java.applet.Applet;
  9. import java.awt.*;
  10.  
  11. /*
  12.  * Class OSImageFile is a persistence-capable class
  13.  * Subclass of BitMapObject
  14.  * Capable of being an discrete instance in the database
  15.  */
  16.  
  17. class OSImageFile extends BitMapObject {
  18.  
  19.   // Database fields
  20.  
  21.   private String path;
  22.   private int x;
  23.   private int y;
  24.  
  25.   private boolean enlargeX;
  26.   private boolean enlargeY;
  27.   private int factorX;
  28.   private int factorY;
  29.  
  30.   public OSImageFile(String path, int x, int y) {
  31.     this.path = path;
  32.     this.x = x;
  33.     this.y = y;
  34.     enlargeX = false;
  35.     enlargeY = false;
  36.     factorX = 1;
  37.     factorY = 1;
  38.   }
  39.  
  40.   // Method to draw the figure
  41.   
  42.   public void drawFigure(Graphics g) {
  43.     // Does not know where to draw the figure
  44.     // Must use drawFigure(Graphics g, Frame parent);
  45.   }
  46.  
  47.   public void drawFigure(Graphics g, Frame parent) {
  48.     Image image = parent.getToolkit().getImage(format(path));
  49.     if (image != null) {
  50.       parent.prepareImage(image, parent);    
  51.       if (enlargeX && enlargeY) {
  52.         g.drawImage(image, x, y, image.getWidth(parent) * factorX,
  53.                     image.getHeight(parent) * factorY,
  54.                     parent);
  55.       }
  56.       else if (!enlargeX && enlargeY) {
  57.         g.drawImage(image, x, y, image.getWidth(parent) / factorX,
  58.                     image.getHeight(parent) * factorY,
  59.                     parent);
  60.       }
  61.       else if (enlargeX && !enlargeY) {
  62.         g.drawImage(image, x, y, image.getWidth(parent) * factorX,
  63.                     image.getHeight(parent) / factorY,
  64.                     parent);
  65.       }
  66.       else {
  67.         g.drawImage(image, x, y, image.getWidth(parent) / factorX,
  68.                     image.getHeight(parent) / factorY,
  69.                     parent);
  70.       }
  71.     }
  72.   }
  73.           
  74.   // Methods to access private data
  75.  
  76.   public String getFile() {
  77.     return path;
  78.   }
  79.  
  80.   public void setFile(String path) {
  81.     this.path = path;
  82.   }
  83.  
  84.   public Point getPoint() {
  85.     return new Point(x, y);
  86.   }
  87.  
  88.   public void setPoint(Point point) {
  89.     x = point.x;
  90.     y = point.y;
  91.   }
  92.  
  93.   public boolean getEnlargeX() {
  94.     return enlargeX;
  95.   }
  96.  
  97.   public void setEnlargeX(boolean enlargeX) {
  98.     this.enlargeX = enlargeX;
  99.   }
  100.  
  101.   public boolean getEnlargeY() {
  102.     return enlargeY;
  103.   }
  104.  
  105.   public void setEnlargeY(boolean enlargeY) {
  106.     this.enlargeY = enlargeY;
  107.   }
  108.  
  109.   public int getFactorX() {
  110.     return factorX;
  111.   }
  112.  
  113.   public void setFactorX(int factorX) {
  114.     this.factorX = factorX;
  115.   }
  116.  
  117.   public int getFactorY() {
  118.     return factorY;
  119.   }
  120.  
  121.   public void setFactorY(int factorY) {
  122.     this.factorY = factorY;
  123.   }
  124.  
  125.   // Method to format a DOS path to a unix path
  126.  
  127.   public String format(String p) {
  128.     int len = p.length();
  129.     if (len <= 2) {
  130.       return null;
  131.     }
  132.     if (p.toCharArray()[0] == '/') {
  133.       return p;
  134.     }
  135.     String form = "/" + p;
  136.     char buf[] = form.toCharArray();
  137.     for (int i = 1; i <= len; i++) {
  138.       if (buf[i] == 92) {
  139.         buf[i] = '/';
  140.       }
  141.     }
  142.     return new String(buf);
  143.   }
  144.  
  145.   // Default hashCode method
  146.  
  147.   public int hashCode() {
  148.     return super.hashCode();
  149.   }
  150. }
  151.  
  152.