1 24 25 package org.objectweb.cjdbc.console.gui.objects; 26 27 import java.awt.Color ; 28 import java.awt.datatransfer.DataFlavor ; 29 import java.awt.datatransfer.Transferable ; 30 import java.awt.datatransfer.UnsupportedFlavorException ; 31 import java.awt.dnd.DnDConstants ; 32 import java.awt.dnd.DragSource ; 33 import java.io.File ; 34 import java.io.IOException ; 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 46 public class ConfigurationFileObject extends AbstractGuiObject 47 implements 48 Transferable 49 50 { 51 private File filePath; 52 private String text; 53 54 61 public ConfigurationFileObject(ControllerTransferListener listener,String filePath) 62 { 63 this(listener,new File (filePath)); 64 } 65 66 72 public ConfigurationFileObject(ControllerTransferListener listener,File filePath) 73 { 74 super(); 75 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 dragSource = DragSource.getDefaultDragSource(); 85 dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, listener); } 89 90 93 public DataFlavor [] getTransferDataFlavors() 94 { 95 return new DataFlavor []{}; 96 } 97 98 101 public boolean isDataFlavorSupported(DataFlavor flavor) 102 { 103 return true; 104 } 105 106 109 public Object getTransferData(DataFlavor flavor) 110 throws UnsupportedFlavorException , IOException 111 { 112 if(flavor.equals(DataFlavor.stringFlavor)) 113 return filePath.getAbsolutePath(); 114 else 115 return null; 116 } 117 118 123 public String getFilePath() 124 { 125 return filePath.getAbsolutePath(); 126 } 127 } 128 | Popular Tags |