root / src / gr / ebs / gss / client / commands / ViewImageCommand.java @ 44d84dc0
History | View | Annotate | Download (3.1 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 gr.ebs.gss.client.commands; |
20 |
|
21 |
import gr.ebs.gss.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 |
public void execute() { |
58 |
containerPanel.hide(); |
59 |
|
60 |
final Image image = new Image(); |
61 |
// Hook up a load handler, so that we can be informed if the image
|
62 |
// fails to load.
|
63 |
image.addLoadHandler(new LoadHandler() {
|
64 |
|
65 |
@Override
|
66 |
public void onLoad(LoadEvent event) { |
67 |
errorLabel.setText("");
|
68 |
} |
69 |
}); |
70 |
image.addErrorHandler(new ErrorHandler() {
|
71 |
|
72 |
@Override
|
73 |
public void onError(ErrorEvent event) { |
74 |
errorLabel.setText("An error occurred while loading.");
|
75 |
} |
76 |
}); |
77 |
image.setUrl(imageDownloadURL); |
78 |
final DialogBox imagePopup = new DialogBox(true, true); |
79 |
imagePopup.setAnimationEnabled(true);
|
80 |
imagePopup.setText("Showing image in actual size");
|
81 |
VerticalPanel imageViewPanel = new VerticalPanel();
|
82 |
errorLabel.setText("loading image...");
|
83 |
imageViewPanel.add(errorLabel); |
84 |
imageViewPanel.add(image); |
85 |
imagePopup.setWidget(imageViewPanel); |
86 |
image.setTitle("Click to close");
|
87 |
image.addClickHandler(new ClickHandler() {
|
88 |
|
89 |
@Override
|
90 |
public void onClick(ClickEvent event) { |
91 |
imagePopup.hide(); |
92 |
} |
93 |
}); |
94 |
imagePopup.setPopupPosition(0, 0); |
95 |
imagePopup.show(); |
96 |
} |
97 |
} |