Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ConfigurationFileObject.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2004 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Nicolas Modrzyk
00022  * Contributor(s): ______________________.
00023  */
00024 
00025 package org.objectweb.cjdbc.console.gui.objects;
00026 
00027 import java.awt.Color;
00028 import java.awt.datatransfer.DataFlavor;
00029 import java.awt.datatransfer.Transferable;
00030 import java.awt.datatransfer.UnsupportedFlavorException;
00031 import java.awt.dnd.DnDConstants;
00032 import java.awt.dnd.DragSource;
00033 import java.io.File;
00034 import java.io.IOException;
00035 
00036 import org.objectweb.cjdbc.console.gui.constants.GuiCommands;
00037 import org.objectweb.cjdbc.console.gui.constants.GuiIcons;
00038 import org.objectweb.cjdbc.console.gui.dnd.listeners.ControllerTransferListener;
00039 
00040 /**
00041  * This class defines a ConfigurationFileObject
00042  * 
00043  * @author <a href="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
00044  * @version 1.0
00045  */
00046 public class ConfigurationFileObject extends AbstractGuiObject
00047     implements
00048       Transferable
00049 
00050 {
00051   private File       filePath;
00052   private String     text;
00053 
00054   /**
00055    * Creates a new <code>ConfigurationFileObject</code> object
00056    * 
00057    * @param filePath the path of the file represented by this configuration
00058    *            object
00059    * @param listener for drag and drop
00060    */
00061   public ConfigurationFileObject(ControllerTransferListener listener,String filePath)
00062   {
00063     this(listener,new File(filePath));
00064   }
00065 
00066   /**
00067    * Creates a new <code>ConfigurationFileObject</code> object
00068    * 
00069    * @param filePath file represented by this configuration object
00070    * @param listener for drag and drop
00071    */
00072   public ConfigurationFileObject(ControllerTransferListener listener,File filePath)
00073   {
00074     super();
00075     //addMouseMotionListener(listener);
00076     //addMouseListener(listener);
00077     this.filePath = filePath;
00078     text = filePath.getName();
00079     setText(text);
00080     setBackground(Color.white);
00081     setIcon(GuiIcons.CONFIGURATION_FILE_OBJECT_ICON);
00082     setActionCommand(GuiCommands.COMMAND_SELECT_XML_FILE);
00083     
00084     DragSource dragSource = DragSource.getDefaultDragSource();
00085     dragSource.createDefaultDragGestureRecognizer(this, // What component
00086         DnDConstants.ACTION_COPY_OR_MOVE, // What drag types?
00087         listener);// the listener
00088   }
00089 
00090   /**
00091    * @see java.awt.datatransfer.Transferable#getTransferDataFlavors()
00092    */
00093   public DataFlavor[] getTransferDataFlavors()
00094   {
00095     return new DataFlavor[]{};
00096   }
00097 
00098   /**
00099    * @see java.awt.datatransfer.Transferable#isDataFlavorSupported(java.awt.datatransfer.DataFlavor)
00100    */
00101   public boolean isDataFlavorSupported(DataFlavor flavor)
00102   {
00103     return true;
00104   }
00105 
00106   /**
00107    * @see java.awt.datatransfer.Transferable#getTransferData(java.awt.datatransfer.DataFlavor)
00108    */
00109   public Object getTransferData(DataFlavor flavor)
00110       throws UnsupportedFlavorException, IOException
00111   {
00112     if(flavor.equals(DataFlavor.stringFlavor))
00113       return filePath.getAbsolutePath();
00114     else 
00115       return null;
00116   }
00117 
00118   /**
00119    * Returns the filePath value.
00120    * 
00121    * @return Returns the filePath.
00122    */
00123   public String getFilePath()
00124   {
00125     return filePath.getAbsolutePath();
00126   }
00127 }

Generated on Mon Apr 11 22:01:30 2005 for C-JDBC by  doxygen 1.3.9.1