Drag a File to System (VLC)

Hi,
I want to drag a file from a Java Application from a JButton to a VLC Player outside the application, so it will be played in VLC. The application knows the path. I use a button to have some area that is easy and fast to hit.
To add drag functionallity to a button I use the drag source examples from www.java2s.com/Code/Java/Swing-JFC/JLabelDragSource.htm. I made some minor changes to support a button and now I can drag easily a string (the path). But VLC seems not to accept a string. So I think I have to use the javaFileListFlavor as the mime type.
The example I mentioned uses explicit a class for a DragSource and a rewritten Transferable class. I think to add javaFileListFlavor behaviour it is nessecary to add this to the Transferable class. But I don't really understand some things in the coding, escpecially at the end of the class. Here is my current code:
import java.awt.Font;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragSource;
import java.awt.dnd.DragSourceDragEvent;
import java.awt.dnd.DragSourceDropEvent;
import java.awt.dnd.DragSourceEvent;
import java.awt.dnd.DragSourceListener;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Iterator;
import javax.swing.*;
class JButtonTransferable implements Transferable {
     GeneralEnvironment genE;
     public JButtonTransferable(JButton button, GeneralEnvironment genE) {
          this.button = button;
          this.genE = genE;
     // Implementation of the Transferable interface
     public DataFlavor[] getTransferDataFlavors() {
          return flavors;
     public boolean isDataFlavorSupported(DataFlavor fl) {
          for (int i = 0; i < flavors.length; i++) {
               if (fl.equals(flavors)) {
                    return true;
          return false;
     public Object getTransferData(DataFlavor fl) {
          if (!isDataFlavorSupported(fl)) {
               return null;
          if (fl.equals(DataFlavor.stringFlavor)) {
               // String - return the text as a String
               //return button.getText() + " (DataFlavor.stringFlavor)";
               return genE.getClipDragString();
          } else if (fl.equals(jButtonFlavor)) {
               // The JButton itself - just return the button.
               return button;
          } else {
               // Plain text - return an InputStream
               try {
                    //String targetText = button.getText() + " (plain text flavor)";
                    String targetText = genE.getClipDragString(); // + " (plain text flavor)";
                    int length = targetText.length();
                    ByteArrayOutputStream os = new ByteArrayOutputStream();
                    OutputStreamWriter w = new OutputStreamWriter(os);
                    w.write(targetText, 0, length);
                    w.flush();
                    byte[] bytes = os.toByteArray();
                    w.close();
                    return new ByteArrayInputStream(bytes);
               } catch (IOException e) {
                    return null;
     // A flavor that transfers a copy of the JButton
     public static final DataFlavor jButtonFlavor = new DataFlavor(JButton.class, "Swing JLabel");
     private JButton button; // The button being transferred
     private static final DataFlavor[] flavors = new DataFlavor[] {
          DataFlavor.stringFlavor, new DataFlavor("text/plain; charset=ascii", "ASCII text"), jButtonFlavor
}The genE Object (GeneralEnvironment) is my own object that is capable to provide a current path as a string.
My problem is, that I don't know how to add javaFileListFlavor in this environment. I saw examples on javaFileListFlavor, but they have different classes they add and rewrite. Unfortunatly I can't bring them together. Anyone an idea?
- Frankie
Edited by: rebelman on Apr 11, 2010 3:00 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Oho ... my fault. Solved
I was not recognizing that the last line of code was a simple init of an array. When I found out that this is the case it was simple to add file drag support. The main changes are here. The array init is now formatted different:
     public Object getTransferData(DataFlavor fl) {
          if (!isDataFlavorSupported(fl)) {
               return null;
          if (fl.equals(DataFlavor.stringFlavor)) {
               // String - return the text as a String
               //return button.getText() + " (DataFlavor.stringFlavor)";
               return genE.getClipDragString();
          } else if (fl.equals(jButtonFlavor)) {
               // The JButton itself - just return the button.
               return button;
          } else if (fl.equals(DataFlavor.javaFileListFlavor)) {
               Vector<File> files = new Vector<File>(1,1);
               files.add( new File(genE.getClipDragString()) );
               return files;
          } else {
               // Plain text - return an InputStream
               try {
                    //String targetText = button.getText() + " (plain text flavor)";
                    String targetText = genE.getClipDragString(); // + " (plain text flavor)";
                    int length = targetText.length();
                    ByteArrayOutputStream os = new ByteArrayOutputStream();
                    OutputStreamWriter w = new OutputStreamWriter(os);
                    w.write(targetText, 0, length);
                    w.flush();
                    byte[] bytes = os.toByteArray();
                    w.close();
                    return new ByteArrayInputStream(bytes);
               } catch (IOException e) {
                    return null;
     // A flavor that transfers a copy of the JButton
     public static final DataFlavor jButtonFlavor = new DataFlavor(JButton.class, "Swing JLabel");
     private JButton button; // The button being transferred
     private static final DataFlavor[] flavors = new DataFlavor[] {
          DataFlavor.stringFlavor,
          DataFlavor.javaFileListFlavor,
          new DataFlavor("text/plain; charset=ascii", "ASCII text"),
          jButtonFlavor
     };So know it workes and files (or pathes that I have in the app) can be easily dragged from a button to VLC player on windows (other OS'es I haven't testet.
Thanks for patience,
- Frankie

Similar Messages

  • I have been dragging my files to a external drive to have a back-up for them and I lost some of my folders. They just went completely missing. I didn't delete them, and it was all stuff that I have worked on in the past month. How do I get them back?

    I have been dragging my files to a external drive to have a back-up for them and I lost some of my folders. They just went completely missing. I didn't delete them, and it was all stuff that I have worked on in the past month. How do I get them back?

    You really should be doing backups with an actual backup application, especially one that will work automatically, and, if your external HD is large enough, back up your entire system.  These can automatically back up only what's changed since the  previous backup, and some will keep "archive" copies of things you've changed or deleted, also.
    Too many things can go wrong, such as your internal HD failing, and you'll have a major project to reinstall everything.
    You already have Time Machine, built-in to OSX.  You might want to review the Time Machine Tutorial, and perhaps browse Time Machine - Frequently Asked Questions.
    #27 in the second link mentions some alternatives, too.

  • Can't drag any files from iTunes

    Suddenly, I can't drag any of the songs in my library in iTunes to my iPod, to other playlists, or to anywhere. When I try to click and drag, the file doesn't stick to the cursor. It just stays put. I am using the latest version of iTunes on the lastest system 10. Any ideas?
    Thanks.
    Sam

    Sounds like a permissions problem.

  • Why can't I drag my files in finder to an external hard drive?

    I'm trying to drag my files from finder to an external hard drive--I just get the universal "do not" symbol.  How do I do this?

    1.youd need a program like PARAGON to write to a NTFS drive from your Mac.
    2. IF you can offload that data onto your PC or other computer, THEN format same in Mac OSX extended journaled, you can just drag and drop files to it.
    3. To show the HD on desktop go to Finder > preferences > General > check on "external disks" and "hard disks"
    4. The "EASY" option really is to get another HD for use with your Mac, unless of course you need specific files off that drive ON your Mac.
    $70 for a good cheap quality 1TB external USB HD.
    5.  FAT32 and (better option>) EXFAT can read/write to BOTH Mac and PC   (however time machine will not use either)
    6. See mac format below, HFS+ i.e. "mac osx extended journaled"
    FORMAT TYPES
    FAT32 (File Allocation Table)
    Read/Write FAT32 from both native Windows and native Mac OS X.
    Maximum file size: 4GB.
    Maximum volume size: 2TB
    You can use this format if you share the drive between Mac OS X and Windows computers and have no files larger than 4GB.
    NTFS (Windows NT File System)
    Read/Write NTFS from native Windows.
    Read only NTFS from native Mac OS X
    To Read/Write/Format NTFS from Mac OS X, here are some alternatives:
    For Mac OS X 10.4 or later (32 or 64-bit), install Paragon (approx $20) (Best Choice for Lion)
    Native NTFS support can be enabled in Snow Leopard and Lion, but is not advisable, due to instability.
    AirPort Extreme (802.11n) and Time Capsule do not support NTFS
    Maximum file size: 16 TB
    Maximum volume size: 256TB
    You can use this format if you routinely share a drive with multiple Windows systems.
    HFS+ ((((MAC FORMAT)))) (Hierarchical File System, a.k.a. Mac OS Extended (Journaled) Don't use case-sensitive)
    Read/Write HFS+ from native Mac OS X
    Required for Time Machine or Carbon Copy Cloner or SuperDuper! backups of Mac internal hard drive.
    To Read HFS+ (but not Write) from Windows, Install HFSExplorer
    Maximum file size: 8EiB
    Maximum volume size: 8EiB
    You can use this format if you only use the drive with Mac OS X, or use it for backups of your Mac OS X internal drive, or if you only share it with one Windows PC (with MacDrive installed on the PC)
    EXFAT (FAT64)
    Supported in Mac OS X only in 10.6.5 or later.
    Not all Windows versions support exFAT. 
    exFAT (Extended File Allocation Table)
    AirPort Extreme (802.11n) and Time Capsule do not support exFAT
    Maximum file size: 16 EiB
    Maximum volume size: 64 ZiB
    You can use this format if it is supported by all computers with which you intend to share the drive.  See "disadvantages" for details.

  • Reset icons for a file type system wide?

    All of the .mpg files on my system are from a camcorder that records MPEG-2 video with 5.1-channel audio that QuickTime cannot play.
    By default all of these .mpg files had a QuickTime icon, even though QuickTime can't play them. I assigned a different application (VLC) to these files through the normal Get Info >> Open With >> Change All method and now all of my .mpg files open with VLC and play just fine.
    However, after I pressed Change All it seems the system changed about half of the icons on my .mpg files to VLC's icon and left the rest with QuickTime icons.
    Is there any way to change all the .mpg icons back to one or the other (preferably VLC, since that's what actually plays them)?
    Needless to say changing icons one file at a time would be too time consuming.
    Any help appreciated.

    The problem I had may be similar to yours. I de-installed iWork 8, after testing it. I have a registered copy of iWork 6 and i was happy.
    Anyway, after the de-installation all the Pages icons where folder icons!?! While searching the net for a solution, because none of the described methods worked, I remembered that *Onyx, the maintenance program, has a function to delete and rebuild the application-file links*.
    So I did this and everything was fine after assigning the default application (Pages)...except one of my pdf file icons on the desktop was broken, so be aware!

  • Very basic question regarding drag/drop files in 10.6.5

    Just (finally) updated to Snow Leopard and the simple way of dragging a file to the bar (just above the list of items in the folder) so as to move it to that folder no longer works.
    I prefer not to drag it to above other files in the folder and hoping that the file won't end up in a folder (which has now happened several times).
    There must be a simple-no-brainer way of doing this as there was before in 10.5 and as far back as I can remember (been using Macs since the mid-90's).
    Why did Apple decide to change this? Did they find a simpler way that I haven't figured out?
    Thanks for any advice.
    RonL

    MacRumors forum answered my question almost immediately... and yes they acknowledged that Apple had changed this in Snow Leopard for no good reason.
    On both my Leopard and Snow Leopard systems, you cannot drag a file to the title bar (not the "name bar"). On both systems, you can drag a file to the empty space in a window. I just tested to make sure. So, either your description of the problem is completely and utterly inadequate, you are misunderstanding what was said on MacRumors, or someone on MacRumors doesn't know what they're talking about.
    How long have you guys been using Macs?
    26 years, like baltwo. As a Mac support professional, programmer, web designer and more. I've forgotten more about Macs than you have ever known, I'm sure. Nobody here is impressed that you have used Macs for a little more than half that time, and your rudeness is most definitely not appreciated.
    It's one thing to not give me an answer... no problem, fine, but it is an entirely different thing to say that what I have done for years, and that has worked easily for me, has never worked.
    You claim that it changed with Snow Leopard. Clearly, it did not. As I've said, I have both Leopard and Snow Leopard systems and have verified that as fact. Once upon a time you could drag to the title bar, but I honestly don't have any idea when that behavior changed. I'd guess in 10.0, but have no way to verify that at this point.

  • Drag drop file viewer

    I am somewhat new to java. I built my app in JSP. I need to create an interface for viewing shared files. where the user could drag a file from their Desktop to that window and it would save to the server then be viewable on that page. Is this even possible or am I just dreaming. So far the only thing close Ive seen is MS-Sharepoint. Any advice would be greatly appreciated.

    Hi.
    Firstly...do you have 4.0.1? If not, make sure you update the software.
    Secondly I'll admit to being fairly new to FCE. So with that in mind I found an outstanding book that helped me get started. It's called Final Cut Express 4 Editing Workshop, by Tom Wolsky. The book takes you from your system, developing a good work flow, and basic editing. From there he gets into some more advanced titling, animation, and various corrections that can be applied to your projects. It even comes with a dvd with lessons that make the whole book interactive. It has answered a lot of questions that I had and got me going in the right direction.
    There are a few other FCE/FCP users here that I'm sure will have more info, but like I said, this book helped me quite a bit.
    Good Luck

  • All of a sudden, I need to use my password to drag a file to 'Trash'; how do I turn off the password requirement?

    I've had this MacBook Air for 9 months and never had to type a pasword in so I could drag a file to the trash. Yesterday, the computer started requiring me to type my password in so that a file could be dragged to 'Trash'. Why did this start happening, and how do I turn off the requirment for my password?

    Repairing the permissions of a home folder in Lion is a complicated procedure. I don’t know of a simpler one that always works.
    Back up all data now. Before proceeding, you must be sure you can restore your system to its present state
    Launch the Terminal application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ Open LaunchPad. Click Utilities, then Terminal in the page that opens.
    Drag or copy — do not type — the following line into the Terminal window, then press return:
    chmod -R -N ~
    The command will take a noticeable amount of time to run. When a new line ending in a dollar sign ($) appears below what you entered, it’s done. You may see a few error messages about an “invalid argument” while the command is running. You can ignore those. If you get an error message with the words “Permission denied,” enter this:
    sudo !!
    You'll be prompted for your login password, which won't be displayed when you type it. You may get a one-time warning not to screw up.
    Next, boot into Recovery by holding down the key combination command-R at startup. Release the keys when you see a gray screen with a spinning dial.
    When the Recovery screen appears, select Utilities ▹ Terminal from the menu bar.
    In the Terminal window, enter “resetpassword” (without the quotes) and press return. A Reset Password window opens. You’re not going to reset the password.
    Select your boot volume if not already selected.
    Select your username from the menu labeled Select the user account if not already selected.
    Under Reset Home Directory Permissions and ACLs, click the Reset button.
    Select  ▹ Restart from the menu bar.

  • Dragging a File Onto Fluxbox Toolbar

    Hello.
    My first post in the Arch Linux forums. Let me start out by saying that I find the community great. Arch Linux is indeed an amazing distribution. It took me quite some effort to get my laptop working but I am immensely satisfied with the results I have managed to obtain.
    I am using Fluxbox as a WIndow Manager and have configured it to suit my muscle memory from the Ubuntu days. One of the things that I have gotten used to from Ubuntu 12.04 is the ability to drag a file from a FIle Manager onto the taskbar and the corresponidng application to get automatically maximized so that I can drag the file onto it.
    One example: Drag an image file onto an open session of LibreOffice Impress and paste it onto a slide directly.
    Another: Drag a file to a GMail window tab on task bar and drop it as an attachment.
    Another: Drag subtitle file onto VLC
    etc.
    I tried the following but could not achieve this behavior with Fluxbox.
    OnToolbar Mouse1:Maximize
    OnToolbar Mouse1:Click1
    Can someone guide me in the right direction? Thanks in advance.
    PS: Being new on the forums, I may be inadvertently breaking some forum norm, please do let me know if this is the case.

    I read somewhere that this feature was taken out which kinda ***** since I used it quite a bit. Anyway, it still works from the Trash icon and you can just drag it to whichever place you want it to go on the sidebar.

  • Trying to drag pdf files i have and combine them into one pdf file in the account i just purchased with Adobe. when i drag a pdf file over Adobe doesn't accept it. says it can not convert this type of file. but it is an Adobe file. Do I need to change it?

    Trying to drag pdf files i have and combine them into one pdf file in the account i just purchased with Adobe. when i drag a pdf file over Adobe doesn't accept it. says it can not convert this type of file. but it is an Adobe file. Do I need to change it in some other form befor dragging it?

    Hello djensen1x,
    Could you please let me know what version of Acrobat are you using.
    Also, tell me your workflow of combining those PDF files?
    Please share the screenshot of the error message that you get.
    Hope to get your response.
    Regards,
    Anubha

  • Drag a file from a folder to my desktop

    When I try to drag a file from a folder to my desktop, it gets thrown to the upper left-hand corner, almost all of it 'off' the desktop, not where I tried to 'set' it...wuwt?

    In ~/Library/Preferences: Trash helpviewer.plist and helpviewer.plist.lockfile
    In ~/Library/Caches: Trash all folders
    In Macintosh HD/Library/Caches: Trash all folders
    Restart iMac, and then Empty Trash.
    The credit goes to whoever posted this on the net… it worked for me

  • Unable to double-click or drag/drop files to open.

    I'm running Photoshop CC 64 on a Windows 7 64 machine and am only able to open files in Photoshop by going to File->Open. Double-clicking from Explorer doesn't work and i can not drag/drop files into the open application window or taskbar icon. Right clicking on files and selecting "Open with" also doesn't work.
    I checked file associations and made sure to choose CC 64. If I right click on the shortcut and choose "Run As Administrator" which I have to do in order to get files to open between Lightroom and Photoshop (both need to be Run As Administrator), I'm still unable to open from Windows Explorer. However, if I check the box to "Run this program as administrator" in the shortcut's Compatibility tab, I can double-click to open from Explorer but am prompted with a UAC warning every time. Dragging/dropping into the open app still doesn't work.
    Opening between Bridge and PS works as expected so long as both programs are "Run As Administrator"
    Been searching the forums here and seen suggestions of similar but not the same issue, at least not that I've found.
    Anyone else experiencing? Suggested remedies?

    This is an OS permission problem.  Make sure you have ownership of the HD.  Do a web search on how to check.  External HD can be a problem for permission.

  • Bridge CS5 Windows crashes when I command/move or drag/drop files internally

    Bridge CS5 crashes with a Microsoft "report error" dialog whenever I drag images from one folder to another inside of Bridge, or use the right-click "Move To . . ." mouse command.  After months of successful use of the Bridge CS5, this behavior suddenly began.  Unfortunately, I can't now remember whether I did anything to my Windows environment at that time.  Bridge does not have trouble with dragging or command/moving files into Photoshop, but dragging image files (jpg) from a search screen or the Windows Explorer can also end in a crash.
    I'm running Windows XP SP3 32-bit on a 4-processor machine with adequate ram and lots of hard drive/scratch drive.  I deinstalled every trace of Bridge and reinstalled the upgrade 4.0.2.1, which makes me up to date. Working with Adobe Support I also cleared and uninstalled, and then reinstalled Photoshop, Bridge, etc. to fix some other problems.
    I have experimented with purging the Bridge cache for individual folders I was dragging from and to, but didn't purge all caches.  Typically, the crash appears a few seconds after dragging/moving a file - continuosly sucking-me into thinking things are at last repaired.  On occasion images are lost - i.e. really destroyed, or dropped into some limbo somewhere.
    I'd be truly grateful for any ideas to try, no matter how extensive or simple.
    Thanks!

    Hi Robert,
    I'm a developer from Br team. Thanks for reporting Br. problems.
    It seems like a memory issue. Please try this to help us identify the root cause:
    1. Disable all startup scripts (Edit->Preferences->Startup Scripts->Disable All), then restart Br.
    2. When Br is running, kill "SwitchBoard" process in task manager.
    3. When do Copy&Move operations, don't use Drag&Drop, try to use "Move To / Copy To" menu. (A known issue of Bridge, should be fixed in later versions)
    Does the crash still happens?
    Thanks very much!

  • I have dragged 2 files to the trash bin but I cannot delete them from the trash bin. It keeps telling me these files are in use when they are not. How do I delete these files? One is a txt file and the other is an xls file

    I have dragged 2 files to the trash bin but I cannot delete them from the trash bin. It keeps telling me these files are in use when they are not. How do I delete these files? One is a txt file and the other is an xls file

    From the Finder menu select 'Secure Empty Trash'. If this or the suggestion above doesn't resolve the problem take a look at the various suggestions in this link:
    http://www.thexlab.com/faqs/trash.html

  • How can I add .m4r files (thatI have shortened to 30 seconds or less) to iTunes 11.0.1? I cannot find a ringtones folder in Itunes ans it won't let me drag the files to the sidebar...

    How can I add .m4r files (that I have shortened to 30 seconds or less) to iTunes 11.0.1? I cannot find a ringtones folder in Itunes and it won't let me drag the files to the sidebar...thanks!

    How can I add .m4r files (that I have shortened to 30 seconds or less) to iTunes 11.0.1? I cannot find a ringtones folder in Itunes and it won't let me drag the files to the sidebar...thanks!

Maybe you are looking for