home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1998 / MacHack 1998.toast / Papers / OS Shell in Java / Facade / DesktopFolder.java < prev    next >
Encoding:
Java Source  |  1998-06-18  |  2.1 KB  |  95 lines  |  [TEXT/dosa]

  1. //    DesktopFolder.java : this is a Java source code file for the program Facade.
  2. //    Copyright 1998, Andrew S. Downs
  3. //    andrew.downs@tulane.edu
  4. //
  5. //    This source code is distributed as freeware.
  6. //    Just keep this author information in the file.  Enjoy!
  7.  
  8. import java.awt.*;
  9. import java.awt.event.*;
  10. import java.io.*;
  11. import java.util.*;
  12.  
  13. public class DesktopFolder extends DesktopFrameItem implements Serializable, MouseListener, MouseMotionListener {
  14.     boolean drag = false;
  15.  
  16.     int initialX = 0;
  17.     int initialY = 0;
  18.     
  19.     // The folder icon is shared among all instances.
  20.     static Image image;
  21.     
  22.     // For when this class implements its own drawing...
  23.     Polygon rightArrowPolygon = new Polygon();
  24.     Polygon downArrowPolygon = new Polygon();
  25.     
  26.     DesktopFolder() {
  27.         super();
  28.         this.addMouseListener( this );
  29.         this.addMouseMotionListener( this );
  30.     }
  31.     
  32.     public Polygon getRightArrowPolygon() {
  33.         return this.rightArrowPolygon;
  34.     }
  35.  
  36.     public Polygon getDownArrowPolygon() {
  37.         return this.downArrowPolygon;
  38.     }
  39.  
  40.     public Image getImage() {
  41.         return image;
  42.     }
  43.     
  44.     public static void setImage( Image i ) {
  45.         image = i;
  46.     }
  47.  
  48.     public void mouseDragged( MouseEvent e ) {
  49.         if ( this.drag ) {
  50.             this.setLocation( this.getBounds().x - this.initialX + e.getX(), this.getBounds().y - this.initialY + e.getY() );
  51.             this.repaint();
  52.         }
  53.     }
  54.     
  55.     public void mouseMoved( MouseEvent e ) {
  56.     }
  57.         
  58.     public void mouseEntered( MouseEvent e ) {
  59.     }
  60.         
  61.     public void mouseExited( MouseEvent e ) {
  62.     }
  63.         
  64.     public void mousePressed( MouseEvent e ) {
  65.         if ( this.getBounds().contains( e.getPoint() ) ) {
  66.             this.initialX = e.getX();
  67.             this.initialY = e.getY();
  68.             this.drag = true;
  69.             return;
  70.         }
  71.     }
  72.     
  73.     public void mouseReleased( MouseEvent e ) {
  74.         if ( this.drag ) {
  75.             this.drag = false;
  76.             this.repaint();
  77.         }
  78.     }
  79.     
  80.     public void mouseClicked( MouseEvent e ) {
  81.         if ( e.getClickCount() == 2 ) {
  82.             if ( !Desktop.windowExists( this.getPath() ) ) {
  83.                 DesktopFrame dw = new DesktopFrame( this.getPath() );
  84.                 dw.setLabel( this.getLabel() );
  85.                 dw.pack();
  86.                 dw.validate();
  87.                 dw.show();
  88.                 dw.toFront();
  89.                 dw.repaint();
  90.             }
  91.         }
  92.     }
  93. }
  94.  
  95.