List of usage examples for java.awt.datatransfer UnsupportedFlavorException getMessage
public String getMessage()
From source file:com.qspin.qtaste.ui.TestCaseTree.java
public void drop(DropTargetDropEvent dtde) { //try//from ww w . j av a2s . co m { try { TCTreeNode tcTreeNode = (TCTreeNode) dtde.getTransferable().getTransferData(localObjectFlavor); Point dropPoint = dtde.getLocation(); // int index = locationToIndex (dropPoint); TreePath path = getPathForLocation(dropPoint.x, dropPoint.y); Object targetNode = path.getLastPathComponent(); if (targetNode instanceof TCTreeNode) { // rename the dragged dir into the new target one TCTreeNode tcTargetNode = (TCTreeNode) targetNode; FileNode fn = (FileNode) tcTargetNode.getUserObject(); if (fn.isTestcaseDir()) { dtde.rejectDrop(); return; } FileNode draggedFileNode = (FileNode) tcTreeNode.getUserObject(); draggedFileNode.getFile() .renameTo(new File(fn.getFile() + "/" + draggedFileNode.getFile().getName())); // update target tree testCasePane.parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); TCTreeNode parentTreeNode = (TCTreeNode) tcTargetNode.getParent(); if (parentTreeNode != null) { parentTreeNode.removeAllChildren(); FileNode parentFileNode = (FileNode) parentTreeNode.getUserObject(); addTreeToDir(parentFileNode.getFile(), parentTreeNode); ((DefaultTreeModel) getModel()).reload(parentTreeNode); } else { tcTargetNode.removeAllChildren(); FileNode targetFileNode = (FileNode) tcTargetNode.getUserObject(); addTreeToDir(targetFileNode.getFile(), tcTargetNode); ((DefaultTreeModel) getModel()).reload(tcTargetNode); } // update source tree parentTreeNode = (TCTreeNode) tcTreeNode.getParent(); if (parentTreeNode != null) { parentTreeNode.removeAllChildren(); FileNode parentFileNode = (FileNode) parentTreeNode.getUserObject(); addTreeToDir(parentFileNode.getFile(), parentTreeNode); ((DefaultTreeModel) getModel()).reload(parentTreeNode); } else { tcTreeNode.removeAllChildren(); FileNode targetFileNode = (FileNode) tcTreeNode.getUserObject(); addTreeToDir(targetFileNode.getFile(), tcTreeNode); ((DefaultTreeModel) getModel()).reload(tcTreeNode); } testCasePane.parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); dtde.getDropTargetContext().dropComplete(true); } else { dtde.rejectDrop(); } } catch (UnsupportedFlavorException ex) { logger.error(ex.getMessage()); } catch (IOException ex) { logger.error(ex.getMessage()); } } }
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//from w ww.j a v a 2 s .c o 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); }
From source file:tk.tomby.tedit.core.Workspace.java
/** * Creates a new WorkSpace object.//from w w w . j a va 2 s . c o m */ public Workspace() { super(); setLayout(new BorderLayout()); setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); MessageManager.addMessageListener(MessageManager.BUFFER_GROUP_NAME, new IMessageListener<BufferMessage>() { public void receiveMessage(BufferMessage message) { Workspace.this.receiveMessage(message); } }); MessageManager.addMessageListener(MessageManager.PREFERENCE_GROUP_NAME, new IMessageListener<PreferenceMessage>() { public void receiveMessage(PreferenceMessage message) { Workspace.this.receiveMessage(message); } }); bufferPane = new JTabbedPane(); bufferPane.setMinimumSize(new Dimension(600, 400)); bufferPane.setPreferredSize(new Dimension(800, 600)); bufferPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); bottomPort = createDockingPort(0, 80); rightPort = createDockingPort(80, 0); leftPort = createDockingPort(80, 0); splitPaneRight = createSplitPane(JSplitPane.HORIZONTAL_SPLIT, bufferPane, rightPort); splitPaneLeft = createSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPort, splitPaneRight); splitPaneBottom = createSplitPane(JSplitPane.VERTICAL_SPLIT, splitPaneLeft, bottomPort); bufferPane.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent evt) { MessageManager .sendMessage(new WorkspaceMessage(evt.getSource(), bufferPane.getSelectedComponent())); } }); bufferPane.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if (evt.getClickCount() == 2) { splitPaneLeft.setDividerLocation(0.0d); splitPaneBottom.setDividerLocation(1.0d); splitPaneRight.setDividerLocation(1.0d); } } }); DropTarget dropTarget = new DropTarget(bufferPane, new DropTargetAdapter() { public void drop(DropTargetDropEvent dtde) { if (log.isDebugEnabled()) { log.debug("drop start"); } try { if (log.isDebugEnabled()) { log.debug(dtde.getSource()); } Transferable tr = dtde.getTransferable(); DataFlavor[] flavors = tr.getTransferDataFlavors(); for (int i = 0; i < flavors.length; i++) { DataFlavor flavor = flavors[i]; if (log.isDebugEnabled()) { log.debug("mime-type:" + flavor.getMimeType()); } if (flavor.isMimeTypeEqual("text/plain")) { final Object obj = tr.getTransferData(flavor); if (log.isDebugEnabled()) { log.debug(obj); } if (obj instanceof String) { TaskManager.execute(new Runnable() { public void run() { BufferFactory factory = new BufferFactory(); IBuffer buffer = factory.createBuffer(); buffer.open((String) obj); addBuffer(buffer); } }); } dtde.dropComplete(true); return; } } } catch (UnsupportedFlavorException e) { log.warn(e.getMessage(), e); } catch (IOException e) { log.warn(e.getMessage(), e); } dtde.rejectDrop(); if (log.isDebugEnabled()) { log.debug("drop end"); } } }); bufferPane.setDropTarget(dropTarget); this.add(BorderLayout.CENTER, splitPaneBottom); }