01: /* Imagemap.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Tue Mar 28 00:25:48 2006, Created by tomyeh
10: }}IS_NOTE
11:
12: Copyright (C) 2006 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.zul;
20:
21: import org.zkoss.zk.ui.Component;
22: import org.zkoss.zk.ui.UiException;
23:
24: /**
25: * An image map.
26: *
27: * <p>There are two ways to use Imagemap:</p>
28: *
29: * <ol>
30: * <li>Listen to the onClick event, which is an instance of
31: * {@link org.zkoss.zk.ui.event.MouseEvent}. Then, you could call
32: * getX() and getY() to retrieve where user has clicked.</li>
33: * <li>Assign one or multiple of {@link Area} as its children.
34: * Then, listen to the onClick event, and use
35: * {@link org.zkoss.zk.ui.event.MouseEvent#getArea} to retrieve
36: * which area is clicked.</li>
37: * </ol>
38: *
39: * <p>Note: IE 5.5/6 (not 7) has a bug that failed to render PNG with
40: * alpha transparency. See http://homepage.ntlworld.com/bobosola/index.htm for details.
41: * Thus, if you want to display such image, you have to use the alphafix mold.
42: * <code><imagemap mold="alphafix"/></code>
43: *
44: * @author tomyeh
45: */
46: public class Imagemap extends Image {
47: //-- super --//
48: public String getOuterAttrs() {
49: //Imagemap handles onclick by itself, so don't generate z.lfclk
50: final String attrs = super .getOuterAttrs();
51: final String attrnm = " z.lfclk=";
52: final int j = attrs.indexOf(attrnm);
53: if (j < 0)
54: return attrs;
55: int k = attrs.indexOf('"', j + attrnm.length());
56: assert k > 0 : attrs;
57: k = attrs.indexOf('"', k + 1);
58: assert k > 0 : attrs;
59: return attrs.substring(0, j) + attrs.substring(k + 1);
60: }
61:
62: /** Default: childable.
63: */
64: public boolean isChildable() {
65: return true;
66: }
67:
68: public boolean insertBefore(Component newChild, Component refChild) {
69: if (!(newChild instanceof Area))
70: throw new UiException("Unsupported child for imagemap: "
71: + newChild);
72: return super.insertBefore(newChild, refChild);
73: }
74: }
|