initial implementation of a simple image viewer ("View Image" command in the file...
[pithos] / src / gr / ebs / gss / client / commands / ViewImageCommand.java
1 /*\r
2  * Copyright 2009 Electronic Business Systems Ltd.\r
3  *\r
4  * This file is part of GSS.\r
5  *\r
6  * GSS is free software: you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License as published by\r
8  * the Free Software Foundation, either version 3 of the License, or\r
9  * (at your option) any later version.\r
10  *\r
11  * GSS is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU General Public License\r
17  * along with GSS.  If not, see <http://www.gnu.org/licenses/>.\r
18  */\r
19 package gr.ebs.gss.client.commands;\r
20 \r
21 import gr.ebs.gss.client.FileMenu;\r
22 \r
23 import com.google.gwt.user.client.Command;\r
24 import com.google.gwt.user.client.ui.ClickListener;\r
25 import com.google.gwt.user.client.ui.DialogBox;\r
26 import com.google.gwt.user.client.ui.Image;\r
27 import com.google.gwt.user.client.ui.Label;\r
28 import com.google.gwt.user.client.ui.LoadListener;\r
29 import com.google.gwt.user.client.ui.PopupPanel;\r
30 import com.google.gwt.user.client.ui.VerticalPanel;\r
31 import com.google.gwt.user.client.ui.Widget;\r
32 \r
33 \r
34 public class ViewImageCommand implements Command {\r
35 \r
36         final FileMenu.Images newImages;\r
37 \r
38         private PopupPanel containerPanel;\r
39 \r
40         private String imageDownloadURL;\r
41 \r
42         private Label errorLabel = new Label();\r
43 \r
44         /**\r
45          * @param _containerPanel\r
46          * @param _newImages the images of all the possible delete dialogs\r
47          */\r
48         public ViewImageCommand(PopupPanel _containerPanel, final FileMenu.Images _newImages, String _imageDownloadURL) {\r
49                 containerPanel = _containerPanel;\r
50                 newImages = _newImages;\r
51                 imageDownloadURL = _imageDownloadURL;\r
52         }\r
53 \r
54         public void execute() {\r
55                 containerPanel.hide();\r
56 \r
57                 final Image image = new Image();\r
58                 // Hook up a load listener, so that we can be informed if the image fails\r
59             // to load.\r
60             image.addLoadListener(new LoadListener() {\r
61                 public void onError(Widget sender) {\r
62                         errorLabel.setText("An error occurred while loading.");\r
63                 }\r
64 \r
65                 public void onLoad(Widget sender) {\r
66                 }\r
67             });\r
68             image.setUrl(imageDownloadURL);\r
69             //final PopupPanel imagePopup = new PopupPanel(true);\r
70             final DialogBox imagePopup = new DialogBox(true, true);\r
71             imagePopup.setAnimationEnabled(true);\r
72             imagePopup.setText("Showing image in actual size");\r
73             VerticalPanel imageViewPanel = new VerticalPanel();\r
74             imageViewPanel.add(errorLabel);\r
75             imageViewPanel.add(image);\r
76             imagePopup.setWidget(imageViewPanel);\r
77             image.setTitle("Click to close");\r
78             image.addClickListener(new ClickListener() {\r
79                 public void onClick(Widget sender) {\r
80                         imagePopup.hide();\r
81                 }\r
82             });\r
83             imagePopup.setPopupPosition(0, 0);\r
84             imagePopup.show();\r
85         }\r
86 }\r