001    package 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    
023    import com.google.gwt.core.client.JavaScriptObject;
024    import com.google.gwt.core.client.JsArrayString;
025    import com.google.gwt.i18n.client.LocaleInfo;
026    
027    /**
028     * @author Jeff Isenhart
029     * @see http://arshaw.com/fullcalendar/docs/text/monthNames/
030     * @see http://arshaw.com/fullcalendar/docs/text/monthNamesShort/
031     */
032    public class MonthNames implements IsJavaScriptObject {
033    
034        private JavaScriptObject names;
035    
036        public MonthNames() {
037            newInstance();
038        }
039    
040        private native void newInstance() /*-{
041            //default vals...
042            var theInstance = this;
043            theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.MonthNames::names = {};
044            theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.MonthNames::names.monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
045            theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.MonthNames::names.monthNamesShort = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
046        }-*/;
047    
048        public void localize() {
049            localize(LocaleInfo.getCurrentLocale().getDateTimeFormatInfo().monthsFull(),
050                    LocaleInfo.getCurrentLocale().getDateTimeFormatInfo().monthsShort());
051        }
052    
053        /**
054         * To pass in localized names directly
055         *
056         * @param longNames
057         * @param shortNames
058         */
059        public void localize(final String[] longNames, final String[] shortNames) {
060            assert longNames != null && longNames.length == 12;
061            assert shortNames != null && shortNames.length == 12;
062            final JsArrayString longOnes = (JsArrayString) JsArrayString.createArray();
063            for (final String name : longNames) {
064                longOnes.push(name);
065            }
066    
067            final JsArrayString shortOnes = (JsArrayString) JsArrayString.createArray();
068            for (final String name : shortNames) {
069                shortOnes.push(name);
070            }
071            localize(longOnes, shortOnes);
072        }
073    
074        /**
075         * To pass in localized names directly
076         *
077         * @param longNames
078         * @param shortNames
079         */
080        public native void localize(JsArrayString longNames, JsArrayString shortNames) /*-{
081            var theInstance = this;
082            theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.MonthNames::names.monthNames = longNames;
083            theInstance.@org.gwtbootstrap3.extras.fullcalendar.client.ui.MonthNames::names.monthNamesShort = shortNames;
084        }-*/;
085    
086        @Override
087        public JavaScriptObject toJavaScript() {
088            return names;
089        }
090    }