001: /* Area.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: Tue Mar 28 00:27:29 2006, Created by tomyeh
010: }}IS_NOTE
011:
012: Copyright (C) 2006 Potix Corporation. All Rights Reserved.
013:
014: {{IS_RIGHT
015: This program is distributed under GPL Version 2.0 in the hope that
016: it will be useful, but WITHOUT ANY WARRANTY.
017: }}IS_RIGHT
018: */
019: package org.zkoss.zul;
020:
021: import org.zkoss.lang.Objects;
022: import org.zkoss.xml.HTMLs;
023:
024: import org.zkoss.zk.ui.Component;
025: import org.zkoss.zk.ui.AbstractComponent;
026: import org.zkoss.zk.ui.UiException;
027: import org.zkoss.zk.ui.WrongValueException;
028:
029: /**
030: * An area of a {@link Imagemap}.
031: *
032: * @author tomyeh
033: */
034: public class Area extends AbstractComponent {
035: private String _shape;
036: private String _coords;
037: private String _tooltiptext;
038:
039: public Area() {
040: }
041:
042: public Area(String coords) {
043: setCoords(coords);
044: }
045:
046: /** Returns the shape of this area.
047: * <p>Default: null (means rectangle).
048: */
049: public final String getShape() {
050: return _shape;
051: }
052:
053: /** Sets the shape of this area.
054: *
055: * @exception WrongValueException if shape is not one of
056: * null, "rect", "rectangle", "circle", "circ", "ploygon", and "poly".
057: */
058: public final void setShape(String shape) throws WrongValueException {
059: if (shape != null)
060: if (shape.length() == 0)
061: shape = null;
062: else if (!"rect".equals(shape)
063: && !"rectangle".equals(shape)
064: && !"circle".equals(shape) && !"circ".equals(shape)
065: && !"polygon".equals(shape)
066: && !"poly".equals(shape))
067: throw new WrongValueException("Unknown shape: " + shape);
068: if (!Objects.equals(shape, _shape)) {
069: _shape = shape;
070: smartUpdate("shape", _shape);
071: }
072: }
073:
074: /** Returns the coordination of this area.
075: */
076: public final String getCoords() {
077: return _coords;
078: }
079:
080: /** Sets the coords of this area.
081: * Its content depends on {@link #getShape}:
082: * <dl>
083: * <dt>circle</dt>
084: * <dd>coords="x,y,r"</dd>
085: * <dt>polygon</dt>
086: * <dd>coords="x1,y1,x2,y2,x3,y3..."<br/>
087: * The polygon is automatically closed, so it is not necessary to repeat
088: * the first coordination.</dd>
089: * <dt>rectangle</dt>
090: * <dd>coords="x1,y1,x2,y2"</dd>
091: * </dl>
092: *
093: * <p>Note: (0, 0) is the upper-left corner.
094: */
095: public final void setCoords(String coords) {
096: if (coords != null && coords.length() == 0)
097: coords = null;
098: if (!Objects.equals(coords, _coords)) {
099: _coords = coords;
100: smartUpdate("coords", _coords);
101: }
102: }
103:
104: /** Returns the text as the tooltip.
105: * <p>Default: null.
106: */
107: public String getTooltiptext() {
108: return _tooltiptext;
109: }
110:
111: /** Sets the text as the tooltip.
112: */
113: public void setTooltiptext(String tooltiptext) {
114: if (tooltiptext != null && tooltiptext.length() == 0)
115: tooltiptext = null;
116: if (!Objects.equals(_tooltiptext, tooltiptext)) {
117: _tooltiptext = tooltiptext;
118: smartUpdate("title", _tooltiptext);
119: }
120: }
121:
122: /** Returns the attributes for generating the HTML tag; never return null.
123: *
124: * <p>Used only by component developers.
125: */
126: public String getOuterAttrs() {
127: final StringBuffer sb = new StringBuffer(64).append(
128: " href=\"javascript:zkArea.onclick('")
129: .append(getUuid()).append("')\"");
130: HTMLs.appendAttribute(sb, "shape", _shape);
131: HTMLs.appendAttribute(sb, "coords", _coords);
132: HTMLs.appendAttribute(sb, "title", _tooltiptext);
133: HTMLs.appendAttribute(sb, "z.aid", getId());
134: return sb.toString();
135: }
136:
137: //-- super --//
138: public void setId(String id) {
139: final String old = getId();
140: super .setId(id);
141:
142: id = getId();
143: if (!old.equals(id))
144: smartUpdate("z.aid", id);
145: }
146:
147: public void setParent(Component parent) {
148: if (parent != null && !(parent instanceof Imagemap))
149: throw new UiException(
150: "Area's parent must be imagemap, not " + parent);
151: super.setParent(parent);
152: }
153: }
|