當前位置: 首頁>>代碼示例>>Java>>正文


Java DragGestureEvent.startDrag方法代碼示例

本文整理匯總了Java中java.awt.dnd.DragGestureEvent.startDrag方法的典型用法代碼示例。如果您正苦於以下問題:Java DragGestureEvent.startDrag方法的具體用法?Java DragGestureEvent.startDrag怎麽用?Java DragGestureEvent.startDrag使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.dnd.DragGestureEvent的用法示例。


在下文中一共展示了DragGestureEvent.startDrag方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: dragGestureRecognized

import java.awt.dnd.DragGestureEvent; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
public void dragGestureRecognized(DragGestureEvent dge) {
    JComponent c = (JComponent)dge.getComponent();
    DefaultTransferHandler th
        = (DefaultTransferHandler)c.getTransferHandler();
    Transferable t = th.createTransferable(c);
    if (t == null) {
        logger.warning("Unable to create transferable for: " + dge);
        th.exportDone(c, null, NONE);
        return;
    }

    this.scrolls = c.getAutoscrolls();
    c.setAutoscrolls(false);
    try {
        Cursor cursor = getCursor(c);
        dge.startDrag(cursor, t, this);
    } catch (RuntimeException re) {
        c.setAutoscrolls(this.scrolls);
    }
}
 
開發者ID:FreeCol,項目名稱:freecol,代碼行數:24,代碼來源:DefaultTransferHandler.java

示例2: beginDragging

import java.awt.dnd.DragGestureEvent; //導入方法依賴的package包/類
protected void beginDragging(DragGestureEvent dge) {
  // this call is needed to instantiate the boundingBox object
 final BufferedImage bImage = makeDragImage(dragPieceOffCenterZoom);

  final Point dragPointOffset = new Point(
    getOffsetMult() * (boundingBox.x + currentPieceOffsetX - EXTRA_BORDER),
    getOffsetMult() * (boundingBox.y + currentPieceOffsetY - EXTRA_BORDER)
  );

  dge.startDrag(
    Cursor.getPredefinedCursor(Cursor.HAND_CURSOR),
    bImage,
    dragPointOffset,
    new StringSelection(""),
    this
  );

  dge.getDragSource().addDragSourceMotionListener(this);
}
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:20,代碼來源:PieceMover.java

示例3: dragGestureRecognized

