home *** CD-ROM | disk | FTP | other *** search
/ Datatid 2000 #1 / Datatid-2000-01.iso / Internet / SPLASH / SPLASH12.EXE / data1.cab / Plugins / _Imaging / Graphics_Button / GraphicsButton.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-12-18  |  4.2 KB  |  167 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.Dimension;
  6. import java.awt.Event;
  7. import java.awt.Graphics;
  8. import java.awt.Image;
  9. import java.net.MalformedURLException;
  10. import java.net.URL;
  11.  
  12. public class GraphicsButton extends Applet {
  13.    Image buttonFace;
  14.    AudioClip clip;
  15.    boolean clicked = false;
  16.    boolean enabled = true;
  17.    // $FF: renamed from: x int
  18.    final int field_0;
  19.    // $FF: renamed from: y int
  20.    final int field_1;
  21.  
  22.    protected final void drawCenteredImage(Graphics var1, int var2, int var3, int var4, int var5) {
  23.       if (this.buttonFace != null) {
  24.          int var6 = (var4 - this.buttonFace.getWidth(this)) / 2;
  25.          int var7 = (var5 - this.buttonFace.getHeight(this)) / 2;
  26.          var1.drawImage(this.buttonFace, var6 > 0 ? var6 + var2 : var2, var7 > 0 ? var7 + var3 : var3, this);
  27.       } else {
  28.          System.out.println("Cannot paint a picture: buttonFace == null");
  29.       }
  30.    }
  31.  
  32.    protected void drawRaisedFrame(Graphics var1) {
  33.       Dimension var2 = ((Component)this).size();
  34.       this.drawCenteredImage(var1, 1, 1, var2.width - 3, var2.height - 3);
  35.       var1.setColor(Color.gray);
  36.       var1.drawLine(var2.width - 2, 0, var2.width - 2, var2.height - 2);
  37.       var1.drawLine(0, var2.height - 2, var2.width - 2, var2.height - 2);
  38.       var1.setColor(Color.white);
  39.       var1.drawLine(0, 0, 0, var2.height - 1);
  40.       var1.drawLine(0, 0, var2.width - 1, 0);
  41.       var1.setColor(Color.black);
  42.       var1.drawLine(var2.width - 1, 0, var2.width - 1, var2.height - 2);
  43.       var1.drawLine(0, var2.height - 1, var2.width - 1, var2.height - 1);
  44.    }
  45.  
  46.    protected void drawIndentedFrame(Graphics var1) {
  47.       Dimension var2 = ((Component)this).size();
  48.       this.drawCenteredImage(var1, 2, 2, var2.width - 3, var2.height - 3);
  49.       var1.setColor(Color.gray);
  50.       var1.drawLine(1, 0, 1, var2.height - 1);
  51.       var1.drawLine(0, 1, var2.width, 1);
  52.       var1.setColor(Color.black);
  53.       var1.drawLine(0, 0, 0, var2.height);
  54.       var1.drawLine(0, 0, var2.width, 0);
  55.       var1.setColor(Color.white);
  56.       var1.drawLine(var2.width - 1, 0, var2.width - 1, var2.height - 1);
  57.       var1.drawLine(0, var2.height - 1, var2.width - 1, var2.height - 1);
  58.    }
  59.  
  60.    public boolean mouseDown(Event var1, int var2, int var3) {
  61.       if (this.enabled) {
  62.          this.clicked = true;
  63.          ((Component)this).repaint();
  64.       }
  65.  
  66.       return true;
  67.    }
  68.  
  69.    // $FF: renamed from: go () void
  70.    protected void method_0() {
  71.       System.out.println("Loading: " + ((Applet)this).getParameter("href"));
  72.  
  73.       URL var1;
  74.       try {
  75.          var1 = new URL(((Applet)this).getDocumentBase(), ((Applet)this).getParameter("href"));
  76.       } catch (MalformedURLException var2) {
  77.          System.out.println("Bad URL:" + ((Applet)this).getParameter("href"));
  78.          ((Applet)this).getAppletContext().showStatus("Cannot load this document");
  79.          return;
  80.       }
  81.  
  82.       if (((Applet)this).getParameter("target") != null) {
  83.          ((Applet)this).getAppletContext().showDocument(var1, ((Applet)this).getParameter("target"));
  84.       } else {
  85.          ((Applet)this).getAppletContext().showDocument(var1);
  86.       }
  87.    }
  88.  
  89.    public boolean mouseUp(Event var1, int var2, int var3) {
  90.       if (this.enabled) {
  91.          this.clicked = false;
  92.          if (((Component)this).inside(var2, var3)) {
  93.             this.method_0();
  94.          }
  95.  
  96.          ((Component)this).repaint();
  97.       }
  98.  
  99.       return true;
  100.    }
  101.  
  102.    public String getAppletInfo() {
  103.       return "GraphicsButton v 1.0.3 by Beno├«t Marchal <bmarchal@acm.com>\r\nCopyright ┬⌐ 1996, Beno├«t Marchal. All Rights Reserved.\nhttp://ourworld.compuserve.com/homepages/bmarchal/";
  104.    }
  105.  
  106.    public String[][] getParameterInfo() {
  107.       String[][] var1 = new String[][]{{"src", "url", "image for button"}, {"href", "url", "url to retrieve on click"}, {"target", "string", "load URL into frame target"}, {"audiotip", "url", "sound when user flies over the button"}, {"tooltip", "string", "help for user (typically description of href)"}};
  108.       return var1;
  109.    }
  110.  
  111.    public boolean mouseEnter(Event var1, int var2, int var3) {
  112.       if (this.clip != null) {
  113.          this.clip.play();
  114.       }
  115.  
  116.       return true;
  117.    }
  118.  
  119.    public boolean mouseMove(Event var1, int var2, int var3) {
  120.       ((Applet)this).getAppletContext().showStatus(((Applet)this).getParameter("Tooltip"));
  121.       return true;
  122.    }
  123.  
  124.    public void update(Graphics var1) {
  125.       this.paint(var1);
  126.    }
  127.  
  128.    public void init() {
  129.       this.buttonFace = ((Applet)this).getImage(((Applet)this).getDocumentBase(), ((Applet)this).getParameter("src"));
  130.       if (((Applet)this).getParameter("AudioTip") != null) {
  131.          this.clip = ((Applet)this).getAudioClip(((Applet)this).getDocumentBase(), ((Applet)this).getParameter("AudioTip"));
  132.       } else {
  133.          this.clip = null;
  134.       }
  135.  
  136.       this.enabled = ((Applet)this).getParameter("href") != null;
  137.    }
  138.  
  139.    public void stop() {
  140.       if (this.clip != null) {
  141.          this.clip.stop();
  142.       }
  143.  
  144.    }
  145.  
  146.    public void destroy() {
  147.       this.buttonFace = null;
  148.       this.clip = null;
  149.    }
  150.  
  151.    public void paint(Graphics var1) {
  152.       Image var2 = ((Component)this).createImage(((Component)this).size().width, ((Component)this).size().height);
  153.       Graphics var3 = var2.getGraphics();
  154.       var3.setColor(Color.lightGray);
  155.       var3.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  156.       if (this.clicked && this.enabled) {
  157.          this.drawIndentedFrame(var3);
  158.       } else {
  159.          this.drawRaisedFrame(var3);
  160.       }
  161.  
  162.       var1.drawImage(var2, 0, 0, this);
  163.       Object var5 = null;
  164.       Object var4 = null;
  165.    }
  166. }
  167.