KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > console > gui > objects > ConfigurationFileObject


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.console.gui.objects;
26
27 import java.awt.Color JavaDoc;
28 import java.awt.datatransfer.DataFlavor JavaDoc;
29 import java.awt.datatransfer.Transferable JavaDoc;
30 import java.awt.datatransfer.UnsupportedFlavorException JavaDoc;
31 import java.awt.dnd.DnDConstants JavaDoc;
32 import java.awt.dnd.DragSource JavaDoc;
33 import java.io.File JavaDoc;
34 import java.io.IOException JavaDoc;
35
36 import org.objectweb.cjdbc.console.gui.constants.GuiCommands;
37 import org.objectweb.cjdbc.console.gui.constants.GuiIcons;
38 import org.objectweb.cjdbc.console.gui.dnd.listeners.ControllerTransferListener;
39
40 /**
41  * This class defines a ConfigurationFileObject
42  *
43  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
44  * @version 1.0
45  */

46 public class ConfigurationFileObject extends AbstractGuiObject
47     implements
48       Transferable JavaDoc
49
50 {
51   private File JavaDoc filePath;
52   private String JavaDoc text;
53
54   /**
55    * Creates a new <code>ConfigurationFileObject</code> object
56    *
57    * @param filePath the path of the file represented by this configuration
58    * object
59    * @param listener for drag and drop
60    */

61   public ConfigurationFileObject(ControllerTransferListener listener,String JavaDoc filePath)
62   {
63     this(listener,new File JavaDoc(filePath));
64   }
65
66   /**
67    * Creates a new <code>ConfigurationFileObject</code> object
68    *
69    * @param filePath file represented by this configuration object
70    * @param listener for drag and drop
71    */

72   public ConfigurationFileObject(ControllerTransferListener listener,File JavaDoc filePath)
73   {
74     super();
75     //addMouseMotionListener(listener);
76
//addMouseListener(listener);
77
this.filePath = filePath;
78     text = filePath.getName();
79     setText(text);
80     setBackground(Color.white);
81     setIcon(GuiIcons.CONFIGURATION_FILE_OBJECT_ICON);
82     setActionCommand(GuiCommands.COMMAND_SELECT_XML_FILE);
83     
84     DragSource JavaDoc dragSource = DragSource.getDefaultDragSource();
85     dragSource.createDefaultDragGestureRecognizer(this, // What component
86
DnDConstants.ACTION_COPY_OR_MOVE, // What drag types?
87
listener);// the listener
88
}
89
90   /**
91    * @see java.awt.datatransfer.Transferable#getTransferDataFlavors()
92    */

93   public DataFlavor JavaDoc[] getTransferDataFlavors()
94   {
95     return new DataFlavor JavaDoc[]{};
96   }
97
98   /**
99    * @see java.awt.datatransfer.Transferable#isDataFlavorSupported(java.awt.datatransfer.DataFlavor)
100    */

101   public boolean isDataFlavorSupported(DataFlavor JavaDoc flavor)
102   {
103     return true;
104   }
105
106   /**
107    * @see java.awt.datatransfer.Transferable#getTransferData(java.awt.datatransfer.DataFlavor)
108    */

109   public Object JavaDoc getTransferData(DataFlavor JavaDoc flavor)
110       throws UnsupportedFlavorException JavaDoc, IOException JavaDoc
111   {
112     if(flavor.equals(DataFlavor.stringFlavor))
113       return filePath.getAbsolutePath();
114     else
115       return null;
116   }
117
118   /**
119    * Returns the filePath value.
120    *
121    * @return Returns the filePath.
122    */

123   public String JavaDoc getFilePath()
124   {
125     return filePath.getAbsolutePath();
126   }
127 }
128
Popular Tags