home *** CD-ROM | disk | FTP | other *** search
/ The Best of Windows 95.com 1996 September / WIN95_09961.iso / java / mojo1-2e.exe / MOJODISK / DATA.4 / plugins / ticker.def < prev    next >
Encoding:
Text File  |  1996-07-01  |  9.8 KB  |  505 lines

  1. DEF_COMPONENTNAME
  2. TickerTape
  3. DEF_SUPERCLASS
  4. Applet
  5. DEF_SUPERCOMPONENT
  6.  
  7. DEF_PACKAGE
  8. plugins
  9. widgets
  10. DEF_ENDLIST
  11. DEF_SUBCOMPONENTLIST
  12. DEF_ENDLIST
  13. DEF_SUBCOMPONENTCLASSLIST
  14. DEF_ENDLIST
  15. DEF_CATEGORY
  16. Widgets
  17. DEF_BITMAP
  18. tickerm.bmp
  19. DEF_THUMBNAIL_UP
  20. ticker.bmp
  21. DEF_THUMBNAIL_DOWN
  22. 2-ticker.bmp
  23. DEF_VISUAL
  24. DEF_TOOL
  25. DEF_IMPORTS
  26. java.util.Date
  27. java.io.InputStream
  28. java.net.URL
  29. DEF_ENDLIST
  30. DEF_REQUIRES
  31. DEF_ENDLIST
  32. DEF_IMPLEMENTS
  33. Runnable
  34. DEF_ENDLIST
  35. DEF_DECLARATION
  36. // A class that produces a tickertape message...
  37. //  Variable Declarations
  38.   String message_error = "Error - No Message . . .";
  39.   String message = null;
  40.  
  41.   int font_size;
  42.   Color bgColor;
  43.   Color fgColor; 
  44.   Font the_font;
  45.   String tmpURL = null;  
  46.   String tmpLink = null;
  47. /** The width of the string in pixels.  Need this to know this so we
  48.        can reset the string. */
  49.   int messageWidth;
  50.  
  51.   /** keep track of where we are printing the current string. */
  52.   int position;
  53.  
  54.   /** the number of seconds between reload of URL. */
  55.   int update_seconds = 0;
  56.  
  57.   /** The time to reload URL.  If this is null, never reaload. */
  58.   Date update_time = null;
  59.  
  60.   /** The URL that contains the text to be update regularly. */
  61.   URL update = null;
  62.  
  63.   /** if this is not equal null it will link to the location when the
  64.       applet is clicked on. */
  65.   URL link = null;
  66.  
  67.   /** The InputStream that goes with the URL.  This must be closed and
  68.       the reopen in order to get a new line. */
  69.   InputStream info;
  70.  
  71.   /** Stupid thread thing. */
  72.   Thread ticker = null;
  73.  
  74.   /** If this is set to false it will never try to load a message from
  75.       a URL, even if reload is true.  */
  76.   boolean reload_ever = true;
  77.  
  78.   /** This is set to false after a message is loaded.  Set it to true
  79.       when you want it to reload the message. */
  80.   boolean reload = false;
  81.  
  82.   /** Just a way to check if the thread is suspended or not.  If
  83.       through some bug this gets set wrong it will just print wrong
  84.       commands. */
  85.   boolean suspend = false;
  86.  
  87.   final static int SUSPEND_KEY = 19;  // C-s
  88.   final static String SUSPEND_DESC = "C-s to suspend.";
  89.  
  90.   final static int RESUME_KEY = 17;  // C-q
  91.   final static String RESUME_DESC = "C-q to resume.";
  92.  
  93.   /** The amount of time to rest between redrawing line. */
  94.   int rest = 100;
  95.  
  96.   /** abount of space to jump.  Hopefully negative numbers will move
  97.       it in the other direction. */
  98.   int jump = 5;
  99.  
  100.  
  101.  
  102.  
  103. DEF_ENDLIST
  104. DEF_EVENT
  105.   public boolean keyUp(java.awt.Event evt, int key) {
  106.     if (key == SUSPEND_KEY) {
  107.       ticker.suspend();
  108.       suspend = true;
  109.     } else  if (key == RESUME_KEY){
  110.       ticker.resume();
  111.       suspend = false;
  112.     }
  113.     update_status();
  114.     return true;
  115.   }
  116. DEF_ENDLIST
  117. DEF_EVENT
  118.   public boolean mouseEnter(java.awt.Event evt, int x, int y) {
  119.     update_status();
  120.     return true;
  121.   }
  122. DEF_ENDLIST
  123. DEF_EVENT
  124.   public boolean mouseExit(java.awt.Event evt, int x, int y) {
  125.     if (link != null) {
  126.       showStatus("");
  127.     }
  128.     return true;
  129.   }
  130. DEF_ENDLIST
  131. DEF_METHOD
  132. void initialize() {
  133.     String tmpParam;
  134.  
  135. //    the_font = new Font(getFont().getName(), getFont().getStyle(),
  136. //          font_size);
  137. //    setFont(the_font);
  138.  
  139.     if (jump == 0) {
  140.     jump = 5;
  141.     System.err.println("Zero value for jump, setting to 5.");
  142.       }
  143.  
  144.       if (rest < 0) {
  145.     rest = 100; // Grr, no unsigned.
  146.     System.err.println("Negative value for rest, setting to 100.");
  147.       }
  148.   
  149.       setBackground(bgColor);
  150.  
  151.       setForeground(fgColor);
  152.  
  153.       update_time = new Date();
  154.       update_time.setTime(update_time.getTime() + (update_seconds * 1000));
  155.  
  156.     if (tmpURL == null) {
  157.       reload_ever = false;
  158.       if (message == null) {
  159.     message = message_error;
  160.       }
  161.     } else {
  162.       try {    
  163.         update = new URL(applet.getDocumentBase(), tmpURL); 
  164.       } catch (java.net.MalformedURLException e) {
  165.     reload_ever = false;
  166.         }
  167.     }
  168.       if ((getMessage() == false) && (message == null)) {
  169.     message = message_error;
  170.       }
  171.  
  172.     messageWidth = getFontMetrics(getFont()).stringWidth(message); 
  173.  
  174.     try {
  175.       link = new URL (applet.getDocumentBase(), tmpLink);
  176.     } catch (java.net.MalformedURLException e) {
  177.       link = null;
  178.     }
  179.  
  180.     position = (jump < 0) ? -messageWidth : size().width;
  181.     start();
  182. }
  183. DEF_ENDLIST
  184. DEF_METHOD
  185.   boolean getMessage() {
  186.  
  187.     if (reload_ever == true) {
  188.       try {
  189.     info = update.openStream();
  190.       } catch (java.io.IOException e) {
  191.     return false;
  192.       }
  193.     
  194.       StringBuffer makeMessage = new StringBuffer();
  195.       char in;
  196.       /* Had to do this twice because Macs print `\n` as a little box.
  197.          The box is away. */
  198.       try {
  199.     in = (char)info.read(); 
  200.       } catch (java.io.IOException e) {
  201.     return false;
  202.       }
  203.       while (in != '\n') {
  204.     makeMessage.append(in);
  205.     try {
  206.       in = (char)info.read(); 
  207.     } catch (java.io.IOException e) {
  208.       return false;
  209.     }
  210.       }
  211.  
  212.       try {
  213.     info.close();
  214.       } catch (java.io.IOException e) {
  215.     reload_ever = false;
  216.       }
  217.       message = makeMessage.toString();
  218.     }
  219.     return true;
  220.   }
  221. DEF_ENDLIST
  222. DEF_METHOD
  223.   public void start() {
  224.     if (ticker == null) {
  225.       ticker = new Thread(this);
  226.       ticker.start();
  227.     }
  228.   }
  229. DEF_ENDLIST
  230. DEF_METHOD
  231.   public void stop() {
  232.     ticker = null;
  233.   }
  234. DEF_ENDLIST
  235. DEF_METHOD
  236.   public void run() {
  237.     while (ticker != null) {
  238.       repaint();
  239.       if (((jump < 0) && (position > size().width)) ||
  240.       (position < -messageWidth)) {
  241.     position = (jump < 0) ? -messageWidth : size().width;
  242.     if ((update_time != null) && (new Date()).after(update_time)) {
  243.       reload = true;
  244.     }
  245.     
  246.     if (reload == true) {
  247.       getMessage();
  248.       messageWidth = getFontMetrics(getFont()).stringWidth(message); 
  249.       reload = false;
  250.       if (update_time != null) {
  251.         update_time = new Date();
  252.         update_time.setTime(update_time.getTime() +
  253.                 (update_seconds * 1000));
  254.       }
  255.     }
  256.       }
  257.       try {
  258.     Thread.sleep(rest);
  259.       }
  260.       catch (InterruptedException e) {
  261.     ticker = null;
  262.     System.err.println("Stupid sleep.");
  263.       }
  264.  
  265.       position -= jump;
  266.     }
  267.   }
  268. DEF_ENDLIST
  269. DEF_METHOD
  270.   public boolean mouseUp(java.awt.Event evt, int x, int y) {
  271.     if (link == null) {
  272.       reload = true;
  273.     } else {
  274.       getAppletContext().showDocument(link);
  275.     }
  276.     return true;
  277.   }
  278. DEF_ENDLIST
  279. DEF_METHOD
  280.   public void update_status() {
  281.     if (link == null) {
  282.       if (suspend) {
  283.     showStatus(RESUME_DESC);
  284.       } else {
  285.     showStatus(SUSPEND_DESC);
  286.       }
  287.     } else {
  288.           showStatus(link.toExternalForm());
  289.     }
  290.   }
  291. DEF_ENDLIST
  292. DEF_METHOD
  293.   public void paint(Graphics g) {
  294.     g.drawString(message, position, getFont().getSize());
  295.   }
  296. DEF_ENDLIST
  297. DEF_METHOD
  298. public void setTickerJump(int aParam)
  299. {
  300.   jump = aParam;
  301. }
  302. DEF_ENDLIST
  303. DEF_METHOD
  304. public int getTickerJump()
  305. {
  306.   return jump;
  307. }
  308. DEF_ENDLIST
  309. DEF_METHOD
  310. public void setTickerRest(int aParam)
  311. {
  312.   rest = aParam;
  313. }
  314. DEF_ENDLIST
  315. DEF_METHOD
  316. public int getTickerRest()
  317. {
  318.   return rest;
  319. }
  320. DEF_ENDLIST
  321. DEF_METHOD
  322. public void setBGColor(Color aParam)
  323. {
  324.   bgColor = aParam;
  325. }
  326. DEF_ENDLIST
  327. DEF_METHOD
  328. public Color getBGColor()
  329. {
  330.   return bgColor;
  331. }
  332. DEF_ENDLIST
  333. DEF_METHOD
  334. public void setFGColor(Color aParam)
  335. {
  336.   fgColor = aParam;
  337. }
  338. DEF_ENDLIST
  339. DEF_METHOD
  340. public Color getFGColor ()
  341. {
  342.   return fgColor;
  343. }
  344. DEF_ENDLIST
  345. DEF_METHOD
  346. public void setTickerUpdate(int aParam)
  347. {
  348.   update_seconds = aParam;
  349. }
  350. DEF_ENDLIST
  351. DEF_METHOD
  352. public int getTickerUpdate()
  353. {
  354.   return update_seconds;
  355. }
  356. DEF_ENDLIST
  357. DEF_METHOD
  358. public void setTickerURL(String aParam)
  359. {
  360.   tmpURL = aParam;
  361.   if (aParam == "")
  362.     tmpURL = null;
  363. }
  364. DEF_ENDLIST
  365. DEF_METHOD
  366. public String getTickerURL()
  367. {
  368.   return tmpURL;
  369. }
  370. DEF_ENDLIST
  371. DEF_METHOD
  372. public void setTickerMessage(String aParam)
  373. {
  374.   message = aParam;
  375.   if (aParam == "")
  376.     message = null;
  377. }
  378. DEF_ENDLIST
  379. DEF_METHOD
  380. public String getTickerMessage()
  381. {
  382.   return message;
  383. }
  384. DEF_ENDLIST
  385. DEF_METHOD
  386. public void setTickerLink(String aParam)
  387. {
  388.   tmpLink = aParam;
  389.   if (aParam == "")
  390.     tmpLink = null;
  391. }
  392. DEF_ENDLIST
  393. DEF_METHOD
  394. public String getTickerLink()
  395. {
  396.   return tmpLink;
  397. }
  398. DEF_ENDLIST
  399. DEF_PROPERTY
  400. Jump Size
  401. int
  402. setTickerJump(AVALUE);
  403. AVALUE=getTickerJump();
  404. 5
  405. DEF_ENDLIST
  406. DEF_PROPERTY
  407. Rest Time
  408. int
  409. setTickerRest(AVALUE);
  410. AVALUE=getTickerRest();
  411. 100
  412. DEF_ENDLIST
  413. DEF_PROPERTY
  414. BackGround Color
  415. Color
  416. setBGColor(AVALUE);
  417. AVALUE=getBGColor();
  418. Color.black
  419. DEF_ENDLIST
  420. DEF_PROPERTY
  421. ForeGround Color
  422. Color
  423. setFGColor(AVALUE);
  424. AVALUE=getFGColor();
  425. Color.white
  426. DEF_ENDLIST
  427. DEF_PROPERTY
  428. Update Time
  429. int
  430. setTickerUpdate(AVALUE);
  431. AVALUE=getTickerUpdate();
  432. 0
  433. DEF_ENDLIST
  434. DEF_PROPERTY
  435. URL
  436. String
  437. setTickerURL(AVALUE);
  438. AVALUE=getTickerURL();
  439.  
  440. DEF_ENDLIST
  441. DEF_PROPERTY
  442. Message
  443. String  
  444. setTickerMessage(AVALUE);
  445. AVALUE=getTickerMessage();
  446.  
  447. DEF_ENDLIST
  448. DEF_PROPERTY
  449. Link To:
  450. String
  451. setTickerLink(AVALUE);
  452. AVALUE=getTickerLink();
  453.  
  454. DEF_ENDLIST
  455. DEF_PROPERTY
  456. Top
  457. int
  458. move(bounds().x, AVALUE);
  459. AVALUE = bounds().y;
  460. 0
  461. DEF_ENDLIST
  462. DEF_PROPERTY
  463. Left
  464. int
  465. move(AVALUE, bounds().y);
  466. AVALUE = bounds().x;
  467. 0
  468. DEF_ENDLIST
  469. DEF_PROPERTY
  470. Height
  471. int
  472. resize(bounds().width, AVALUE);
  473. AVALUE = bounds().height;
  474. 32
  475. DEF_ENDLIST
  476. DEF_PROPERTY
  477. Width
  478. int
  479. resize(AVALUE, bounds().height);
  480. AVALUE = bounds().width;
  481. 155
  482. DEF_ENDLIST
  483. DEF_PROPERTY
  484. FontName
  485. String
  486. setFont(new Font(AVALUE, getFont().getStyle(), getFont().getSize()));
  487. AVALUE = getFont().getName();
  488. Courier
  489. DEF_ENDLIST
  490. DEF_PROPERTY
  491. FontStyle
  492. int
  493. setFont(new Font(getFont().getName(), AVALUE, getFont().getSize()));
  494. AVALUE = getFont().getStyle();
  495. Font.PLAIN
  496. DEF_ENDLIST
  497. DEF_PROPERTY
  498. FontSize
  499. int
  500. setFont(new Font(getFont().getName(), getFont().getStyle(), AVALUE));
  501. AVALUE = getFont().getSize();
  502. 10
  503. DEF_ENDLIST
  504. DEF_ENDCOMPONENT
  505.