Refine search
/** * Constructor allowing the list model to be specified * * @param model an instance of DnDListModel * @throws IllegalArgumentException if model is null */ public DnDList(DnDListModel<T> model) { super(model); if (model == null) { throw new IllegalArgumentException("model must not be null"); } // this.setModel(model); src = new DragSource(); src.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_MOVE, this); tgt = new DropTarget(this, this); movingItems = false; overIndex = -1; }
/** Creates drag source with asociated list where drag * will take place. * Also creates the default gesture and asociates this with * given component */ IndexedDragSource(JList comp) { this.comp = comp; // initialize gesture DragSource ds = DragSource.getDefaultDragSource(); ds.createDefaultDragGestureRecognizer(comp, DnDConstants.ACTION_MOVE, this); }
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new GridLayout(0, 2, 10, 10)); ((JComponent) frame.getContentPane()).setBorder(new EmptyBorder(10, 10, 10, 10)); setBorder(new LineBorder(Color.GRAY)); images = new ArrayList<>(25); DragGestureRecognizer dgr = DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer( this, DnDConstants.ACTION_COPY_OR_MOVE, new DragGestureHandler(this)); DropTarget dt = new DropTarget( this, DnDConstants.ACTION_COPY_OR_MOVE, if (image != null) { if (!contains(image)) { int x = (int) Math.round(Math.random() * getWidth()); int y = (int) Math.round(Math.random() * getHeight()); addImageAt(new Point(x, y), image); imagePane.removeImage(di); DragSource ds = dge.getDragSource(); ds.startDrag( dge, null,
rowTable.setAutoscrolls(true); rowTable.setDragEnabled(true); rowTable.setTransferHandler(new RowHeaderTransferHandler()); rowTable.setDropMode(DropMode.INSERT_ROWS); final JScrollPane scrollPane = new JScrollPane(mainTable); DragSource ds = new DragSource(); ds.addDragSourceMotionListener(dsml); DragSource dragSource = DragSource.getDefaultDragSource(); dragSource.addDragSourceMotionListener(dsml); glassPane = new FinalGlassPane(this) { if (isDragged && !isOutsideTable) { g2.setPaint(Color.GREEN); g2.drawLine(x + 2, y + 1, x + mainTable.getWidth() - 4, y + 1); g2.drawLine(x, y, x + mainTable.getWidth(), y); g2.drawLine(x + 2, y - 1, x + mainTable.getWidth() - 4, y - 1);
dragSource1 = new DragSource(); dragSource1.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, this); dragSource1.startDrag(evt, DragSource.DefaultCopyDrop, transferable, this); DropTarget dropTarget = new DropTarget(this, this);
public final void dragGestureRecognized(DragGestureEvent dge) { TreePath path = tree.getSelectionPath(); if (path != null) { draggedNode = (DefaultMutableTreeNode)path.getLastPathComponent(); draggedNodeParent = (DefaultMutableTreeNode)draggedNode.getParent(); if (drawImage) { Rectangle pathBounds = tree.getPathBounds(path); //getpathbounds of selectionpath JComponent lbl = (JComponent)tree.getCellRenderer().getTreeCellRendererComponent(tree, draggedNode, false , tree.isExpanded(path),((DefaultTreeModel)tree.getModel()).isLeaf(path.getLastPathComponent()), 0,false);//returning the label lbl.setBounds(pathBounds);//setting bounds to lbl image = new BufferedImage(lbl.getWidth(), lbl.getHeight(), java.awt.image.BufferedImage.TYPE_INT_ARGB_PRE);//buffered image reference passing the label's ht and width Graphics2D graphics = image.createGraphics();//creating the graphics for buffered image graphics.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f)); //Sets the Composite for the Graphics2D context lbl.setOpaque(false); lbl.paint(graphics); //painting the graphics to label graphics.dispose(); } dragSource.startDrag(dge, DragSource.DefaultMoveNoDrop , image, new Point(0,0), new TransferableNode(draggedNode), this); } }
l.setOpaque(true); l.setBackground(Color.RED); JPanel p = new JPanel(new BorderLayout()); p.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createEmptyBorder(5, 5, 5, 5), BorderFactory.createLineBorder(Color.BLUE, 2))); private Point startPt; private Point dragOffset; private final int gestureMotionThreshold = DragSource.getDragThreshold();
public void setEnableDragAndDrop() { dragSource = DragSource.getDefaultDragSource(); dragSource.createDefaultDragGestureRecognizer(this, getDelegateConstants(), this); dt = new DropTarget(this, this); }
btn.setFont(new java.awt.Font("Tahoma", 1, 48)); // NOI18N btn.setForeground(new java.awt.Color(255, 0, 0)); DropTarget dropTarget = new DropTarget(mainPanel, DnDConstants.ACTION_MOVE, dropHandler, true); mainPanel.setDropTarget(dropTarget); dgr = DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer( comp, DnDConstants.ACTION_MOVE, ds.startDrag(dge, Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR), transferable, this); spacer.setBackground(Color.RED);
public JComponent makeUI() { DragPanel p1 = new DragPanel(); p1.setBorder(BorderFactory.createLineBorder(Color.BLACK)); p1.add(new JLabel(UIManager.getIcon("OptionPane.warningIcon"))); p1.add(new JLabel(UIManager.getIcon("OptionPane.errorIcon"))); p1.addMouseListener(handler); LabelTransferHandler th = new LabelTransferHandler(); p1.setTransferHandler(th); JPanel p = new JPanel(new GridLayout(1,2)); p.add(p1); p2.setBorder(BorderFactory.createLineBorder(Color.BLACK)); p2.addMouseListener(handler); p2.setTransferHandler(th); window.setAlwaysOnTop(true); window.setBackground(new Color(0,true)); DragSource.getDefaultDragSource().addDragSourceMotionListener( new DragSourceMotionListener() { @Override public void dragMouseMoved(DragSourceDragEvent dsde) {
p.setBorder(new TitledBorder("Drag Image onto this panel")); p.setTransferHandler(dnd); panel.setBorder(new TitledBorder("Drag Image from here to Panel above")); DragSource ds1 = new DragSource(); ds1.createDefaultDragGestureRecognizer(label1, DnDConstants.ACTION_COPY, dlistener); DragSource ds2 = new DragSource(); ds2.createDefaultDragGestureRecognizer(label2, DnDConstants.ACTION_COPY, dlistener); DragSource ds3 = new DragSource(); ds3.createDefaultDragGestureRecognizer(label3, DnDConstants.ACTION_COPY, dlistener); dropTarget = new DropTarget(panel, DnDConstants.ACTION_COPY, this, true, null); try { DropTarget test = (DropTarget) event.getSource(); Component ca = (Component) test.getComponent(); Point dropPoint = ca.getMousePosition(); Transferable tr = event.getTransferable();
layeredPane.setBorder(BorderFactory.createLineBorder(Color.BLACK)); layeredPane.setLayout(new BoxLayout(layeredPane, BoxLayout.Y_AXIS)); layeredPane.setDropTarget(new DropTarget() { layeredPane.revalidate(); layeredPane.repaint(); } catch(UnsupportedFlavorException | IOException e) { dragSource = new DragSource(); dragSource.createDefaultDragGestureRecognizer( this, DnDConstants.ACTION_COPY_OR_MOVE, this); setBorder(BorderFactory.createLineBorder(Color.DARK_GRAY)); dragSource.startDrag(
window.setAlwaysOnTop(true); window.setBackground(new Color(0,true)); DragSource.getDefaultDragSource().addDragSourceMotionListener( new DragSourceMotionListener() { @Override public void dragMouseMoved(DragSourceDragEvent dsde) { label.setBorder(p.draggingLabel.getBorder()); label.setText(p.draggingLabel.getMac()); label.setPreferredSize(p.draggingLabel.getPreferredSize());
add(new JScrollPane(list), BorderLayout.WEST); DragGestureRecognizer dgr = DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer( list, DnDConstants.ACTION_COPY_OR_MOVE, add(panel); DropTarget dt = new DropTarget( panel, DnDConstants.ACTION_COPY_OR_MOVE, Transferable t = new UserTransferable(user); DragSource ds = dge.getDragSource(); ds.startDrag( dge, null, dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE); panel.add(new JLabel(user.getName())); panel.revalidate(); panel.repaint(); } else {
/** Creates a new instance of SplashDnDSupport */ DragManager(JComponent component) { this.component = component; dSource = new DragSource(); dRecognizer = dSource.createDefaultDragGestureRecognizer(this.component,DnDConstants.ACTION_MOVE,this); dTarget = new DropTarget(this.component,DnDConstants.ACTION_MOVE,this); component.addMouseMotionListener(this); oCursor = component.getCursor(); }
/** * Creates a droppable text pane. */ public DroppableTextPane() { new DropTarget(this, this); dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, this); }
table.setTransferHandler(dnd); table.setPreferredScrollableViewportSize(table.getPreferredSize()); return table; DragSource ds1 = new DragSource(); ds1.createDefaultDragGestureRecognizer(label1, DnDConstants.ACTION_COPY, dlistener); DragSource ds2 = new DragSource(); ds2.createDefaultDragGestureRecognizer(label2, DnDConstants.ACTION_COPY, dlistener); DragSource ds3 = new DragSource(); ds3.createDefaultDragGestureRecognizer(label3, DnDConstants.ACTION_COPY, dlistener);
public void configureDnD(Component c) { if (drag!=null) { DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer( c,DnDConstants.ACTION_COPY_OR_MOVE,new ClarionDragGesture(this)); } if (drop!=null) { try { c.setDropTarget(new DropTarget()); c.getDropTarget().addDropTargetListener(new ClarionDropTargetListener(this)); } catch (TooManyListenersException e) { e.printStackTrace(); } } }
public TreeDragSource(JTree tree, int actions, ProjectController eventController) { sourceTree = tree; this.eventController = eventController; source = new DragSource(); recognizer = source.createDefaultDragGestureRecognizer(sourceTree, actions, this); }
public IterationStrategyEditor() { super(); // Make this a drag source DragSource dragSource = DragSource.getDefaultDragSource(); dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_MOVE, this); // Also, make this JTree a drag target DropTarget dropTarget = new DropTarget(this, new CDropTargetListener()); dropTarget.setDefaultActions(DnDConstants.ACTION_MOVE); setCellRenderer(new DefaultTreeCellRenderer() { public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus); if (value instanceof CrossNode) { setIcon(IterationStrategyEditor.joinIteratorIcon); setText("cross product"); } else if (value instanceof DotNode) { setIcon(IterationStrategyEditor.lockStepIteratorIcon); setText("dot product"); } else if (value instanceof LeafNode) { setIcon(IterationStrategyEditor.baclavaIteratorIcon); } return this; } }); // }