From: Fotis Stamatelopoulos Date: Tue, 7 Jul 2009 12:49:55 +0000 (+0300) Subject: initial implementation of a simple image viewer ("View Image" command in the file... X-Git-Tag: pithos/v0.7.8~323^2~14^2~362 X-Git-Url: https://code.grnet.gr/git/pithos/commitdiff_plain/b0cdfc28dc8a7e9092e964cc9dcaf5464387494a?ds=sidebyside initial implementation of a simple image viewer ("View Image" command in the file context menu) --- diff --git a/src/gr/ebs/gss/client/FileContextMenu.java b/src/gr/ebs/gss/client/FileContextMenu.java index b795e5a..23df4fb 100644 --- a/src/gr/ebs/gss/client/FileContextMenu.java +++ b/src/gr/ebs/gss/client/FileContextMenu.java @@ -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.ViewImageCommand; 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 viewImageItem; + /** * 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/demo.png") + AbstractImagePrototype viewImage(); +} 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("" + link[0] + newImages.download().getHTML() + " Save As" + link[1] + "", 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("" + newImages.viewImage().getHTML() + " View Image", 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) diff --git a/src/gr/ebs/gss/client/FileMenu.java b/src/gr/ebs/gss/client/FileMenu.java index 5a0a467..6e68ab1 100644 --- a/src/gr/ebs/gss/client/FileMenu.java +++ b/src/gr/ebs/gss/client/FileMenu.java @@ -122,6 +122,15 @@ public class FileMenu extends PopupPanel implements ClickListener { * and save location */ void createDownloadLink(String[] link, boolean forceDownload) { + String downloadURL = getDownloadURL(); + if (!downloadURL.isEmpty()) { + link[0] = ""; + link[1] = ""; + } + } + + public String getDownloadURL() { GSS app = GSS.get(); Object selection = app.getCurrentSelection(); if (selection != null && selection instanceof FileResource) { @@ -129,10 +138,9 @@ public class FileMenu extends PopupPanel implements ClickListener { String dateString = RestCommand.getDate(); String resource = file.getUri().substring(app.getApiPath().length()-1,file.getUri().length()); String sig = app.getCurrentUserResource().getUsername()+" "+RestCommand.calculateSig("GET", dateString, resource, RestCommand.base64decode(app.getToken())); - link[0] = ""; - link[1] = ""; + return file.getUri() + "?Authorization=" + URL.encodeComponent(sig) + "&Date="+URL.encodeComponent(dateString); } + return ""; } public MenuBar createMenu() { diff --git a/src/gr/ebs/gss/client/commands/ViewImageCommand.java b/src/gr/ebs/gss/client/commands/ViewImageCommand.java new file mode 100644 index 0000000..ccc2400 --- /dev/null +++ b/src/gr/ebs/gss/client/commands/ViewImageCommand.java @@ -0,0 +1,86 @@ +/* + * Copyright 2009 Electronic Business Systems Ltd. + * + * This file is part of GSS. + * + * GSS is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GSS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GSS. If not, see . + */ +package gr.ebs.gss.client.commands; + +import gr.ebs.gss.client.FileMenu; + +import com.google.gwt.user.client.Command; +import com.google.gwt.user.client.ui.ClickListener; +import com.google.gwt.user.client.ui.DialogBox; +import com.google.gwt.user.client.ui.Image; +import com.google.gwt.user.client.ui.Label; +import com.google.gwt.user.client.ui.LoadListener; +import com.google.gwt.user.client.ui.PopupPanel; +import com.google.gwt.user.client.ui.VerticalPanel; +import com.google.gwt.user.client.ui.Widget; + + +public class ViewImageCommand implements Command { + + final FileMenu.Images newImages; + + private PopupPanel containerPanel; + + private String imageDownloadURL; + + private Label errorLabel = new Label(); + + /** + * @param _containerPanel + * @param _newImages the images of all the possible delete dialogs + */ + public ViewImageCommand(PopupPanel _containerPanel, final FileMenu.Images _newImages, String _imageDownloadURL) { + containerPanel = _containerPanel; + newImages = _newImages; + imageDownloadURL = _imageDownloadURL; + } + + public void execute() { + containerPanel.hide(); + + final Image image = new Image(); + // Hook up a load listener, so that we can be informed if the image fails + // to load. + image.addLoadListener(new LoadListener() { + public void onError(Widget sender) { + errorLabel.setText("An error occurred while loading."); + } + + public void onLoad(Widget sender) { + } + }); + image.setUrl(imageDownloadURL); + //final PopupPanel imagePopup = new PopupPanel(true); + final DialogBox imagePopup = new DialogBox(true, true); + imagePopup.setAnimationEnabled(true); + imagePopup.setText("Showing image in actual size"); + VerticalPanel imageViewPanel = new VerticalPanel(); + imageViewPanel.add(errorLabel); + imageViewPanel.add(image); + imagePopup.setWidget(imageViewPanel); + image.setTitle("Click to close"); + image.addClickListener(new ClickListener() { + public void onClick(Widget sender) { + imagePopup.hide(); + } + }); + imagePopup.setPopupPosition(0, 0); + imagePopup.show(); + } +} diff --git a/src/gr/ebs/gss/resources/demo.png b/src/gr/ebs/gss/resources/demo.png new file mode 100644 index 0000000..4d40262 Binary files /dev/null and b/src/gr/ebs/gss/resources/demo.png differ