/** * One of three methods defined by the Transferable interface. * * <p>Returns supported DataFlavor. Again, we're only supporting this actual Object within the * JVM. * * <p>For more information, see the JavaDoc for DataFlavor. * * @return */ public DataFlavor[] getTransferDataFlavors() { DataFlavor[] flavors = {null}; System.out.println( "Step 4 of 7: Querying for acceptable DataFlavors to determine what is available. Our example only supports our custom RandomDragAndDropPanel DataFlavor."); try { flavors[0] = ServoOrchestratorGUI_middlemiddle_main.getDragAndDropPanelDataFlavor(); } catch (Exception ex) { System.err.println("Problem lazy loading: " + ex.getMessage()); ex.printStackTrace(System.err); return null; } return flavors; }
/** * One of three methods defined by the Transferable interface. * * <p>Determines whether this object supports the DataFlavor. In this case, only one is supported: * for this object itself. * * @param flavor * @return True if DataFlavor is supported, otherwise false. */ public boolean isDataFlavorSupported(DataFlavor flavor) { System.out.println( "Step 6 of 7: Verifying that DataFlavor is supported. Our example only supports our custom RandomDragAndDropPanel DataFlavor."); DataFlavor[] flavors = {null}; try { flavors[0] = ServoOrchestratorGUI_middlemiddle_main.getDragAndDropPanelDataFlavor(); } catch (Exception ex) { System.err.println("Problem lazy loading: " + ex.getMessage()); ex.printStackTrace(System.err); return false; } for (DataFlavor f : flavors) { if (f.equals(flavor)) { return true; } } return false; }
/** * One of three methods defined by the Transferable interface. * * <p>If multiple DataFlavor's are supported, can choose what Object to return. * * <p>In this case, we only support one: the actual JPanel. * * <p>Note we could easily support more than one. For example, if supports text and drops to a * JTextField, could return the label's text or any arbitrary text. * * @param flavor * @return */ public Object getTransferData(DataFlavor flavor) { System.out.println( "Step 7 of 7: Returning the data from the Transferable object. In this case, the actual panel is now transfered!"); DataFlavor thisFlavor = null; try { thisFlavor = ServoOrchestratorGUI_middlemiddle_main.getDragAndDropPanelDataFlavor(); } catch (Exception ex) { System.err.println("Problem lazy loading: " + ex.getMessage()); ex.printStackTrace(System.err); return null; } // For now, assume wants this class... see loadDnD if (thisFlavor != null && flavor.equals(thisFlavor)) { return ServoOrchestratorGUI_middlemiddle_panel.this; } return null; }