home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / in4wjcxu / src / como / commlet / draw / graphicsobject.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  1.8 KB  |  94 lines

  1.  
  2. package como.commlet.draw;
  3.  
  4. import como.io.*;
  5. import como.util.*;
  6. import java.awt.*;
  7. import java.io.*;
  8. import java.util.*; 
  9. import java.lang.*;
  10.  
  11. public abstract class GraphicsObject implements Saveable
  12. {
  13.     protected Color color;
  14.     protected  int x;
  15.     protected  int y;
  16.     String name;
  17.     boolean filled;
  18.     Graphics lastgraphics;
  19.     Panel proppanel;
  20.  
  21.     public GraphicsObject()
  22.     {
  23.         color=Color.white;
  24.         name = "Untitled-"+this.getClass().getName();
  25.         x = 100;
  26.         y = 100;
  27.     }
  28.     public abstract GraphicsObject getNew ();
  29.     public boolean handleEvent(Event evt) {
  30.         return false;
  31.     }
  32.     public void layoutPropPanel(Panel p) {
  33.         p.removeAll();
  34.         proppanel = p;
  35.         updatePropPanel();
  36.     }
  37.     public void updatePropPanel() {
  38.     }
  39.     public boolean handlePropPanelEvent(Event evt,DrawCanvas d) {
  40.         return false;
  41.     }
  42.     public void draw(Graphics g,Color c) {
  43.         lastgraphics = g;
  44.     }
  45.     public void draw(Graphics g)
  46.     {
  47.         lastgraphics = g;
  48.         draw(g,color);
  49.     }
  50.     public void redraw() {
  51.         if (lastgraphics != null) draw(lastgraphics);
  52.         // TODO: Do not take colormode into account
  53.     }
  54.     public void moveTo(int nx, int ny) {
  55.         x = nx;
  56.         y = ny;
  57.         redraw();
  58.         updatePropPanel();            
  59.     }
  60.     public Color getColor() {
  61.         return color;        
  62.     }
  63.     public void setFilled(boolean b)
  64.     {
  65.         filled = b;
  66.         redraw();
  67.     }
  68.         
  69.     public int getX() { return x; }
  70.     public int getY() { return y; }
  71.     public void setColor(Color c) {
  72.         color =c ;        
  73.         redraw();    
  74.         updatePropPanel();
  75.     }
  76.     public String toString() {
  77.         return name +" "+x+" "+y+" "+color.getRed()+" "+color.getGreen()+" "+color.getBlue()+" ";
  78.     }
  79.     public void load(ObjectInputStream s) throws IOException {
  80.         name = s.readString();
  81.         x = s.readInt();
  82.         y = s.readInt();
  83.         color = (Color)s.readObject();
  84.         filled = s.readBoolean();
  85.     }
  86.     public void save(ObjectOutputStream s)  throws IOException{
  87.         s.writeString(name);
  88.         s.writeInt(x);
  89.         s.writeInt(y);
  90.         s.writeObject(color);
  91.         s.writeBoolean(filled);
  92.     }
  93. }
  94.