home *** CD-ROM | disk | FTP | other *** search
- import java.awt.Component;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.Rectangle;
- import java.util.StringTokenizer;
-
- public final class TextEvent extends AnimationEvent {
- private int m_textWidth;
- private int m_textHeight;
- private int m_textDescent;
- private int m_textAscent;
- private Font m_font;
- private String m_text;
- private int m_position = 0;
- private int m_direction = 0;
- private int m_yPos;
-
- public void drawFrame(Graphics g) {
- int x = 0;
- if (this.m_direction == 0) {
- x = (int)((long)(-this.m_textWidth) + super.m_xOffset / 16L);
- } else {
- x = (int)((long)super.m_animation.m_size.width - super.m_xOffset / 16L);
- }
-
- g.setColor(super.m_colour);
- g.setFont(this.m_font);
- g.drawString(this.m_text, x, this.m_yPos);
- }
-
- public void initFromParams(String params) {
- super.initFromParams(params);
- StringTokenizer st = new StringTokenizer(params, ";");
- String szToken = st.nextToken();
- int nColon = szToken.indexOf(58);
- String fontName = "ARIAL";
- int fontSize = 72;
- int fontStyle = 0;
- if (nColon != -1) {
- String szName = szToken.substring(0, nColon).toUpperCase();
- String szValue = szToken.substring(nColon + 1);
- if (!szName.equals("TYPE") || !szValue.equals("TEXT")) {
- return;
- }
- }
-
- while(st.hasMoreTokens()) {
- szToken = st.nextToken();
- nColon = szToken.indexOf(58);
- if (nColon != -1) {
- String var17 = szToken.substring(0, nColon).toUpperCase();
- String var18 = szToken.substring(nColon + 1);
- if (var17.equals("TEXT")) {
- this.m_text = var18;
- } else if (var17.equals("FONT")) {
- fontName = var18;
- } else if (var17.equals("STYLE")) {
- if (var18.equals("BOLD")) {
- ++fontStyle;
- } else if (var18.equals("ITALIC")) {
- fontStyle += 2;
- } else if (var18.equals("BOLDITALIC")) {
- fontStyle += 3;
- }
- } else if (var17.equals("SIZE")) {
- fontSize = Integer.valueOf(var18);
- } else if (var17.equals("POSITION")) {
- if (var18.equals("TOP")) {
- this.m_position = 0;
- } else if (var18.equals("MIDDLE")) {
- this.m_position = 1;
- } else if (var18.equals("BOTTOM")) {
- this.m_position = 2;
- }
- } else if (var17.equals("DIRECTION")) {
- if (var18.equals("RIGHTWARDS")) {
- this.m_direction = 0;
- } else if (var18.equals("LEFTWARDS")) {
- this.m_direction = 1;
- }
- }
- }
- }
-
- this.m_font = new Font(fontName, fontStyle, fontSize);
- Image imTemp = super.m_component.createImage(1, 1);
- Graphics grTemp = imTemp.getGraphics();
- grTemp.setFont(this.m_font);
- FontMetrics fm = grTemp.getFontMetrics();
- this.m_textWidth = fm.stringWidth(this.m_text);
- this.m_textAscent = fm.getMaxAscent();
- this.m_textDescent = fm.getMaxDescent();
- if (this.m_position == 0) {
- this.m_yPos = this.m_textAscent;
- } else if (this.m_position == 1) {
- this.m_yPos = this.m_textAscent + (super.m_animation.m_size.height - this.m_textAscent - this.m_textDescent) / 2;
- } else if (this.m_position == 2) {
- this.m_yPos = super.m_animation.m_size.height - this.m_textDescent;
- }
-
- grTemp.dispose();
- }
-
- public TextEvent(Component component, Animation anim) {
- super(component, anim);
- }
-
- public String getUrl(int mx, int my) {
- int x = 0;
- int y = 0;
- if (this.m_direction == 0) {
- x = (int)((long)(-this.m_textWidth) + super.m_xOffset / 16L);
- } else {
- x = (int)((long)super.m_animation.m_size.width - super.m_xOffset / 16L);
- }
-
- if (this.m_position == 0) {
- y = 0;
- } else if (this.m_position == 1) {
- y = (super.m_animation.m_size.height - this.m_textAscent - this.m_textDescent) / 2;
- } else if (this.m_position == 2) {
- y = super.m_animation.m_size.height - this.m_textAscent - this.m_textDescent;
- }
-
- Rectangle rect = new Rectangle(x, y, this.m_textWidth, this.m_textAscent + this.m_textDescent);
- return rect.inside(mx, my) ? super.m_url : null;
- }
-
- public void incFrame() {
- super.incFrame();
- int x = 0;
- if (this.m_direction == 0) {
- x = (int)((long)(-this.m_textWidth) + super.m_xOffset / 16L);
- if (x > super.m_animation.m_size.width) {
- super.m_xOffset = 0L;
- }
- } else {
- x = (int)((long)super.m_animation.m_size.width - super.m_xOffset / 16L);
- if (x < -this.m_textWidth) {
- super.m_xOffset = 0L;
- }
- }
-
- }
- }
-