Drag, drop AND MouseEvents

I am trying to build a mapping application and data running on the issues of the event presented with DND. I would like to draw a line "stretching" between "ports". When the target port, I would like to drop some info on it. The commented code below (with the _port.setOnDragDetected method) is the stretch described (ports are expanded to the demonstration).  If this block of code is uncommented, the drop works as I need to, but events are delivered to the linework.  Problem is that I need two.
public class DataXferView extends Application {

    private Line connection;
    private Group root;
    private HashMap<String, Color> colorMap;

    private void init(Stage primaryStage) {
        colorMap = new HashMap<String, Color>();
        colorMap.put("1", Color.LIGHTBLUE);
        colorMap.put("2", Color.ORANGE);
        root = new Group();
        primaryStage.setScene(new Scene(root, 400, 300));

        Group outPort1 = createOutPort(50.0, 50.0, "1");
        Group outPort2 = createOutPort(50.0, 125.0, "2");
        Group inPort = createInPort(250.0, 75.0);

        root.getChildren().add(inPort);
        root.getChildren().add(outPort1);
        root.getChildren().add(outPort2);
    }

    private Group createOutPort(double _topLeftX, double _topLeftY, String _portId) {
        Group outPortBox = new Group();
        Rectangle borderBox = RectangleBuilder.create().x(_topLeftX).y(_topLeftY)
                .width(100).height(40).fill(Color.WHITE).stroke(Color.BLACK).build();

        Circle port = CircleBuilder.create().centerX(_topLeftX + 80)
                .centerY(_topLeftY + 20).radius(10.0f)
                .fill(colorMap.get(_portId)).stroke(Color.DARKGREY).build();
        port.setUserData(_portId);

        setOutPortEvents(port);
        outPortBox.getChildren().addAll(borderBox, port);
        return outPortBox;
    }

    private void setOutPortEvents(final Circle _port) {
        _port.setOnMousePressed(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent me) {
                connection = LineBuilder.create().stroke(_port.getFill()).strokeWidth(2.0)
                        .startX(_port.getCenterX()).startY(_port.getCenterY())
                        .endX(_port.getCenterX()).endY(_port.getCenterY()).build();
                root.getChildren().add(connection);
             }
        });

        _port.setOnMouseDragged(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent me) {
                connection.setEndX(me.getSceneX());
                connection.setEndY(me.getSceneY());
            }
        });

