@Override public boolean importData(TransferSupport support) throws ConverterException { try { if (support.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { List<File> files = (List<File>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); for (File file : files) { FileInputStream fis = null; OutputStream out = null; try { out = getOutputStream(file, ".hex"); fis = new FileInputStream(file); byte[] buffer = new byte[bufferSize]; int count = 0; while (-1 != (count = fis.read(buffer))) { if (count == bufferSize) { out.write(Hex.encodeHexString(buffer).getBytes("UTF-8")); } else { byte[] tmp = Arrays.copyOf(Hex.encodeHexString(buffer).getBytes("UTF-8"), count); out.write(tmp); } } } catch (Exception e) { throw new ConverterException(e); } finally { IOUtils.closeQuietly(out); IOUtils.closeQuietly(fis); } } return true; } else if (support.isDataFlavorSupported(DataFlavor.stringFlavor)) { String data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor); OutputStream out = null; try { byte[] encode = Hex.encodeHexString(data.getBytes()).getBytes(); out = getOutputStream(null, ".hex"); out.write(encode); } catch (Exception e) { throw new ConverterException(e); } finally { IOUtils.closeQuietly(out); } } } catch (Exception e) { throw new ConverterException(e); } return false; }
@Override public boolean canImport(TransferSupport support) { Transferable t = support.getTransferable(); if (!support.isDrop()) return false; if (support.isDataFlavorSupported(AnimationTreeTransferHandler.HierarchicalDataFlavor)) { support.setDropAction(LINK); return true; } else return false; }
@Override public boolean importData(TransferSupport support) { Transferable t = support.getTransferable(); try { HierarchicalData[] data = (HierarchicalData[]) t.getTransferData(AnimationTreeTransferHandler.HierarchicalDataFlavor); FrameEditor rec = (FrameEditor) support.getComponent(); for (Object obj : data) if (obj instanceof Animation) { Animation animation = (Animation) obj; for (Frame frame : animation.getFrames()) { rec.openImage(frame); } } else if (obj instanceof Frame) { rec.openImage((Frame) obj); } return true; } catch (Exception e) { e.printStackTrace(); return false; } }