001: /* Separator.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: Tue Jul 19 12:31:35 2005, Created by tomyeh
010: }}IS_NOTE
011:
012: Copyright (C) 2005 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.WrongValueException;
025: import org.zkoss.zul.impl.XulElement;
026:
027: /**
028: * A separator.
029: *
030: * @author tomyeh
031: */
032: public class Separator extends XulElement {
033: private String _orient = "horizontal";
034: private String _spacing;
035: private boolean _bar;
036:
037: public Separator() {
038: }
039:
040: /**
041: * @param orient either "horizontal" or "vertical".
042: */
043: public Separator(String orient) {
044: setOrient(orient);
045: }
046:
047: /** Returns the orient.
048: * <p>Default: "horizontal".
049: */
050: public String getOrient() {
051: return _orient;
052: }
053:
054: /** Sets the orient.
055: * @param orient either "horizontal" or "vertical".
056: */
057: public void setOrient(String orient) throws WrongValueException {
058: if (!"horizontal".equals(orient) && !"vertical".equals(orient))
059: throw new WrongValueException(orient);
060:
061: if (!Objects.equals(_orient, orient)) {
062: _orient = orient;
063: smartUpdate("class", getSclass());
064: }
065: }
066:
067: /** Returns whether to display a visual bar as the separator.
068: * <p>Default: false
069: */
070: public boolean isBar() {
071: return _bar;
072: }
073:
074: /** Sets whether to display a visual bar as the separator.
075: */
076: public void setBar(boolean bar) {
077: if (_bar != bar) {
078: _bar = bar;
079: smartUpdate("class", getSclass());
080: }
081: }
082:
083: /** Returns the spacing.
084: * <p>Default: null (depending on CSS).
085: */
086: public String getSpacing() {
087: return _spacing;
088: }
089:
090: /** Sets the spacing.
091: * @param spacing the spacing (such as "0", "5px", "3pt" or "1em")
092: */
093: public void setSpacing(String spacing) {
094: if (spacing != null && spacing.length() == 0)
095: spacing = null;
096: if (!Objects.equals(_spacing, spacing)) {
097: _spacing = spacing;
098: smartUpdate("style", getRealStyle());
099: }
100: }
101:
102: protected String getRealStyle() {
103: final String style = super .getRealStyle();
104: if (_spacing == null)
105: return style;
106:
107: final StringBuffer sb = new StringBuffer(64).append("margin:");
108: if ("vertical".equals(_orient))
109: sb.append("0 ").append(_spacing);
110: else
111: sb.append(_spacing).append(" 0");
112: return sb.append(';').append(style).toString();
113: }
114:
115: //-- super --//
116: /** Returns the style class.
117: * If the style class is not defined ({@link #setSclass} is not called
118: * or called with null or empty), it returns the style class based
119: * on {@link #getOrient} and {@link #isBar}.
120: */
121: public String getSclass() {
122: final String scls = super .getSclass();
123: if (scls != null)
124: return scls;
125: return "vertical".equals(getOrient()) ? isBar() ? "vsep-bar"
126: : "vsep" : isBar() ? "hsep-bar" : "hsep";
127: }
128:
129: //-- Component --//
130: /** Default: not childable.
131: */
132: public boolean isChildable() {
133: return false;
134: }
135: }
|