initial implementation of a simple image viewer ("View Image" command in the file...
authorFotis Stamatelopoulos <fstamatelopoulos@gmail.com>
Tue, 7 Jul 2009 12:49:55 +0000 (15:49 +0300)
committerFotis Stamatelopoulos <fstamatelopoulos@gmail.com>
Tue, 7 Jul 2009 12:49:55 +0000 (15:49 +0300)
src/gr/ebs/gss/client/FileContextMenu.java
src/gr/ebs/gss/client/FileMenu.java
src/gr/ebs/gss/client/commands/ViewImageCommand.java [new file with mode: 0644]
src/gr/ebs/gss/resources/demo.png [new file with mode: 0644]

index b795e5a..23df4fb 100644 (file)
@@ -27,6 +27,7 @@ import gr.ebs.gss.client.commands.RefreshCommand;
 import gr.ebs.gss.client.commands.RestoreTrashCommand;
 import gr.ebs.gss.client.commands.ToTrashCommand;
 import gr.ebs.gss.client.commands.UploadFileCommand;
 import gr.ebs.gss.client.commands.RestoreTrashCommand;
 import gr.ebs.gss.client.commands.ToTrashCommand;
 import gr.ebs.gss.client.commands.UploadFileCommand;
+import gr.ebs.gss.client.commands.ViewImageCommand;
 import gr.ebs.gss.client.dnd.DnDTreeItem;
 import gr.ebs.gss.client.rest.resource.FileResource;
 import gr.ebs.gss.client.rest.resource.FolderResource;
 import gr.ebs.gss.client.dnd.DnDTreeItem;
 import gr.ebs.gss.client.rest.resource.FileResource;
 import gr.ebs.gss.client.rest.resource.FolderResource;
@@ -73,6 +74,8 @@ public class FileContextMenu extends PopupPanel implements ClickListener {
 
        private MenuItem saveAsItem;
 
 
        private MenuItem saveAsItem;
 
+       private MenuItem viewImageItem;
+
        /**
         * The image bundle for this widget's images that reuses images defined in
         * other menus.
        /**
         * The image bundle for this widget's images that reuses images defined in
         * other menus.
@@ -90,7 +93,10 @@ public class FileContextMenu extends PopupPanel implements ClickListener {
 
                @Resource("gr/ebs/gss/resources/border_remove.png")
                AbstractImagePrototype unselectAll();
 
                @Resource("gr/ebs/gss/resources/border_remove.png")
                AbstractImagePrototype unselectAll();
-       }
+
+               @Resource("gr/ebs/gss/resources/demo.png")
+               AbstractImagePrototype viewImage();
+}
 
        public static native String getDate()/*-{
                return (new Date()).toUTCString();
 
        public static native String getDate()/*-{
                return (new Date()).toUTCString();
@@ -169,6 +175,14 @@ public class FileContextMenu extends PopupPanel implements ClickListener {
                        gss.getTopPanel().getFileMenu().createDownloadLink(link, true);
                        saveAsItem = new MenuItem("<span>" + link[0] + newImages.download().getHTML() + " Save As" + link[1] + "</span>", true, downloadCmd);
                        contextMenu.addItem(saveAsItem);
                        gss.getTopPanel().getFileMenu().createDownloadLink(link, true);
                        saveAsItem = new MenuItem("<span>" + link[0] + newImages.download().getHTML() + " Save As" + link[1] + "</span>", true, downloadCmd);
                        contextMenu.addItem(saveAsItem);
+                       boolean isImage = false;
+                       if (GSS.get().getCurrentSelection() != null)
+                               isImage = ((FileResource) GSS.get().getCurrentSelection()).getContentType().startsWith("image/");
+                       if (isImage) {
+                               viewImageItem = new MenuItem("<span>" + newImages.viewImage().getHTML() + "&nbsp;View Image</span>", true,
+                                                       new ViewImageCommand(this, images, gss.getTopPanel().getFileMenu().getDownloadURL()));
+                               contextMenu.addItem(viewImageItem);
+                       }
                        contextMenu.addItem(cutItem);
                        contextMenu.addItem(copyItem);
                        if(currentFolder!=null && currentFolder.getUserObject() instanceof FolderResource)
                        contextMenu.addItem(cutItem);
                        contextMenu.addItem(copyItem);
                        if(currentFolder!=null && currentFolder.getUserObject() instanceof FolderResource)
index 5a0a467..6e68ab1 100644 (file)
@@ -122,6 +122,15 @@ public class FileMenu extends PopupPanel implements ClickListener {
         *                              and save location\r
         */\r
        void createDownloadLink(String[] link, boolean forceDownload) {\r
         *                              and save location\r
         */\r
        void createDownloadLink(String[] link, boolean forceDownload) {\r
+               String downloadURL = getDownloadURL();\r
+               if (!downloadURL.isEmpty()) {\r
+                       link[0] = "<a class='hidden-link' href='" + downloadURL\r
+                                       + (forceDownload ? "&dl=1" : "") + "' target='_blank'>";\r
+                       link[1] = "</a>";\r
+               }\r
+       }\r
+\r
+       public String getDownloadURL() {\r
                GSS app = GSS.get();\r
                Object selection = app.getCurrentSelection();\r
                if (selection != null && selection instanceof FileResource) {\r
                GSS app = GSS.get();\r
                Object selection = app.getCurrentSelection();\r
                if (selection != null && selection instanceof FileResource) {\r
@@ -129,10 +138,9 @@ public class FileMenu extends PopupPanel implements ClickListener {
                        String dateString = RestCommand.getDate();\r
                        String resource = file.getUri().substring(app.getApiPath().length()-1,file.getUri().length());\r
                        String sig = app.getCurrentUserResource().getUsername()+" "+RestCommand.calculateSig("GET", dateString, resource, RestCommand.base64decode(app.getToken()));\r
                        String dateString = RestCommand.getDate();\r
                        String resource = file.getUri().substring(app.getApiPath().length()-1,file.getUri().length());\r
                        String sig = app.getCurrentUserResource().getUsername()+" "+RestCommand.calculateSig("GET", dateString, resource, RestCommand.base64decode(app.getToken()));\r
-                       link[0] = "<a class='hidden-link' href='" + file.getUri() + "?Authorization=" + URL.encodeComponent(sig) + "&Date="+URL.encodeComponent(dateString)\r
-                                       + (forceDownload ? "&dl=1" : "") + "' target='_blank'>";\r
-                       link[1] = "</a>";\r
+                       return file.getUri() + "?Authorization=" + URL.encodeComponent(sig) + "&Date="+URL.encodeComponent(dateString);\r
                }\r
                }\r
+               return "";\r
        }\r
 \r
        public MenuBar createMenu() {\r
        }\r
 \r
        public MenuBar createMenu() {\r
diff --git a/src/gr/ebs/gss/client/commands/ViewImageCommand.java b/src/gr/ebs/gss/client/commands/ViewImageCommand.java
new file mode 100644 (file)
index 0000000..ccc2400
--- /dev/null
@@ -0,0 +1,86 @@
+/*\r
+ * Copyright 2009 Electronic Business Systems Ltd.\r
+ *\r
+ * This file is part of GSS.\r
+ *\r
+ * GSS is free software: you can redistribute it and/or modify\r
+ * it under the terms of the GNU General Public License as published by\r
+ * the Free Software Foundation, either version 3 of the License, or\r
+ * (at your option) any later version.\r
+ *\r
+ * GSS is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ * You should have received a copy of the GNU General Public License\r
+ * along with GSS.  If not, see <http://www.gnu.org/licenses/>.\r
+ */\r
+package gr.ebs.gss.client.commands;\r
+\r
+import gr.ebs.gss.client.FileMenu;\r
+\r
+import com.google.gwt.user.client.Command;\r
+import com.google.gwt.user.client.ui.ClickListener;\r
+import com.google.gwt.user.client.ui.DialogBox;\r
+import com.google.gwt.user.client.ui.Image;\r
+import com.google.gwt.user.client.ui.Label;\r
+import com.google.gwt.user.client.ui.LoadListener;\r
+import com.google.gwt.user.client.ui.PopupPanel;\r
+import com.google.gwt.user.client.ui.VerticalPanel;\r
+import com.google.gwt.user.client.ui.Widget;\r
+\r
+\r
+public class ViewImageCommand implements Command {\r
+\r
+       final FileMenu.Images newImages;\r
+\r
+       private PopupPanel containerPanel;\r
+\r
+       private String imageDownloadURL;\r
+\r
+       private Label errorLabel = new Label();\r
+\r
+       /**\r
+        * @param _containerPanel\r
+        * @param _newImages the images of all the possible delete dialogs\r
+        */\r
+       public ViewImageCommand(PopupPanel _containerPanel, final FileMenu.Images _newImages, String _imageDownloadURL) {\r
+               containerPanel = _containerPanel;\r
+               newImages = _newImages;\r
+               imageDownloadURL = _imageDownloadURL;\r
+       }\r
+\r
+       public void execute() {\r
+               containerPanel.hide();\r
+\r
+               final Image image = new Image();\r
+               // Hook up a load listener, so that we can be informed if the image fails\r
+           // to load.\r
+           image.addLoadListener(new LoadListener() {\r
+               public void onError(Widget sender) {\r
+                       errorLabel.setText("An error occurred while loading.");\r
+               }\r
+\r
+               public void onLoad(Widget sender) {\r
+               }\r
+           });\r
+           image.setUrl(imageDownloadURL);\r
+           //final PopupPanel imagePopup = new PopupPanel(true);\r
+           final DialogBox imagePopup = new DialogBox(true, true);\r
+           imagePopup.setAnimationEnabled(true);\r
+           imagePopup.setText("Showing image in actual size");\r
+           VerticalPanel imageViewPanel = new VerticalPanel();\r
+           imageViewPanel.add(errorLabel);\r
+           imageViewPanel.add(image);\r
+           imagePopup.setWidget(imageViewPanel);\r
+           image.setTitle("Click to close");\r
+           image.addClickListener(new ClickListener() {\r
+               public void onClick(Widget sender) {\r
+                       imagePopup.hide();\r
+               }\r
+           });\r
+           imagePopup.setPopupPosition(0, 0);\r
+           imagePopup.show();\r
+       }\r
+}\r
diff --git a/src/gr/ebs/gss/resources/demo.png b/src/gr/ebs/gss/resources/demo.png
new file mode 100644 (file)
index 0000000..4d40262
Binary files /dev/null and b/src/gr/ebs/gss/resources/demo.png differ