![JAR search and dependency download from the Maven repository](/logo.png)
gwt.material.design.addins.client.livestamp.MaterialLiveStamp Maven / Gradle / Ivy
/*
* #%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.addins.client.livestamp;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import gwt.material.design.addins.client.MaterialAddins;
import gwt.material.design.client.MaterialDesignBase;
import gwt.material.design.client.base.AbstractValueWidget;
import gwt.material.design.client.base.JsLoader;
import java.util.Date;
//@formatter:off
/**
* The livestamp will update automatically as time goes by.
*
*
XML Namespace Declaration
*
* {@code
* xmlns:ma='urn:import:gwt.material.design.addins.client'
* }
*
*
*
UiBinder Usage:
*
* {@code
*
* // Configure the dates
* livestamp.setDate(new Date(115, 2, 1));
* }
*
*
* @author kevzlou7979
* @see Material Live Stamp
* @see LiveStamp 1.1.2
*/
public class MaterialLiveStamp extends AbstractValueWidget implements JsLoader {
private Date date = new Date();
static {
if (MaterialAddins.isDebug()) {
MaterialDesignBase.injectDebugJs(MaterialLiveStampDebugClientBundle.INSTANCE.momentDebugJs());
MaterialDesignBase.injectDebugJs(MaterialLiveStampDebugClientBundle.INSTANCE.liveStampDebugJs());
} else {
MaterialDesignBase.injectJs(MaterialLiveStampClientBundle.INSTANCE.momentJs());
MaterialDesignBase.injectJs(MaterialLiveStampClientBundle.INSTANCE.liveStampJs());
}
}
public MaterialLiveStamp() {
super(Document.get().createSpanElement());
}
@Override
protected void onLoad() {
super.onLoad();
load();
}
@Override
public void load() {
if (date != null) {
setValue(date);
} else {
GWT.log("You must specify the date value.", new IllegalStateException());
}
}
@Override
public void unload() {
getElement().removeAttribute("data-livestamp");
}
@Override
public void reload() {
unload();
load();
}
@Override
public void setValue(Date date, boolean fireEvents) {
this.date = date;
getElement().setAttribute("data-livestamp", date.toString());
super.setValue(date, fireEvents);
}
@Override
public Date getValue() {
return date;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy