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;
024import com.google.gwt.core.client.JsArrayString;
025import com.google.gwt.i18n.client.LocaleInfo;
026
027/**
028 * @author Jeff Isenhart
029 * @see http://arshaw.com/fullcalendar/docs/text/dayNames/
030 * @see http://arshaw.com/fullcalendar/docs/text/dayNamesShort/
031 */
032public class DayNames implements IsJavaScriptObject {
033    private JavaScriptObject names;
034
035    public DayNames() {
036        newInstance();
037    }
038
039    private native void newInstance() /*-{
040        //default vals...
041        var theInstance = this;
042        theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.DayNames::names = {};
043        theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.DayNames::names.dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
044        theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.DayNames::names.dayNamesShort = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
045    }-*/;
046
047    public void localize() {
048        localized(LocaleInfo.getCurrentLocale().getDateTimeFormatInfo().weekdaysFull(),
049                LocaleInfo.getCurrentLocale().getDateTimeFormatInfo().weekdaysShort());
050    }
051
052    /**
053     * pass in localized names directly
054     *
055     * @param longNames
056     * @param shortNames
057     */
058    public void localized(final String[] longNames, final String[] shortNames) {
059        assert longNames != null && longNames.length == 7;
060        assert shortNames != null && shortNames.length == 7;
061        final JsArrayString longOnes = (JsArrayString) JsArrayString.createArray();
062        for (final String name : longNames) {
063            longOnes.push(name);
064        }
065
066        final JsArrayString shortOnes = (JsArrayString) JsArrayString.createArray();
067        for (final String name : shortNames) {
068            shortOnes.push(name);
069        }
070        localized(longOnes, shortOnes);
071    }
072
073    /**
074     * pass in localized names directly
075     *
076     * @param longNames
077     * @param shortNames
078     */
079    public native void localized(JsArrayString longNames, JsArrayString shortNames) /*-{
080        var theInstance = this;
081        theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.DayNames::names.dayNames = longNames;
082        theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.DayNames::names.dayNamesShort = shortNames;
083    }-*/;
084
085    @Override
086    public JavaScriptObject toJavaScript() {
087        return names;
088    }
089}