//        _port.setOnDragDetected(new EventHandler<MouseEvent>() {
//
//            @Override
//            public void handle(MouseEvent me) {
//               Dragboard db = _port.startDragAndDrop(TransferMode.ANY);
//                // Put a string on a dragboard
//                ClipboardContent content = new ClipboardContent();
//                content.putString((String)_port.getUserData());
//                db.setContent(content);
//            }
//        });
        
    }

    private Group createInPort(double _topLeftX, double _topLeftY) {
        Group inPortBox = new Group();
        Rectangle borderBox = RectangleBuilder.create().x(_topLeftX).y(_topLeftY)
                                            .width(100).height(40).fill(Color.WHITE).stroke(Color.BLACK).build();

        Circle port = CircleBuilder.create().centerX(_topLeftX + 20).centerY(_topLeftY + 20)
                            .radius(10.0f).fill(Color.WHITE).stroke(Color.DARKGREY).build();
                            
        setInPortEvents(port);
        inPortBox.getChildren().addAll(borderBox, port);
        return inPortBox;
    }

    private void setInPortEvents(final Circle _port) {
        _port.setOnDragOver(new EventHandler<DragEvent>() {

            @Override
            public void handle(DragEvent event) {
               if (event.getGestureSource() != _port
                        && event.getDragboard().hasString()) {
                   event.acceptTransferModes(TransferMode.ANY);
                }
                event.consume();
            }
        });

        _port.setOnDragEntered(new EventHandler<DragEvent>() {

            @Override
            public void handle(DragEvent event) {
                if (event.getGestureSource() != _port
                        && event.getDragboard().hasString()) {
                    _port.setStroke(Color.RED);
                }
                event.consume();
            }
        });

        _port.setOnDragExited(new EventHandler<DragEvent>() {

            @Override
            public void handle(DragEvent event) {
                _port.setStroke(Color.DARKGREY);
                event.consume();
            }
        });

        _port.setOnDragDropped(new EventHandler<DragEvent>() {

            @Override
            public void handle(DragEvent event) {
               Dragboard db = event.getDragboard();
                boolean success = false;
                if (db.hasString()) {
                     _port.setFill(colorMap.get(db.getString()));
                    success = true;
                }
                event.setDropCompleted(success);
                event.consume();
            }
        });
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        init(primaryStage);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
This is the problem that is described here: http://javafx-jira.kenai.com/browse/RT-16916?

And the solution will be included in the final version of 2.1 (I am current using 2.1 b07)?

Workaround advice are appreciated. Thank you.

The attached code contains the following changes:
-the block of initialization of the DND is no comment
-the MouseDragged Manager is removed, instead, the DragOver filter is added to the stage
-the line is marked mouseTransparent, otherwise he keeps eating the DragOver events that we want to be delivered to the port target

He deserves a little more work, for example, it allows a transfer of data between applications, but not for the lines between applications, but the basic idea should be clear.

public class DataXferView extends Application {

    private Line connection;
    private Group root;
    private HashMap colorMap;

    private void init(Stage primaryStage) {
        colorMap = new HashMap();
        colorMap.put("1", Color.LIGHTBLUE);
        colorMap.put("2", Color.ORANGE);
        root = new Group();
        Scene scene = new Scene(root, 400, 300);
        primaryStage.setScene(scene);

        scene.addEventFilter(DragEvent.DRAG_OVER, new EventHandler() {
            @Override
            public void handle(DragEvent me) {
                if (me.getGestureSource() != null) {
                    connection.setEndX(me.getSceneX());
                    connection.setEndY(me.getSceneY());
                }
            }
        });

        Group outPort1 = createOutPort(50.0, 50.0, "1");
        Group outPort2 = createOutPort(50.0, 125.0, "2");
        Group inPort = createInPort(250.0, 75.0);

        root.getChildren().add(inPort);
        root.getChildren().add(outPort1);
        root.getChildren().add(outPort2);
    }

    private Group createOutPort(double _topLeftX, double _topLeftY, String _portId) {
        Group outPortBox = new Group();
        Rectangle borderBox = RectangleBuilder.create().x(_topLeftX).y(_topLeftY)
                .width(100).height(40).fill(Color.WHITE).stroke(Color.BLACK).build();

        Circle port = CircleBuilder.create().centerX(_topLeftX + 80)
                .centerY(_topLeftY + 20).radius(10.0f)
                .fill(colorMap.get(_portId)).stroke(Color.DARKGREY).build();
        port.setUserData(_portId);

        setOutPortEvents(port);
        outPortBox.getChildren().addAll(borderBox, port);
        return outPortBox;
    }

    private void setOutPortEvents(final Circle _port) {
        _port.setOnMousePressed(new EventHandler() {

            @Override
            public void handle(MouseEvent me) {
                connection = LineBuilder.create().stroke(_port.getFill()).strokeWidth(2.0)
                        .startX(_port.getCenterX()).startY(_port.getCenterY())
                        .endX(_port.getCenterX()).endY(_port.getCenterY()).build();
                connection.setMouseTransparent(true);
                root.getChildren().add(connection);
             }
        });

        _port.setOnDragDetected(new EventHandler() {

            @Override
            public void handle(MouseEvent me) {
               Dragboard db = _port.startDragAndDrop(TransferMode.ANY);
                // Put a string on a dragboard
                ClipboardContent content = new ClipboardContent();
                content.putString((String)_port.getUserData());
                db.setContent(content);
            }
        });

    }

    private Group createInPort(double _topLeftX, double _topLeftY) {
        Group inPortBox = new Group();
        Rectangle borderBox = RectangleBuilder.create().x(_topLeftX).y(_topLeftY)
                                            .width(100).height(40).fill(Color.WHITE).stroke(Color.BLACK).build();

        Circle port = CircleBuilder.create().centerX(_topLeftX + 20).centerY(_topLeftY + 20)
                            .radius(10.0f).fill(Color.WHITE).stroke(Color.DARKGREY).build();

        setInPortEvents(port);
        inPortBox.getChildren().addAll(borderBox, port);
        return inPortBox;
    }

    private void setInPortEvents(final Circle _port) {
        _port.setOnDragOver(new EventHandler() {

            @Override
            public void handle(DragEvent event) {
               if (event.getGestureSource() != _port
                        && event.getDragboard().hasString()) {
                   event.acceptTransferModes(TransferMode.ANY);
                }
                event.consume();
            }
        });

        _port.setOnDragEntered(new EventHandler() {

            @Override
            public void handle(DragEvent event) {
                if (event.getGestureSource() != _port
                        && event.getDragboard().hasString()) {
                    _port.setStroke(Color.RED);
                }
                event.consume();
            }
        });

        _port.setOnDragExited(new EventHandler() {

            @Override
            public void handle(DragEvent event) {
                _port.setStroke(Color.DARKGREY);
                event.consume();
            }
        });

        _port.setOnDragDropped(new EventHandler() {

            @Override
            public void handle(DragEvent event) {
               Dragboard db = event.getDragboard();
                boolean success = false;
                if (db.hasString()) {
                     _port.setFill(colorMap.get(db.getString()));
                    success = true;
                }
                event.setDropCompleted(success);
                event.consume();
            }
        });
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        init(primaryStage);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

Tags: Java

Similar Questions

  • Drag &amp; Drop and start

    After the Fusion 8 upgrade, I noticed that I can not drag and drop between Windows7 and MacOS (10.10.5)

    MORE when I run Merge (automatic start of Windows), NOW I get a "Windows is not stopped... successfully." "whenever I start, even if operating manual.

    I did nothing else than to pay and install the upgrade of Fusion 8.1

    I'd like to go back the way it was... drag & don't drop between Windows and Mac... no error starting Windows... suggestions?

    Thought of her old post on a similar problem.

    Once the update of Fusion to the 7 8 tools VMWare had to be installed... Once installed the two drag & drop began work and error starting Windows stopped... would have been nice to know to reinstall the VMWare Tools.

  • Drag &amp; drop and right click to stop work in Premiere Pro

    Hello!

    We use Adobe Premiere Pro in the business for a while now. Only today it began to happen that first would completely freeze on the attempt to drag and drop a file in sequence. Drag / move cursor would remain same after the release of the left mouse button and the interface user of first overall would freeze. Here is an example of what is happening: https://youtu.be/hXbBY342HLI

    It is the latest version of Premiere Pro. I tried to clean the Adobe programs and settings power off the PC completely and everything reinstalled again. It does not solve the issue.

    This problem will not occur in all the projects that I noticed. But I don't see anything in common between the projects in which what happens.

    Does anyone have a similar problem?

    Try to delete the sequence markers In/Out.

  • Hi, PDF images, drag drop and place, ready for printing

    Hi, I have a client who is a small magazine. They use PDF to images and print copy and brings together them in a layout. This entire provision is then sent to the printing company.

    The customer wants to drag and drop PDF files to a container/s on the layout. There may be a few snap involved too. Has anyone ever heard talk about this before? I guess they use PDF, so it has the safety element and images and type cannot be changed accidentally.

    Is there a best practice in this respect? I am a novice in the management of the PDF.

    Thank you very much

    Phil

    I am sure that he met the two of us. The only thing had it right in this discussion was to click on the links to the right answer for each of our messages. Your 'dumb' message seemed to be in response to John post so I if you meet John. Regardless of who answered that this whole discussion is really stupid. Phil has an apparent problem completely describing her problem. Instead of posting of the specific error messages, he simply said "no go."

  • Drag drop and object rotation

    Want to develop simple puzzle games (in the browser) where forms (for example, a form of puzzle piece) can be simultaneously dragged and swivels, then fell on the screen or canvas.  The game mode is to click and drag the shape or object, while simultaneously turning the piece using the arrow keys.  Is this possible in Flash?  This simple general activity of simultaneous drag and rotate, then fall, is my basic game scheduled together web site.  I'm new to Flash, but have developed Windows executables for many years.  I'm trying to decide whether to buy and learn Flash as a platform for interactive educational puzzle running games in the browser windows.

    Simultaneous portion is critical, am concerned about the questions to get the focus for key downs on a polygon, or an image, or anything that would work well as a piece of the puzzle.

    Thank you very much

    I wasn't too sure the simultaneous drag and rotation, so I did a small sample file.  It confirms that you can do both at the same time.  Drag with the mouse and hold down the left or right arrow key to turn.

    http://www.nedwebs.com/Flash/AS3_Drag_and_Rotate.swf

  • Drag, Drop, and docking station...

    Hey guys... someone knows how to do this on FLEX?

    http://Nettuts.S3.amazonaws.com/127_iNETTUTS/demo/index.html

    or something similar to this?

    Thank you

    CyA

    You can change this http://examples.adobe.com/flex3/devnet/dashboard/main.html , then all you need to do is add panels. title windows or whatever it is that act as 'zones', you'll be ready to go.

  • Drag &amp; Drop sometimes gives excessive use of persistent processor (WKS TP June 2012)

    The host Windows 7 x 64 SP1 Workstation Tech Prev June 2012 16 GB, 4 CPU

    Comments Windows 8 x 64 Release Preview 2 GB, 2 vCPUs

    Drag / drop a file from the host to the client desktop sometimes shows the pointer of the mouse as circle with slash and translates VMware tool Core Service using 100% of the total CPU, or 50% on the two vCPUs.

    Before a Drag & Drop and after a Drag & Drop

    DragDrop1CPU.jpg

    Most of the time the CPU spikes result when Drag & Drop fails, that is, it shows a circle with a slash in the world mouse pointer, then roll the mouse off the desktop and on the back and an icon from the taskbar a few times shows finally the mouse pointer from the anchor and it can be moved successfully on the desk of comments.

    And after a few minutes, this excessive CPU reduced to 1 vCPU charge, but never goes away until vmtoolsd is finished.

    DragDrop2CPU.jpg

    Details:

    DragDrop3CPU.jpg

    DragDrop4CPU.jpg

    I noticed that there are 2 vmtoolds.exe running, dieting and the other under the user, but under the user.

    Also, I remember seeing this same behavior in an older computer, like 6.

    You can use the Task Manager to kill the vmtoolsd.exe process that uses 100% of CPU.  To restart it, you run a command line like this:

    "C:\Program Files\VMware\VMware Tools\vmtoolsd.exe" -n vmusr

    The exact command line to run is located in the registry:

    HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run, VMware user process string value

  • I have just noticed that the function drop and drag for attachments stopped working in Yahoo and Gmail. Is it because of Firefox?

    I am currently using Firefox 19. Last week, I found that, in the Yahoo and Gmail, I can't attach files using drag and drop; I used no drag and drop for a little while if I can't say that it began with a particular Firefox update. Unlike some FF16 users I have no problem dragging autour tabs in the browser. I know that in the past, certain issues with attachments were obviously related to the browser and so the reason why I consider that this link now. I use Windows XP SP3.

    Tylerdowner, hi.

    Thanks for your reply, but remembering the cause of a problem attach previous many Firefox users had at the time of FF13 related to implementation network.http.spdy.enabled to 'true' I decided to check again in this parameter: config.

    To solve my problem at the time I, like others, changed the setting SPDY of the "true" to "false", and what I found was not changed automatically with the latest versions of FF. I found, however, that there are now two other parameters SPDY v2 and v3, which were set to 'true '. In case they were in conflict with the first setting to "false", I changed this last to 'true' also. This is I went back to Gmail and tried to attach files, first under the normal procedure by clicking the attachments and selection of a file in the dialog box, which worked (previously on 'true' it had not worked); Second, I tried to fix with the help of drag / drop, now works. I also found that drag & drop in Yahoo also work.

    Thus, a conflict between the SPDY versions could have the cause of the problem when network.http.spdy.enabled has been set to 'false '?

    If the problem persists I'll let you know. (I've attached a snapshot of the current settings).

  • I'm unable to select, crop, or drop and drag. I also cannot manually move or resize a window or a file.

    Help with the selection

    I'm unable to select, crop, or drop and drag. I also cannot manually move or resize a window or a file. What the devil?

    You're not really in the right forum for this...

    Might be interesting to try a system restore to when it worked.

    http://Windows.Microsoft.com/en-us/Windows-Vista/what-is-system-restore

  • Drop and drag the transfer of images on a hard disk on mac-help does not

    I should be able to drop and drag from lightroom on an external hard drive but its not taking the file.  I bring a picture of slide 1 but not a file.  HELP PLEASE!

    This is most likely the problem. Memory sticks are not external drives; LR knows the difference.

  • Drop and drag in a symbol not to frame 0:00

    Hello

    I have seen this great tutorial on the drop and drag ( http://www.youtube.com/watch?v=u4R8jFI_DeE ), but I want to have a drop and a trail which is a symbol and which do not appear until later on in the timeline.

    Is there a way I can do?

    (Sorry I'm new on creationComplete)

    Looks like you are really struggling with the scope in the sample.  This is a cleaned up version of your file:

    http://Adobe.LY/1eh3NNi

    What I did was:

    1. 'Circle' and rename it 'combination' to remind me that that was the goal and the element to remove
    2. Removed the code to include the call to yepnope and used the script fancy, new loading feature to include jQuery-UI (look in the section Scripts from the library panel)
    3. Changed the local call until the symbol of combination (in this context, 'sym' means 'the current symbol,' which is 'mix' in this case)

    I hope this helps!

    -Elaine

  • Table of Drag and Drop and copy-paste

    Hi all

    I use dreamweaver CS 5.5 on a macmini.

    I'm pretty new to dreamweaver-things integers and use it mainly for Web sites in html conversion. I usually only through copy - paste:

    Copy the text of the Web site - paste it into dreamweaver - edit in dreamweaver's code view Preview

    Now there's a big problem: if I copy a Table, it is not stick at all. It sticks quite simply nothing.

    If I drag ' drop it, it will only paste the data in the cells, not tab, culminating in a huge test without any format in it and useless to me.

    Is this a known issue? What can I do about it?

    Thanks a lot for all the help

    In case this does not work, you will need to open the code, find the code for the table, copy it and paste it into the code view. I think that when it does not work, it is because you have not copied the whole table and instead caught a snippet of the full table.

  • How to make a reset button and add the action script to reset all my drag drop video clips

    It's HOT need help quickly by the close of business Thursday

    Hello kglad and all, I have a problem with adding a reset button for my drag and drop video clips.

    The problem is, if a student dragging a movie clip to a wrong address on the SWF, I want them to be able to hit a reset button that would lead the SWF even they opened and what would showup a page clear to restart drag them and drop exercise.

    I know how to make a button for this want just the appropriate action script to be able for the user to start over with no symbol of clip from movie on the page.

    Seal55

    You must either code to reset everything or you can reload your current page:

    loadMoveNum(this._url,0);

  • I have version 9.0.1 on 2 pc, both xp sp3. 1 the button "open new tab" is visible, on the other hand, the "Open new tab" button is not yet available in the menu "Customize toolbar" drag / drop. Why?

    I used the same setup file, but on 1 pc, the "Open new tab" button is available in the menu 'Customize toolbar' and can be dragged and drop on the navigation bar. On the other pc, the "Open new tab" button/icon is not yet available for drag / drop. I uninstalled firefox completely, including the settings and preferences, then reinstalled, but that has not fixed the missing button.

    Hello

    Please try to restore the default value in the Customize... window. If it is still not visible, one of the reasons could be that the button is already placed on the toolbar, but can be hidden behind a different icon or toolbar.

    ...............................................................................................................................

    Useful links:

    Everything on tools > Options

    Beyond the tools > Options - about: config

    Subject: config entries

    Information page (Alt + T) tools > Page Info, right-click > view Page information

    Keyboard shortcuts

    View without Plugins

    Files & Firefox profile folder

    Firefox commands

    Basic troubleshooting

    After the upgrade

    Safe mode

    Extensions of the issues

    Troubleshooting Extensions and themes

    Troubleshooting Plugins

    Test Plugins

  • Drag-drop Subvi on selected secondary

    Hi all

    I have an application where the user creates a 'follow-up' layout by dragging the desired data from the tree. In the front panel, I have several sub-panels allowing users to drag & drop data to any as they wish. Attached VI indicates similar stuff.

    However, deleting data, I can't filter what school must be used (in the vi attached, I try to move the data to the two sub-panels but even couldn't handle success that is) should be used to determine what school should show the Subvi (in this case, it is a waveform graph)? Filter mouse events? If I use the mouse enter, I can't use the event filter to drop at the same time.

    How can I feed the data, that are generated inside the second loop, while in these sub - VI that I loaded to the sub-panels? I have to do in case of timeout I suppose, but how can I join the Subvi from there then?

    Ask if you need more questions. Sorry for any possible incomprehensible sentence above

    BR, Palazzo

    Well Yes, there are many different options to pass data to the slot - loaded VI. At some point, you need to store the reference to the loaded VI and use this reference to manipulate the VI. Here's a quick and easy way to make using a local variable of the table:

    It is not very scalable and it certainly has a disadvantage right off the bat. This table will always grow and never get more small, so you'll get overlap VI references. It should still work, but if you kept Drag and drop you would possibly have a memory problem. With a few adjustments, you can solve this problem (specific table indices may be designated for each school, so clear you always the current reference to this specific location of table before loading the secondary).

    FYI, your 1ms waiting is too small. Isn't that nobody have CPU for this.

Maybe you are looking for

  • How to finish a subscription for an app that I am paying?

    I'm trying to figure out how to end my subscription for both applications. where can I find this on my iTunes account?

  • In IE, can't download the PDF

    Hello, in the past I had no difficulties to download the PDF files.  I tried to upload a document to the site of the IRS, but he won't.  I have Adobe Pro 9.0 is installed.  I had previously uninstalled Acroread, because I thought I wouldn't need it. 

  • 'Page' does not name a type with the given Code problem

    Hello I try the code on this page , but I'm getting 'Page' does not designate a type in the Test.hpp file with the following line private: Page * appPage; Container * mRootContainer; }; What could be the solution for this problem?

  • Love can work with legacy P2P free will?

    Hi all! I just want to know that can we use love with our legacy P2P Gre? What happens if I set up love on the side of the hub & P2P on the side with rays my network. If it works?

  • Size max CRL on Cisco ASA

    Hello Have file CRL on Cisco ASA a maximum size in order to cache? For example, on 3080 Concentrator VPN Cisco maxuimum size is 1 MB. Thank you. Best regards. Massimiliano.