home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-08-06 | 7.5 KB | 319 lines |
- /*
- * Copyright (c) 1995 by Jan Andersson, Torpa Konsult AB.
- *
- * Permission to use, copy, and distribute this software for
- * NON-COMMERCIAL purposes and without fee is hereby granted
- * provided that this copyright notice appears in all copies.
- */
- import java.util.StringTokenizer;
-
- /**
- * Attributes of FunScroll Animations
- *
- * @version 1.1 97/08/06
- * @author Jan Andersson (janne@torpa.se)
- */
- public class FunScrollAttr
- {
- // type of attribute
- static final int TEXT = 1; // text
- static final int IMAGE = 2; // image
-
- // scroll styles:
- static final int NONE = 0; // no scrolling (default)
- static final int LEFT = 1; // scroll left
- static final int RIGHT = 2; // ... right
- static final int UP = 3; // ... up
- static final int DOWN = 4; // ... down
- static final int TYPED = 5; // ... typed (char by char)
- //static final int GROW = 6; // size grow
- //static final int SHRINK = 7; // size expand
- static final int FADE = 8; // .... fade
- static final int UP_LINE = 9; // .... up (line-by-line)
- static final int EXPLODE = 10;// explode (only for endScroll)
-
- // animate styles:
- static final int NORMAL = 0; // normal (default)
- static final int NERVOUS = 1; // "nervous" text
- static final int SINEWAVE = 2; // sine-wave text
- // text draw styles:
- static final int EMBOSS = 1;
- static final int ENGRAVE = 2;
- static final int SHADOW = 3;
- // text line alignment
- static final int CENTER = 0;
-
- int type = TEXT; // attribute type
- String param = ""; // parameter (message line or image)
- String delimiters = "<>"; // used delimiters (default is "<>")
- int startScroll = NONE; // start scroll style
- int endScroll = NONE; // end scroll style
- int showDelay = 0; // show delay
- int endDelay = -1; // end delay
- int style = NORMAL; // animate style
- int drawStyle = NONE; // text draw style
- int align = CENTER; // text line alignment
- String color = null; // text color
- String bgImage = null; // background image
- String bgText = null; // background text
- int bgOffsetX = 0; // X offset, background
- int bgOffsetY = 0; // Y offset, background
- int offsetX = 0; // X offset, animation
- int offsetY = 0; // Y offset, animation
-
- public FunScrollAttr(String line, String delim)
- {
- if (delim != null) {
- // used specified delimiter
- delimiters = delim;
- }
- parse(line);
- }
-
- public int type()
- {
- return type;
- }
-
- public String param()
- {
- return param;
- }
-
- public int startScroll()
- {
- return startScroll;
- }
-
- public int endScroll()
- {
- return endScroll;
- }
-
- public int showDelay()
- {
- return showDelay;
- }
-
- public int endDelay()
- {
- return endDelay;
- }
-
- public int style()
- {
- return style;
- }
-
- public int align()
- {
- return align;
- }
-
- public int drawStyle()
- {
- return drawStyle;
- }
-
- public String color()
- {
- return color;
- }
-
- public String bgImage()
- {
- return bgImage;
- }
-
- public String bgText()
- {
- return bgText;
- }
-
- public int bgOffsetX()
- {
- return bgOffsetX;
- }
-
- public int bgOffsetY()
- {
- return bgOffsetY;
- }
-
- public int offsetX()
- {
- return offsetX;
- }
-
- public int offsetY()
- {
- return offsetY;
- }
-
- void parse(String line)
- {
- StringTokenizer st = new StringTokenizer(line, delimiters);
- boolean gotText = false;
- while (st.hasMoreTokens()) {
- int scroll = -1;
- String token = st.nextToken();
- //System.out.println("token:"+token);
- // get scroll style
- if (token.equalsIgnoreCase("left"))
- scroll = LEFT;
- else if (token.equalsIgnoreCase("right"))
- scroll = RIGHT;
- else if (token.equalsIgnoreCase("up"))
- scroll = UP;
- else if (token.equalsIgnoreCase("down"))
- scroll = DOWN;
- else if (token.equalsIgnoreCase("typed"))
- scroll = TYPED;
- // else if (token.equalsIgnoreCase("grow"))
- // scroll = GROW;
- // else if (token.equalsIgnoreCase("shrink"))
- // scroll = SHRINK;
- else if (token.equalsIgnoreCase("fade"))
- scroll = FADE;
- else if (token.equalsIgnoreCase("up-line"))
- scroll = UP_LINE;
- else if (gotText && token.equalsIgnoreCase("explode"))
- scroll = EXPLODE;
- if (scroll >= 0) {
- if (!gotText)
- startScroll = scroll;
- else
- endScroll = scroll;
- continue;
- }
-
- // get type
- if (token.equalsIgnoreCase("image")) {
- type = IMAGE;
- continue;
- }
-
- // get text style
- if (token.equalsIgnoreCase("nervous")) {
- style = NERVOUS;
- continue;
- }
- if (token.equalsIgnoreCase("sine-wave")) {
- style = SINEWAVE;
- continue;
- }
-
- // get text draw style
- if (token.equalsIgnoreCase("emboss")) {
- drawStyle = EMBOSS;
- continue;
- }
- if (token.equalsIgnoreCase("engrave")) {
- drawStyle = ENGRAVE;
- continue;
- }
- if (token.equalsIgnoreCase("shadow")) {
- drawStyle = SHADOW;
- continue;
- }
-
- // get color
- if (token.length() > 6 &&
- token.substring(0,6).equalsIgnoreCase("color=")) {
- color = token.substring(6);
- continue;
- }
-
- // get background image
- if (token.length() > 8 &&
- token.substring(0,8).equalsIgnoreCase("bgImage=")) {
- bgImage = token.substring(8);
- continue;
- }
-
- // get background text
- if (token.length() > 7 &&
- token.substring(0,7).equalsIgnoreCase("bgText=")) {
- bgText = token.substring(7);
- continue;
- }
-
- // get background X offset
- if (token.length() > 10 &&
- token.substring(0,10).equalsIgnoreCase("bgOffsetX=")) {
- bgOffsetX = string2int(token.substring(10));
- continue;
- }
- // get background Y offset
- if (token.length() > 10 &&
- token.substring(0,10).equalsIgnoreCase("bgOffsetY=")) {
- bgOffsetY = string2int(token.substring(10));
- continue;
- }
- // get animation X offset
- if (token.length() > 8 &&
- token.substring(0,8).equalsIgnoreCase("offsetX=")) {
- offsetX = string2int(token.substring(8));
- continue;
- }
- // get animation Y offset
- if (token.length() > 8 &&
- token.substring(0,8).equalsIgnoreCase("offsetY=")) {
- offsetY = string2int(token.substring(8));
- continue;
- }
-
-
- // get color
- if (token.length() > 6 &&
- token.substring(0,6).equalsIgnoreCase("align=")) {
- String alignStr = token.substring(6);
- if (alignStr.equalsIgnoreCase("left"))
- align = LEFT;
- else if (alignStr.equalsIgnoreCase("right"))
- align = RIGHT;
- else
- align = CENTER;
- continue;
- }
-
- // check if integer, if so assume delay value
- boolean isInt = true;
- for (int i=0; i<token.length(); i++) {
- int digit = Character.digit(token.charAt(i), 10);
- if (digit < 0) {
- // not a digit
- isInt = false;
- break;
- }
- }
- if (isInt) {
- if (!gotText)
- showDelay = string2int(token);
- else
- endDelay = string2int(token);
- continue;
- }
- else {
- // assume text string parsed
- if (!gotText) {
- param = token;
- gotText = true;
- }
- }
- }
- }
-
- int string2int(String s)
- {
- try {
- Integer intObj = new Integer(s);
- return intObj.intValue();
- }
- catch (NumberFormatException nfe) {
- return 0;
- }
- }
-
- }
-