001    /* JAPI - (Yet another (hopefully) useful) Java API
002     *
003     * Copyright (C) 2004-2006 Christian Hujer
004     *
005     * This program is free software; you can redistribute it and/or
006     * modify it under the terms of the GNU General Public License as
007     * published by the Free Software Foundation; either version 2 of the
008     * License, or (at your option) any later version.
009     *
010     * This program is distributed in the hope that it will be useful, but
011     * WITHOUT ANY WARRANTY; without even the implied warranty of
012     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013     * General Public License for more details.
014     *
015     * You should have received a copy of the GNU General Public License
016     * along with this program; if not, write to the Free Software
017     * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
018     * 02111-1307, USA.
019     */
020    
021    package net.sf.japi.swing.bookmarks;
022    
023    import java.awt.datatransfer.DataFlavor;
024    import java.awt.datatransfer.Transferable;
025    import javax.swing.JComponent;
026    import javax.swing.JTree;
027    import javax.swing.TransferHandler;
028    
029    /** Class for DnD in Bookmarks displaying JTrees.
030     * @author <a href="mailto:chris@riedquat.de">Christian Hujer</a>
031     * @todo improve implementation
032     */
033    public class BookmarkTransferHandler extends TransferHandler {
034    
035        /** Serial Version. */
036        private static final long serialVersionUID = 1L;
037    
038        /** {@inheritDoc} */
039        @Override
040        public Transferable createTransferable(final JComponent c) {
041            return new BookmarkTransferable((BookmarkManager.Bookmark)((JTree)c).getSelectionPath().getLastPathComponent());
042        }
043    
044        /** {@inheritDoc}
045         * @todo correctly implement this
046         */
047        @Override
048        public boolean canImport(final JComponent comp, final DataFlavor[] transferFlavors) {
049            // TODO
050            return true;
051        }
052    
053        /** {@inheritDoc} */
054        @Override
055        public int getSourceActions(final JComponent c) {
056            return COPY_OR_MOVE;
057        }
058    
059    } // class BookmarkTransferHandler