home *** CD-ROM | disk | FTP | other *** search
/ Popular Software (Premium Edition) / mycd.iso / INTERNET / PFRONT98 / DATA.Z / fphover.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-09-26  |  11.4 KB  |  524 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Event;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.MediaTracker;
  11. import java.awt.image.FilteredImageSource;
  12. import java.awt.image.ImageFilter;
  13. import java.awt.image.ImageObserver;
  14. import java.awt.image.ImageProducer;
  15. import java.net.MalformedURLException;
  16. import java.net.URL;
  17.  
  18. public class fphover extends Applet {
  19.    private String m_image = "";
  20.    private String m_hoverImage = "";
  21.    private Color m_bgColor;
  22.    private Color m_color;
  23.    private Color m_hoverColor;
  24.    private String m_effectString;
  25.    private String m_sound;
  26.    private String m_hoverSound;
  27.    private String m_url;
  28.    private String m_target;
  29.    private String m_text;
  30.    private Color m_textColor;
  31.    private String m_textAlign;
  32.    private String m_textVAlign;
  33.    private String m_font;
  34.    private String m_fontStyle;
  35.    private int m_fontSize;
  36.    private final String PARAM_image;
  37.    private final String PARAM_hoverImage;
  38.    private final String PARAM_bgColor;
  39.    private final String PARAM_color;
  40.    private final String PARAM_hoverColor;
  41.    private final String PARAM_effect;
  42.    private final String PARAM_sound;
  43.    private final String PARAM_hoverSound;
  44.    private final String PARAM_url;
  45.    private final String PARAM_target;
  46.    private final String PARAM_text;
  47.    private final String PARAM_textColor;
  48.    private final String PARAM_textAlign;
  49.    private final String PARAM_textVAlign;
  50.    private final String PARAM_font;
  51.    private final String PARAM_fontStyle;
  52.    private final String PARAM_fontSize;
  53.    private int m_effect;
  54.    private Image m_srcImage;
  55.    private Image m_srcHoverImage;
  56.    private AudioClip m_audio;
  57.    private AudioClip m_hoverAudio;
  58.    private URL m_docUrl;
  59.    private int m_hover;
  60.    private int m_textWidth;
  61.    private boolean m_textMask;
  62.    private Image m_textImage;
  63.    private int m_iTextAlign;
  64.    private int m_iTextVAlign;
  65.    private int m_textImageWidth;
  66.    private int m_textImageHeight;
  67.    private boolean m_textImageError;
  68.    private boolean m_srcImageError;
  69.    private boolean m_srcHoverImageError;
  70.    private boolean m_applyEffectWait;
  71.    private FontMetrics m_fm;
  72.    private static final int COLOR = 0;
  73.    private static final int IMAGE = 1;
  74.    private static final int EFFECT = 2;
  75.    private int m_normalType;
  76.    private int m_hoverType;
  77.    private boolean m_noErase;
  78.    private int m_w;
  79.    private int m_h;
  80.    private int m_x;
  81.    private int m_y;
  82.  
  83.    public boolean mouseMove(Event evt, int x, int y) {
  84.       return true;
  85.    }
  86.  
  87.    public void stop() {
  88.    }
  89.  
  90.    public boolean mouseEnter(Event evt, int x, int y) {
  91.       this.m_hover = 1;
  92.       if (this.m_hoverAudio != null) {
  93.          this.m_hoverAudio.play();
  94.       }
  95.  
  96.       ((Applet)this).showStatus(this.m_url);
  97.       if (this.m_normalType != 1 || this.m_hoverType != 1 || !this.m_image.equals(this.m_hoverImage)) {
  98.          ((Component)this).repaint();
  99.       }
  100.  
  101.       return true;
  102.    }
  103.  
  104.    public boolean mouseExit(Event evt, int x, int y) {
  105.       this.m_hover = 0;
  106.       if (this.m_normalType != 1 || this.m_hoverType != 1 || !this.m_image.equals(this.m_hoverImage)) {
  107.          ((Component)this).repaint();
  108.       }
  109.  
  110.       return true;
  111.    }
  112.  
  113.    public void paint(Graphics g) {
  114.       this.getXY();
  115.       if (this.m_hover == 0) {
  116.          if (!this.m_srcImageError) {
  117.             g.drawImage(this.m_srcImage, 0, 0, this);
  118.          }
  119.       } else {
  120.          if (!this.m_srcHoverImageError) {
  121.             g.drawImage(this.m_srcHoverImage, 0, 0, this);
  122.          }
  123.  
  124.          if (this.m_effect == 5) {
  125.             this.m_x += -1;
  126.             this.m_y += -1;
  127.          }
  128.  
  129.          if (this.m_effect == 6) {
  130.             ++this.m_x;
  131.             ++this.m_y;
  132.          }
  133.       }
  134.  
  135.       if (this.m_textMask) {
  136.          if (!this.m_textImageError) {
  137.             g.drawImage(this.m_textImage, this.m_x, this.m_y, this);
  138.          }
  139.       } else {
  140.          g.setColor(this.m_textColor);
  141.          g.drawString(this.m_text, this.m_x, this.m_y);
  142.       }
  143.  
  144.    }
  145.  
  146.    public boolean mouseUp(Event evt, int x, int y) {
  147.       if (!this.m_url.equalsIgnoreCase("") && this.m_docUrl != null) {
  148.          if (this.m_target.equalsIgnoreCase("")) {
  149.             ((Applet)this).getAppletContext().showDocument(this.m_docUrl);
  150.          } else {
  151.             ((Applet)this).getAppletContext().showDocument(this.m_docUrl, this.m_target);
  152.          }
  153.       }
  154.  
  155.       if (this.m_audio != null) {
  156.          this.m_audio.play();
  157.       }
  158.  
  159.       return true;
  160.    }
  161.  
  162.    public String[][] getParameterInfo() {
  163.       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"}};
  164.       return info;
  165.    }
  166.  
  167.    public void destroy() {
  168.    }
  169.  
  170.    public fphover() {
  171.       this.m_bgColor = Color.white;
  172.       this.m_color = Color.white;
  173.       this.m_hoverColor = Color.white;
  174.       this.m_effectString = "";
  175.       this.m_sound = "";
  176.       this.m_hoverSound = "";
  177.       this.m_url = "";
  178.       this.m_target = "";
  179.       this.m_text = "";
  180.       this.m_textColor = Color.black;
  181.       this.m_textAlign = "center";
  182.       this.m_textVAlign = "middle";
  183.       this.m_font = "Dialog";
  184.       this.m_fontStyle = "bold";
  185.       this.m_fontSize = 14;
  186.       this.PARAM_image = "image";
  187.       this.PARAM_hoverImage = "hoverImage";
  188.       this.PARAM_bgColor = "bgColor";
  189.       this.PARAM_color = "color";
  190.       this.PARAM_hoverColor = "hoverColor";
  191.       this.PARAM_effect = "effect";
  192.       this.PARAM_sound = "sound";
  193.       this.PARAM_hoverSound = "hoverSound";
  194.       this.PARAM_url = "url";
  195.       this.PARAM_target = "target";
  196.       this.PARAM_text = "text";
  197.       this.PARAM_textColor = "textColor";
  198.       this.PARAM_textAlign = "textAlign";
  199.       this.PARAM_textVAlign = "textVAlign";
  200.       this.PARAM_font = "font";
  201.       this.PARAM_fontStyle = "fontStyle";
  202.       this.PARAM_fontSize = "fontSize";
  203.       this.m_hoverType = 2;
  204.    }
  205.  
  206.    public void getXY() {
  207.       this.m_w = ((Component)this).size().width;
  208.       this.m_h = ((Component)this).size().height;
  209.       this.m_x = 0;
  210.       this.m_y = 0;
  211.       if (this.m_textMask) {
  212.          if (this.m_textImageWidth < 0 || this.m_textImageHeight < 0) {
  213.             return;
  214.          }
  215.  
  216.          if (this.m_iTextAlign == 0) {
  217.             this.m_x = (this.m_w - this.m_textImageWidth) / 2;
  218.          } else if (this.m_iTextAlign == 1) {
  219.             this.m_x = this.m_w - this.m_textImageWidth;
  220.          }
  221.  
  222.          if (this.m_iTextVAlign == 0) {
  223.             this.m_y = (this.m_h - this.m_textImageHeight) / 2;
  224.          } else if (this.m_iTextVAlign == 1) {
  225.             this.m_y = this.m_h - this.m_textImageHeight;
  226.          }
  227.       } else {
  228.          this.m_x = (this.m_w - this.m_textWidth) / 2;
  229.          this.m_y = (this.m_h + this.m_fm.getAscent() - this.m_fm.getDescent()) / 2;
  230.       }
  231.  
  232.    }
  233.  
  234.    public void update(Graphics g) {
  235.       if (!this.m_noErase) {
  236.          g.clearRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  237.       }
  238.  
  239.       this.paint(g);
  240.    }
  241.  
  242.    public void start() {
  243.    }
  244.  
  245.    public String getAppletInfo() {
  246.       return "Name: fphover\r\n" + "Author: Tom Blumer\r\n" + "Created with Microsoft Visual J++ Version 1.1";
  247.    }
  248.  
  249.    public boolean mouseDown(Event evt, int x, int y) {
  250.       return true;
  251.    }
  252.  
  253.    public void init() {
  254.       String param = ((Applet)this).getParameter("image");
  255.       if (param != null) {
  256.          this.m_image = param;
  257.       }
  258.  
  259.       if (!this.m_image.equalsIgnoreCase("")) {
  260.          this.m_normalType = 1;
  261.       }
  262.  
  263.       param = ((Applet)this).getParameter("hoverImage");
  264.       if (param != null) {
  265.          this.m_hoverImage = param;
  266.       }
  267.  
  268.       if (!this.m_hoverImage.equalsIgnoreCase("")) {
  269.          this.m_hoverType = 1;
  270.       }
  271.  
  272.       param = ((Applet)this).getParameter("bgColor");
  273.       if (param != null) {
  274.          if (param.charAt(0) == '#') {
  275.             param = param.substring(1);
  276.          }
  277.  
  278.          this.m_bgColor = new Color(Integer.parseInt(param, 16));
  279.       }
  280.  
  281.       param = ((Applet)this).getParameter("color");
  282.       if (param != null) {
  283.          if (param.charAt(0) == '#') {
  284.             param = param.substring(1);
  285.          }
  286.  
  287.          this.m_color = new Color(Integer.parseInt(param, 16));
  288.       }
  289.  
  290.       param = ((Applet)this).getParameter("hoverColor");
  291.       if (param != null) {
  292.          if (param.charAt(0) == '#') {
  293.             param = param.substring(1);
  294.          }
  295.  
  296.          this.m_hoverColor = new Color(Integer.parseInt(param, 16));
  297.       }
  298.  
  299.       param = ((Applet)this).getParameter("effect");
  300.       if (param != null) {
  301.          this.m_effectString = param;
  302.       }
  303.  
  304.       this.m_effect = 2;
  305.       if (this.m_effectString.equalsIgnoreCase("fill")) {
  306.          this.m_effect = 0;
  307.       } else if (this.m_effectString.equalsIgnoreCase("average")) {
  308.          this.m_effect = 1;
  309.       } else if (this.m_effectString.equalsIgnoreCase("glow")) {
  310.          this.m_effect = 2;
  311.       } else if (this.m_effectString.equalsIgnoreCase("reverseGlow")) {
  312.          this.m_effect = 3;
  313.       } else if (this.m_effectString.equalsIgnoreCase("lightglow")) {
  314.          this.m_effect = 4;
  315.       } else if (this.m_effectString.equalsIgnoreCase("bevelOut")) {
  316.          this.m_effect = 5;
  317.       } else if (this.m_effectString.equalsIgnoreCase("bevelIn")) {
  318.          this.m_effect = 6;
  319.       }
  320.  
  321.       param = ((Applet)this).getParameter("sound");
  322.       if (param != null) {
  323.          this.m_sound = param;
  324.       }
  325.  
  326.       param = ((Applet)this).getParameter("hoverSound");
  327.       if (param != null) {
  328.          this.m_hoverSound = param;
  329.       }
  330.  
  331.       param = ((Applet)this).getParameter("url");
  332.       if (param != null) {
  333.          this.m_url = param;
  334.       }
  335.  
  336.       param = ((Applet)this).getParameter("target");
  337.       if (param != null) {
  338.          this.m_target = param;
  339.       }
  340.  
  341.       param = ((Applet)this).getParameter("text");
  342.       if (param != null) {
  343.          this.m_text = param;
  344.       }
  345.  
  346.       param = ((Applet)this).getParameter("textColor");
  347.       if (param != null) {
  348.          if (param.charAt(0) == '#') {
  349.             param = param.substring(1);
  350.          }
  351.  
  352.          this.m_textColor = new Color(Integer.parseInt(param, 16));
  353.       }
  354.  
  355.       param = ((Applet)this).getParameter("textAlign");
  356.       if (param != null) {
  357.          this.m_textAlign = param;
  358.       }
  359.  
  360.       this.m_iTextAlign = 0;
  361.       if (this.m_textAlign.equalsIgnoreCase("left")) {
  362.          this.m_iTextAlign = -1;
  363.       } else if (this.m_textAlign.equalsIgnoreCase("right")) {
  364.          this.m_iTextAlign = 1;
  365.       }
  366.  
  367.       param = ((Applet)this).getParameter("textVAlign");
  368.       if (param != null) {
  369.          this.m_textVAlign = param;
  370.       }
  371.  
  372.       this.m_iTextVAlign = 0;
  373.       if (this.m_textVAlign.equalsIgnoreCase("top")) {
  374.          this.m_iTextVAlign = -1;
  375.       } else if (this.m_textVAlign.equalsIgnoreCase("bottom")) {
  376.          this.m_iTextVAlign = 1;
  377.       }
  378.  
  379.       param = ((Applet)this).getParameter("font");
  380.       if (param != null) {
  381.          this.m_font = param;
  382.       }
  383.  
  384.       this.m_textMask = this.m_font.equalsIgnoreCase("") || this.m_font.equalsIgnoreCase("TextMask");
  385.       param = ((Applet)this).getParameter("fontStyle");
  386.       if (param != null) {
  387.          this.m_fontStyle = param;
  388.       }
  389.  
  390.       param = ((Applet)this).getParameter("fontSize");
  391.       if (param != null) {
  392.          this.m_fontSize = Integer.parseInt(param);
  393.       }
  394.  
  395.       ((Component)this).setBackground(this.m_bgColor);
  396.       MediaTracker tracker = new MediaTracker(this);
  397.       if (this.m_textMask) {
  398.          this.m_textImage = ((Applet)this).getImage(((Applet)this).getDocumentBase(), this.m_text);
  399.          tracker.addImage(this.m_textImage, 1);
  400.       } else {
  401.          int nStyle = 0;
  402.          if (this.m_fontStyle.equalsIgnoreCase("bold")) {
  403.             nStyle = 1;
  404.          }
  405.  
  406.          if (this.m_fontStyle.equalsIgnoreCase("italic")) {
  407.             nStyle = 2;
  408.          }
  409.  
  410.          if (this.m_fontStyle.equalsIgnoreCase("bolditalic")) {
  411.             nStyle = 3;
  412.          }
  413.  
  414.          Font font = new Font(this.m_font, nStyle, this.m_fontSize);
  415.          ((Component)this).setFont(font);
  416.          this.m_fm = ((Component)this).getFontMetrics(font);
  417.          this.m_textWidth = this.m_fm.stringWidth(this.m_text);
  418.       }
  419.  
  420.       int w = ((Component)this).size().width;
  421.       int h = ((Component)this).size().height;
  422.       if (this.m_normalType == 1) {
  423.          this.m_srcImage = ((Applet)this).getImage(((Applet)this).getDocumentBase(), this.m_image);
  424.          tracker.addImage(this.m_srcImage, 2);
  425.       } else {
  426.          this.m_srcImage = ((Component)this).createImage(w, h);
  427.          Graphics g = this.m_srcImage.getGraphics();
  428.          g.setColor(this.m_color);
  429.          g.fillRect(0, 0, w, h);
  430.       }
  431.  
  432.       if (this.m_hoverType == 1) {
  433.          this.m_srcHoverImage = ((Applet)this).getImage(((Applet)this).getDocumentBase(), this.m_hoverImage);
  434.          tracker.addImage(this.m_srcHoverImage, 3);
  435.       }
  436.  
  437.       try {
  438.          tracker.waitForAll();
  439.          this.m_textImageError = tracker.isErrorID(1);
  440.          this.m_srcImageError = tracker.isErrorID(2);
  441.          this.m_srcHoverImageError = tracker.isErrorID(3);
  442.       } catch (InterruptedException var17) {
  443.       }
  444.  
  445.       int iw = this.m_srcImage.getWidth(this);
  446.       int ih = this.m_srcImage.getHeight(this);
  447.       int hiw = iw;
  448.       int hih = ih;
  449.       if (this.m_hoverType == 1) {
  450.          hiw = this.m_srcHoverImage.getWidth(this);
  451.          hih = this.m_srcHoverImage.getHeight(this);
  452.       }
  453.  
  454.       if (this.m_textMask) {
  455.          this.m_textImageWidth = this.m_textImage.getWidth(this);
  456.          this.m_textImageHeight = this.m_textImage.getHeight(this);
  457.       }
  458.  
  459.       MediaTracker tracker2 = new MediaTracker(this);
  460.       this.m_applyEffectWait = false;
  461.       if (this.m_textMask && this.m_textColor != Color.black && !this.m_textImageError) {
  462.          this.m_textImage = this.applyEffect(this.m_textImage, 7, this.m_textColor);
  463.          tracker2.addImage(this.m_textImage, 3);
  464.          this.m_applyEffectWait = true;
  465.       }
  466.  
  467.       if (this.m_hoverType == 2) {
  468.          this.m_srcHoverImage = this.applyEffect(this.m_srcImage, this.m_effect, this.m_hoverColor);
  469.          tracker2.addImage(this.m_srcHoverImage, 2);
  470.          this.m_applyEffectWait = true;
  471.       }
  472.  
  473.       if (this.m_applyEffectWait) {
  474.          try {
  475.             tracker2.waitForAll();
  476.          } catch (InterruptedException var16) {
  477.          }
  478.       }
  479.  
  480.       try {
  481.          this.m_docUrl = new URL(((Applet)this).getDocumentBase(), this.m_url);
  482.       } catch (MalformedURLException var15) {
  483.       }
  484.  
  485.       if (!this.m_sound.equalsIgnoreCase("")) {
  486.          this.m_audio = ((Applet)this).getAudioClip(((Applet)this).getDocumentBase(), this.m_sound);
  487.       }
  488.  
  489.       if (!this.m_hoverSound.equalsIgnoreCase("")) {
  490.          this.m_hoverAudio = ((Applet)this).getAudioClip(((Applet)this).getDocumentBase(), this.m_hoverSound);
  491.       }
  492.  
  493.       if (iw == hiw && ih == hih && iw > 0 && ih > 0) {
  494.          this.m_noErase = true;
  495.          Image imageTemp = ((Component)this).createImage(iw, ih);
  496.          Graphics gs = imageTemp.getGraphics();
  497.          gs.setColor(this.m_bgColor);
  498.          gs.fillRect(0, 0, iw, ih);
  499.          gs.drawImage(this.m_srcImage, 0, 0, (ImageObserver)null);
  500.          this.m_srcImage = imageTemp;
  501.          Image hoverImageTemp = ((Component)this).createImage(iw, ih);
  502.          Graphics gh = hoverImageTemp.getGraphics();
  503.          gh.setColor(this.m_bgColor);
  504.          gh.fillRect(0, 0, iw, ih);
  505.          gh.drawImage(this.m_srcHoverImage, 0, 0, (ImageObserver)null);
  506.          this.m_srcHoverImage = hoverImageTemp;
  507.       }
  508.  
  509.    }
  510.  
  511.    public boolean mouseDrag(Event evt, int x, int y) {
  512.       return true;
  513.    }
  514.  
  515.    public Image applyEffect(Image srcImage, int effect, Color color) {
  516.       int w = ((Component)this).size().width;
  517.       int h = ((Component)this).size().height;
  518.       ImageFilter filter = new fphoverx(w, h, color, effect);
  519.       ImageProducer producer = new FilteredImageSource(srcImage.getSource(), filter);
  520.       Image srcNewImage = ((Component)this).createImage(producer);
  521.       return srcNewImage;
  522.    }
  523. }
  524.