List of usage examples for java.awt.datatransfer UnsupportedFlavorException UnsupportedFlavorException
public UnsupportedFlavorException(DataFlavor flavor)
From source file:unikn.dbis.univis.navigation.tree.VTree.java
/** * A <code>DragGestureRecognizer</code> has detected * a platform-dependent drag initiating gesture and * is notifying this listener/* w w w .ja va 2 s. c o m*/ * in order for it to initiate the action for the user. * <p/> * * @param dge the <code>DragGestureEvent</code> describing * the gesture that has just occurred */ public void dragGestureRecognized(DragGestureEvent dge) { // Gets the selected tree node. Object o = getLastSelectedPathComponent(); if (o instanceof DefaultMutableTreeNode) { // Gets the user object of the tree node. Object userObject = ((DefaultMutableTreeNode) o).getUserObject(); if (userObject instanceof VDimension) { final VDimension dimension = (VDimension) userObject; // Whether the selected dimension allows drag and drop // or not. if (dimension.isDragable() && !dimension.isDropped()) { dge.startDrag(DragSource.DefaultMoveDrop, new Transferable() { /** * Returns an array of DataFlavor objects indicating the flavors the data * can be provided in. The array should be ordered according to preference * for providing the data (from most richly descriptive to least descriptive). * * @return an array of data flavors in which this data can be transferred */ public DataFlavor[] getTransferDataFlavors() { return new DataFlavor[] { VDataReferenceFlavor.COMBINATION_FLAVOR, VDataReferenceFlavor.DIMENSION_FLAVOR }; } /** * Returns whether or not the specified data flavor is supported for * this object. * * @param flavor the requested flavor for the data * @return boolean indicating whether or not the data flavor is supported */ public boolean isDataFlavorSupported(DataFlavor flavor) { for (DataFlavor dataFlavor : getTransferDataFlavors()) { if (dataFlavor.match(flavor)) { return true; } } return false; } /** * Returns an object which represents the data to be transferred. The class * of the object returned is defined by the representation class of the flavor. * * @param flavor the requested flavor for the data * @throws java.awt.datatransfer.UnsupportedFlavorException * if the requested data flavor is * not supported. * @see java.awt.datatransfer.DataFlavor#getRepresentationClass */ public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException { if (VDataReferenceFlavor.COMBINATION_FLAVOR.match(flavor)) { VCube cube = null; for (VDataReference dataReference = dimension; dataReference != null; dataReference = dataReference .getParent()) { if (dataReference instanceof VCube) { // cube = (VCube) dataReference; break; } } VCombination combination = new VCombinationImpl(); combination.setCube(cube); combination.setDimension(dimension); combination.setMeasure(measure); combination.setFunction(function); return combination; } else if (VDataReferenceFlavor.DIMENSION_FLAVOR.match(flavor)) { return dimension; } throw new UnsupportedFlavorException(flavor); } }); } else { if (LOG.isInfoEnabled()) { LOG.info("The dimension node isn't summable or has been drag and dropped in the past."); } } } else if (userObject instanceof VMeasure) { final VMeasure measure = (VMeasure) userObject; dge.startDrag(DragSource.DefaultMoveDrop, new Transferable() { /** * Returns an array of DataFlavor objects indicating the flavors the data * can be provided in. The array should be ordered according to preference * for providing the data (from most richly descriptive to least descriptive). * * @return an array of data flavors in which this data can be transferred */ public DataFlavor[] getTransferDataFlavors() { return new DataFlavor[] { VDataReferenceFlavor.MEASURE_FLAVOR }; } /** * Returns whether or not the specified data flavor is supported for * this object. * * @param flavor the requested flavor for the data * @return boolean indicating whether or not the data flavor is supported */ public boolean isDataFlavorSupported(DataFlavor flavor) { for (DataFlavor dataFlavor : getTransferDataFlavors()) { if (dataFlavor.match(flavor)) { return true; } } return false; } /** * Returns an object which represents the data to be transferred. The class * of the object returned is defined by the representation class of the flavor. * * @param flavor the requested flavor for the data * @throws java.awt.datatransfer.UnsupportedFlavorException * if the requested data flavor is * not supported. * @see java.awt.datatransfer.DataFlavor#getRepresentationClass */ public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException { if (VDataReferenceFlavor.MEASURE_FLAVOR.match(flavor)) { return measure; } throw new UnsupportedFlavorException(flavor); } }); } } }