home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 October / PCO1097.ISO / FilesBBS / FREI / FSCROLL.EXE / SRC / FunScrollAttr.java < prev    next >
Encoding:
Java Source  |  1997-08-06  |  7.5 KB  |  319 lines

  1. /*
  2.  * Copyright (c) 1995 by Jan Andersson, Torpa Konsult AB.
  3.  *
  4.  * Permission to use, copy, and distribute this software for
  5.  * NON-COMMERCIAL purposes and without fee is hereby granted
  6.  * provided that this copyright notice appears in all copies.
  7.  */
  8. import java.util.StringTokenizer;
  9.  
  10. /**
  11.  * Attributes of FunScroll Animations
  12.  *
  13.  * @version 1.1 97/08/06
  14.  * @author  Jan Andersson (janne@torpa.se)
  15.  */
  16. public class FunScrollAttr
  17. {
  18.                 // type of attribute
  19.    static final int TEXT = 1;    // text
  20.    static final int IMAGE = 2;    // image
  21.    
  22.                 // scroll styles:
  23.    static final int NONE = 0;    // no scrolling (default)
  24.    static final int LEFT = 1;    // scroll left
  25.    static final int RIGHT = 2;    // ... right
  26.    static final int UP = 3;    // ... up
  27.    static final int DOWN = 4;    // ... down
  28.    static final int TYPED = 5;    // ... typed (char by char)
  29.    //static final int GROW = 6;    // size grow
  30.    //static final int SHRINK = 7;    // size expand
  31.    static final int FADE = 8;    // .... fade
  32.    static final int UP_LINE = 9; // .... up (line-by-line)
  33.    static final int EXPLODE = 10;// explode (only for endScroll)
  34.    
  35.                 // animate styles:
  36.    static final int NORMAL = 0;    // normal (default)
  37.    static final int NERVOUS = 1; // "nervous" text
  38.    static final int SINEWAVE = 2; // sine-wave text
  39.                     // text draw styles:
  40.    static final int EMBOSS = 1;     
  41.    static final int ENGRAVE = 2;
  42.    static final int SHADOW = 3;
  43.                 // text line alignment
  44.    static final int CENTER = 0;
  45.    
  46.    int type = TEXT;        // attribute type
  47.    String param = "";        // parameter (message line or image)
  48.    String delimiters = "<>";    // used delimiters (default is "<>")
  49.    int startScroll = NONE;    // start scroll style
  50.    int endScroll = NONE;    // end scroll style
  51.    int showDelay = 0;        // show delay
  52.    int endDelay = -1;        // end delay
  53.    int style = NORMAL;        // animate style
  54.    int drawStyle = NONE;    // text draw style
  55.    int align = CENTER;        // text line alignment
  56.    String color = null;        // text color
  57.    String bgImage = null;    // background image
  58.    String bgText = null;    // background text
  59.    int bgOffsetX = 0;        // X offset, background
  60.    int bgOffsetY = 0;        // Y offset, background
  61.    int offsetX = 0;        // X offset, animation
  62.    int offsetY = 0;        // Y offset, animation
  63.    
  64.    public FunScrollAttr(String line, String delim)
  65.    {
  66.       if (delim != null) {
  67.      // used specified delimiter
  68.      delimiters = delim;
  69.       }
  70.       parse(line);
  71.    }
  72.  
  73.    public int type()
  74.    {
  75.       return type;
  76.    }
  77.  
  78.    public String param()
  79.    {
  80.       return param;
  81.    }
  82.    
  83.    public int startScroll()
  84.    {
  85.       return startScroll;
  86.    }
  87.    
  88.    public int endScroll()
  89.    {
  90.       return endScroll;
  91.    }
  92.    
  93.    public int showDelay()
  94.    {
  95.       return showDelay;
  96.    }
  97.    
  98.    public int endDelay()
  99.    {
  100.       return endDelay;
  101.    }
  102.  
  103.    public int style()
  104.    {
  105.       return style;
  106.    }
  107.  
  108.    public int align()
  109.    {
  110.       return align;
  111.    }
  112.    
  113.    public int drawStyle()
  114.    {
  115.       return drawStyle;
  116.    }
  117.  
  118.    public String color()
  119.    {
  120.       return color;
  121.    }
  122.  
  123.    public String bgImage()
  124.    {
  125.       return bgImage;
  126.    }
  127.  
  128.    public String bgText()
  129.    {
  130.       return bgText;
  131.    }
  132.    
  133.    public int bgOffsetX()
  134.    {
  135.       return bgOffsetX;
  136.    }
  137.  
  138.    public int bgOffsetY()
  139.    {
  140.       return bgOffsetY;
  141.    }
  142.  
  143.    public int offsetX()
  144.    {
  145.       return offsetX;
  146.    }
  147.  
  148.    public int offsetY()
  149.    {
  150.       return offsetY;
  151.    }
  152.  
  153.    void parse(String line)
  154.    {
  155.       StringTokenizer st = new StringTokenizer(line, delimiters);
  156.       boolean gotText = false;
  157.       while (st.hasMoreTokens()) {
  158.      int scroll = -1;
  159.      String token = st.nextToken();
  160.      //System.out.println("token:"+token);
  161.      // get scroll style
  162.      if (token.equalsIgnoreCase("left")) 
  163.         scroll = LEFT;
  164.      else if (token.equalsIgnoreCase("right")) 
  165.         scroll = RIGHT;
  166.      else if (token.equalsIgnoreCase("up")) 
  167.         scroll = UP;
  168.      else if (token.equalsIgnoreCase("down")) 
  169.         scroll = DOWN;
  170.      else if (token.equalsIgnoreCase("typed")) 
  171.         scroll = TYPED;
  172. //      else if (token.equalsIgnoreCase("grow")) 
  173. //         scroll = GROW;
  174. //      else if (token.equalsIgnoreCase("shrink")) 
  175. //         scroll = SHRINK;
  176.      else if (token.equalsIgnoreCase("fade")) 
  177.         scroll = FADE;
  178.      else if (token.equalsIgnoreCase("up-line")) 
  179.         scroll = UP_LINE;
  180.      else if (gotText && token.equalsIgnoreCase("explode")) 
  181.         scroll = EXPLODE;
  182.      if (scroll >= 0) {
  183.         if (!gotText)
  184.            startScroll = scroll;
  185.         else
  186.            endScroll = scroll;
  187.         continue;
  188.      }
  189.  
  190.      // get type
  191.      if (token.equalsIgnoreCase("image")) {
  192.         type = IMAGE;
  193.         continue;
  194.      }
  195.  
  196.      // get text style
  197.      if (token.equalsIgnoreCase("nervous")) {
  198.         style = NERVOUS;
  199.         continue;
  200.      }
  201.      if (token.equalsIgnoreCase("sine-wave")) {
  202.         style = SINEWAVE;
  203.         continue;
  204.      }
  205.      
  206.      // get text draw style
  207.      if (token.equalsIgnoreCase("emboss")) {
  208.         drawStyle = EMBOSS;
  209.         continue;
  210.      }
  211.      if (token.equalsIgnoreCase("engrave")) {
  212.         drawStyle = ENGRAVE;
  213.         continue;
  214.      }
  215.      if (token.equalsIgnoreCase("shadow")) {
  216.         drawStyle = SHADOW;
  217.         continue;
  218.      }
  219.  
  220.      // get color
  221.      if (token.length() > 6 &&
  222.          token.substring(0,6).equalsIgnoreCase("color=")) {
  223.         color = token.substring(6);
  224.         continue;
  225.      }
  226.  
  227.      // get background image
  228.      if (token.length() > 8 &&
  229.          token.substring(0,8).equalsIgnoreCase("bgImage=")) {
  230.         bgImage = token.substring(8);
  231.         continue;
  232.      }
  233.  
  234.      // get background text
  235.      if (token.length() > 7 &&
  236.          token.substring(0,7).equalsIgnoreCase("bgText=")) {
  237.         bgText = token.substring(7);
  238.         continue;
  239.      }
  240.  
  241.      // get background X offset
  242.      if (token.length() > 10 &&
  243.          token.substring(0,10).equalsIgnoreCase("bgOffsetX=")) {
  244.         bgOffsetX = string2int(token.substring(10));
  245.         continue;
  246.      }
  247.      // get background Y offset
  248.      if (token.length() > 10 &&
  249.          token.substring(0,10).equalsIgnoreCase("bgOffsetY=")) {
  250.         bgOffsetY = string2int(token.substring(10));
  251.         continue;
  252.      }
  253.      // get animation X offset
  254.      if (token.length() > 8 &&
  255.          token.substring(0,8).equalsIgnoreCase("offsetX=")) {
  256.         offsetX = string2int(token.substring(8));
  257.         continue;
  258.      }
  259.      // get animation Y offset
  260.      if (token.length() > 8 &&
  261.          token.substring(0,8).equalsIgnoreCase("offsetY=")) {
  262.         offsetY = string2int(token.substring(8));
  263.         continue;
  264.      }
  265.  
  266.  
  267.      // get color
  268.      if (token.length() > 6 &&
  269.          token.substring(0,6).equalsIgnoreCase("align=")) {
  270.         String alignStr = token.substring(6);
  271.         if (alignStr.equalsIgnoreCase("left"))
  272.            align = LEFT;
  273.         else if (alignStr.equalsIgnoreCase("right"))
  274.            align = RIGHT;
  275.         else
  276.            align = CENTER;
  277.         continue;
  278.      }
  279.  
  280.      // check if integer, if so assume delay value
  281.      boolean isInt = true;
  282.      for (int i=0; i<token.length(); i++) {
  283.         int digit = Character.digit(token.charAt(i), 10);
  284.         if (digit < 0) {
  285.            // not a digit
  286.            isInt = false;
  287.            break;
  288.         }
  289.      }
  290.      if (isInt) {
  291.         if (!gotText)
  292.            showDelay = string2int(token);
  293.         else
  294.            endDelay = string2int(token);
  295.         continue;
  296.      }
  297.      else {
  298.         // assume text string parsed
  299.         if (!gotText) {
  300.            param = token;
  301.            gotText = true;
  302.         }
  303.      }
  304.       }
  305.    }
  306.  
  307.    int string2int(String s)
  308.    {
  309.       try {
  310.      Integer intObj = new Integer(s);
  311.      return intObj.intValue();
  312.       }
  313.       catch (NumberFormatException nfe) {
  314.      return 0;
  315.       }
  316.    }
  317.    
  318. }
  319.