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