001/*
002 * ModeShape (http://www.modeshape.org)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *       http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.modeshape.web.client;
017
018import com.smartgwt.client.widgets.Img;
019import com.smartgwt.client.widgets.layout.HLayout;
020
021/**
022 * Loading indicator.
023 * 
024 * @author kulikov
025 */
026public class LoadingIcon {
027    private final Img loadingImg = new Img("loading.gif");    
028    private final HLayout disabledHLayout = new HLayout();
029    
030    /**
031     * Shows loading indicator at the given place of screen.
032     * 
033     * @param x horizontal coordinate (from left corner).
034     * @param y vertical coordinate (from right corner).
035     */
036    public void show(int x, int y) {
037        disabledHLayout.setSize("100%", "100%");
038        disabledHLayout.setStyleName("disabledBackgroundStyle");
039        disabledHLayout.show();
040
041        loadingImg.setSize("100px", "100px");
042        loadingImg.setTop(y); //loading image height is 50px
043        loadingImg.setLeft(x); //loading image width is 50px
044        loadingImg.show();
045        loadingImg.bringToFront();
046    }
047    
048    /**
049     * Hides this indicator.
050     */
051    public void hide() {
052        loadingImg.hide();
053        disabledHLayout.hide();
054    }
055}