+/*
+ * Copyright 2011 Google Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
package com.google.gwt.query.client.plugins;
import com.google.gwt.core.client.GWT;
import com.google.gwt.query.client.Predicate;
/**
- * GWT clone of jQueryUi-core
- *
- * @author Julien Dramaix (julien.dramaix@gmail.com, @jdramaix)
+ * GWT clone of jQueryUi-core. This class define some function present in the
+ * jQuery-ui core and not directly in jQuery
*
*/
public class GQueryUi extends GQuery {
+ /**
+ * A POJO used to store dimension of an element
+ *
+ */
+ public static class Dimension {
+ private int height = 0;
+ private int width = 0;
+
+ public Dimension(Element e) {
+ width = e.getOffsetWidth();
+ height = e.getOffsetHeight();
+ }
+
+ public Dimension(int width, int height) {
+ this.width = width;
+ this.height = height;
+ }
+
+ /**
+ * return the height value.
+ */
+ public int getHeight() {
+ return height;
+ }
+
+ /**
+ * return the width value
+ */
+ public int getWidth() {
+ return width;
+ }
+ }
+
/**
* This object allows you to have a full copy of the original Event and
* implements some useful method of the jQuery event model. This is also
*
* TOBEFIXED : the method preventDefault() must be called directly on the
* original event
- *
- *
- * @author jdramaix
+ *
*
*/
public static class Event extends com.google.gwt.user.client.Event {
+ /**
+ * Create a new {@link Event} by copying the <code>originalEvent</code>.
+ */
public static Event create(com.google.gwt.user.client.Event originalEvent) {
Event gQueryEvent = createObject().cast();
copy(originalEvent, gQueryEvent);
protected Event() {
}
+ /**
+ * Return the original event (the one created by the browser)
+ */
public final native com.google.gwt.user.client.Event getOriginalEvent()/*-{
return this.originalEvent;
}-*/;
+ /**
+ * Tell whether ctrl or cmd key is pressed
+ *
+ */
+ public final boolean isMetaKeyPressed() {
+ return getMetaKey() || getCtrlKey();
+ }
+
/**
* The mouse position relative to the left edge of the document
*
- * @param mouseEvent
- * @return the mouse x-position in the page
*/
public final int pageX() {
return getClientX() + document.getScrollLeft();
/**
* The mouse position relative to the top edge of the document.
*
- * @param mouseEvent
- * @return the mouse y-position in the page
*/
public final int pageY() {
return getClientY() + document.getScrollTop();
}
- /**
- * Tell if ctrl or cmd key is pressed
- *
- * @return
- */
- public final boolean isMetaKeyPressed() {
- return getMetaKey() || getCtrlKey();
- }
-
- }
-
- public static class Dimension {
- private int width = 0;
- private int height = 0;
-
- public Dimension(Element e) {
- width = e.getOffsetWidth();
- height = e.getOffsetHeight();
- }
-
- public Dimension(int width, int height) {
- this.width = width;
- this.height = height;
- }
-
- public int getHeight() {
- return height;
- }
-
- public int getWidth() {
- return width;
- }
}
private static class GQueryUiImpl {
- private final Element getViewportElement() {
- return GQuery.document.isCSS1Compat() ? GQuery.document
- .getDocumentElement() : GQuery.document.getBody();
- }
-
public GQuery scrollParent(final GQueryUi gQueryUi) {
GQuery scrollParent;
}
+ protected boolean scrollParentPositionTest(GQueryUi gQueryUi) {
+ return "absolute".equals(gQueryUi.css("position"));
+ }
+
+ private final Element getViewportElement() {
+ return GQuery.document.isCSS1Compat() ? GQuery.document
+ .getDocumentElement() : GQuery.document.getBody();
+ }
+
private boolean isOverflowEnabled(GQuery e) {
String overflow = e.css("overflow", true) + e.css("overflow-x", true)
+ e.css("overflow-y", true);
return overflow.contains("auto") || overflow.contains("scroll");
}
- protected boolean scrollParentPositionTest(GQueryUi gQueryUi) {
- return "absolute".equals(gQueryUi.css("position"));
- }
-
}
@SuppressWarnings("unused")
});
}
- protected HasHandlers eventBus;
-
- private GQueryUiImpl impl = GWT.create(GQueryUiImpl.class);
-
+ /**
+ * Return true if the <code>descendant</code> is a child of the parent. Return false elsewhere.
+ */
public static boolean contains(Element parent, Element descendant) {
return parent != descendant && parent.isOrHasChild(descendant);
}
+ protected static void trigger(GwtEvent<?> e, Function callback,
+ Element element, HasHandlers handlerManager) {
+ if (handlerManager != null && e != null) {
+ handlerManager.fireEvent(e);
+ }
+ if (callback != null) {
+ callback.f(element);
+ }
+ }
+
+ protected HasHandlers eventBus;
+
+ private GQueryUiImpl impl = GWT.create(GQueryUiImpl.class);
+
public GQueryUi() {
super();
}
}
/**
- * this function returns the immediate scrolling parent.
- *
- * @return the immediate scrolling parent
+ * Return the immediate scrolling parent.
*/
public GQuery scrollParent() {
return impl.scrollParent(this);
/**
* fire event and call callback function.
*
- * @param e
- * @param callback
- * @param element
*/
protected void trigger(GwtEvent<?> e, Function callback, Element element) {
trigger(e, callback, element, eventBus);
}
- protected static void trigger(GwtEvent<?> e, Function callback,
- Element element, HasHandlers handlerManager) {
- if (handlerManager != null && e != null) {
- handlerManager.fireEvent(e);
- }
- if (callback != null) {
- callback.f(element);
- }
- }
-
}
/*
- * Copyright 2010 The gwtquery plugins team.
+ * Copyright 2011 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
*/
package com.google.gwt.query.client.plugins;
+/**
+ * Object use to configure a Plugin extending {@link MousePlugin}
+ *
+ */
public class MouseOptions {
- /**
- * Prevents plugin working from starting on specified elements.
- */
private String[] cancel;
- /**
- * Time in milliseconds to define when the plugin should start. It helps
- * preventing unwanted selections when clicking on an element. Default : 0
- *
- */
private int delay;
- /**
- * Tolerance, in pixels, for when plugin should start. If specified, selecting
- * will not start until after mouse is dragged beyond distance. Default : 1
- *
- */
private int distance;
public MouseOptions() {
initDefault();
}
+ /**
+ * Return an array of css selectors. The plugin will not start when the mouse
+ * interacts with the elements selected by the selectors.
+ *
+ */
public String[] getCancel() {
return cancel;
}
+ /**
+ * Return the tolerance, in pixels, for when plugin should start. If
+ * specified, the plugin will not start until after mouse is dragged beyond
+ * distance.
+ *
+ */
public int getDelay() {
return delay;
}
+ /**
+ * return the time in milliseconds that define when the plugin should start.
+ */
public int getDistance() {
return distance;
}
/**
* Prevents starting of the plugin on specified elements
- * @param cancel array of css selectors
+ *
+ * @param cancel
+ * array of css selectors
*/
public void setCancel(String... cancel) {
this.cancel = cancel;
/**
* Time in milliseconds to define when the plugin should start. It helps
- * preventing unwanted selections when clicking on an element.
- * @param delay
+ * preventing unwanted selections when clicking on an element.
+ *
*/
public void setDelay(int delay) {
this.delay = delay;
}
/**
- * Tolerance, in pixels, for when plugin should start. If specified, selecting
- * will not start until after mouse is dragged beyond distance. Default : 1
- * @param distance
+ * Tolerance, in pixels, for when plugin should start. If specified, the
+ * plugin will not start until after mouse is dragged beyond distance. Default
+ * : 1
+ *
*/
public void setDistance(int distance) {
this.distance = distance;
protected void initDefault() {
delay = 0;
- distance = 1; //by default, the mouse have to move one pixel !
- cancel = new String[]{"input", "option"};
+ distance = 1; // by default, the mouse have to move one pixel !
+ cancel = new String[] { "input", "option" };
}
}
-
/*\r
- * Copyright 2010 The gwtquery plugins team.\r
+ * Copyright 2011 Google Inc.\r
* \r
* Licensed under the Apache License, Version 2.0 (the "License"); you may not\r
* use this file except in compliance with the License. You may obtain a copy of\r
/**\r
* Base class for all plug-in that need to handle some mouse interactions.\r
* \r
- * @author Julien Dramaix (julien.dramaix@gmail.com, @jdramaix)\r
- * \r
*/\r
public abstract class MousePlugin extends GQueryUi {\r
\r
private Event mouseDownEvent;\r
private boolean mouseStarted = false;\r
private Duration mouseUpDuration;\r
- // private int mouseDownX;\r
- // private int mouseDownY;\r
private MouseOptions options;\r
private boolean preventClickEvent = false;\r
\r
* Return a String identifying the plugin. This string is used as namespace\r
* when we bind handlers.\r
* \r
- * @return\r
*/\r
protected abstract String getPluginName();\r
\r
/**\r
* This method initialize all needed handlers\r
* \r
- * @param options\r
*/\r
protected void initMouseHandler(MouseOptions options) {\r
this.options = options;\r
/**\r
* Test if the mouse down event must be handled by the plugin or not.\r
* \r
- * \r
*/\r
protected boolean mouseCapture(Element draggable, Event event) {\r
return true;\r
/**\r
* Method called when mouse click\r
* \r
- * @param element\r
- * @param event\r
- * @return\r
*/\r
protected boolean mouseClick(Element element, Event event) {\r
return true;\r
* You should not override this method. Instead, override\r
* {@link #mouseStart(Element, Event)} method\r
* \r
- * @param element\r
- * @param event\r
- * @return\r
*/\r
protected boolean mouseDown(Element element, Event event) {\r
\r
/**\r
* Method called when the mouse is dragging\r
* \r
- * @param element\r
- * @param event\r
- * @return\r
*/\r
protected abstract boolean mouseDrag(Element element, Event event);\r
\r
* You should not override this method. Instead, override\r
* {@link #mouseMove(Element, Event)} method\r
* \r
- * @param element\r
- * @param event\r
- * @return\r
*/\r
protected boolean mouseMove(Element element, Event event) {\r
if (mouseStarted) {\r
* Method called when the mouse is clicked and all conditions for starting the\r
* plugin are met.\r
* \r
- * @param element\r
- * @param event\r
- * @return\r
*/\r
protected abstract boolean mouseStart(Element element, Event event);\r
\r
/**\r
* Method called when the mouse button is released\r
* \r
- * @param element\r
- * @param event\r
- * @return\r
*/\r
protected abstract boolean mouseStop(Element element, Event event);\r
\r
* You should not override this method. Instead, override\r
* {@link #mouseStop(Element, Event)} method\r
* \r
- * @param element\r
- * @param event\r
- * @return\r
*/\r
protected boolean mouseUp(Element element, Event event) {\r
unbindOtherMouseEvent();\r