All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gwt.material.design.client.ui.MaterialPushpin Maven / Gradle / Ivy

There is a newer version: 2.8.3
Show newest version
/*
 * #%L
 * GwtMaterial
 * %%
 * Copyright (C) 2015 - 2017 GwtMaterialDesign
 * %%
 * 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.
 * #L%
 */
package gwt.material.design.client.ui;

import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.user.client.ui.Widget;
import gwt.material.design.client.js.JsPushpinOptions;

import static gwt.material.design.client.js.JsMaterialElement.$;
//@formatter:off

/**
 * Pushpin is our fixed positioning plugin. You can check out our live examples: the fixed Table of Contents on the right.
 * 

UiBinder Usage:

*

*

 * {@code
 * // CAN BE CALLED AS A HELPER STATIC CONTEXT
 * MaterialPushpin.apply(target, source.getOffsetHeight() + 600);
 *
 * // INSTANTIATE THE PUSHPIN COMPONENT
 * MaterialPushpin pushpin = new MaterialPushpin();
 * pushpin.setWidget(source);
 * pushpin.setTop(300.0);
 * pushpin.setOffset(64.0);
 * pushpin.setBottom(500.0);
 * pushpin.apply();
 * }
 * 
* * @author kevzlou7979 * @see Material PushPin */ public class MaterialPushpin { private Widget widget; private JsPushpinOptions options = new JsPushpinOptions(); public MaterialPushpin() {} /** * Apply the pushpin feature into the target widget */ public void apply() { Scheduler.get().scheduleDeferred(() -> { if (widget != null) { $(widget.getElement()).pushpin(options); } else { GWT.log("Please set your widget before applying the pushpin", new IllegalStateException()); } }); } /** * A pushpinned element has 3 states. One above and below the scrolling threshold, * and the pinned state where the element becomes fixed. * * @param widget - Target widget to apply the pushpin feature * @param offset - The offset from the top the element will be fixed at. (Default: 0) */ public static void apply(Widget widget, Double offset) { apply(widget, null, null, offset); } /** * A pushpinned element has 3 states. One above and below the scrolling threshold, * and the pinned state where the element becomes fixed. * * @param widget - Target widget to apply the pushpin feature * @param top - The distance in pixels from the top of the page where the element becomes fixed. (Default: 0) * @param offset - The offset from the top the element will be fixed at. (Default: 0) */ public static void apply(Widget widget, Double top, Double offset) { apply(widget, top, null, offset); } /** * A pushpinned element has 3 states. One above and below the scrolling threshold, * and the pinned state where the element becomes fixed. * * @param widget - Target widget to apply the pushpin feature * @param top - The distance in pixels from the top of the page where the element becomes fixed. (Default: 0) * @param bottom - The distance in pixels from the top of the page where the elements stops being fixed. (Default: Infinity) * @param offset - The offset from the top the element will be fixed at. (Default: 0) */ public static void apply(Widget widget, Double top, Double bottom, Double offset) { MaterialPushpin pushpin = new MaterialPushpin(); pushpin.setWidget(widget); pushpin.setTop(top); pushpin.setBottom(bottom); pushpin.setOffset(offset); pushpin.apply(); } /** * Get the target widget which the pushpin was applied */ public Widget getWidget() { return widget; } /** * Set the target widget to apply the pushpin feature */ public void setWidget(Widget widget) { this.widget = widget; } /** * Get the offset from the top the element will be fixd at. */ public Double getOffset() { return options.offset; } /** * Set the offset from the top the element will be fixed at. (Default: 0) */ public void setOffset(Double offset) { options.offset = (offset != null) ? offset : 0; } /** * Get the distance in pixels from the top of the page where the element becomes fixed. (Default: 0) */ public Double getTop() { return options.top; } /** * Set the distance in pixels from the top of the page where the element becomes fixed. (Default: 0) */ public void setTop(Double top) { options.top = (top != null) ? top : 0; } /** * Get the distance in pixels from the top of the page where the elements stops being fixed. (Default: Infinity) */ public Double getBottom() { return options.bottom; } /** * Set the distance in pixels from the top of the page where the elements stops being fixed. (Default: Infinity) */ public void setBottom(Double bottom) { // Avoid overriding the bottom property if it's null, // as it takes "Infinity" as the default value if (bottom != null) { options.bottom = bottom; } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy