001package org.gwtbootstrap3.extras.fullcalendar.client.ui;
002
003/*
004 * #%L
005 * GwtBootstrap3
006 * %%
007 * Copyright (C) 2013 - 2014 GwtBootstrap3
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
023import com.google.gwt.core.client.JavaScriptObject;
024
025import java.util.Map;
026
027/**
028 * @author Jeff Isenhart
029 * @http://arshaw.com/fullcalendar/docs/text/timeFormat/
030 */
031public class TimeFormat extends AbstractViewOptionFormat implements IsJavaScriptObject {
032    private JavaScriptObject format;
033
034    public TimeFormat() {
035        this("h(:mm)t", null);
036    }
037
038    public TimeFormat(final String defaultValue, Map<ViewOptionHash, String> options) {
039        newInstance(defaultValue);
040        if (options == null) {
041            options = getDefaultOptions();
042        }
043        for (final ViewOptionHash option : options.keySet()) {
044            setFormat(option.name(), options.get(option));
045        }
046    }
047
048    @Override
049    /**
050     * @see http://arshaw.com/fullcalendar/docs/text/timeFormat/
051     */
052    protected void populateDefaultOptions(final Map<ViewOptionHash, String> options) {
053        options.put(ViewOptionHash.agenda, "h:mm{ - h:mm}");
054    }
055
056    private native void newInstance(String defaultValue) /*-{
057        var theInstance = this;
058        theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.TimeFormat::format = {};
059        theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.TimeFormat::format.timeFormat = {
060            // for all other views
061            '': defaultValue
062        };
063
064    }-*/;
065
066    private native void setFormat(String format, String viewOption) /*-{
067        var theInstance = this;
068        theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.TimeFormat::format.timeFormat[viewOption] = format;
069    }-*/;
070
071    @Override
072    public JavaScriptObject toJavaScript() {
073        return format;
074    }
075}