home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-01-24 | 3.1 KB | 152 lines |
- package COM.odi.demo.OSDraw;
-
- /**
- * <H3>Copyright (C) Object Design Inc. 1996, 1997</H3>
- */
-
- import COM.odi.*;
- import java.applet.Applet;
- import java.awt.*;
-
- /*
- * Class OSImageFile is a persistence-capable class
- * Subclass of BitMapObject
- * Capable of being an discrete instance in the database
- */
-
- class OSImageFile extends BitMapObject {
-
- // Database fields
-
- private String path;
- private int x;
- private int y;
-
- private boolean enlargeX;
- private boolean enlargeY;
- private int factorX;
- private int factorY;
-
- public OSImageFile(String path, int x, int y) {
- this.path = path;
- this.x = x;
- this.y = y;
- enlargeX = false;
- enlargeY = false;
- factorX = 1;
- factorY = 1;
- }
-
- // Method to draw the figure
-
- public void drawFigure(Graphics g) {
- // Does not know where to draw the figure
- // Must use drawFigure(Graphics g, Frame parent);
- }
-
- public void drawFigure(Graphics g, Frame parent) {
- Image image = parent.getToolkit().getImage(format(path));
- if (image != null) {
- parent.prepareImage(image, parent);
- if (enlargeX && enlargeY) {
- g.drawImage(image, x, y, image.getWidth(parent) * factorX,
- image.getHeight(parent) * factorY,
- parent);
- }
- else if (!enlargeX && enlargeY) {
- g.drawImage(image, x, y, image.getWidth(parent) / factorX,
- image.getHeight(parent) * factorY,
- parent);
- }
- else if (enlargeX && !enlargeY) {
- g.drawImage(image, x, y, image.getWidth(parent) * factorX,
- image.getHeight(parent) / factorY,
- parent);
- }
- else {
- g.drawImage(image, x, y, image.getWidth(parent) / factorX,
- image.getHeight(parent) / factorY,
- parent);
- }
- }
- }
-
- // Methods to access private data
-
- public String getFile() {
- return path;
- }
-
- public void setFile(String path) {
- this.path = path;
- }
-
- public Point getPoint() {
- return new Point(x, y);
- }
-
- public void setPoint(Point point) {
- x = point.x;
- y = point.y;
- }
-
- public boolean getEnlargeX() {
- return enlargeX;
- }
-
- public void setEnlargeX(boolean enlargeX) {
- this.enlargeX = enlargeX;
- }
-
- public boolean getEnlargeY() {
- return enlargeY;
- }
-
- public void setEnlargeY(boolean enlargeY) {
- this.enlargeY = enlargeY;
- }
-
- public int getFactorX() {
- return factorX;
- }
-
- public void setFactorX(int factorX) {
- this.factorX = factorX;
- }
-
- public int getFactorY() {
- return factorY;
- }
-
- public void setFactorY(int factorY) {
- this.factorY = factorY;
- }
-
- // Method to format a DOS path to a unix path
-
- public String format(String p) {
- int len = p.length();
- if (len <= 2) {
- return null;
- }
- if (p.toCharArray()[0] == '/') {
- return p;
- }
- String form = "/" + p;
- char buf[] = form.toCharArray();
- for (int i = 1; i <= len; i++) {
- if (buf[i] == 92) {
- buf[i] = '/';
- }
- }
- return new String(buf);
- }
-
- // Default hashCode method
-
- public int hashCode() {
- return super.hashCode();
- }
- }
-
-