* that contains a copy of the selected furniture in home.
*/
@Override
protected Transferable createTransferable(JComponent source) {
this.copiedFurniture = Home.getFurnitureSubList(this.home.getSelectedItems());
final Transferable transferable = new HomeTransferableList(this.copiedFurniture);
if (source instanceof FurnitureTable) {
// Create a text that describes furniture in CSV format
this.copiedCSV = ((FurnitureTable)source).getClipboardCSV();
// Create a transferable that contains copied furniture and its CSV description
return new Transferable () {
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
if (DataFlavor.stringFlavor.equals(flavor)) {
return copiedCSV;
} else {
return transferable.getTransferData(flavor);
}
}
public DataFlavor [] getTransferDataFlavors() {
ArrayList<DataFlavor> dataFlavors =
new ArrayList<DataFlavor>(Arrays.asList(transferable.getTransferDataFlavors()));
dataFlavors.add(DataFlavor.stringFlavor);
return dataFlavors.toArray(new DataFlavor [dataFlavors.size()]);
}
public boolean isDataFlavorSupported(DataFlavor flavor) {
return transferable.isDataFlavorSupported(flavor)
|| DataFlavor.stringFlavor.equals(flavor);
}
};
} else {
return transferable;