001/*
002 * #%L
003 * GwtMaterial
004 * %%
005 * Copyright (C) 2015 - 2017 GwtMaterialDesign
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 * 
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 * 
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020package gwt.material.design.addins.client.dnd.constants;
021
022/**
023 * Drags, resizes and gestures can be restricted to a certain area. By default,
024 * restricting is relative to the pointer coordinates – the action coordinates,
025 * not the element’s dimensions, will be kept within the restriction area.
026 *
027 * @author kevzlou7979
028 * @see <a href="http://interactjs.io/docs/restriction/#restrict">Documentation</a>
029 */
030public class Restriction {
031
032    public interface Restrict {
033        String PARENT = "parent";
034        String SELF = "self";
035    }
036
037    private Object restriction = Restrict.PARENT;
038    private boolean endOnly = true;
039    private double top = 0;
040    private double left = 0;
041    private double right = 1;
042    private double bottom = 1;
043
044    public Restriction() {
045    }
046
047    public Restriction(Object restriction, boolean endOnly, double top, double left, double bottom, double right) {
048        this.restriction = restriction;
049        this.endOnly = endOnly;
050        this.top = top;
051        this.right = right;
052        this.bottom = bottom;
053        this.left = left;
054    }
055
056    public Object getRestriction() {
057        return restriction;
058    }
059
060    /**
061     * This constant value specifies the area that the action will be confined to.
062     * 'self' – restrict to the target element’s rect
063     * 'parent' – restrict to the rect of the element’s parentNode or
064     * a CSS selector string – if one of the parents of the target element matches
065     * this selector, it’s rect will be used as the restriction area.
066     *
067     * @see <a href="http://interactjs.io/docs/restriction/#restriction">Documentation</a>
068     */
069    public void setRestriction(Object restriction) {
070        this.restriction = restriction;
071    }
072
073    public boolean isEndOnly() {
074        return endOnly;
075    }
076
077    /**
078     * The endOnly option is used to restrict just before the end of a drag or resize.
079     * Before the end event is fired, an extra <action>move event is restricted and fired.
080     * If inertia is enabled and endOnly is set to true then the pointer will follow a curve
081     * to the restricted coordinates.
082     *
083     * @see <a href="http://interactjs.io/docs/restriction/#endonly">Documentation</a>
084     */
085    public void setEndOnly(boolean endOnly) {
086        this.endOnly = endOnly;
087    }
088
089    public double getTop() {
090        return top;
091    }
092
093    /**
094     * Top restriction of the element being allowed to hang over the restriction edges.
095     *
096     * @see <a href="http://interactjs.io/docs/restriction/#elementrect">Documentation</a>
097     */
098    public void setTop(double top) {
099        this.top = top;
100    }
101
102    public double getRight() {
103        return right;
104    }
105
106    /**
107     * Right restriction of the element being allowed to hang over the restriction edges.
108     *
109     * @see <a href="http://interactjs.io/docs/restriction/#elementrect">Documentation</a>
110     */
111    public void setRight(double right) {
112        this.right = right;
113    }
114
115    public double getBottom() {
116        return bottom;
117    }
118
119    /**
120     * Bottom restriction of the element being allowed to hang over the restriction edges.
121     *
122     * @see <a href="http://interactjs.io/docs/restriction/#elementrect">Documentation</a>
123     */
124    public void setBottom(double bottom) {
125        this.bottom = bottom;
126    }
127
128    public double getLeft() {
129        return left;
130    }
131
132    /**
133     * Left restriction of the element being allowed to hang over the restriction edges.
134     *
135     * @see <a href="http://interactjs.io/docs/restriction/#elementrect">Documentation</a>
136     */
137    public void setLeft(double left) {
138        this.left = left;
139    }
140}