3

I was wondering if there was some sort of API library for Java (Swing) that allows your program to tell the system that it just opened a file so it can add it to the user's recent documents for any OS (like Windows' SHAddToRecentDocs). Does such a thing exist? Note: I am not considering j7Goodies as a solution.

Edit: The file in question I have already opened and I don't want the system to open it. I also keep track of recent documents in my program, I want to know how to tell the system I opened it without the system instructing the default program to open it.

BrainStorm.exe
  • 1,565
  • 3
  • 23
  • 40
  • "_It also would be nice if it could set the progress on its button..._" This doesn't make any sense. What button? – jahroy Mar 21 '13 at 22:00
  • My guess is it's up to the OS to track the user's recent documents. What you would be looking for is an API that allows you to access a user's _Recent Documents_ in an OS agnostic manner. – jahroy Mar 21 '13 at 22:01
  • Yes, that would be it. I'd like to tell the OS that the user just opened "this file". In regards to "Progress on its button", mean like allowing Java to tell the os how far it is on a long operation like when you are downloading a file. – BrainStorm.exe Mar 21 '13 at 22:09
  • Got it. I thought you wanted _Java_ to be told when a new file was opened. Didn't realize you wanted to use Java to _tell the system_ that a file has been opened. Thanks for clarifying. What platform are you on? Are you using Swing? – jahroy Mar 21 '13 at 22:26
  • Here's [a link about using Progress bars in Swing](http://docs.oracle.com/javase/tutorial/uiswing/components/progress.html). Here's a [question about loading circles](http://stackoverflow.com/q/1101268/778118) using Swing... and [another related question](http://stackoverflow.com/q/11846589/778118). – jahroy Mar 21 '13 at 22:39
  • Like when Firefox is downloading a file in Win 7, you see a progress bar in Firefox's task-bar button. That's what I meant, but it is not required. – BrainStorm.exe Mar 21 '13 at 22:56
  • 1
    You might want to edit your question to include such details. There's really no way people would have guessed that based on your original question. You should also edit the tags to include `Swing`. I would have edited them for you, but you still haven't confirmed that you **are** using Swing. You'll have a much better chance of getting a good answer if you include as much detail as possible in your question. As it stands (no details, irrelevant tags, confusing title) this question probably won't get much attention. – jahroy Mar 21 '13 at 23:14

1 Answers1

3

The class java.awt.Desktop includes an open() method that does this on Mac OSX. You'll want to test on your other target platforms. If you can't use the feature directly, this earlier incarnation of the API may suggest an approach.

Absent a better implementation, this FileMenu can be used within an application. Also, consider one of the persistence mechanisms mentions here.

Addendum: Internally, java.awt.Desktop delegates to an instance of a platform-specific java.awt.peer.DesktopPeer for each supported platform. You might be able to leverage the approach taken in existing implementations for the platforms you intend to support.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
  • 2
    `Desktop#open()` does this on Windows 7 as well. – FThompson Mar 22 '13 at 01:25
  • @Vulcan: Thanks! For testing on other platforms, [`FileBrowser`](http://codereview.stackexchange.com/q/4446/6692) also exercises `Desktop#open()`. – trashgod Mar 22 '13 at 01:27
  • AFAIK, there's no public API for that; you may be able to find concrete implementations of `java.awt.peer.DesktopPeer` for further study. – trashgod Mar 23 '13 at 03:02