001    package org.gwtbootstrap3.extras.growl.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 org.gwtbootstrap3.extras.animate.client.ui.constants.Animation;
024    
025    /**
026     * This class represent basic Growl`s options, that you can use to customize display of each Growl.
027     * <p/>
028     * You can also set current state as default for all new Growls.
029     *
030     * @author jeffisenhart
031     * @author Sven Jacobs
032     * @author Joshua Godi
033     * @author Pavel Zlámal
034     * @see #makeDefault()
035     */
036    public class GrowlOptions {
037    
038        /**
039         * Set element name or class or ID to append Growl to. Default is 'body'.
040         *
041         * @param element Name, class or ID
042         */
043        public final native void setElement(String element) /*-{
044            this.element = element;
045        }-*/;
046    
047        /**
048         * Set position of Growl on screen. Default position is TOP_RIGHT.
049         *
050         * @param position Growl`s position.
051         * @see org.gwtbootstrap3.extras.growl.client.ui.GrowlPosition
052         */
053        public final void setPosition(final GrowlPosition position) {
054    
055            if (position != null) {
056                setGrowlPosition(position.getPosition().split("-")[0],
057                        position.getPosition().split("-")[1]);
058            } else {
059                setPosition(GrowlPosition.TOP_RIGHT);
060            }
061    
062        }
063    
064        /**
065         * Set native property of Growl`s position.
066         *
067         * @param vertical 'top' or 'bottom'
068         * @param horizontal 'left', 'center' or 'right'
069         */
070        private native void setGrowlPosition(String vertical, String horizontal) /*-{
071            this.placement = { from: vertical, align: horizontal };
072        }-*/;
073    
074        /**
075         * Allow display of dismiss button [X] in top right corner of Growl. Default is TRUE.
076         *
077         * @param allowDismiss TRUE = display dismiss button / FALSE = hide dismiss button
078         */
079        public final native void setAllowDismiss(boolean allowDismiss) /*-{
080            this.allow_dismiss = allowDismiss;
081        }-*/;
082    
083        /**
084         * Set offset (space between Growl and screen/browser edges) for each axis. Default is 20 PX for both.
085         *
086         * @param offX Offset for X axis in PX
087         * @param offY Offset for Y axis in PX
088         */
089        public final native void setOffset(int offX, int offY) /*-{
090            this.offset = { x: offX, y: offY };
091        }-*/;
092    
093        /**
094         * Set custom spacing between two Growls. Default is 10 PX.
095         *
096         * @param space Spacing in PX
097         */
098        public final native void setSpacing(int space) /*-{
099            this.spacing = space;
100        }-*/;
101    
102        /**
103         * Set custom Z-index. Default is 1031.
104         *
105         * @param zIndex Z-index
106         */
107        public final native void setZIndex(int zIndex) /*-{
108            this.z_index = zIndex;
109        }-*/;
110    
111        /**
112         * Set delay, how long Growl stays on screen. Default is 5000 ms.
113         * Set to zero for unlimited time.
114         *
115         * @param mDelay Delay in milliseconds or zero for unlimited
116         */
117        public final native void setDelay(int mDelay) /*-{
118            this.delay = mDelay;
119        }-*/;
120    
121        /**
122         * Set timer. It's value is removed from remaining 'delay' on each 'timer' period.
123         * This way you can speed up hiding of Growl. If timer > remaining delay, Growl is
124         * hidden after delay runs out (ignoring timer).
125         *
126         * @param timer Time in milliseconds
127         * @see #setDelay(int)
128         */
129        public final native void setTimer(int timer) /*-{
130            this.timer = timer;
131        }-*/;
132    
133        /**
134         * Set custom URL target. Default is "_blank".
135         * <p/>
136         * See http://www.w3schools.com/tags/att_a_target.asp for possible values.
137         *
138         * @param urlTarget URL target
139         */
140        public final native void setUrlTarget(String urlTarget) /*-{
141            this.url_target = urlTarget;
142        }-*/;
143    
144        /**
145         * Pause countdown of display timeout when mouse is hovering above the Growl.
146         * Countdown continues (not restarted) if mouse leaves the Growl.
147         *
148         * @param pauseOnMouseOver TRUE = pause / FALSE = not pause
149         */
150        public final native void setPause(boolean pauseOnMouseOver) /*-{
151            if (pauseOnMouseOver) {
152                this.mouse_over = 'pause'
153            } else {
154                this.mouse_over = false;
155            }
156        }-*/;
157    
158    
159        /**
160         * Set Animation to Growl when it enters and exit the screen.
161         *
162         * Default is enter = Animation.FADE_IN_DOWN, exit = Animation.FADE_OUT_UP
163         *
164         * @see org.gwtbootstrap3.extras.animate.client.ui.constants.Animation
165         *
166         * @param enter animation style when Growl enters the screen
167         * @param exit  animation style when Growl exists the screen
168         */
169        public final void setAnimation(Animation enter, Animation exit) {
170            setAnimation((enter != null) ? enter.getCssName() : Animation.NO_ANIMATION.getCssName(),
171                    (exit != null) ? exit.getCssName() : Animation.NO_ANIMATION.getCssName());
172        }
173    
174        /**
175         * Set custom CSS style for animations of Growl when it enters and exits the screen.
176         * You must write your own CSS animation definition.
177         *
178         * @param enter animation style when Growl enters the screen
179         * @param exit  animation style when Growl exists the screen
180         */
181        public final native void setAnimation(String enter, String exit) /*-{
182            this.animate = { enter: enter, exit: exit };
183        }-*/;
184    
185        /**
186         * Set type of icon you will use for Growl. Default is 'class', which
187         * allows to use iconic fonts like FontAwesome.
188         * If you want to use images instead of class, set value to "image".
189         *
190         * @param iconType "class" or "image"
191         */
192        public final native void setIconType(String iconType) /*-{
193            this.icon_type = iconType;
194        }-*/;
195    
196        /**
197         * Set custom HTML Template of Growl. Default value is:
198         * <p/>
199         *
200         * &lt;div data-growl="container" class="alert" role="alert"&gt;<br/>
201         * &nbsp;&nbsp;&lt;button type="button" class="close" data-growl="dismiss"&gt;<br/>
202         * &nbsp;&nbsp;&nbsp;&nbsp;&lt;span aria-hidden="true"&gt;×&lt;/span&gt;<br/>
203         * &nbsp;&nbsp;&nbsp;&nbsp;&lt;span class="sr-only"&gt;Close&lt;/span&gt;<br/>
204         * &nbsp;&nbsp;&lt;/button&gt;<br/>
205         * &nbsp;&nbsp;&lt;span data-growl="icon"&gt;&lt;/span&gt;<br/>
206         * &nbsp;&nbsp;&lt;span data-growl="title"&gt;&lt;/span&gt;<br/>
207         * &nbsp;&nbsp;&lt;span data-growl="message"&gt;&lt;/span&gt;<br/>
208         * &nbsp;&nbsp;&lt;a href="#" data-growl="url"&gt;&lt;/a&gt;<br/>
209         * &lt;/div&gt;
210         *
211         * <p/>
212         * See documentation at: http://bootstrap-growl.remabledesigns.com/
213         *
214         * @param html Custom HTML template
215         */
216        public final native void setTemplate(String html) /*-{
217            this.template = html;
218        }-*/;
219    
220        /**
221         * Make this GrowlOptions setting as default for all new Growls.
222         * <p/>
223         * Values set to this GrowlOptions overrides original default values.
224         * If value for some property is not set, original default value is kept.
225         */
226        public final native void makeDefault() /*-{
227            $wnd.jQuery.growl(false, this);
228        }-*/;
229    
230        /**
231         * Set type of Growl (CSS style class name). Default is INFO.
232         *
233         * @param type one of INFO, WARNING, DANGER, SUCCESS
234         * @see org.gwtbootstrap3.extras.growl.client.ui.GrowlType
235         */
236        public final void setType(final GrowlType type) {
237            if (type != null) {
238                setType(type.getCssName());
239            }
240        }
241    
242        /**
243         * Set custom style name to Growl. Resulting class name is "alert-[customType]".
244         *
245         * @param customType Style name to set
246         */
247        public final native void setType(String customType) /*-{
248            this.type = customType;
249        }-*/;
250    
251    }