/** Move a block it's prior location to the drop location */ @Override public boolean importData(TransferSupport supp) { if (canImport(supp)) { IconList list = (IconList) supp.getComponent().getParent().getParent().getParent(); JViewport panel = (JViewport) supp.getComponent().getParent(); try { Transferable t = supp.getTransferable(); int from = (int) t.getTransferData(DataFlavor.imageFlavor); list.move( from, (int) (Math.ceil( supp.getDropLocation().getDropPoint().getX() * list.length() / panel.getViewSize().getWidth() - 1)), false); } catch (Exception e) { e.printStackTrace(); return false; } return true; } return false; }
@Override public boolean importData(TransferSupport support) { DataFlavor f = getStringFlavor(support.getDataFlavors()); Object drop = null; String s = null; if (f != null) { try { drop = support.getTransferable().getTransferData(f); } catch (UnsupportedFlavorException e) { Logger.getLogger(this.getClass()).debug("Internal error.", e); // $NON-NLS-1$ } catch (IOException e) { Logger.getLogger(this.getClass()).debug("Internal error.", e); // $NON-NLS-1$ } } else { try { drop = support.getTransferable().getTransferData(DataFlavor.stringFlavor); } catch (UnsupportedFlavorException e) { Logger.getLogger(this.getClass()).debug("Internal error.", e); // $NON-NLS-1$ } catch (IOException e) { Logger.getLogger(this.getClass()).debug("Internal error.", e); // $NON-NLS-1$ } } if (drop != null) { s = String.valueOf(drop); } if (s != null) { return importString(s, support); } return false; }
@Override public boolean canImport(TransferSupport support) { if (!support.isDataFlavorSupported(DominoTransferable.getFlavor())) return false; if (!(support.getComponent() instanceof DominoDisplay)) return false; return true; }
@Override public boolean importData(TransferSupport support) { if (!canImport(support) || support.getDropAction() != TransferHandler.MOVE) return false; playerDominoesDialog.setTradePlacesDominoDisplay((DominoDisplay) support.getComponent()); return true; }
@Override public boolean importData(TransferSupport support) { if (!isDataFlavorValid(support)) return false; DropLocation dl = support.getDropLocation(); if (!(dl instanceof JTree.DropLocation)) return false; dropLocation = (JTree.DropLocation) dl; Transferable transferable = support.getTransferable(); if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) { try { LayerTreeModel model = layersTree.getLayerModel(); List<?> files = (List<?>) transferable.getTransferData(DataFlavor.javaFileListFlavor); int i = 0; for (Object o : files) { if (o instanceof File) { File file = (File) o; URL url = file.toURI().toURL(); ILayerDefinition definition = new LayerDefinition(file.getName(), url, null, Icons.file.getURL(), true, false); INode node = LayerNode.createFromLayerDefinition(definition); addNodeToTree(dropLocation, model, node, false, i++); } } layersTree.getUI().relayout(); dropLocation = null; } catch (Exception e) { return false; } } return true; }
@Override @SuppressWarnings("unchecked") public boolean importData(TransferSupport support) { if (!this.canImport(support)) return false; if (support.getComponent() == mTextArea && mTextHandler.importData(support)) { // dropping text on text area was handled return true; } List<File> files; try { files = (List<File>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); } catch (UnsupportedFlavorException | IOException ex) { // should never happen (or JDK is buggy) return false; } for (File file : files) { if (Utils.isAllowedAttachmentFile(file)) { mChatView.sendFile(file); } } return !files.isEmpty(); }
/* (non-Javadoc) * @see javax.swing.TransferHandler#importData(javax.swing.TransferHandler.TransferSupport) */ @Override public boolean importData(TransferSupport support) { try { if (support.getComponent() instanceof JTree) { JTree tree = (JTree) support.getComponent(); Point dropPoint = support.getDropLocation().getDropPoint(); TreePath path = tree.getPathForLocation(dropPoint.x, dropPoint.y); Object node = path.getLastPathComponent(); if (support.isDataFlavorSupported(ProcessVar.PvDataFlavors[0])) { ProcessVar tVar = (ProcessVar) ((PvTreeNode) node).getUserObject(); ProcessVar chldPv = (ProcessVar) support.getTransferable().getTransferData(ProcessVar.PvDataFlavors[0]); Object chldKey = chldPv.getKeyValue(); tVar.put(chldKey, chldPv, PvChangeEvent.PV_ADDED); DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); model.nodeStructureChanged((TreeNode) model.getRoot()); return true; } } } catch (UnsupportedFlavorException e) { ProcessVar.log.error(this.toString() + ":" + e.getMessage()); } catch (IOException e) { ProcessVar.log.error(this.toString() + ":" + e.getMessage()); } // anything else is handled by superclass return super.importData(support); }
public boolean canImport(TransferSupport support) { if (!inDrag || !support.isDataFlavorSupported(DATA_FLAVOUR)) { return false; } JList.DropLocation dl = (JList.DropLocation) support.getDropLocation(); if (dl.getIndex() == -1) { return false; } else { return true; } }
@Override public boolean canImport(TransferSupport support) { if (support.isDrop() && !mDropEnabled) return false; if (support.getComponent() == mTextArea && mTextHandler.canImport(support)) return true; for (DataFlavor flavor : support.getDataFlavors()) { if (flavor.isFlavorJavaFileListType()) { return true; } } return false; }
/** * Imports the drop data by going over the list of supported callbacks. This method will return * true if a callback could be found that could successfully import the drop data, or false * otherwise. * * @param support The TransferSupport describing the drop event. * @return true if a callback could be found that could successfully import the drop data, or * false otherwise. */ @Override public boolean importData(final TransferSupport support) { try { final DataFlavor[] flavors = support.getDataFlavors(); for (DataFlavor flavor : flavors) { final LinkedList<DropHandlerCallback> callbacks = _callbackMapping.get(flavor); if (callbacks == null) continue; final Object data = support.getTransferable().getTransferData(flavor); for (DropHandlerCallback callback : callbacks) if (callback.importData(support.getComponent(), data)) return true; } } catch (Exception e) { return false; } return false; }
/** * Checks whether a callback has been registered for any of the data flavors supported by this * drop event. * * @param support The TransferSupport describing the drop event. * @return Whether or not a callback for any of the support's data flavors has been registered. */ @Override public boolean canImport(final TransferSupport support) { for (DataFlavor flavor : _callbackMapping.keySet()) { final LinkedList<DropHandlerCallback> callbackLinkedList = _callbackMapping.get(flavor); if (callbackLinkedList.size() > 0 && support.isDataFlavorSupported(flavor)) return true; } return false; }
public boolean importData(TransferSupport support) { if (!canImport(support)) { return false; } Transferable transferable = support.getTransferable(); try { Object draggedImage = transferable.getTransferData(DATA_FLAVOUR); JList.DropLocation dl = (JList.DropLocation) support.getDropLocation(); DefaultListModel model = (DefaultListModel) playlist.getModel(); int dropIndex = dl.getIndex(); if (model.indexOf(draggedImage) < dropIndex) { dropIndex--; } model.removeElement(draggedImage); model.add(dropIndex, draggedImage); callback.notify(Command.NEW_QUEUE, Arrays.asList(model.toArray()), gui.getCurrentZone()); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
/** Can only import into a BlockIconPanel */ @Override public boolean canImport(TransferSupport supp) { return (supp.getComponent() instanceof JPanel && supp.getComponent().getName() != null && supp.getComponent().getName().equals("BlockIconPanel")); }
private boolean isDataFlavorValid(TransferSupport support) { // only support string flavor, or a file list (if a file has been dragged into the tree) return support.isDataFlavorSupported(DataFlavor.stringFlavor) || support.isDataFlavorSupported(DataFlavor.javaFileListFlavor); }
@Override public boolean canImport(TransferSupport support) { if (!isDataFlavorValid(support)) return false; return support.getComponent() == layersTree; }
@Override public boolean canImport(TransferSupport support) { DataFlavor f = getStringFlavor(support.getDataFlavors()); return f != null; }
/* (non-Javadoc) * @see javax.swing.TransferHandler#canImport(javax.swing.TransferHandler.TransferSupport) */ @Override public boolean canImport(TransferSupport support) { return support != null && support.isDataFlavorSupported(ProcessVar.PvDataFlavors[0]); }