Statistics
| Branch: | Tag: | Revision:

root / web_client / src / gr / grnet / pithos / web / client / commands / ViewImageCommand.java @ 7529fcd7

History | View | Annotate | Download (3.9 kB)

1 ab1eb3f8 Christos Stathis
/*
2 58777026 Christos Stathis
 * Copyright 2011 GRNET S.A. All rights reserved.
3 58777026 Christos Stathis
 *
4 58777026 Christos Stathis
 * Redistribution and use in source and binary forms, with or
5 58777026 Christos Stathis
 * without modification, are permitted provided that the following
6 58777026 Christos Stathis
 * conditions are met:
7 58777026 Christos Stathis
 *
8 58777026 Christos Stathis
 *   1. Redistributions of source code must retain the above
9 58777026 Christos Stathis
 *      copyright notice, this list of conditions and the following
10 58777026 Christos Stathis
 *      disclaimer.
11 58777026 Christos Stathis
 *
12 58777026 Christos Stathis
 *   2. Redistributions in binary form must reproduce the above
13 58777026 Christos Stathis
 *      copyright notice, this list of conditions and the following
14 58777026 Christos Stathis
 *      disclaimer in the documentation and/or other materials
15 58777026 Christos Stathis
 *      provided with the distribution.
16 58777026 Christos Stathis
 *
17 58777026 Christos Stathis
 * THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
18 58777026 Christos Stathis
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 58777026 Christos Stathis
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 58777026 Christos Stathis
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
21 58777026 Christos Stathis
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 58777026 Christos Stathis
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 58777026 Christos Stathis
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
24 58777026 Christos Stathis
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 58777026 Christos Stathis
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 58777026 Christos Stathis
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
27 58777026 Christos Stathis
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 58777026 Christos Stathis
 * POSSIBILITY OF SUCH DAMAGE.
29 58777026 Christos Stathis
 *
30 58777026 Christos Stathis
 * The views and conclusions contained in the software and
31 58777026 Christos Stathis
 * documentation are those of the authors and should not be
32 58777026 Christos Stathis
 * interpreted as representing official policies, either expressed
33 58777026 Christos Stathis
 * or implied, of GRNET S.A.
34 ab1eb3f8 Christos Stathis
 */
