Drag'n drop : reacting/animating on drag, according to mouse pos in target

Hi fellow Java coders,
I'm using drag'n drop support for some JPanel I'm using in order to make them able to change their layout in their parent or to stack themselves in a tab panel.
The drag n drop itself works fine (I took the example provided in do, the one with drag'n'dropped children pics).
But I would like to be able to react according to mouse position in the target panel, the one that receives the drop. I would like to change mouse cursor according to where is the mouse position inside the target panel, or animating / repainting things inside this target panel.
The lock I have is that with drag'n drop, MouseListener is not called at all when in drag movement, so I can't handle mouse events.
Is there a way to handle this case, when you wan't to react when dragging data above a possible target component, before having dropped it ?
Thank you in advance,
Alexis.

This grew larger than I planned, but here is an example that show different cursors for different components.
Drag from the center and the cursor will change for each of the border labels.
The code I origionally used this in uses custom cursors Crated by System.createCustomCursor.
This is not really pretty, but it works.
import java.awt.*;
import java.awt.dnd.*;
import javax.swing.*;
import java.awt.dnd.peer.*;
import java.awt.datatransfer.*;
public class DnDFeedBack extends JFrame
    public DnDFeedBack()
        super( "DnD Feed Back Example");
        setDefaultCloseOperation( EXIT_ON_CLOSE );
        JPanel panel = new JPanel( new BorderLayout() );
        JLabel comp = new JLabel( "North Drop" );
        comp.setBorder( BorderFactory.createLineBorder( Color.black ) );
        new DTFeedBackListener( comp, Cursor.getPredefinedCursor( Cursor.HAND_CURSOR ) );
        panel.add( comp, BorderLayout.NORTH );
        comp = new JLabel( "East Drop" );
        comp.setBorder( BorderFactory.createLineBorder( Color.black ) );
        new DTFeedBackListener( comp, Cursor.getPredefinedCursor( Cursor.CROSSHAIR_CURSOR ));
        panel.add( comp, BorderLayout.EAST );
        comp = new JLabel( "West Drop" );
        comp.setBorder( BorderFactory.createLineBorder( Color.black ) );
        new DTFeedBackListener( comp, Cursor.getPredefinedCursor( Cursor.TEXT_CURSOR ));
        panel.add( comp, BorderLayout.WEST );
        comp = new JLabel( "South Drop" );
        comp.setBorder( BorderFactory.createLineBorder( Color.black ) );
        new DTFeedBackListener( comp, Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR ));
        panel.add( comp, BorderLayout.SOUTH );
        comp = new JLabel( "Drag Source" );
        comp.setBorder( BorderFactory.createLineBorder( Color.black ) );
        new FeedBackDS( comp );
        panel.add( comp, BorderLayout.CENTER );
        setContentPane( panel );
        pack();
        setLocationRelativeTo( null );
        setVisible( true );
    public static void main( String[] args )
        new DnDFeedBack();
    public class FeedBackDS extends DragSourceAdapter implements DragGestureListener
        public FeedBackDS( JComponent comp )
            new MYDragSource().createDefaultDragGestureRecognizer(
                                                                 comp, // component where drag originates
                                                                 DnDConstants.ACTION_COPY_OR_MOVE, // actions
                                                                 this); // drag gesture listener
        public void dragGestureRecognized(DragGestureEvent dge)
            dge.startDrag( DragSource.DefaultMoveNoDrop,
                           new java.awt.datatransfer.StringSelection( "FAKE DATA") );
    public class DTFeedBackListener extends DropTargetAdapter
        JComponent comp;
        Cursor cursor;
        public DTFeedBackListener( JComponent comp, Cursor cursor )
            DropTarget dt = new DropTarget( comp, this );
            dt.setDefaultActions(DnDConstants.ACTION_COPY_OR_MOVE);
            this.comp = comp;
            this.cursor = cursor;
        public void dragExit(DropTargetEvent dte)
            setFeedBackCursor(DragSource.DefaultMoveNoDrop);
        public void dragEnter(DropTargetDragEvent dtde)
            dtde.acceptDrag( DnDConstants.ACTION_COPY_OR_MOVE );
            setFeedBackCursor(cursor);
        public void drop(DropTargetDropEvent dtde){}
    public class MYDragSource extends DragSource
        public MYDragSource()
            super();
        protected DragSourceContext createDragSourceContext(DragSourceContextPeer dscp, DragGestureEvent dgl, Cursor dragCursor, Image dragImage, Point imageOffset, Transferable t, DragSourceListener dsl)
            return new MYDragSourceContext(dscp, dgl, dragCursor, dragImage, imageOffset, t, dsl);
    private static Cursor fbCursor;
    public class MYDragSourceContext extends DragSourceContext
        private transient DragSourceContextPeer peer;
        private Cursor              cursor;
        public MYDragSourceContext(DragSourceContextPeer dscp, DragGestureEvent dgl, Cursor dragCursor, Image dragImage, Point imageOffset, Transferable t, DragSourceListener dsl)
            super( dscp, dgl, dragCursor, dragImage, imageOffset, t, dsl);
            peer         = dscp;
            cursor       = dragCursor;
        protected synchronized void updateCurrentCursor(int dropOp, int targetAct, int status)
            setCursorImpl(fbCursor);
        private void setCursorImpl(Cursor c)
            if( cursor == null || !cursor.equals(c) )
                cursor = c;
                if( peer != null ) peer.setCursor(cursor);
    public static void setFeedBackCursor( Cursor cursor )
        fbCursor = cursor;
}

