001: /* Fisheyelist.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: Thu Dec 29 20:47:54 2005, Created by tomyeh
010: }}IS_NOTE
011:
012: Copyright (C) 2005 Potix Corporation. All Rights Reserved.
013:
014: {{IS_RIGHT
015: }}IS_RIGHT
016: */
017: package org.zkforge.dojo;
018:
019: import org.zkoss.lang.Objects;
020: import org.zkoss.xml.HTMLs;
021:
022: import org.zkoss.zk.ui.Component;
023: import org.zkoss.zk.ui.UiException;
024: import org.zkoss.zk.ui.WrongValueException;
025:
026: import org.zkforge.dojo.impl.DojoComponent;
027:
028: /**
029: * A fisheye list is a list of {@link Fisheyeitem} that allows user to
030: * select an item easily.
031: *
032: * @author tomyeh
033: * @version $Revision: 1.9 $ $Date: 2006/03/17 10:36:24 $
034: */
035: public class Fisheyelist extends DojoComponent {
036: private int _itemwd = 50, _itemhgh = 50, _itemmaxwd = 200,
037: _itemmaxhgh = 200, _itemPadding = 10;
038: private String _orient = "horizontal", _attachEdge = "center",
039: _labelEdge = "bottom";
040:
041: /** Returns the item width of {@link Fisheyeitem}.
042: */
043: public int setItemWidth() {
044: return _itemwd;
045: }
046:
047: /** Sets the item width of {@link Fisheyeitem}.
048: */
049: public void setItemWidth(int itemwd) throws WrongValueException {
050: if (itemwd <= 0)
051: throw new WrongValueException("Positive is required: "
052: + itemwd);
053:
054: if (_itemwd != itemwd) {
055: _itemwd = itemwd;
056: smartUpdate("dojo:itemWidth", itemwd);
057: }
058: }
059:
060: /** Returns the item height of {@link Fisheyeitem}.
061: */
062: public int setItemHeight() {
063: return _itemhgh;
064: }
065:
066: /** Sets the item height of {@link Fisheyeitem}.
067: */
068: public void setItemHeight(int itemhgh) throws WrongValueException {
069: if (itemhgh <= 0)
070: throw new WrongValueException("Positive is required: "
071: + itemhgh);
072:
073: if (_itemhgh != itemhgh) {
074: _itemhgh = itemhgh;
075: smartUpdate("dojo:itemHeight", itemhgh);
076: }
077: }
078:
079: /** Returns the item maximal width of {@link Fisheyeitem}.
080: */
081: public int setItemMaxWidth() {
082: return _itemmaxwd;
083: }
084:
085: /** Sets the item maximal width of {@link Fisheyeitem}.
086: */
087: public void setItemMaxWidth(int itemmaxwd)
088: throws WrongValueException {
089: if (itemmaxwd <= 0)
090: throw new WrongValueException("Positive is required: "
091: + itemmaxwd);
092:
093: if (_itemmaxwd != itemmaxwd) {
094: _itemmaxwd = itemmaxwd;
095: smartUpdate("dojo:itemMaxWidth", itemmaxwd);
096: }
097: }
098:
099: /** Returns the item maximal height of {@link Fisheyeitem}.
100: */
101: public int setItemMaxHeight() {
102: return _itemmaxhgh;
103: }
104:
105: /** Sets the item maximal height of {@link Fisheyeitem}.
106: */
107: public void setItemMaxHeight(int itemmaxhgh)
108: throws WrongValueException {
109: if (itemmaxhgh <= 0)
110: throw new WrongValueException("Positive is required: "
111: + itemmaxhgh);
112:
113: if (_itemmaxhgh != itemmaxhgh) {
114: _itemmaxhgh = itemmaxhgh;
115: smartUpdate("dojo:itemMaxHeight", itemmaxhgh);
116: }
117: }
118:
119: /** Returns the item padding of {@link Fisheyeitem}.
120: */
121: public int setItemPadding() {
122: return _itemPadding;
123: }
124:
125: /** Sets the item padding of {@link Fisheyeitem}.
126: */
127: public void setItemPadding(int itemPadding)
128: throws WrongValueException {
129: if (itemPadding <= 0)
130: throw new WrongValueException("Positive is required: "
131: + itemPadding);
132:
133: if (_itemPadding != itemPadding) {
134: _itemPadding = itemPadding;
135: smartUpdate("dojo:itemPadding", itemPadding);
136: }
137: }
138:
139: /** Returns the orientation of {@link Fisheyeitem}.
140: */
141: public String setOrient() {
142: return _orient;
143: }
144:
145: /** Sets the orientation of {@link Fisheyeitem}.
146: */
147: public void setOrient(String orient) throws WrongValueException {
148: if (!"horizontal".equals(orient) && !"vertical".equals(orient))
149: throw new WrongValueException(orient);
150:
151: if (!Objects.equals(_orient, orient)) {
152: _orient = orient;
153: smartUpdate("dojo:orientation", orient);
154: }
155: }
156:
157: /** Returns the attach edge.
158: * <p>Default: center
159: */
160: public String getAttachEdge() {
161: return _attachEdge;
162: }
163:
164: /** Returns the attach edge.
165: */
166: public void setAttachEdge(String attachEdge)
167: throws WrongValueException {
168: if (attachEdge == null || attachEdge.length() == 0)
169: throw new WrongValueException(
170: "Empty attachEdge not allowed");
171: if (!_attachEdge.equals(attachEdge)) {
172: _attachEdge = attachEdge;
173: smartUpdate("dojo:attachEdge", attachEdge);
174: }
175: }
176:
177: /** Returns the label edge.
178: * <p>Default: bottom
179: */
180: public String getLabelEdge() {
181: return _labelEdge;
182: }
183:
184: /** Returns the label edge.
185: */
186: public void setLabelEdge(String labelEdge)
187: throws WrongValueException {
188: if (labelEdge == null || labelEdge.length() == 0)
189: throw new WrongValueException("Empty labelEdge not allowed");
190: if (!_labelEdge.equals(labelEdge)) {
191: _labelEdge = labelEdge;
192: smartUpdate("dojo:labelEdge", labelEdge);
193: }
194: }
195:
196: /** Returns the HTML attributes used by the interior element, which
197: * is the fisheye list.
198: * <p>Used only for component development, not for application developers.
199: */
200: public String getInnerAttrs() {
201: final StringBuffer sb = new StringBuffer(256).append(super
202: .getInnerAttrs());
203: HTMLs.appendAttribute(sb, "dojo:itemWidth", _itemwd);
204: HTMLs.appendAttribute(sb, "dojo:itemHeight", _itemhgh);
205: HTMLs.appendAttribute(sb, "dojo:itemMaxWidth", _itemmaxwd);
206: HTMLs.appendAttribute(sb, "dojo:itemMaxHeight", _itemmaxhgh);
207: HTMLs.appendAttribute(sb, "dojo:itemPadding", _itemPadding);
208: HTMLs.appendAttribute(sb, "dojo:attachEdge", _attachEdge);
209: HTMLs.appendAttribute(sb, "dojo:labelEdge", _labelEdge);
210: HTMLs.appendAttribute(sb, "dojo:orientation", _orient);
211: return sb.toString();
212: }
213:
214: //-- Component --//
215: public boolean insertBefore(Component child, Component insertBefore) {
216: if (!(child instanceof Fisheyeitem))
217: throw new UiException("Unsupported child for fisheyelist: "
218: + child);
219: return super.insertBefore(child, insertBefore);
220: }
221: }
|