GWT Clipboard Past Buffer - java

I maintain a GWT web application. Our users often upload screen shot image files via a standard file upload dialog. I'm trying to think of some slightly more user friendly approach. I was wondering if there might be any way to allow the users to "paste" the image data after clicking the print-screen button.
I read some other posts that said that GWT can't nativly copy anything to or read from the clipboard buffer, but what about if the user manually pastes the image via ctrl-V or right clicking and pasting.
If anybody knows how I can accomplish this in GWT or has any other ideas let me know.

There is an event for pasting:
com.google.gwt.user.client.Event.ONPASTE
I use this but only for pasting text (user must user Ctrl+V or right-click>Paste).
I guess there may be a way for you to use this.
To capture the event, I sink it to my Widget first:
sinkEvents(Event.ONPASTE | Event.ONKEYPRESS | Event.ONKEYDOWN | Event.ONFOCUS);
Then, I implement onBrowserEvent(Event):
public void onBrowserEvent(Event event) {
super.onBrowserEvent(event);
switch (event.getTypeInt()) {
case Event.ONPASTE: paste(event);
}
}
Hope you can find a way to adapt this for images.

Related

Pasting text from clipboard using a button across different apps (Android)

I tried finding something similar on the net, but couldn't. What I want, specifically, is the ability to have a button paste some text that originated in some other app rather than the one I'm making. So, say you copy some text from the "Google Chrome" app and go through the regular long tap and copy. Then, you open this app and press a button and it fetches the text from the clipboard and pastes it in a TextView. I understand that this isn't possible with the clipboard manager since all the examples I've seen show it as an object that stores information from within the app.
No, ClipboardManager is a system service, providing access to a device-wide clipboard.
Part of the reason why many examples might show both copying and pasting to the clipboard is so that the example is self-contained.
So, you get a ClipboardManager from getSystemService(), get the current contents via getPrimaryClip(), and use the ClipData as you see fit.
For example, this sample project contains two apps: drag/ and drop/. Mostly, this is to illustrate cross-app drag-and-drop operations on Android 7.0. But, drop/ supports a "Paste" action bar item (with associated keyboard shortcut), where I grab whatever is on the clipboard and, if it has a Uri, use it:
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId()==R.id.paste) {
boolean handled=false;
ClipData clip=
getSystemService(ClipboardManager.class)
.getPrimaryClip();
if (clip!=null) {
ClipData.Item clipItem=clip.getItemAt(0);
if (clipItem!=null) {
imageUri=clipItem.getUri();
if (imageUri!=null) {
showThumbnail();
handled=true;
}
}
}
if (!handled) {
Toast
.makeText(this, "Could not paste an image!", Toast.LENGTH_LONG)
.show();
}
return(handled);
}
return(super.onOptionsItemSelected(item));
}
There is no code in this app to put stuff on the clipboard, though the associated drag/ app has code for that.
I think what you want to achieve is available in this open-source library: https://github.com/heruoxin/Clip-Stack
The idea is that it keeps track of the clipboard entries in its own internal database while running a (in your case a floating button) service and then pasting that.

How to implement printing in chrome pacakaged app created from GWT Application.?

I have integrated the GWT application with Chrome packaged app with help of DirectLinkerinstaller like the code below:
public class CSPCompatibleLinker extends DirectInstallLinker {
#Override
protected String getJsInstallLocation(LinkerContext context) {
return "com/google/gwt/core/ext/linker/impl/installLocationMainWindow.js";
}
}
But now I want to call print function from Chrome packaged app. When I call window.print() it allows me to print current window, but I need to open a new separate window and print that.
Could you anyone please help me in this?
I can't answer anything about GWT or DirectLinkerinstaller, but here's an answer about Chrome Apps, assuming that's what you're asking about:
You use the chrome.app.window.create API to create a window. Then, you can call the print method for that window.
In my apps, I seldom want to print what's in a window, but rather something I've generated specifically for printing. For that, I create a PDF with jsPDF (Google it), which works well. Then I display the PDF in a window, and let the user print the PDF (or save it).

Eclipse plugin - accessing the editor