import java.awt.dnd.DragGestureEvent; //導入方法依賴的package包/類
public void dragGestureRecognized(DragGestureEvent dge) {
    String [] filesAsStringArray = list.getItems();
    File [] files = new File[filesAsStringArray.length];
    for (int fileNumber=0; fileNumber<filesAsStringArray.length ; fileNumber++ ) {
        files[fileNumber]=new File(filesAsStringArray[fileNumber]);
    }
    dge.startDrag(null, new FileListTransferable(Arrays.asList(files)));
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:9,代碼來源:SourceFileListFrame.java

示例4: triggerDrag

import java.awt.dnd.DragGestureEvent; //導入方法依賴的package包/類
private boolean triggerDrag(JFrame f,Point p,DragGestureEvent dge,JComponent c) {
	Rectangle r = new Rectangle(0,0,c.getWidth(),c.getHeight());
	r = SwingUtilities.convertRectangle(c, 
			r, 
			f);
	
	if(r.contains(p)) {
		draggingFromToolbar = true;
			draggingDefaults = false;
		draggingComponent = c.getName();
		MockComponent mc = new MockComponent(c);
		Transferable transferable = new MockComponentTransferable(mc);
		BufferedImage bi = mc.getBufferedImage();
		dge.startDrag(DragSource.DefaultMoveDrop, 
				bi, 
				new Point(r.x-p.x, r.y-p.y), 
				transferable, 
				dragSourceListener);
		return true;
	}
	return false;
}
 
開發者ID:mickleness,項目名稱:pumpernickel,代碼行數:23,代碼來源:CustomizedToolbar.java

示例5: dragGestureRecognized

import java.awt.dnd.DragGestureEvent; //導入方法依賴的package包/類
/**
 * Drag gesture recognized. Start the drag off if valid.
 *
 * @param evt
 *            Drag gesture event
 */
@Override
public void dragGestureRecognized(DragGestureEvent evt) {
	DragEntry dragEntry = kseFrame.dragSelectedEntry();

	if (dragEntry == null) {
		return;
	}

	ImageIcon icon = dragEntry.getImage();

	// Draw image as drag cursor
	Toolkit toolkit = Toolkit.getDefaultToolkit();
	Dimension dim = toolkit.getBestCursorSize(icon.getIconWidth(), icon.getIconHeight());
	BufferedImage buffImage = new BufferedImage(dim.width, dim.height, BufferedImage.TYPE_INT_ARGB_PRE);
	icon.paintIcon(evt.getComponent(), buffImage.getGraphics(), 0, 0);
	cursor = toolkit.createCustomCursor(buffImage, new Point(0, 0), "keystore-entry");

	evt.startDrag(cursor, new KeyStoreEntryTransferable(dragEntry), this);
}
 
開發者ID:kaikramer,項目名稱:keystore-explorer,代碼行數:26,代碼來源:KeyStoreEntryDragGestureListener.java

示例6: dragGestureRecognized

import java.awt.dnd.DragGestureEvent; //導入方法依賴的package包/類
public void dragGestureRecognized(DragGestureEvent dge) {
	if (model == null || !isDraggingEnabled) {
		return;
	}
	int index = getImageIndexAt(dge.getDragOrigin().x, dge.getDragOrigin().y);
	if (index < 0) {
		return;
	}
	Transferable transferable = model.getTransferable(index);
	if (transferable == null) {
		return;
	}
	//dge.startDrag(Toolkit.getDefaultToolkit().createCustomCursor(model.getImage(index), new Point(0, 0), "Thumbnail"), transferable, this);
	dge.startDrag(getDragCursor(), transferable, this);
	DragSource.getDefaultDragSource().addDragSourceMotionListener(this);
}
 
開發者ID:RPTools,項目名稱:rplib,代碼行數:17,代碼來源:ImagePanel.java

示例7: dragGestureRecognized

import java.awt.dnd.DragGestureEvent; //導入方法依賴的package包/類
public void dragGestureRecognized(DragGestureEvent e)
{
  JComponent c = (JComponent) e.getComponent();
  TransferHandler th = c.getTransferHandler();
  Transferable t = th.createTransferable(c);
  if (t != null)
    {
      autoscrolls = c.getAutoscrolls();
      c.setAutoscrolls(false);
      try
        {
          e.startDrag(null, t, this);
          return;
        }
      finally
        {
          c.setAutoscrolls(autoscrolls);
        }
    }
  th.exportDone(c, t, NONE);
}
 
開發者ID:nmldiegues,項目名稱:jvm-stm,代碼行數:22,代碼來源:TransferHandler.java

示例8: dragGestureRecognized

import java.awt.dnd.DragGestureEvent; //導入方法依賴的package包/類
public void dragGestureRecognized(DragGestureEvent event) {
	// ignore right-click-drags
	if (((MouseEvent) event.getTriggerEvent()).isPopupTrigger())
		return;

	// figure out what's being dragged
	Point p = event.getDragOrigin();
	BaseSample bar = bgp.getBar(p);

	// this only makes sense with Files...
	if(bar.getLoader() instanceof FileElement) {
		// make a Transferable to send
		Transferable transfer = new Tree.TransferableFile(
				((FileElement)bar.getLoader()).getFilename());

		// let the drag begin!
		event.startDrag(DragSource.DefaultCopyDrop, transfer, this);
	}
}
 
開發者ID:ltrr-arizona-edu,項目名稱:tellervo,代碼行數:20,代碼來源:BargraphFrame.java

示例9: dragGestureRecognized

import java.awt.dnd.DragGestureEvent; //導入方法依賴的package包/類
public void dragGestureRecognized( DragGestureEvent dge ) {
    Transferable t = null;
    
    if( dge.getComponent() instanceof CategoryButton ) {
        //trying to drag a palette category
        CategoryButton button = (CategoryButton)dge.getComponent();
        draggingCategory = button.getCategory();
        t = draggingCategory.getTransferable();
        
    } else if( dge.getComponent() instanceof CategoryList ) {
        //trying to drag a palette item
        CategoryList list = (CategoryList)dge.getComponent();
        int selIndex = list.locationToIndex( dge.getDragOrigin() );
        draggingItem = list.getItemAt( selIndex );
        if( null == draggingItem ) {
            return;
        }
        t = draggingItem.drag();
        dragSourceCategoryList = list;
    }
    if( null != t ) {
        dge.getDragSource().addDragSourceListener( getDragSourceListener() );
        try {
            dge.startDrag( null, t );
        } catch( InvalidDnDOperationException idndE ) {
            //attempt to fix #110670
            try {
                dge.startDrag( null, t );
            } catch( InvalidDnDOperationException e ) {
                ERR.log( Level.INFO, idndE.getMessage(), e );
            }
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:35,代碼來源:DnDSupport.java

示例10: dragGestureRecognized

import java.awt.dnd.DragGestureEvent; //導入方法依賴的package包/類
public void dragGestureRecognized(DragGestureEvent dge) {

      Point mousePosition = dge.getDragOrigin();
      Point piecePosition = new Point(myStack.pos);

      // Check drag starts inside piece
      Rectangle r = myStack.stackConfigurer.getPieceBoundingBox();
      r.translate(piecePosition.x, piecePosition.y);
      if (!r.contains(mousePosition)) {
        return;
      }

      originalPieceOffsetX = piecePosition.x - mousePosition.x;
      originalPieceOffsetY = piecePosition.y - mousePosition.y;

      drawWin = null;

      makeDragCursor();
      setDragCursor();

      SwingUtilities.convertPointToScreen(mousePosition, drawWin);
      moveDragCursor(mousePosition.x, mousePosition.y);

      // begin dragging
      try {
        dge.startDrag(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR),
                      new StringSelection(""), this); // DEBUG
        dge.getDragSource().addDragSourceMotionListener(this);
      }
      catch (InvalidDnDOperationException e) {
        ErrorDialog.bug(e);
      }
    }
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:34,代碼來源:SetupStack.java

示例11: dragGestureRecognized

import java.awt.dnd.DragGestureEvent; //導入方法依賴的package包/類
public void dragGestureRecognized(DragGestureEvent dge) {

        final Point mousePosition = dge.getDragOrigin();
        dragStart = new Point(mousePosition);
        final Region r = grid.getRegion(mousePosition);
        if (r == null) {
          return;
        }

        Point piecePosition = new Point(r.getOrigin());

        originalPieceOffsetX = piecePosition.x - mousePosition.x;
        originalPieceOffsetY = piecePosition.y - mousePosition.y;

        drawWin = null;

        makeDragCursor();
        setDragCursor();

        SwingUtilities.convertPointToScreen(drawOffset, drawWin);
        SwingUtilities.convertPointToScreen(mousePosition, drawWin);
        moveDragCursor(mousePosition.x, mousePosition.y);

        // begin dragging
        try {
          dge.startDrag(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR),
                        new StringSelection(""), this); //$NON-NLS-1$
          dge.getDragSource().addDragSourceMotionListener(this);
        }
        catch (InvalidDnDOperationException e) {
          ErrorDialog.bug(e);
        }
      }
 
開發者ID:ajmath,項目名稱:VASSAL-src,代碼行數:34,代碼來源:RegionGrid.java

示例12: dragGestureRecognized

import java.awt.dnd.DragGestureEvent; //導入方法依賴的package包/類
@Override
public void dragGestureRecognized(DragGestureEvent dge) {
	Cursor cursor = null;
	if(dge.getComponent() instanceof RepositoryViewer){
		RepositoryViewer rv = (RepositoryViewer) dge.getComponent();
		KernelRepositoryEntry kre = (KernelRepositoryEntry) rv.getSelectedValue();
		
		if(dge.getDragAction()==DnDConstants.ACTION_COPY){
			cursor = DragSource.DefaultCopyDrop;
		}
		
		dge.startDrag(cursor, new TransferableKernelRepositoryEntry(kre));
	}
}
 
開發者ID:roscisz,項目名稱:KernelHive,代碼行數:15,代碼來源:RepositoryViewerDragGestureListener.java

示例13: dragGestureRecognized

import java.awt.dnd.DragGestureEvent; //導入方法依賴的package包/類
public void dragGestureRecognized(DragGestureEvent dge) {
    java.util.List<URI> uriList = Stream.of(list.getItems())
                                            .map(File::new)
                                            .map(File::toURI)
                                            .collect(Collectors.toList());

    dge.startDrag(null, new URIListTransferable(uriList));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:SourceFileListFrame.java

示例14: dragGestureRecognized

import java.awt.dnd.DragGestureEvent; //導入方法依賴的package包/類
public void dragGestureRecognized(DragGestureEvent e)
{
  try
    {
      Transferable t = new StringSelection(getText());
      e.startDrag(DragSource.DefaultCopyNoDrop, t, this);
    }
  catch (InvalidDnDOperationException e2)
    {
      System.out.println(e2);
    }
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:13,代碼來源:Demo.java

示例15: dragGestureRecognized

import java.awt.dnd.DragGestureEvent; //導入方法依賴的package包/類
@Override
public void dragGestureRecognized(DragGestureEvent dge) {
	rootFrame.glassPane.setImage(PivotSlice.getScreenShot(this));
	if (dge.getDragAction() == DnDConstants.ACTION_COPY) {
		dge.startDrag(DragSource.DefaultCopyDrop, new TransferableConstraint(constrData));
	}
	else {
		dge.startDrag(DragSource.DefaultMoveDrop, new TransferableConstraint(constrData));
		setConstraintData(new ConstraintData(constrData.facetID));
		childUpdated();
	}
	
	rootFrame.logger.logAction("filter-drag constraint");
}
 
開發者ID:jeffjianzhao,項目名稱:PivotSlice,代碼行數:15,代碼來源:Constraint.java


注:本文中的java.awt.dnd.DragGestureEvent.startDrag方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。