Statistics
| Branch: | Tag: | Revision:

root / web_client / src / org / gss_project / gss / web / client / commands / ViewImageCommand.java @ f1ec19a9

History | View | Annotate | Download (3 kB)

1
/*
2
 * Copyright 2009 Electronic Business Systems Ltd.
3
 *
4
 * This file is part of GSS.
5
 *
6
 * GSS is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * GSS is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with GSS.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
package org.gss_project.gss.web.client.commands;
20

    
21
import org.gss_project.gss.web.client.FileMenu;
22

    
23
import com.google.gwt.event.dom.client.ClickEvent;
24
import com.google.gwt.event.dom.client.ClickHandler;
25
import com.google.gwt.event.dom.client.ErrorEvent;
26
import com.google.gwt.event.dom.client.ErrorHandler;
27
import com.google.gwt.event.dom.client.LoadEvent;
28
import com.google.gwt.event.dom.client.LoadHandler;
29
import com.google.gwt.user.client.Command;
30
import com.google.gwt.user.client.ui.DialogBox;
31
import com.google.gwt.user.client.ui.Image;
32
import com.google.gwt.user.client.ui.Label;
33
import com.google.gwt.user.client.ui.PopupPanel;
34
import com.google.gwt.user.client.ui.VerticalPanel;
35

    
36

    
37
public class ViewImageCommand implements Command {
38

    
39
        final FileMenu.Images newImages;
40

    
41
        private PopupPanel containerPanel;
42

    
43
        private String imageDownloadURL;
44

    
45
        private Label errorLabel = new Label();
46

    
47
        /**
48
         * @param _containerPanel
49
         * @param _newImages the images of all the possible delete dialogs
50
         */
51
        public ViewImageCommand(PopupPanel _containerPanel, final FileMenu.Images _newImages, String _imageDownloadURL) {
52
                containerPanel = _containerPanel;
53
                newImages = _newImages;
54
                imageDownloadURL = _imageDownloadURL;
55
        }
56

    
57
        @Override
58
        public void execute() {
59
                containerPanel.hide();
60

    
61
                final Image image = new Image();
62
                // Hook up a load handler, so that we can be informed if the image
63
                // fails to load.
64
            image.addLoadHandler(new LoadHandler() {
65

    
66
                        @Override
67
                        public void onLoad(LoadEvent event) {
68
                                errorLabel.setText("");
69
                        }
70
                });
71
                image.addErrorHandler(new ErrorHandler() {
72

    
73
                        @Override
74
                        public void onError(ErrorEvent event) {
75
                                errorLabel.setText("An error occurred while loading.");
76
                        }
77
                });
78
            image.setUrl(imageDownloadURL);
79
            final DialogBox imagePopup = new DialogBox(true, true);
80
            imagePopup.setAnimationEnabled(true);
81
            imagePopup.setText("Showing image in actual size");
82
            VerticalPanel imageViewPanel = new VerticalPanel();
83
            errorLabel.setText("loading image...");
84
            imageViewPanel.add(errorLabel);
85
            imageViewPanel.add(image);
86
            imagePopup.setWidget(imageViewPanel);
87
            image.setTitle("Click to close");
88
            image.addClickHandler(new ClickHandler() {
89

    
90
                        @Override
91
                        public void onClick(ClickEvent event) {
92
                            imagePopup.hide();
93
                    }
94
            });
95
            imagePopup.setPopupPosition(0, 0);
96
            imagePopup.show();
97
        }
98
}