home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.applet.AudioClip;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Event;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.MediaTracker;
- import java.awt.image.FilteredImageSource;
- import java.awt.image.ImageFilter;
- import java.awt.image.ImageObserver;
- import java.awt.image.ImageProducer;
- import java.net.MalformedURLException;
- import java.net.URL;
-
- public class fphover extends Applet {
- private String m_image = "";
- private String m_hoverImage = "";
- private Color m_bgColor;
- private Color m_color;
- private Color m_hoverColor;
- private String m_effectString;
- private String m_sound;
- private String m_hoverSound;
- private String m_url;
- private String m_target;
- private String m_text;
- private Color m_textColor;
- private String m_textAlign;
- private String m_textVAlign;
- private String m_font;
- private String m_fontStyle;
- private int m_fontSize;
- private final String PARAM_image;
- private final String PARAM_hoverImage;
- private final String PARAM_bgColor;
- private final String PARAM_color;
- private final String PARAM_hoverColor;
- private final String PARAM_effect;
- private final String PARAM_sound;
- private final String PARAM_hoverSound;
- private final String PARAM_url;
- private final String PARAM_target;
- private final String PARAM_text;
- private final String PARAM_textColor;
- private final String PARAM_textAlign;
- private final String PARAM_textVAlign;
- private final String PARAM_font;
- private final String PARAM_fontStyle;
- private final String PARAM_fontSize;
- private int m_effect;
- private Image m_srcImage;
- private Image m_srcHoverImage;
- private AudioClip m_audio;
- private AudioClip m_hoverAudio;
- private URL m_docUrl;
- private int m_hover;
- private int m_textWidth;
- private boolean m_textMask;
- private Image m_textImage;
- private int m_iTextAlign;
- private int m_iTextVAlign;
- private int m_textImageWidth;
- private int m_textImageHeight;
- private boolean m_textImageError;
- private boolean m_srcImageError;
- private boolean m_srcHoverImageError;
- private boolean m_applyEffectWait;
- private FontMetrics m_fm;
- private static final int COLOR = 0;
- private static final int IMAGE = 1;
- private static final int EFFECT = 2;
- private int m_normalType;
- private int m_hoverType;
- private boolean m_noErase;
- private int m_w;
- private int m_h;
- private int m_x;
- private int m_y;
-
- public boolean mouseMove(Event evt, int x, int y) {
- return true;
- }
-
- public void stop() {
- }
-
- public boolean mouseEnter(Event evt, int x, int y) {
- this.m_hover = 1;
- if (this.m_hoverAudio != null) {
- this.m_hoverAudio.play();
- }
-
- ((Applet)this).showStatus(this.m_url);
- if (this.m_normalType != 1 || this.m_hoverType != 1 || !this.m_image.equals(this.m_hoverImage)) {
- ((Component)this).repaint();
- }
-
- return true;
- }
-
- public boolean mouseExit(Event evt, int x, int y) {
- this.m_hover = 0;
- if (this.m_normalType != 1 || this.m_hoverType != 1 || !this.m_image.equals(this.m_hoverImage)) {
- ((Component)this).repaint();
- }
-
- return true;
- }
-
- public void paint(Graphics g) {
- this.getXY();
- if (this.m_hover == 0) {
- if (!this.m_srcImageError) {
- g.drawImage(this.m_srcImage, 0, 0, this);
- }
- } else {
- if (!this.m_srcHoverImageError) {
- g.drawImage(this.m_srcHoverImage, 0, 0, this);
- }
-
- if (this.m_effect == 5) {
- this.m_x += -1;
- this.m_y += -1;
- }
-
- if (this.m_effect == 6) {
- ++this.m_x;
- ++this.m_y;
- }
- }
-
- if (this.m_textMask) {
- if (!this.m_textImageError) {
- g.drawImage(this.m_textImage, this.m_x, this.m_y, this);
- }
- } else {
- g.setColor(this.m_textColor);
- g.drawString(this.m_text, this.m_x, this.m_y);
- }
-
- }
-
- public boolean mouseUp(Event evt, int x, int y) {
- if (!this.m_url.equalsIgnoreCase("") && this.m_docUrl != null) {
- if (this.m_target.equalsIgnoreCase("")) {
- ((Applet)this).getAppletContext().showDocument(this.m_docUrl);
- } else {
- ((Applet)this).getAppletContext().showDocument(this.m_docUrl, this.m_target);
- }
- }
-
- if (this.m_audio != null) {
- this.m_audio.play();
- }
-
- return true;
- }
-
- public String[][] getParameterInfo() {
- String[][] info = new String[][]{{"image", "String", "Normal button image"}, {"hoverImage", "String", "Hover button image"}, {"bgColor", "int", "Background color"}, {"color", "int", "Normal color"}, {"hoverColor", "int", "Hover color"}, {"effect", "int", "Effect for hover image"}, {"sound", "String", "Sound Url"}, {"hoverSound", "String", "Hover sound Url"}, {"url", "String", "Url"}, {"target", "String", "Target frame"}, {"text", "String", "Text"}, {"textColor", "int", "Text color"}, {"textAlign", "String", "Text alignment"}, {"textVAlign", "String", "Text vertical alignment"}, {"font", "String", "Font"}, {"fontStyle", "String", "Font style"}, {"fontSize", "int", "Font size in points"}};
- return info;
- }
-
- public void destroy() {
- }
-
- public fphover() {
- this.m_bgColor = Color.white;
- this.m_color = Color.white;
- this.m_hoverColor = Color.white;
- this.m_effectString = "";
- this.m_sound = "";
- this.m_hoverSound = "";
- this.m_url = "";
- this.m_target = "";
- this.m_text = "";
- this.m_textColor = Color.black;
- this.m_textAlign = "center";
- this.m_textVAlign = "middle";
- this.m_font = "Dialog";
- this.m_fontStyle = "bold";
- this.m_fontSize = 14;
- this.PARAM_image = "image";
- this.PARAM_hoverImage = "hoverImage";
- this.PARAM_bgColor = "bgColor";
- this.PARAM_color = "color";
- this.PARAM_hoverColor = "hoverColor";
- this.PARAM_effect = "effect";
- this.PARAM_sound = "sound";
- this.PARAM_hoverSound = "hoverSound";
- this.PARAM_url = "url";
- this.PARAM_target = "target";
- this.PARAM_text = "text";
- this.PARAM_textColor = "textColor";
- this.PARAM_textAlign = "textAlign";
- this.PARAM_textVAlign = "textVAlign";
- this.PARAM_font = "font";
- this.PARAM_fontStyle = "fontStyle";
- this.PARAM_fontSize = "fontSize";
- this.m_hoverType = 2;
- }
-
- public void getXY() {
- this.m_w = ((Component)this).size().width;
- this.m_h = ((Component)this).size().height;
- this.m_x = 0;
- this.m_y = 0;
- if (this.m_textMask) {
- if (this.m_textImageWidth < 0 || this.m_textImageHeight < 0) {
- return;
- }
-
- if (this.m_iTextAlign == 0) {
- this.m_x = (this.m_w - this.m_textImageWidth) / 2;
- } else if (this.m_iTextAlign == 1) {
- this.m_x = this.m_w - this.m_textImageWidth;
- }
-
- if (this.m_iTextVAlign == 0) {
- this.m_y = (this.m_h - this.m_textImageHeight) / 2;
- } else if (this.m_iTextVAlign == 1) {
- this.m_y = this.m_h - this.m_textImageHeight;
- }
- } else {
- this.m_x = (this.m_w - this.m_textWidth) / 2;
- this.m_y = (this.m_h + this.m_fm.getAscent() - this.m_fm.getDescent()) / 2;
- }
-
- }
-
- public void update(Graphics g) {
- if (!this.m_noErase) {
- g.clearRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
- }
-
- this.paint(g);
- }
-
- public void start() {
- }
-
- public String getAppletInfo() {
- return "Name: fphover\r\n" + "Author: Tom Blumer\r\n" + "Created with Microsoft Visual J++ Version 1.1";
- }
-
- public boolean mouseDown(Event evt, int x, int y) {
- return true;
- }
-
- public void init() {
- String param = ((Applet)this).getParameter("image");
- if (param != null) {
- this.m_image = param;
- }
-
- if (!this.m_image.equalsIgnoreCase("")) {
- this.m_normalType = 1;
- }
-
- param = ((Applet)this).getParameter("hoverImage");
- if (param != null) {
- this.m_hoverImage = param;
- }
-
- if (!this.m_hoverImage.equalsIgnoreCase("")) {
- this.m_hoverType = 1;
- }
-
- param = ((Applet)this).getParameter("bgColor");
- if (param != null) {
- if (param.charAt(0) == '#') {
- param = param.substring(1);
- }
-
- this.m_bgColor = new Color(Integer.parseInt(param, 16));
- }
-
- param = ((Applet)this).getParameter("color");
- if (param != null) {
- if (param.charAt(0) == '#') {
- param = param.substring(1);
- }
-
- this.m_color = new Color(Integer.parseInt(param, 16));
- }
-
- param = ((Applet)this).getParameter("hoverColor");
- if (param != null) {
- if (param.charAt(0) == '#') {
- param = param.substring(1);
- }
-
- this.m_hoverColor = new Color(Integer.parseInt(param, 16));
- }
-
- param = ((Applet)this).getParameter("effect");
- if (param != null) {
- this.m_effectString = param;
- }
-
- this.m_effect = 2;
- if (this.m_effectString.equalsIgnoreCase("fill")) {
- this.m_effect = 0;
- } else if (this.m_effectString.equalsIgnoreCase("average")) {
- this.m_effect = 1;
- } else if (this.m_effectString.equalsIgnoreCase("glow")) {
- this.m_effect = 2;
- } else if (this.m_effectString.equalsIgnoreCase("reverseGlow")) {
- this.m_effect = 3;
- } else if (this.m_effectString.equalsIgnoreCase("lightglow")) {
- this.m_effect = 4;
- } else if (this.m_effectString.equalsIgnoreCase("bevelOut")) {
- this.m_effect = 5;
- } else if (this.m_effectString.equalsIgnoreCase("bevelIn")) {
- this.m_effect = 6;
- }
-
- param = ((Applet)this).getParameter("sound");
- if (param != null) {
- this.m_sound = param;
- }
-
- param = ((Applet)this).getParameter("hoverSound");
- if (param != null) {
- this.m_hoverSound = param;
- }
-
- param = ((Applet)this).getParameter("url");
- if (param != null) {
- this.m_url = param;
- }
-
- param = ((Applet)this).getParameter("target");
- if (param != null) {
- this.m_target = param;
- }
-
- param = ((Applet)this).getParameter("text");
- if (param != null) {
- this.m_text = param;
- }
-
- param = ((Applet)this).getParameter("textColor");
- if (param != null) {
- if (param.charAt(0) == '#') {
- param = param.substring(1);
- }
-
- this.m_textColor = new Color(Integer.parseInt(param, 16));
- }
-
- param = ((Applet)this).getParameter("textAlign");
- if (param != null) {
- this.m_textAlign = param;
- }
-
- this.m_iTextAlign = 0;
- if (this.m_textAlign.equalsIgnoreCase("left")) {
- this.m_iTextAlign = -1;
- } else if (this.m_textAlign.equalsIgnoreCase("right")) {
- this.m_iTextAlign = 1;
- }
-
- param = ((Applet)this).getParameter("textVAlign");
- if (param != null) {
- this.m_textVAlign = param;
- }
-
- this.m_iTextVAlign = 0;
- if (this.m_textVAlign.equalsIgnoreCase("top")) {
- this.m_iTextVAlign = -1;
- } else if (this.m_textVAlign.equalsIgnoreCase("bottom")) {
- this.m_iTextVAlign = 1;
- }
-
- param = ((Applet)this).getParameter("font");
- if (param != null) {
- this.m_font = param;
- }
-
- this.m_textMask = this.m_font.equalsIgnoreCase("") || this.m_font.equalsIgnoreCase("TextMask");
- param = ((Applet)this).getParameter("fontStyle");
- if (param != null) {
- this.m_fontStyle = param;
- }
-
- param = ((Applet)this).getParameter("fontSize");
- if (param != null) {
- this.m_fontSize = Integer.parseInt(param);
- }
-
- ((Component)this).setBackground(this.m_bgColor);
- MediaTracker tracker = new MediaTracker(this);
- if (this.m_textMask) {
- this.m_textImage = ((Applet)this).getImage(((Applet)this).getDocumentBase(), this.m_text);
- tracker.addImage(this.m_textImage, 1);
- } else {
- int nStyle = 0;
- if (this.m_fontStyle.equalsIgnoreCase("bold")) {
- nStyle = 1;
- }
-
- if (this.m_fontStyle.equalsIgnoreCase("italic")) {
- nStyle = 2;
- }
-
- if (this.m_fontStyle.equalsIgnoreCase("bolditalic")) {
- nStyle = 3;
- }
-
- Font font = new Font(this.m_font, nStyle, this.m_fontSize);
- ((Component)this).setFont(font);
- this.m_fm = ((Component)this).getFontMetrics(font);
- this.m_textWidth = this.m_fm.stringWidth(this.m_text);
- }
-
- int w = ((Component)this).size().width;
- int h = ((Component)this).size().height;
- if (this.m_normalType == 1) {
- this.m_srcImage = ((Applet)this).getImage(((Applet)this).getDocumentBase(), this.m_image);
- tracker.addImage(this.m_srcImage, 2);
- } else {
- this.m_srcImage = ((Component)this).createImage(w, h);
- Graphics g = this.m_srcImage.getGraphics();
- g.setColor(this.m_color);
- g.fillRect(0, 0, w, h);
- }
-
- if (this.m_hoverType == 1) {
- this.m_srcHoverImage = ((Applet)this).getImage(((Applet)this).getDocumentBase(), this.m_hoverImage);
- tracker.addImage(this.m_srcHoverImage, 3);
- }
-
- try {
- tracker.waitForAll();
- this.m_textImageError = tracker.isErrorID(1);
- this.m_srcImageError = tracker.isErrorID(2);
- this.m_srcHoverImageError = tracker.isErrorID(3);
- } catch (InterruptedException var17) {
- }
-
- int iw = this.m_srcImage.getWidth(this);
- int ih = this.m_srcImage.getHeight(this);
- int hiw = iw;
- int hih = ih;
- if (this.m_hoverType == 1) {
- hiw = this.m_srcHoverImage.getWidth(this);
- hih = this.m_srcHoverImage.getHeight(this);
- }
-
- if (this.m_textMask) {
- this.m_textImageWidth = this.m_textImage.getWidth(this);
- this.m_textImageHeight = this.m_textImage.getHeight(this);
- }
-
- MediaTracker tracker2 = new MediaTracker(this);
- this.m_applyEffectWait = false;
- if (this.m_textMask && this.m_textColor != Color.black && !this.m_textImageError) {
- this.m_textImage = this.applyEffect(this.m_textImage, 7, this.m_textColor);
- tracker2.addImage(this.m_textImage, 3);
- this.m_applyEffectWait = true;
- }
-
- if (this.m_hoverType == 2) {
- this.m_srcHoverImage = this.applyEffect(this.m_srcImage, this.m_effect, this.m_hoverColor);
- tracker2.addImage(this.m_srcHoverImage, 2);
- this.m_applyEffectWait = true;
- }
-
- if (this.m_applyEffectWait) {
- try {
- tracker2.waitForAll();
- } catch (InterruptedException var16) {
- }
- }
-
- try {
- this.m_docUrl = new URL(((Applet)this).getDocumentBase(), this.m_url);
- } catch (MalformedURLException var15) {
- }
-
- if (!this.m_sound.equalsIgnoreCase("")) {
- this.m_audio = ((Applet)this).getAudioClip(((Applet)this).getDocumentBase(), this.m_sound);
- }
-
- if (!this.m_hoverSound.equalsIgnoreCase("")) {
- this.m_hoverAudio = ((Applet)this).getAudioClip(((Applet)this).getDocumentBase(), this.m_hoverSound);
- }
-
- if (iw == hiw && ih == hih && iw > 0 && ih > 0) {
- this.m_noErase = true;
- Image imageTemp = ((Component)this).createImage(iw, ih);
- Graphics gs = imageTemp.getGraphics();
- gs.setColor(this.m_bgColor);
- gs.fillRect(0, 0, iw, ih);
- gs.drawImage(this.m_srcImage, 0, 0, (ImageObserver)null);
- this.m_srcImage = imageTemp;
- Image hoverImageTemp = ((Component)this).createImage(iw, ih);
- Graphics gh = hoverImageTemp.getGraphics();
- gh.setColor(this.m_bgColor);
- gh.fillRect(0, 0, iw, ih);
- gh.drawImage(this.m_srcHoverImage, 0, 0, (ImageObserver)null);
- this.m_srcHoverImage = hoverImageTemp;
- }
-
- }
-
- public boolean mouseDrag(Event evt, int x, int y) {
- return true;
- }
-
- public Image applyEffect(Image srcImage, int effect, Color color) {
- int w = ((Component)this).size().width;
- int h = ((Component)this).size().height;
- ImageFilter filter = new fphoverx(w, h, color, effect);
- ImageProducer producer = new FilteredImageSource(srcImage.getSource(), filter);
- Image srcNewImage = ((Component)this).createImage(producer);
- return srcNewImage;
- }
- }
-