Similar Messages

  • Cannot click and drag with bluetooth mouse?

    I have installed bluetooth mouse and works fine but cannot click and drag using the mouse in any applications. will highlight stuff and cursor moves fine but then cannot drag using the mouse. Any ideas?

    I was trying with this code which I got from this website as I am beginner of AS3.
    var images:MovieClip = images_mc;
    var offsetFrame:int = images.currentFrame;
    var offsetX:Number = 0;
    var offsetY:Number = 0;
    var percent:Number = 0;
    images.addEventListener(MouseEvent.MOUSE_DOWN,startDragging);
    images.addEventListener(MouseEvent.MOUSE_UP,stopDragging);
    function startDragging(e:MouseEvent):void
    images.addEventListener(MouseEvent.MOUSE_MOVE,drag);
    offsetX = e.stageX;
    offsetY = e.stageY;
    function stopDragging(e:MouseEvent):void
    images.removeEventListener(MouseEvent.MOUSE_MOVE,drag);
    offsetFrame = images.currentFrame;
    function drag(e:MouseEvent):void
    percent =  (e.stageX - offsetX)/images.width;
    percent =  (e.stageY - offsetY)/images.height;
    var frame:int = Math.round(percent*images.totalFrames) + offsetFrame +1;
    while (frame>images.totalFrames)
      frame -=  images.totalFrames;
    while (frame<=0)
      frame +=  images.totalFrames;
    images.gotoAndStop(frame);
    This has to rotate in top also i.e., I also have images sequence placed with top view also.
    If I use keyboard, it has to work with arrow keys also and also with mouse interactivity.

  • Move container sprite according to mouse movement

    Hi All,
    Currently I'm developing a game where there is a object which follows mouse. Also there are other objects and a map on the screen.I want all of background content(whole map and other objects) to move when user moves mouse left or right. That is, if user moves mouse on right side then all content(except object which moves as per mouse) should move left side so that user can see remaining part of map on the right side.
    As of now I have created new Container sprite in which I have added all of my objects and map. So when user moves the mouse right, I move the container sprite to left so it looks all stuff moves to left. Code looks like as below
    var pt:Point = new Point(character.x, character.y);
    pt = dori.localToGlobal(pt);
    if (pt.x > (stage.width * 0.5))
                        container.x -= 5;
    Structure of project is such that, I add Container directly to stage. and this container contains everything like map, character and other objects.
    Now issue is that as soon as mouse goes beyond middle of stage...it creates distance between mouse location and character..!! I mean it does move according to mouse but some distance get created between mouse and character. and this distance keeps increasing as I continue to move mouse away from center of stage!!
    I'm really stuck with this issue. Please someone help with this. I hope I have explained this well. Let me know if you need more info but please help.

    No see......I dont want ease in n all....and character following the mouse logic is working fine if I dont use above linear interpolation to move the container mc.....
    but I do want to move container mc as well so I will have to use what you gave to move the all background objects when user moves mouse....
    so Again to clarify, in the game when user moves mouse the character should follow and at the same time bakckground objects which are in container mc should move opposite to mouse movement so that remainng mape gets visible to the user....
    just now when I was debuggin the linear interpolation logic...I got to know that there something I need to change in it...because accroding to that logic...let say for example
    stageWidth is 480
    maze.width is 551
    then x1 will be  480
    y1 will be -71
    x2 will be 0 and
    y2 will be 0
    so m = (y1 - y2) / (x1 - x2) = -71 - 0 / 480 - 0
    m = -0.147
    b = y1 - m * x1 = -71 - (-0.147 * 480) = 0
    so on each enter frame when mouseX wil be multiplied with m....it will create lag in moving container(character is in container as well!
    bcoz
    container.x = m * stageRef.mouseX + b;
    so I'm confused!!
    where do u think shall correction be made??

  • Drag and Drop Return Animation

    I've created a drag and drop interaction and would like the
    dragged object to animate back to the start location when the
    target location is not correct. Currently I have it snapping back,
    but would like to animate it using some kind of 'do while' loop to
    it's original x,y, location.
    Any help would be much appreciated.

    I do these a lot at work. If you are using the tweening
    prototypes(
    http://laco.wz.cz/tween/?page=download)
    then you can simply do something like this
    if(droptarget == wrong answer){
    droped_object.slideTo(originalx, originaly, 1,
    "easeOutQuad");
    this way it is animated back with inertia and easing

  • Can't drag and drop in Finder with trackpad or magic mouse

    I can't seem to drag and drop anthing in the Finder window since updating to Mavericks (10.9). I've tried changing all magic mouse and trackpad settings.  I can drag and drop windows and apps on the dock.  No sure what the issue is....any help is appreciated!

    Had the same problem. Reinstalled the software - all is well. Cured many ills with the initial installation - don't bother trying to play with permissions, etc. Just reinstall.
    Thank goodness this isn't Micro$oft or you'd have to sit in front of the computer to keep answering the "Okay to reboot" questions every time a chunk of code is installed.

  • Drop Zone Animation

    Is there a way to make a drop zone slide across and off screen in DVD Pro, or is this something you must do in motion?

    Why is it that idvd has animated drop zones, and DVD Pro does not?
    DVD SP does have animated Drop zones, simply drag an m2v from the bin to the menu and a pop up provides choices, and the drop zone is animated, but you asked about something different.
    As mentioned iDVD and DVD SP are different
    http://discussions.apple.com/thread.jspa?messageID=2767014&#2767014
    You may be better off with iDVD for the short term unless you need the features of DVD SP.
    Opening an iDVD project is something that many users who use DVD SP probably would not think is high on the "hit parade" of things Apple should change, things higher up include proper HD & blu-ray authoring, clearing out/cleaning up the abstraction layer, etc.
    Remember iDVD is more of a consumer app (and I do like it alot and use it for kicks), but DVD SP is geared to be more "pro". It is actually very easy to use and incredibly powerful, do not be disappointed, you should not be. Use each tool for what it is and what it is designed to accomplish

  • Review Widget: "drag the correct answer to the target" - not working for me?

    Ive read the (very limited) help on this problem, and I must be doing something wrong
    I simply want to indicate the right answer A or B - couldnt be simpler.
    Apple says:
    "To indicate the correct answer: Select it or drag the label or image to the target. To have more than one correct answer, hold down the Command key while you select the answers."
    Its just not working. I assume it means drag the CHOICE A button OR CHOICE A text (thats all there is) to some target on the inspector but that doesnt work nothing happens. (And where is "the target" what target? Where? I cant find a "drop" green plus appearing anywhere..
    So I then, instead I try dragging the QUESTION TEXT (eg is the sky blue or red) to somewhere and that DOES show a draggable obkect but again where is this "target"? If that means the  Answer a or Answer B back in the widget it self then No, that doesnt do anything, no drop zone is saying "hey drop me here"
    So, like I say, I must be missing somethign really obvious. But Ive no idea. Please help.
    TP

    Hi Andy,
    I am trying to investigate this issue but I havent been able to reproduce it. It would be great if you could give me a few inputs.
    1) Are you able to Publish Comments in the review?
    2) Is there any internet traffic monitoring tool running on your machine?
    3) Close Acrobat and then try killing the AdobeCollabSync.exe from task manager. Now open the review file again and try to sync the comments. Does this work?
    4) Try downloading a fresh copy of this file from Acrobat.com server and replacing your local copy with it.
    If all these things do not work then maybe we can analyze the traffic (using fiddler) on your machine to investigate the problem.
    Thanks,
    Abhilasha

  • Bug? Can't Drag and Hold Mouse Photoshop CS6 on Windows 8 RP

    I am having a few problems with the current Photoshop CS6 on Windows 8RP.
    At first it was only the tilit shift and iris but it turns out it's everything to do with when you need to hold the mouse button and drag. It seems that the problem is isolated to Photoshop as other Adobe programmes are working fine plus other programmes and Windows generally is also fine.
    I am using an Nvidia GTX580 with Windows 7 drivers until the proper version comes which is late of course!
    Plus, I uninstalled my Intellipoint and keyboard drivers too and connected a generic mouse via USB and I still get the same problem.
    Weirdly though, every (let's say) 20 times I try to drag and hold after constantly restarting Photoshop it works once then I have to try again a load of times by restarting the application.
    Any ideas?
    Joe

    I'm running photoshop cs6 on windows 8 RP 64 bits and haven't seen that problem
    and i didn't see that on the consumer preview either.
    This is the driver i'm using:
    http://www.nvidia.com/object/win8-64bit-296.17-preview-driver.html
    Just watch that windows update doesn't try to sneak in there own driver.
    It happened to me twice until i changed the automatic updates to notify
    and also watch that doesn't happen with your monitor profile as well.
    The updated Nvidia drivers for rp are supposed to be released sometime this coming week.
    Do you have any third party plugins or do you have the scriptlistener installed?
    Did you try resetting the photoshop preferences or difference modes under the Advanced setting for the the graphics processor under preferences>preformance in photoshop?

  • InDesign CC 2014 can no longer drag objects with mouse

    I have been using InDesign for months with no problems but suddenly I am having mouse issues. I can use my mouse to resize objects and make selections but dragging objects in the document or in panels (for example, reordering spreads) no longer works. I am using a mac on the latest 2014 CC release of InDesign, and have tried all the usual tricks (Ctrl + Alt + Shift + Cmd on startup to remove preferences, manually deleting preferences (both files), reloading software, rebooting machine, reinstalling InDesign) but the only thing that works is rebooting the machine.
    However, within 20-30 minutes after a reboot, the problem returns out of nowhere. I don't use plugins with InDesign and haven't changed hardware or software recently so I have no idea what's causing this.
    Does anyone have any info that might help me out? From googling around, it seems most people have solved their problems after a preferences dump, but mine keeps on coming back!

    I've actually been discussing this problem in another thread but this one is dedicated to it.
    This cropped up for me prior to the New Year and I've found no solution. I actually did what Steve Werner suggested this week and created a new OS X account. But the problem cropped up in the new account today.
    I don't know if this is a common or not. I'm part of a large creative team and as far as I know, I'm the only user experiencing this. I've trashed preferences, uninstalled and reinstalled InDesign, restarted the computer, etc. Nothing works.

  • Dragging Objects (stopping mouse from moving)

    Hello,
    I am very stuck. I tried looking over my old Director scripts
    for help but I cant make anything of them to help them with
    Actionscript.
    Basically what i want to do is, when i am dragging a a movie
    clip such as 'lungs_mc' i dont want the user to be able to drag it
    outside of a box called 'dragArea_mc' which has co ords of:
    w:560.0, h:538, x: 235, y:57.0.
    Basically when the user drags lungs_mc to the edge of box it
    stops the user from moving the object outside this box, but they
    are still able ot move it inside of the box.
    Any Suggestions??
    If you dont know how to retrain 'lungs_mc' within
    'dragArea_mc' then even retraining them within x and y co ords
    would be great and i will just use < and > for those.
    Also 'lungs_mc' is on the _root and so is 'dragArea_mc'. They
    both must stay on the root to make the whole movie work.
    It would be greatly appreciated if anyone could help as it
    would solve a massive problem for me
    thanks a lot :-)
    Lee

    The startDrag method takes up to 5 parameters, where 4 of
    them can define a bounding box for the dragging:
    lungs_mc.startDrag(false, LEFT, TOP, RIGHT, BOTTOM)
    You can insert the values for the dragging borders there. The
    values are relative to the dragged MC's parent, so keep that in
    mind. If lungs_mc is inside dragArea_mc, you could use
    lungs_mc.startDrag(false, 0, 0, dragArea_mc._width,
    dragArea_mc._height)
    hth,
    blemmo

  • Whole screen is dragging with the mouse

    I have a 23" cinema display - whenever I drag the mouse the whole display moves with it, not as the actual monitor, but the desktop on the screen - the menu bar and everything moves off if I move the mouse up and the menu bar moves down if I move the mouse down !
    It looks a little lacking in sharpness
    I have restarted / run tech tool pro etc to no avail - running the latest version of 10.4 with a G5
    and have been to the displays in system preferences and all is set as it should be, I believe.
    Is there a file that could have been corrupted ? Any help appreciated.....

    Open the Universal Access pane of System Preferences, click on Seeing, and turn off Zoom.
    (33762)

  • My iPod keeps dropping wifi.. Reset according to instructions. Now unresponsive on genius for apps.

    Total Luddite. Trying to come into 21 century..I pod touch was dropping wifi..reset the factory settings, now unresponsive in genius for apps..

    Try:
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:       
    iOS: How to back up           
    - Restore to factory settings/new iOS device.
    -  Make an appointment at the Genius Bar of an Apple store.
    Apple Retail Store - Genius Bar

  • What is the point of dropping the animated feedback in Mail?

    I started using Mail (instead of Eudora) with Lion, and I've gotten pretty used to it by now... not that I don't have my complaints. But in the new upgrade to Mountain Lion, suddenly the feedback animations that tell you Mail is checking the, uh, mail... are no longer available! So now when I tell Mail to Check Mail, I know LESS about what's going on than I did before... if there's any benefit to losing this feedback, I'm sure not understanding it.

    That's good to know, Ashka, but why would I want to open up an extra window to get info that used to be available by default? It's not as if I gained any screen real estate by losing those animations. Just an unnerving sense that nothing's happening!

  • Can I use an animated symbol acting like a mouse cursor?

    Hi,
    I'd like to use an EDGE animated symbol ( a blinking magic wand) as my mouse cursor (hiding the original cursor) that stays on the stage all the time at a certain point in the timeline and when clicked on a hotspot, goes to another point in timeline where the symbol no longer act as a mouse cursor. I used the following code suggested in the following thread by YOSHIOKA Ume
    Re: How to I have an animated symbol follow the coordinates of the cursor when clicked?
    1:create a symbol named "Symbol_1"
    2:add this code on Symbol_1-Timeline.complete.
    //delete this instance when timeline complete. sym.deleteSymbol();
    3:add this code on document.compositionReady.
    //on/off mousemove event handler method
    sym.$("Stage")  
    .mouseover(function(){    
    sym.$("Stage").on("mousemove",draw);  
    //create instance of Symbol_1 on stage.
    function draw(evt){  
    var instance = sym.createChildSymbol("Symbol_1", "Stage");  
    instance.getSymbolElement().css({    
    position:"absolute",    
    top:evt.clientY,    
    left:evt.clientX   });
    But the problem is, the symbol is being repeated/drawn one after another according to the above code, which I don't want. Changing the cursor using CSS requires a URL of a image file, not a symbol inside EDGE as it seems. How can I get back the normal mouse cursor in another point in the timeline (and go back to the animated symbol mode again if needed?). If I click on another hotspot element on the stage, do I actually click on the attached symbol as a cursor? Or the hotspot?
    Also, how can I put a constraint on the cursor so that it stays within a certain rectangular area smaller than the stage?
    A suggestion is much appreciated.

    Here is a example I had to move a symbol around as a mouse cursor and play different part of the symbol timeline based on user action.
    mouseCursor.zip - Google Drive
    To constraint the symbol to stage area,check for the x and y values in the event callback function before moving the symbol.
    To get back the normal cursor set the css back to default
    ex: sym.getSymbol('Stage').getSymbolElement().css({ 'cursor' : 'default'});

  • When I go to a drop down menu, for example bookmarks, I mouse over the text and it turns color with a dark bar; can this be fixed?

    I am running Firefox 5 currently. Ever since the last update to Firefox 4 and currently with firefox 5 I have had this issue. The dropdown menu is normal when it first drops down. When i move my cursor over the text in the menu it changes to a dark blue bar and remains that way until I close the dropdown, it resets until i dropdown and mouseover again. When I make a selection in the menu it works fine.
    I have also noticed that the buttons in the browser and in certain websites have a "sweetspot" you have to hit for the button to function. In past versions if you clicked anywhere on the graphical button it would function.

    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions is causing the problem (switch to the DEFAULT theme: Firefox (Tools) > Add-ons > Appearance/Themes).
    * Don't make any changes on the Safe mode start window.
    * https://support.mozilla.com/kb/Safe+Mode
    In Firefox 4 [http://kb.mozillazine.org/Safe_mode Safe mode] disables extensions and disables hardware acceleration.
    * Tools > Options > Advanced > General > Browsing: "Use hardware acceleration when available"
    If disabling hardware acceleration works then check if there is an update available for your graphics display driver.

Maybe you are looking for

  • Background Jobs running for long time.

    Dear All, I had done the Homogeneous System Copy on my ECC 6 QA System successfully by restoring the offline backup of Production system. My system is up & running but  I have some Performace issues in the system. I also observed that some jobs are r

  • I need help setting up ipad 2 with airport express??

    I am having trouble getting my ipad to play music wirelessly, but my macbook is fine. Is there something I need to do on my ipad to get it to work?

  • Best book for Web Services

    Can you suggest me what's best book for Web Services and XML to study? I'm planning to buy.. Thanks in advance..

  • AIR HTML

    I am developing an application on Adobe Air and insert a section in the HTML component, the site that I use in this compoente opens a popup window using javascript, but Air does not work, does not open the popup. Is there any way to solve this? Thank

  • Help desk number

    I need a help desk number. I have to update some government signature files and I with no headings in this package I cannot see how to call up my digital signature that is file on Firefox. Where are my headings. How do I get to the menu bar that had