home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / netrexx.zip / NetRexx / GifShow.nrx < prev    next >
Text File  |  1997-06-30  |  3KB  |  50 lines

  1. /* ---------------------------------------------------------- */
  2. /* GifShow -- an applet that gets a GIF and fits it to window */
  3. /*                                                            */
  4. /* Parameters:                                                */
  5. /*                                                            */
  6. /*   gif    -- name of the gif to load; it is assumed to      */
  7. /*             be in the same directory, or relative to,      */
  8. /*             the document that calls the applet.            */
  9. /*                                                            */
  10. /* Use as:                                                    */
  11. /*                                                            */
  12. /*   <applet code="GifShow.class" width=200 height=150>       */
  13. /*   <param name=gif value="netrexx.gif">                     */
  14. /*   </applet>                                                */
  15. /*                                                            */
  16. /* ---------------------------------------------------------- */
  17. options binary      -- optional; runs a bit faster if set
  18.  
  19. class GifShow extends Applet
  20.   gif      =String  -- name of the image
  21.   goodimage=Image   -- the Image to draw (null if no good)
  22.  
  23.  /* init gets the requested image, then uses a MediaTracker to track it
  24.     and wait until it has all arrived.  If it looks good, the goodimage
  25.     property is set so paint(g) can use it. */
  26.  method init
  27.   gif=getParameter('gif')                    -- get gif name from applet tags
  28.   if gif=null then gif='netrexx.gif'         -- use default if none
  29.   newimage=getImage(getDocumentBase(), gif)  -- get the image
  30.   tracker=MediaTracker(this)                 -- 'this' is the "observer"
  31.   tracker.addImage(newimage, 0)              -- track image arrival, ID=0
  32.   do
  33.     tracker.waitForID(0)                     -- wait for image 0 to complete
  34.   catch InterruptedException                 -- something stopped us
  35.     return                                   -- can do no more
  36.   end
  37.   -- Good images have useful dimensions, bad images have -1 or 0 in X or Y
  38.   if newimage.getWidth(this)>0
  39.    then if newimage.getHeight(this)>0
  40.    then goodimage=newimage
  41.  
  42.  
  43.  /* paint(g) draws the image to size, if available, or else displays the
  44.     name that it was given. */
  45.  method paint(g=Graphics)
  46.   if goodimage=null
  47.    then g.drawString(gif, 2, 12)             -- Alternative
  48.    else g.drawImage(goodimage, 0, 0, getSize.width, getSize.height, this)
  49.  
  50.