1 36 37 40 41 import java.awt.Graphics ; 42 import java.awt.Image ; 43 import java.net.URL ; 44 import java.net.MalformedURLException ; 45 46 55 class HrefButtonArea extends ImageMapArea { 56 57 URL anchor; 58 59 Image upImage; 60 61 Image downImage; 62 63 boolean pressed = false; 64 65 int border = 5; 66 67 72 public void handleArg(String arg) { 73 try { 74 anchor = new URL (parent.getDocumentBase(), arg); 75 } catch (MalformedURLException e) { 76 anchor = null; 77 } 78 if (border * 2 > W || border * 2 > H) { 79 border = Math.min(W, H) / 2; 80 } 81 } 82 83 public void makeImages() { 84 upImage = parent.getHighlight(X, Y, W, H, 85 new ButtonFilter(false, 86 parent.hlpercent, 87 border, W, H)); 88 downImage = parent.getHighlight(X, Y, W, H, 89 new ButtonFilter(true, 90 parent.hlpercent, 91 border, W, H)); 92 } 93 94 public boolean imageUpdate(Image img, int infoflags, 95 int x, int y, int width, int height) { 96 if (img == (pressed ? downImage : upImage)) { 97 return parent.imageUpdate(img, infoflags, x + X, y + Y, 98 width, height); 99 } else { 100 return (img == downImage || img == upImage); 101 } 102 } 103 104 108 public boolean isTerminal() { 109 return true; 110 } 111 112 116 public void highlight(Graphics g) { 117 if (entered) { 118 g.drawImage(pressed ? downImage : upImage, X, Y, this); 119 } 120 } 121 122 public void enter() { 123 showStatus((anchor != null) 124 ? "Go To " + anchor.toExternalForm() 125 : null); 126 repaint(); 127 } 128 129 public void exit() { 130 showStatus(null); 131 repaint(); 132 } 133 134 138 public boolean press() { 139 pressed = true; 140 repaint(); 141 return true; 142 } 143 144 148 public boolean lift(int x, int y) { 149 pressed = false; 150 repaint(); 151 if (inside(x, y) && anchor != null) { 152 showDocument(anchor); 153 } 154 return true; 155 } 156 } 157 158 | Popular Tags |