home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / IFC_112 / netscape / application / ApplicationEvent.java < prev    next >
Encoding:
Text File  |  1999-05-28  |  2.8 KB  |  111 lines  |  [TEXT/CWIE]

  1. // ApplicationEvent.java
  2. // By Ned Etcode
  3. // Copyright 1996, 1997 Netscape Communications Corp.  All rights reserved.
  4.  
  5. package netscape.application;
  6.  
  7. import netscape.util.*;
  8. import java.awt.Graphics;
  9. import java.awt.Rectangle;
  10.  
  11. /** @note 1.0 update events with null clip rects will draw alot
  12.   * @note 1.0 added PRINT event
  13.   * @note 1.0 converted data to object from Rect, added convience methods
  14.   * @private
  15.   */
  16. public class ApplicationEvent extends Event {
  17.     /* application events */
  18.     static final int GOT_FOCUS = -21,
  19.                   LOST_FOCUS = -22,
  20.                   UPDATE = -23,
  21.                   RESIZE = -24,
  22.                   STOP = -25,
  23.                   APPLET_STOPPED = -26,
  24.                   APPLET_STARTED = -27,
  25.                   PRINT = -28;
  26.     Object data;
  27.  
  28.     static ApplicationEvent newResizeEvent(int width, int height) {
  29.         ApplicationEvent event = new ApplicationEvent();
  30.  
  31.         event.type = RESIZE;
  32.         event.data = new Rect(0, 0, width, height);
  33.         return event;
  34.     }
  35.  
  36.     static ApplicationEvent newUpdateEvent(java.awt.Graphics g) {
  37.         ApplicationEvent event = new ApplicationEvent();
  38.         Rectangle r = g.getClipRect();
  39.  
  40.         event.type = UPDATE;
  41.         if (r == null) {
  42.             event.data = new Rect(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE);
  43.         } else {
  44.             event.data = new Rect(r.x, r.y, r.width, r.height);
  45.         }
  46.         return event;
  47.     }
  48.  
  49.     /** @private **/
  50.     public static ApplicationEvent newFocusEvent(boolean gotFocus) {
  51.         ApplicationEvent event = new ApplicationEvent();
  52.  
  53.         event.type = gotFocus ? GOT_FOCUS : LOST_FOCUS;
  54.         return event;
  55.     }
  56.  
  57.     static ApplicationEvent newPrintEvent(java.awt.Graphics g) {
  58.         ApplicationEvent event = new ApplicationEvent();
  59.  
  60.         event.type = PRINT;
  61.         event.data = g;
  62.         return event;
  63.     }
  64.  
  65.     public String toString() {
  66.         String typeString;
  67.  
  68.         switch (type) {
  69.         case GOT_FOCUS:
  70.             typeString = "GotFocus";
  71.             break;
  72.         case LOST_FOCUS:
  73.             typeString = "LostFocus";
  74.             break;
  75.         case UPDATE:
  76.             typeString = "Update";
  77.             break;
  78.         case RESIZE:
  79.             typeString = "Resize";
  80.             break;
  81.         case STOP:
  82.             typeString = "Stop";
  83.             break;
  84.         case APPLET_STOPPED:
  85.             typeString = "AppletStopped";
  86.             break;
  87.         case APPLET_STARTED:
  88.             typeString = "AppletStarted";
  89.             break;
  90.         case PRINT:
  91.             typeString = "Print";
  92.             break;
  93.         default:
  94.             typeString = "Unknown Type";
  95.             break;
  96.         }
  97.  
  98.         return "ApplicationEvent: " + typeString;
  99.     }
  100.  
  101.     Rect rect() {
  102.         return (Rect)data;
  103.     }
  104.  
  105.     java.awt.Graphics graphics() {
  106.         return (java.awt.Graphics)data;
  107.     }
  108. }
  109.  
  110.  
  111.