001: /*
002: * GWT-Ext Widget Library
003: * Copyright(c) 2007-2008, GWT-Ext.
004: * licensing@gwt-ext.com
005: *
006: * http://www.gwt-ext.com/license
007: */
008:
009: package com.gwtext.client.widgets;
010:
011: import com.google.gwt.core.client.JavaScriptObject;
012: import com.google.gwt.user.client.Element;
013: import com.gwtext.client.util.JavaScriptObjectHelper;
014:
015: /**
016: * Simple class that can provide a shadow effect for any element. Note that the element MUST be absolutely positioned,
017: * and the shadow does not provide any shimming. This should be used only in simple cases -- for more advanced functionality
018: * that can also provide the same shadow effect, see the {@link Layer} class.
019: *
020: */
021: public class Shadow extends BaseExtWidget {
022:
023: /**
024: * Shadow on sides (default)
025: */
026: public static Type SIDES = new Type("sides");
027:
028: /**
029: * For 4-way shadow
030: */
031: public static Type FRAME = new Type("frame");
032:
033: /**
034: * Shadow on bottom right.
035: */
036: public static Type DROP = new Type("drop");
037:
038: /**
039: * Create a new Shadow.
040: *
041: * @param mode The shadow display mode. Supports the following options: sides: Shadow displays on both sides and bottom only,
042: * frame: Shadow displays equally on all four sides, drop: Traditional bottom-right drop shadow (default)
043: * @param offset the number of pixels to offset the shadow from the element (defaults to 4)
044: */
045: public Shadow(String mode, String offset) {
046: JavaScriptObject config = JavaScriptObjectHelper.createObject();
047: JavaScriptObjectHelper.setAttribute(config, "mode", mode);
048: JavaScriptObjectHelper.setAttribute(config, "offset", offset);
049: jsObj = create(config);
050: }
051:
052: private native JavaScriptObject create(JavaScriptObject config) /*-{
053: return new $wnd.Ext.Shadow(config);
054: }-*/;
055:
056: /**
057: * Hides this shadow.
058: */
059: public native void hide() /*-{
060: var shadow = this.@com.gwtext.client.widgets.BaseExtWidget::jsObj;
061: shadow.hide();
062: }-*/;
063:
064: /**
065: * Returns true if the shadow is visible, else false.
066: *
067: * @return true if shadow visible
068: */
069: public native boolean isVisible() /*-{
070: var shadow = this.@com.gwtext.client.widgets.BaseExtWidget::jsObj;
071: return shadow.isVisible();
072: }-*/;
073:
074: /**
075: * Direct alignment when values are already available. {@link #show} must be called at least once before calling
076: * this method to ensure it is initialized.
077: *
078: * @param left The target element left position
079: * @param top The target element top position
080: * @param width The target element width
081: * @param height The target element height
082: */
083: public native void realign(int left, int top, int width, int height) /*-{
084: var shadow = this.@com.gwtext.client.widgets.BaseExtWidget::jsObj;
085: shadow.realign(left, top, width, height);
086: }-*/;
087:
088: /**
089: * Adjust the z-index of this shadow.
090: *
091: * @param zindex The new z-index
092: */
093: public native void setZIndex(int zindex) /*-{
094: var shadow = this.@com.gwtext.client.widgets.BaseExtWidget::jsObj;
095: shadow.setZIndex(zindex);
096: }-*/;
097:
098: /**
099: * Displays the shadow under the target element.
100: *
101: * @param id the element ID
102: */
103: public native void show(String id) /*-{
104: var shadow = this.@com.gwtext.client.widgets.BaseExtWidget::jsObj;
105: shadow.show(id);
106: }-*/;
107:
108: /**
109: * Displays the shadow under the target element.
110: *
111: * @param element the element
112: */
113: public native void show(Element element) /*-{
114: var shadow = this.@com.gwtext.client.widgets.BaseExtWidget::jsObj;
115: shadow.show(element);
116: }-*/;
117:
118: public static class Type {
119: private String type;
120:
121: public Type(String type) {
122: this .type = type;
123: }
124:
125: public String getType() {
126: return type;
127: }
128: }
129: }
|