private void wireDragAndDrop(Component comp) { comp.setDropTarget(new DropTarget(this, new JitterbugDropHandler())); if (comp instanceof Container) { Container cont = (Container) comp; for (int i = 0; i < cont.getComponentCount(); i++) { wireDragAndDrop(cont.getComponent(i)); } } }
protected void setDropTargets() { headerLabel.setDropTarget(new java.awt.dnd.DropTarget(headerLabel, componentElementPanel)); setDropTarget(new java.awt.dnd.DropTarget(this, componentElementPanel)); containingPanel.setDropTarget( new java.awt.dnd.DropTarget(containingPanel, componentElementPanel)); headerPanel.setDropTarget(new java.awt.dnd.DropTarget(headerPanel, componentElementPanel)); grip.setDropTarget(new java.awt.dnd.DropTarget(grip, componentElementPanel)); glue.setDropTarget(new java.awt.dnd.DropTarget(glue, componentElementPanel)); expandButton.setDropTarget(new java.awt.dnd.DropTarget(expandButton, componentElementPanel)); }
/** * Removes the drag-and-drop hooks from the component and optionally from the all children. You * should call this if you add and remove components after you've set up the drag-and-drop. * * @param out Optional {@link PrintStream} for logging drag and drop messages * @param c The component to unregister * @param recursive Recursively unregister components within a container * @since 1.0 */ public static boolean remove(PrintStream out, Component c, boolean recursive) { // Make sure we support log(out, "FileDrop: Removing drag-and-drop hooks."); c.setDropTarget(null); if (recursive && (c instanceof Container)) { Component[] comps = ((Container) c).getComponents(); for (int i = 0; i < comps.length; i++) remove(out, comps[i], recursive); return true; } return false; }
public JmolFileDropper(JmolViewer viewer) { fd_oldFileName = ""; fd_propSupport = new PropertyChangeSupport(this); this.viewer = viewer; addPropertyChangeListener( (pcl = new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { doDrop(evt); } })); Component display = viewer.getDisplay(); display.setDropTarget(new DropTarget(display, this)); display.setEnabled(true); }
/** * Removes the drag-and-drop hooks from the component and optionally from the all children. You * should call this if you add and remove components after you've set up the drag-and-drop. * * @param out Optional {@link java.io.PrintStream} for logging drag and drop messages * @param c The component to unregister * @param recursive Recursively unregister components within a container * @since 1.0 */ public static boolean remove( java.io.PrintStream out, java.awt.Component c, boolean recursive) { // Make sure we support dnd. if (supportsDnD()) { log(out, "FileDrop: Removing drag-and-drop hooks."); c.setDropTarget(null); if (recursive && (c instanceof java.awt.Container)) { java.awt.Component[] comps = ((java.awt.Container) c).getComponents(); for (int i = 0; i < comps.length; i++) remove(out, comps[i], recursive); return true; } // end if: recursive else return false; } // end if: supports DnD else return false; } // end remove