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.client.base.viewport;
021
022import java.util.ArrayList;
023import java.util.List;
024
025/**
026 * View port detection utility.
027 *
028 * @author Ben
029 */
030public class ViewPort {
031
032    private List<ViewPortHandler> handlers = new ArrayList<>();
033
034    /**
035     * When {@link ViewPort} resolution is detected.
036     */
037    public static ViewPortHandler when(Boundary boundary, Boundary... other) {
038        ViewPort viewPort = new ViewPort();
039        ViewPortHandler handler = new ViewPortHandler(viewPort, boundary, other);
040        viewPort.handlers.add(handler);
041        return handler;
042    }
043
044    /**
045     * Or when this {@link ViewPort} resolution is detected.
046     */
047    public ViewPortHandler or(Boundary resolution, Boundary... other) {
048        return when(resolution, other);
049    }
050
051    /**
052     * Unload the view port detection.
053     */
054    public ViewPort unload() {
055        for(ViewPortHandler handler : handlers) {
056            handler.unload();
057        }
058        return this;
059    }
060
061    /**
062     * Load the view port detection.
063     */
064    public ViewPort load() {
065        for(ViewPortHandler handler : handlers) {
066            handler.load();
067        }
068        return this;
069    }
070
071    /**
072     * Destroy the view port detection (use {@link #unload()} to temporarily
073     * disable then {@link #load()} to re-enable.
074     */
075    public ViewPort destroy() {
076        for(ViewPortHandler handler : handlers) {
077            handler.destroy();
078        }
079        return this;
080    }
081}