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.core.Function;
014: import com.gwtext.client.core.JsObject;
015: import com.gwtext.client.widgets.event.ResizableListener;
016:
017: //http://extjs.com/forum/showthread.php?t=1138&highlight=Resizable
018: //http://extjs.com/forum/showthread.php?t=339&highlight=Resizable
019:
020: //todo 'east', 'dd' docs missing from Ext
021: /**
022: * Applies drag handles to an element to make it resizable. The drag handles are inserted into the element and
023: * positioned absolute. Some elements, such as a textarea or image, don't support this. To overcome that, you
024: * can wrap the textarea in a div and set "resizeChild" to true (or to the id of the element), or set wrap:true
025: * in your config and the element will be wrapped for you automatically.
026: */
027: public class Resizable extends JsObject {
028:
029: private Component lazyComponent;
030:
031: /**
032: * Create a new resizable component. The component needs to be attached to the browser DOM.
033: *
034: * @param id the element ID
035: * @param config the resizable config
036: */
037: public Resizable(String id, ResizableConfig config) {
038: jsObj = create(id, config.getJsObj());
039: }
040:
041: /**
042: * Create a new resizable component. The component needs to be attached to the browser DOM.
043: *
044: * @param elem the element
045: * @param config the resizable config
046: */
047: public Resizable(Element elem, ResizableConfig config) {
048: jsObj = create(elem, config.getJsObj());
049: }
050:
051: /**
052: * Create a new resizable component.
053: *
054: * @param component the component
055: * @param config the resizable config
056: */
057: public Resizable(final Component component,
058: final ResizableConfig config) {
059: if (component.isRendered()) {
060: jsObj = create(component.getId(), config == null ? null
061: : config.getJsObj());
062: } else {
063: lazyComponent = component;
064: component.addListener("render", new Function() {
065: public void execute() {
066: jsObj = create(component.getId(),
067: config == null ? null : config.getJsObj());
068: }
069: });
070: }
071: }
072:
073: private native JavaScriptObject create(String id,
074: JavaScriptObject config)/*-{
075: return new $wnd.Ext.Resizable(id, config);
076: }-*/;
077:
078: private native JavaScriptObject create(Element elem,
079: JavaScriptObject config)/*-{
080: return new $wnd.Ext.Resizable(elem, config);
081: }-*/;
082:
083: /**
084: * Add a Resizable listener.
085: *
086: * @param listener the listener
087: */
088: public void addListener(final ResizableListener listener) {
089: if (lazyComponent != null) {
090: lazyComponent.addListener("render", new Function() {
091: public void execute() {
092: addListenerRendered(listener);
093: }
094: });
095: } else {
096: addListenerRendered(listener);
097: }
098: }
099:
100: private native void addListenerRendered(ResizableListener listener) /*-{
101: var rz = this.@com.gwtext.client.core.JsObject::getJsObj()();
102: var rzJ = this;
103:
104: rz.addListener('beforeresize',
105: function(r, event) {
106: var eJ = @com.gwtext.client.core.EventObject::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(event);
107: return listener.@com.gwtext.client.widgets.event.ResizableListener::doBeforeResize(Lcom/gwtext/client/widgets/Resizable;Lcom/gwtext/client/core/EventObject;)(rzJ, eJ);
108: }
109: );
110:
111: rz.addListener('resize',
112: function(r, w, h) {
113: listener.@com.gwtext.client.widgets.event.ResizableListener::onResize(Lcom/gwtext/client/widgets/Resizable;II)(rzJ, w, h);
114: }
115: );
116: }-*/;
117:
118: public static class Handle {
119: private String handle;
120:
121: private Handle(String handle) {
122: this .handle = handle;
123: }
124:
125: public String getHandle() {
126: return handle;
127: }
128: }
129:
130: public static Handle NORTH = new Handle("n");
131: public static Handle SOUTH = new Handle("s");
132: public static Handle EAST = new Handle("e");
133: public static Handle WEST = new Handle("w");
134: public static Handle NORTH_WEST = new Handle("nw");
135: public static Handle SOUTH_WEST = new Handle("sw");
136: public static Handle SOUTH_EAST = new Handle("se");
137: public static Handle NORTH_EAST = new Handle("ne");
138: public static Handle ALL = new Handle("all");
139:
140: }
|