List of usage examples for javax.swing TransferHandler canImport
public boolean canImport(TransferSupport support)
From source file:pl.otros.logview.gui.Log4jPatternParserEditor.java
private void enableDragAndDrop() { logFileContent.setDragEnabled(true); final TransferHandler defaultTransferHandler = logFileContent.getTransferHandler(); TransferHandler transferHandler = new TransferHandler() { @Override// w w w . j av a2s .co m public boolean importData(TransferSupport support) { if (isText(support)) { try { String transferData = (String) support.getTransferable() .getTransferData(DataFlavor.stringFlavor); if (transferData.startsWith("file://")) { String firstLine = transferData; if (firstLine.indexOf('\n') > 0) { firstLine = firstLine.substring(0, firstLine.indexOf('\n') - 1); } loadLogContent(VFS.getManager().resolveFile(firstLine)); } else { defaultTransferHandler.importData(support); } return true; } catch (UnsupportedFlavorException e) { LOGGER.warning("Can't import data, UnsupportedFlavorException: " + e.getMessage()); } catch (IOException e) { LOGGER.warning("Can't import data, IOException: " + e.getMessage()); } } if (isListOfFiles(support)) { try { List data = (List) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); if (data.size() > 0) { File file = (File) data.get(0); loadLogContent(VFS.getManager().resolveFile(file.getAbsolutePath())); return true; } } catch (UnsupportedFlavorException e) { LOGGER.warning("Can't import data, UnsupportedFlavorException: " + e.getMessage()); } catch (IOException e) { LOGGER.warning("Can't import data, IOException: " + e.getMessage()); } } return defaultTransferHandler.importData(support); } @Override public boolean canImport(TransferSupport support) { if (isText(support) || isListOfFiles(support)) { return true; } return defaultTransferHandler.canImport(support); } private boolean isListOfFiles(TransferSupport support) { return support.isDataFlavorSupported(DataFlavor.javaFileListFlavor); } private boolean isText(TransferSupport support) { return DataFlavor.selectBestTextFlavor(support.getDataFlavors()) != null; } }; logFileContent.setTransferHandler(transferHandler); loadLog.setTransferHandler(transferHandler); logFileContentLabel.setTransferHandler(transferHandler); }