001: package org.wingx;
002:
003: import java.awt.Color;
004: import org.wings.*;
005: import org.wings.style.CSSAttributeSet;
006: import org.wings.style.CSSProperty;
007: import org.wings.style.CSSStyle;
008: import org.wings.style.CSSStyleSheet;
009: import org.wings.style.Selector;
010: import org.wings.style.Style;
011:
012: /**
013: * Created by IntelliJ IDEA.
014: * User: hengels
015: * Date: Aug 27, 2006
016: * Time: 9:58:56 PM
017: * To change this template use File | Settings | File Templates.
018: */
019: public class XDivision extends SContainer implements
020: LowLevelEventListener {
021: String title;
022: SIcon icon;
023:
024: /**
025: * Is the XDivision shaded?
026: */
027: boolean shaded;
028:
029: /**
030: * Is the title clickable? Default is false.
031: */
032: protected boolean isTitleClickable = false;
033:
034: public static final Selector SELECTOR_TITLE = new Selector(
035: "xdiv.title");
036:
037: /**
038: * Creates a XDivision instance with the specified LayoutManager
039: * @param l the LayoutManager
040: */
041: public XDivision(SLayoutManager l) {
042: super (l);
043: }
044:
045: /**
046: * Creates a XDivision instance
047: */
048: public XDivision() {
049: }
050:
051: /**
052: * Returns the title of the XDivision.
053: * @return String the title
054: */
055: public String getTitle() {
056: return title;
057: }
058:
059: /**
060: * Sets the title of the XDivision.
061: * @param title the title
062: */
063: public void setTitle(String title) {
064: reloadIfChange(this .title, title);
065: this .title = title;
066: }
067:
068: /**
069: * Sets the title-font of the XDivision.
070: * @param titleFont the font for the title
071: */
072: public void setTitleFont(org.wings.SFont titleFont) {
073: CSSAttributeSet attributes = CSSStyleSheet
074: .getAttributes(titleFont);
075: Style style = getDynamicStyle(SELECTOR_TITLE);
076: if (style == null) {
077: addDynamicStyle(new CSSStyle(SELECTOR_TITLE, attributes));
078: } else {
079: style.remove(CSSProperty.FONT);
080: style.remove(CSSProperty.FONT_FAMILY);
081: style.remove(CSSProperty.FONT_SIZE);
082: style.remove(CSSProperty.FONT_STYLE);
083: style.remove(CSSProperty.FONT_WEIGHT);
084: style.putAll(attributes);
085: }
086: }
087:
088: /**
089: * Returns the title-font of the XDivision.
090: * @return SFont the font for the title
091: */
092: public SFont getTitleFont() {
093: return dynamicStyles == null
094: || dynamicStyles.get(SELECTOR_TITLE) == null ? null
095: : CSSStyleSheet.getFont((CSSAttributeSet) dynamicStyles
096: .get(SELECTOR_TITLE));
097: }
098:
099: /**
100: * Sets the title-color of the XDivision.
101: * @param titleColor the color for the title
102: */
103: public void setTitleColor(Color titleColor) {
104: setAttribute(SELECTOR_TITLE, CSSProperty.COLOR, CSSStyleSheet
105: .getAttribute(titleColor));
106: }
107:
108: /**
109: * Returns the title-color of the XDivision.
110: * @return titleColor the color for the title
111: */
112: public Color getTitleColor() {
113: return dynamicStyles == null
114: || dynamicStyles.get(SELECTOR_TITLE) == null ? null
115: : CSSStyleSheet
116: .getForeground((CSSAttributeSet) dynamicStyles
117: .get(SELECTOR_TITLE));
118: }
119:
120: /**
121: * Determines whether or not the title is clickable.
122: * @param clickable true if the title is clickable
123: */
124: public void setTitleClickable(boolean clickable) {
125: this .isTitleClickable = clickable;
126: }
127:
128: /**
129: * Returns true if the title is clickable.
130: * @return boolean true if the title is clickable
131: */
132: public boolean isTitleClickable() {
133: return this .isTitleClickable;
134: }
135:
136: public SIcon getIcon() {
137: return icon;
138: }
139:
140: public void setIcon(SIcon icon) {
141: reloadIfChange(this .icon, icon);
142: this .icon = icon;
143: }
144:
145: /**
146: * Returns true if the XDivision is shaded.
147: * @return boolean true if the XDivision is shaded
148: */
149: public boolean isShaded() {
150: return shaded;
151: }
152:
153: /**
154: * Determines whether or not the XDivision is shaded.
155: * @param shaded true if the XDivision is shaded
156: */
157: public void setShaded(boolean shaded) {
158: reloadIfChange(this .shaded, shaded);
159: this .shaded = shaded;
160: }
161:
162: public void processLowLevelEvent(String name, String[] values) {
163: if (values.length == 1 && "t".equals(values[0])) {
164: shaded = !shaded;
165: reload();
166: }
167:
168: /*
169: TODO: first focusable component
170: if (!shaded && getComponentCount() > 0)
171: getComponent(0).requestFocus();
172: else
173: requestFocus();
174: */
175: }
176:
177: public void fireIntermediateEvents() {
178: }
179:
180: public boolean isEpochCheckEnabled() {
181: return false;
182: }
183:
184: @Override
185: protected boolean isShowingChildren() {
186: return !shaded;
187: }
188: }
|