当前位置: 首页>>代码示例>>Java>>正文


Java DragSource类代码示例

本文整理汇总了Java中java.awt.dnd.DragSource的典型用法代码示例。如果您正苦于以下问题:Java DragSource类的具体用法?Java DragSource怎么用?Java DragSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DragSource类属于java.awt.dnd包,在下文中一共展示了DragSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addTo

import java.awt.dnd.DragSource; //导入依赖的package包/类
public void addTo(Buildable b) {
  map = (Map) b;
  view = map.getView();
  validator = new SingleChildInstance(map, getClass());
  map.addDrawComponent(this);
  String keyDesc = hotkey == null ? "" : "(" + HotKeyConfigurer.getString(hotkey) + ")";
  GameModule.getGameModule().getPrefs().addOption(Resources.getString("Prefs.general_tab"),
      new BooleanConfigurer(USE_KEYBOARD, Resources.getString("CounterDetailViewer.use_prompt", keyDesc), Boolean.FALSE));
  GameModule.getGameModule().getPrefs().addOption(Resources.getString("Prefs.general_tab"),
      new IntConfigurer(PREFERRED_DELAY, Resources.getString("CounterDetailViewer.delay_prompt"), delay));

  view.addMouseMotionListener(this);
  view.addMouseListener(this);
  view.addKeyListener(this);
  DragSource.getDefaultDragSource().addDragSourceMotionListener(this);

  setAttributeTranslatable(VERSION, false);
  setAttributeTranslatable(SUMMARY_REPORT_FORMAT, true);
  setAttributeTranslatable(COUNTER_REPORT_FORMAT, true);
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:21,代码来源:CounterDetailViewer.java

示例2: createDragGestureRecognizer

import java.awt.dnd.DragSource; //导入依赖的package包/类
@Override
public <T extends DragGestureRecognizer> T
    createDragGestureRecognizer(Class<T> abstractRecognizerClass,
                                DragSource ds, Component c, int srcActions,
                                DragGestureListener dgl)
{
    final LightweightFrame f = SunToolkit.getLightweightFrame(c);
    if (f != null) {
        return f.createDragGestureRecognizer(abstractRecognizerClass, ds, c, srcActions, dgl);
    }

    if (MouseDragGestureRecognizer.class.equals(abstractRecognizerClass))
        return (T)new WMouseDragGestureRecognizer(ds, c, srcActions, dgl);
    else
        return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:WToolkit.java

示例3: createDragGestureRecognizer

import java.awt.dnd.DragSource; //导入依赖的package包/类
public <T extends DragGestureRecognizer> T
createDragGestureRecognizer(Class<T> recognizerClass,
                DragSource ds,
                Component c,
                int srcActions,
                DragGestureListener dgl)
{
    final LightweightFrame f = SunToolkit.getLightweightFrame(c);
    if (f != null) {
        return f.createDragGestureRecognizer(recognizerClass, ds, c, srcActions, dgl);
    }

    if (MouseDragGestureRecognizer.class.equals(recognizerClass))
        return (T)new XMouseDragGestureRecognizer(ds, c, srcActions, dgl);
    else
        return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:XToolkit.java

示例4: ImageDragSource

import java.awt.dnd.DragSource; //导入依赖的package包/类
ImageDragSource() {
    formats = retrieveFormatsToTest();
    passedArray = new boolean[formats.length];
    final DragSourceListener dsl = new DragSourceAdapter() {
        public void dragDropEnd(DragSourceDropEvent e) {
            System.err.println("Drop was successful=" + e.getDropSuccess());
            notifyTransferSuccess(e.getDropSuccess());
            if (++fi < formats.length) {
                leaveFormat(formats[fi]);
            }
        }
    };

    new DragSource().createDefaultDragGestureRecognizer(frame,
            DnDConstants.ACTION_COPY,
            dge -> dge.startDrag(null, new ImageSelection(image), dsl));
    leaveFormat(formats[fi]);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:ImageTransferTest.java

示例5: main

import java.awt.dnd.DragSource; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
    Frame sourceFrame = createFrame("Source Frame", 0, 0);
    Frame targetFrame = createFrame("Target Frame", 250, 250);

    DragSource defaultDragSource
            = DragSource.getDefaultDragSource();
    defaultDragSource.createDefaultDragGestureRecognizer(sourceFrame,
            DnDConstants.ACTION_COPY_OR_MOVE,
            new TestDragGestureListener());
    new DropTarget(targetFrame, DnDConstants.ACTION_COPY_OR_MOVE,
            new TestDropTargetListener(targetFrame));

    Robot robot = new Robot();
    robot.setAutoDelay(50);

    sourceFrame.toFront();
    robot.waitForIdle();

    Point point = getCenterPoint(sourceFrame);
    robot.mouseMove(point.x, point.y);
    robot.waitForIdle();

    mouseDragAndDrop(robot, point, getCenterPoint(targetFrame));

    long time = System.currentTimeMillis() + 200;

    while (!passed) {
        if (time < System.currentTimeMillis()) {
            sourceFrame.dispose();
            targetFrame.dispose();
            throw new RuntimeException("Mouse clicked event is lost!");
        }
        Thread.sleep(10);
    }
    sourceFrame.dispose();
    targetFrame.dispose();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:38,代码来源:MissingEventsOnModalDialogTest.java

示例6: start

import java.awt.dnd.DragSource; //导入依赖的package包/类
public void start() {
    Frame f = new Frame("Use keyboard for DnD change");
    Panel mainPanel;
    Component dragSource, dropTarget;

    f.setBounds(0, 400, 200, 200);
    f.setLayout(new BorderLayout());

    mainPanel = new Panel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.setBackground(Color.blue);

    dropTarget = new DnDTarget(Color.red, Color.yellow);
    dragSource = new DnDSource("Drag ME! (" + (DragSource.isDragImageSupported()?"with ":"without") + " image)" );

    mainPanel.add(dragSource, "North");
    mainPanel.add(dropTarget, "Center");
    f.add(mainPanel, BorderLayout.CENTER);

    f.setVisible(true);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:ImageDecoratedDnD.java

示例7: createDragGestureRecognizer

import java.awt.dnd.DragSource; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <T extends DragGestureRecognizer> T
    createDragGestureRecognizer(Class<T> abstractRecognizerClass,
                                DragSource ds, Component c, int srcActions,
                                DragGestureListener dgl)
{
    final LightweightFrame f = SunToolkit.getLightweightFrame(c);
    if (f != null) {
        return f.createDragGestureRecognizer(abstractRecognizerClass, ds, c, srcActions, dgl);
    }

    if (MouseDragGestureRecognizer.class.equals(abstractRecognizerClass))
        return (T)new WMouseDragGestureRecognizer(ds, c, srcActions, dgl);
    else
        return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:WToolkit.java

示例8: DragManager

import java.awt.dnd.DragSource; //导入依赖的package包/类
/** 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();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:DragManager.java

示例9: add

import java.awt.dnd.DragSource; //导入依赖的package包/类
void add( CategoryDescriptor descriptor ) {
    CategoryList list = descriptor.getList();
    list.setTransferHandler( null );
    list.setDragEnabled(false);
    recognizers.add( DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer( list, DnDConstants.ACTION_MOVE, this ) );
    dropTargets.add( new DropTarget( list, this ) );
    
    CategoryButton button = descriptor.getButton();
    button.setTransferHandler( null );
    recognizers.add( DragSource.getDefaultDragSource().createDefaultDragGestureRecognizer( button, DnDConstants.ACTION_MOVE, this ) );
    dropTargets.add( new DropTarget( button, this ) );
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:DnDSupport.java

示例10: IndexedDragSource

import java.awt.dnd.DragSource; //导入依赖的package包/类
/** 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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:IndexedCustomizer.java

示例11: dragGestureRecognized

import java.awt.dnd.DragSource; //导入依赖的package包/类
/** Initiating the drag */
public void dragGestureRecognized(DragGestureEvent dge) {
    // check allowed actions
    if ((dge.getDragAction() & DnDConstants.ACTION_MOVE) == 0) {
        return;
    }

    // prepare transferable and start the drag
    int index = comp.locationToIndex(dge.getDragOrigin());

    // no index, then no dragging...
    if (index < 0) {
        return;
    }

    //      System.out.println("Starting drag..."); // NOI18N
    // create our flavor for transferring the index
    myFlavor = new DataFlavor(
            String.class, NbBundle.getBundle(IndexedCustomizer.class).getString("IndexedFlavor")
        );

    try {
        dge.startDrag(DragSource.DefaultMoveDrop, new IndexTransferable(myFlavor, index), this);

        // remember the gesture
        this.dge = dge;
    } catch (InvalidDnDOperationException exc) {
        Logger.getLogger(IndexedCustomizer.class.getName()).log(Level.WARNING, null, exc);

        // PENDING notify user - cannot start the drag
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:IndexedCustomizer.java

示例12: run

import java.awt.dnd.DragSource; //导入依赖的package包/类
/** Performs DnD pre-heat.
 */
@Override
public void run() {
    if (!GraphicsEnvironment.isHeadless()) {
        DragSource.getDefaultDragSource();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:DnDWarmUpTask.java

示例13: dragGestureRecognized

import java.awt.dnd.DragSource; //导入依赖的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

示例14: registerDndHandlers

import java.awt.dnd.DragSource; //导入依赖的package包/类
private void registerDndHandlers()
{
	new DragSource().createDefaultDragGestureRecognizer(list, DnDConstants.ACTION_COPY, new DragGestureListener()
	{
		@Override
		public void dragGestureRecognized(DragGestureEvent dge)
		{
			Transferable t = new FileInfoTransferable(getSelectedFile());
			dge.startDrag(DragSource.DefaultMoveDrop, t);
		}
	});

	DnDUtils.registerDropHandler(this, dropHandlers, new HoverHandler()
	{
		@Override
		public void hovering(DropTargetDragEvent e)
		{
			FileInfo fi = getFileUnderMouseCursor();
			if( fi == null )
			{
				int i = getListIndexUnderPoint(e.getLocation());
				if( i >= 0 )
				{
					fi = model.get(i);
				}
			}

			if( fi != null && fi.isDirectory() )
			{
				list.setSelectedValue(fi, true);
			}
			else
			{
				list.getSelectionModel().clearSelection();
			}
		}
	});
}
 
开发者ID:equella,项目名称:Equella,代码行数:39,代码来源:FileListPanel.java

示例15: createDragGestureRecognizer

import java.awt.dnd.DragSource; //导入依赖的package包/类
/**
 * Create a drag gesture recognizer for the lightweight frame.
 */
default public <T extends DragGestureRecognizer> T createDragGestureRecognizer(
        Class<T> abstractRecognizerClass,
        DragSource ds, Component c, int srcActions,
        DragGestureListener dgl)
{
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:LightweightContent.java


注:本文中的java.awt.dnd.DragSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。