tag:blogger.com,1999:blog-2528245647272415122.post8660175255836326999..comments2016-11-04T12:53:40.835+01:00Comments on Phil on development: OSGi Clipboard Monitor for Java (on Windows using JNA)Unknownnoreply@blogger.comBlogger13125tag:blogger.com,1999:blog-2528245647272415122.post-72368872695697493992012-06-14T20:22:36.568+02:002012-06-14T20:22:36.568+02:00Great implementation solution! I was looking for e...Great implementation solution! I was looking for exactly this, as the Java access to System Clipboard on my Windows box is broken. Thanks, AaronAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-2528245647272415122.post-18530756115446726192010-08-24T00:38:52.905+02:002010-08-24T00:38:52.905+02:00Got it. SetWindowLong was returning 0. Added at Us...Got it. SetWindowLong was returning 0. Added at User32, "long SetWindowLongPtr(HWND hWnd, int nIndex, WNDPROC proc);", and now it works. I'm at Win7 x64. Now I'm trying to figure out how to use this :pC4b3z0nhttps://www.blogger.com/profile/14411196878272671701noreply@blogger.comtag:blogger.com,1999:blog-2528245647272415122.post-38160431818003755252010-08-23T04:40:43.985+02:002010-08-23T04:40:43.985+02:00I can't get it to work. The loop of "whil...I can't get it to work. The loop of "while (User32.INSTANCE.PeekMessage(msg, null, 0, 0, User32.PM_REMOVE))" only enters at first run of the while(true) loop. The callback() is never called. I have no idea where I'm failing, I copied the whole code, got all the libraries. Even the WindowsClipboardTests does nothing. I want only to get the clipboard items, without any complications...C4b3z0nhttps://www.blogger.com/profile/14411196878272671701noreply@blogger.comtag:blogger.com,1999:blog-2528245647272415122.post-87588916850615348632010-03-23T21:43:06.945+01:002010-03-23T21:43:06.945+01:00Phil, I created thread based on your blog to listn...Phil, I created thread based on your blog to listnen clipboard change. The sam application is putting data on clipboard clipboard.setContents(data, dataTypes) and listener thread received two clipboard changes events. If you want to check my prototipe please see http://sourceforge.net/projects/clipcomrade/Unknownhttps://www.blogger.com/profile/06732093931453558072noreply@blogger.comtag:blogger.com,1999:blog-2528245647272415122.post-3449932623249220852010-03-23T08:54:48.076+01:002010-03-23T08:54:48.076+01:00Veljko, thanks for trying it out. What kind of inf...Veljko, thanks for trying it out. What kind of information is copied to the clipboard? I would like to reproduce this here.Philipp Kursawehttps://www.blogger.com/profile/01559531684494695413noreply@blogger.comtag:blogger.com,1999:blog-2528245647272415122.post-63416646480365403692010-03-22T21:52:32.005+01:002010-03-22T21:52:32.005+01:00Philipp, thanks for you blog. I have question, how...Philipp, thanks for you blog. I have question, how to stop clipboard listener. I have simple app that listnen to clipboard and paste something on clipboard. After paste it captures two times what has been pasted?Unknownhttps://www.blogger.com/profile/06732093931453558072noreply@blogger.comtag:blogger.com,1999:blog-2528245647272415122.post-91362755963210641072010-02-22T17:49:22.406+01:002010-02-22T17:49:22.406+01:00I understand that you can use the selection servic...I understand that you can use the selection service or whatever Eclipse provides to track the current selection. The clipboard has nothing to do with the selection. <br /><br />If I have an Eclipse based application that allows me to create new editor parts for images, and I copy an image into the clipboard (i.e from Firefox) then in my Eclipse application the "paste" button will be enabled and allows me to create a new editor part with the content of the clipboard. Such use case would not be possible with the the selection service ;)Philipp Kursawehttps://www.blogger.com/profile/01559531684494695413noreply@blogger.comtag:blogger.com,1999:blog-2528245647272415122.post-30264185391330092042010-02-22T17:38:29.657+01:002010-02-22T17:38:29.657+01:00Philipp, I wasn't arguing about the clipboard ...Philipp, I wasn't arguing about the clipboard tracking. But we have different take on a particular application. You are tracking the clipboard and I am saying that issue can be tackled without clipboard tracking. I believe with my solution user would have to do less, i.e. don't need to copy into clipboard before he'll be able to click that button on the toolbar, so button reacts on selection instead of content of the clipboard. That is allEugene Kuleshovhttps://www.blogger.com/profile/08736056465101896635noreply@blogger.comtag:blogger.com,1999:blog-2528245647272415122.post-49479412206642407902010-02-10T17:31:57.648+01:002010-02-10T17:31:57.648+01:00Eugene, thanks for your comment.
I understand th...Eugene, thanks for your comment. <br /><br />I understand the use of the selection service. <br />This post is about a system clipboard monitor. There are no dependencies to the Eclipse Workbench here. <br /><br />Let's imagine a simple image editing software based on Eclipse RCP. You have a toolbar button/menu entry that should only be enabled if there is image data in the system clipboard. Otherwise it would be enabled always and only when you try to paste the clipboard content in your app you will realize that there is actually only text data in the clipboard. A clipboard aware UI is just a usability helper. <br />And totally independent on Eclipse. The only dependencies introduced here are the (optionally) ones to SWT. They are used to show a more fine grained notification mechanism that informs listeners of clipboard changes about the new content of the clipboard. <br />But then, one could easily provide a non-SWT implementation using JNA to read out the clipboard data and replace the SWT implementation. Or use AWT to read out the clipboard. <br />Once again, it's not about the selection service. The use case covered with this monitor are totally non-related to it.Philipp Kursawehttps://www.blogger.com/profile/01559531684494695413noreply@blogger.comtag:blogger.com,1999:blog-2528245647272415122.post-2701917273313139812010-02-10T17:04:15.932+01:002010-02-10T17:04:15.932+01:00First of all you don't really have to use syst...First of all you don't really have to use system clipboard, but selection of the workbench part that has the focus. Then you can just attach the listener that will update the UI according to selection changes.Eugene Kuleshovhttps://www.blogger.com/profile/08736056465101896635noreply@blogger.comtag:blogger.com,1999:blog-2528245647272415122.post-73352355992025991502010-02-10T07:03:53.075+01:002010-02-10T07:03:53.075+01:00Thanks Alex, for your comment. The sample swt bund...Thanks Alex, for your comment. The sample swt bundle was not well thought out. It was merely a demonstration of one possible use case. I thought filtering on the topic is a good idea. The bundle posts multiple events for each detected clipboard format. You are right, that it should better just send one event and set a String[] property for the formats and the EventListener could then filter with a target filter.<br />Unfortunately "swt" is needed to inspect the Clipboard and its also platform dependent. In the sample swt bundle I wanted to create event that do not necessarily imitate MIME types, but a more general approach of just describing roughly whats in the clipboard after the change. After all, the Windows clipboard does not understand the concept of MIME types, neither does the SWT Clipboard widget. And since most application save uncompressed DIB data for images in the Windows clipboard (instead of compressed JPEG or PNG data) I wanted to just send and "IMAGE" event.<br />What MIME-Types do you suggest for the various (SWT supported) clipboard formats?<br /><br /><br />@Eugene: Thank you for your comment. However, the ISelectionService has nothing to do what is presented here. It is in no way related to the (SWT) clipboard. If at all, it gives you only a possible *source* for a clipboard operation. It does not help you to enable UI elements based on whats in the system clipboard.Philipp Kursawehttps://www.blogger.com/profile/01559531684494695413noreply@blogger.comtag:blogger.com,1999:blog-2528245647272415122.post-77352661841691994192010-02-09T20:58:40.446+01:002010-02-09T20:58:40.446+01:00Oh my God! You don't need to reinvent the whee...Oh my God! You don't need to reinvent the wheel and can use ISelectionService instead http://help.eclipse.org/ganymede/index.jsp?topic=/org.eclipse.platform.doc.isv/reference/api/org/eclipse/ui/ISelectionService.htmlEugene Kuleshovhttps://www.blogger.com/profile/08736056465101896635noreply@blogger.comtag:blogger.com,1999:blog-2528245647272415122.post-72500415455821839112010-02-09T20:47:09.033+01:002010-02-09T20:47:09.033+01:00I think the event dispatching is a reasonable idea...I think the event dispatching is a reasonable idea, but it probably needs more work than what is covered at present. For example, data can be pasted onto the clipboard in multiple formats simultaneously (and/or converters can be used) so having a 'publish' event which is tied to the format is a bad idea. You ideally want to be able to publish the 'clipboard has changed' event and then let the filtering be done by properties of the event, not the message. There is support for the OSGi event admin to filter the events prior to dispatch in any case.<br /><br />Furthermore, using capitalised variants (like TXT) are pretty limiting in the face of MIME types (text/plain, text/html). Indeed, Apple has recently changed their type hierarchy to handle nested MIME types, called UTIs:<br /><br />http://www.roughlydrafted.com/2009/09/22/inside-snow-leopards-uti-apple-fixes-the-creator-code/<br /><br />Lastly, I don't think 'swt' is needed at all in this mention. One can write (headless) applications which still may yet use the clipboard.AlBluehttps://www.blogger.com/profile/06362201865553416948noreply@blogger.com