35 ab1eb3f8 Christos Stathis
package gr.grnet.pithos.web.client.commands;
36 ab1eb3f8 Christos Stathis
37 ab1eb3f8 Christos Stathis
import gr.grnet.pithos.web.client.FileMenu;
38 ab1eb3f8 Christos Stathis
39 ab1eb3f8 Christos Stathis
import com.google.gwt.event.dom.client.ClickEvent;
40 ab1eb3f8 Christos Stathis
import com.google.gwt.event.dom.client.ClickHandler;
41 ab1eb3f8 Christos Stathis
import com.google.gwt.event.dom.client.ErrorEvent;
42 ab1eb3f8 Christos Stathis
import com.google.gwt.event.dom.client.ErrorHandler;
43 ab1eb3f8 Christos Stathis
import com.google.gwt.event.dom.client.LoadEvent;
44 ab1eb3f8 Christos Stathis
import com.google.gwt.event.dom.client.LoadHandler;
45 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.Command;
46 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.DialogBox;
47 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.Image;
48 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.Label;
49 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.PopupPanel;
50 ab1eb3f8 Christos Stathis
import com.google.gwt.user.client.ui.VerticalPanel;
51 ab1eb3f8 Christos Stathis
52 ab1eb3f8 Christos Stathis
53 ab1eb3f8 Christos Stathis
public class ViewImageCommand implements Command {
54 ab1eb3f8 Christos Stathis
55 ab1eb3f8 Christos Stathis
        final FileMenu.Images newImages;
56 ab1eb3f8 Christos Stathis
57 ab1eb3f8 Christos Stathis
        private PopupPanel containerPanel;
58 ab1eb3f8 Christos Stathis
59 ab1eb3f8 Christos Stathis
        private String imageDownloadURL;
60 ab1eb3f8 Christos Stathis
61 ab1eb3f8 Christos Stathis
        private Label errorLabel = new Label();
62 ab1eb3f8 Christos Stathis
63 ab1eb3f8 Christos Stathis
        /**
64 ab1eb3f8 Christos Stathis
         * @param _containerPanel
65 ab1eb3f8 Christos Stathis
         * @param _newImages the images of all the possible delete dialogs
66 ab1eb3f8 Christos Stathis
         */
67 ab1eb3f8 Christos Stathis
        public ViewImageCommand(PopupPanel _containerPanel, final FileMenu.Images _newImages, String _imageDownloadURL) {
68 ab1eb3f8 Christos Stathis
                containerPanel = _containerPanel;
69 ab1eb3f8 Christos Stathis
                newImages = _newImages;
70 ab1eb3f8 Christos Stathis
                imageDownloadURL = _imageDownloadURL;
71 ab1eb3f8 Christos Stathis
        }
72 ab1eb3f8 Christos Stathis
73 ab1eb3f8 Christos Stathis
        @Override
74 ab1eb3f8 Christos Stathis
        public void execute() {
75 ab1eb3f8 Christos Stathis
                containerPanel.hide();
76 ab1eb3f8 Christos Stathis
77 ab1eb3f8 Christos Stathis
                final Image image = new Image();
78 ab1eb3f8 Christos Stathis
                // Hook up a load handler, so that we can be informed if the image
79 ab1eb3f8 Christos Stathis
                // fails to load.
80 ab1eb3f8 Christos Stathis
            image.addLoadHandler(new LoadHandler() {
81 ab1eb3f8 Christos Stathis
82 ab1eb3f8 Christos Stathis
                        @Override
83 ab1eb3f8 Christos Stathis
                        public void onLoad(LoadEvent event) {
84 ab1eb3f8 Christos Stathis
                                errorLabel.setText("");
85 ab1eb3f8 Christos Stathis
                        }
86 ab1eb3f8 Christos Stathis
                });
87 ab1eb3f8 Christos Stathis
                image.addErrorHandler(new ErrorHandler() {
88 ab1eb3f8 Christos Stathis
89 ab1eb3f8 Christos Stathis
                        @Override
90 ab1eb3f8 Christos Stathis
                        public void onError(ErrorEvent event) {
91 ab1eb3f8 Christos Stathis
                                errorLabel.setText("An error occurred while loading.");
92 ab1eb3f8 Christos Stathis
                        }
93 ab1eb3f8 Christos Stathis
                });
94 ab1eb3f8 Christos Stathis
            image.setUrl(imageDownloadURL);
95 ab1eb3f8 Christos Stathis
            final DialogBox imagePopup = new DialogBox(true, true);
96 ab1eb3f8 Christos Stathis
            imagePopup.setAnimationEnabled(true);
97 ab1eb3f8 Christos Stathis
            imagePopup.setText("Showing image in actual size");
98 ab1eb3f8 Christos Stathis
            VerticalPanel imageViewPanel = new VerticalPanel();
99 ab1eb3f8 Christos Stathis
            errorLabel.setText("loading image...");
100 ab1eb3f8 Christos Stathis
            imageViewPanel.add(errorLabel);
101 ab1eb3f8 Christos Stathis
            imageViewPanel.add(image);
102 ab1eb3f8 Christos Stathis
            imagePopup.setWidget(imageViewPanel);
103 ab1eb3f8 Christos Stathis
            image.setTitle("Click to close");
104 ab1eb3f8 Christos Stathis
            image.addClickHandler(new ClickHandler() {
105 ab1eb3f8 Christos Stathis
106 ab1eb3f8 Christos Stathis
                        @Override
107 ab1eb3f8 Christos Stathis
                        public void onClick(ClickEvent event) {
108 ab1eb3f8 Christos Stathis
                            imagePopup.hide();
109 ab1eb3f8 Christos Stathis
                    }
110 ab1eb3f8 Christos Stathis
            });
111 ab1eb3f8 Christos Stathis
            imagePopup.setPopupPosition(0, 0);
112 ab1eb3f8 Christos Stathis
            imagePopup.show();
113 ab1eb3f8 Christos Stathis
        }
114 ab1eb3f8 Christos Stathis
}