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    
026    /** Class for transfering a bookmark through a clipboard or drag and drop.
027     * @author <a href="mailto:chris@riedquat.de">Christian Hujer</a>
028     */
029    public class BookmarkTransferable implements Transferable {
030    
031        /** Data Flavor for Bookmarks. */
032        private static final DataFlavor bookmarkDataFlavor = initBookmarkFlavor();
033    
034        /** Initialize DataFlavor for Bookmarks.
035         * @return DataFlavor for Bookmarks
036         */
037        private static DataFlavor initBookmarkFlavor() {
038            try {
039                return new DataFlavor("application/x-jtest-bookmark");
040            } catch (ClassNotFoundException e) {
041                throw new Error(e);
042            }
043        }
044    
045        /** Supported DataFlavors. */
046        private static DataFlavor[] flavors = { bookmarkDataFlavor };
047    
048        /** Bookmark to be transferred. */
049        private final BookmarkManager.Bookmark bookmark;
050    
051        /** Create a BookmarkTransferable.
052         * @param bookmark Bookmark to transfer
053         */
054        public BookmarkTransferable(final BookmarkManager.Bookmark bookmark) {
055            this.bookmark = bookmark;
056        }
057    
058        /** {@inheritDoc} */
059        public Object getTransferData(final DataFlavor flavor) {
060            return bookmark;
061        }
062    
063        /** {@inheritDoc} */
064        public DataFlavor[] getTransferDataFlavors() {
065            return flavors;
066        }
067    
068        /** {@inheritDoc} */
069        public boolean isDataFlavorSupported(final DataFlavor flavor) {
070            return flavor.equals(bookmarkDataFlavor);
071        }
072    
073        /** Get the DataFlavor for Bookmarks.
074         * @return DataFlavor for Bookmarks
075         */
076        public static DataFlavor getBookmarkDataFlavor() {
077            return bookmarkDataFlavor;
078        }
079    
080    } // class BookmarkTransferable