So, I’m currently developing a plugin for the eclipse IDE. In a nutshell, the plugin is a collaborative real time code editor where the editor is eclipse (which is something like Google documents but with the code and on eclipse). Meaning that when I install the plugin, I would be able to connect -using my Gmail account- eclipse to the partner’s eclipse. And when I start coding on my machine, my partner would be seeing what I write and vice versa.
The problem I’m currently facing is accessing eclipse’s editor. For example, I have to monitor all the changes in the active document so that every time a change happens, the other partner’s IDE would be notified with this change.
I found and read about the IDcoumentProvider, IDocument and IEditorInput classes and they’re somehow connected but I can’t understand this connection or how to use it. So if someone can explain this connection I would really appreciate it. Also if there is another way to achieve my goal?
You can access the IEditorPart via the IWorkbenchPage.
IEditorPart editor = ((IWorkbenchPage) PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage()).getActiveEditor();
From there, you have access to various other classes, including the editor's IEditorInput, the File loaded by that editor, or the underlying GUI Control element. (Note that depending on the kind of editor (text files, diagram, etc.) you may have to cast to different classes.)
FileEditorInput input = (FileEditorInput) editor.getEditorInput();
StyledText editorControl = ((StyledText) editor.getAdapter(Control.class));
String path = input.getFile().getRawLocationURI().getRawPath();
Now, you can add a listener to the Control, e.g. a KeyAdapter for monitoring all key strokes occurring in the respective editor.
editorControl.addKeyListener(new KeyAdapter() {
#Override
public void keyPressed(KeyEvent e) {
System.out.println("Editing in file " + path);
}
});
Or, if monitoring all key strokes is too much, you can register an IPropertyListener to the editor. This listener will e.g. be notified whenever the editor gets 'dirty' or when it is saved. The meaning of propId can be found in IWorkbenchPartConstants.
editor.addPropertyListener(new IPropertyListener() {
#Override
public void propertyChanged(Object source, int propId) {
if (propId == IWorkbenchPartConstants.PROP_DIRTY) {
System.out.println("'Dirty' Property Changed");
}
}
});

Drag and Drop downlad from GXT grid to Desktop

I am using GXT for UI development. I have used HTML5 for Dragging file from Desktop to my application and upload it. But now i am having reverse requirement. I want to drag files from browser to desktop which will download the file to desktop.
I know that is possible in Chrome only. And had checked the below demo:
http://www.thecssninja.com/javascript/gmail-dragout
I had tried to implement the above code in my GXT application, but the issue is that i am using Editable Grid which is supporting DnD to TreePanel. Now when i drag from grid to Desktop i think its not capturing the browser event (may be i am wrong here).
Any idea, how it should be done?
Thanks.
Below is the small piece of code which i call after the Data had been inserted in Grid. All records are having the CSS class name as ".icon". The problem is that when i start to drag, the "dragstart" is not being called. Any suggestion?
NOTE: This code is working when i create Buttons, Labels, etc and making them draggable=true with other required parameters.
public static native void test(String id)/*-{
var files = $doc.querySelectorAll('.icon');
for (var i = 0, file; file = files[i]; ++i) {
file.addEventListener("dragstart",function(evt){
$wnd.alert("Drag Event started.. ");
evt.dataTransfer.setData("DownloadURL",this.dataset.downloadurl);
},false);
}
}-*/;
I used this, and it successully performs, no you should check some other place in your code.

GWT Alternate Button to FileUpload

Im writing some java code and im hitting a wall, with FileUpload, i am trying to get a alternate button to activate the filebrowser from the FileUpload.
I tried to dispatch the event from one to another, tried to extend FileUpload to have a button that triggers some action but no luck.
Fileupload upload = new FileUpload();
Button b = new Button("Browse",new ClickHandler() {
// trigger upload Browser
});
Something like this.
You cannot do this due to security restrictions. The restriction is that untrusted code cannot trigger the File Browse dialog to open because it could then do so without user input, possibly tricking the user into thinking the dialog is from a different webapp or entirely different application.
Actually it is possible on IE6 and maybe IE7, all other prohibit this action.
Read my question and answer: gwt fileupload
You might give a shot to SWFUpload in combination with swfupload-gwt.

Categories

Resources