Best way to MouseDrag several objects around a scene.

So I'm having a little trouble tried to drag the 3 s Box in a scene.

Originally, I had it in place where everyone was transferred to an x, is translated Z, then assign a DRC. Then I thought that instead of the click of the mouse on the box itself, I'd be at the root. From there, I would look through all the root.getChildren (then) that see if it contained the x, position y.


So to know who my children root I clicked on I did .setOnDragged of root.getChildren.get (current) to figure out that it was dragged.

The code itself has worked with the exception of find which box I was.

The question that I find, is that I only PositionX, getSceneX and getScreenX. SceneX and X produce the same value and ScreenX is useless. I then tried to do event.getX () - root.getLayoutX () contains the function works, but it did not work and would require me to change many things. getLayoutX() a = 0, since I did not indicate the location of the root, only the locations of the box.

From there on, I was wondering if there was a better way. Then I thought maybe to loop through each element in my root or in an arrayList (which is what I used, but realized the root.getchildren should work like the original) but the problem is he keeps only save one last list, then just shut up and that's it.

So I want to know, what would be the best way to understand what object am I?

Initially, I use contains (Swing) but Swing is different, and as we can save mouseEvents to each node, should we not we know now exactly what we we are, while making a loop in each of them? I think it's easier than having to check each contained unique mouse position, especially if I have 10000 points to check?

Edited by: KonradZuse March 18, 2013 20:05

KonradZuse wrote:
Thanks for the help!

I can now draw a box, so there is no question about it, just that I have several boxes and I need to be able to drag each without knowing the total.

I have 1000 boxes, or 5, I can't save a mouse to each event

Why not?

so I thought I would go, and then I realized after I posted this I could use the function 'Mouse_ENTERED' or 'Mouse_PRESSED' field and then move each individual, but it would still be a loop in each of them and then find who's who.

I do not see that your example below has a certain meaning.

I have never seen sphere.addEventHandler (MouseEvent.ANY, new DragShapeHandler()); so thank you for this tip.

Buy it, you can also do

DragShapeHandler handler = new DragShapeHandler();
box.setOnMousePressed(handler);
box.setOnMouseDragged(handler);

If you prefer the convenience methods. (It is important that convey you the same reference for both).

>

It seems that the "DragShapeHandler" will basically get the source node and then move it? If we really do not need to know which.

OK-ish. It uses event.getSource () to determine the source of the event (i.e., the node on which the event occurred). But you might as well set a field in the DragShapeHandler class with the node that had to be moved:

  class DragShapeHandler implements EventHandler {

    private double sceneAnchorX;
    private double sceneAnchorY;

    private final Node nodeToMove ;

    DragShapeHandler(Node node) {
       this.nodeToMove = node ;
    } 

    @Override
    public void handle(MouseEvent event) {
      if (event.getEventType() == MouseEvent.MOUSE_PRESSED) {
        sceneAnchorX = event.getSceneX();
        sceneAnchorY = event.getSceneY();
      } else if (event.getEventType() == MouseEvent.MOUSE_DRAGGED) {
        double x = event.getSceneX();
        double y = event.getSceneY();
        nodeToMove.setTranslateX(node.getTranslateX() + x - sceneAnchorX);
        nodeToMove.setTranslateY(node.getTranslateY() + y - sceneAnchorY);
        sceneAnchorX = x;
        sceneAnchorY = y;
      }
    }
  }

and then:

...
box.addEventHandler(MouseEvent.ANY, new DragShapeHandler(box));
...
sphere.addEventHandler(MouseEvent.ANY, new DragShapeHandler(sphere));

I slightly prefer the getSource(), I think that, like the box.addEventHandler (..., DragShapeHandler (box)) new; is a little unnatural. Without doubt, however, this version is more robust (it's more type-safe because you are forced to specify a node to drag, while the source of the event could theoretically be any object).

>

That's a lot of sense that you're making a new node and just dragging it as such. so I can creater add a picture of the area between them and I just needed to understand the point of click, to get the box then he would know to do hmm...

Should really "to display the box" as stated above. Just register a Manager with any node you want to be able to drag and the Manager he will drag.

Tags: Java

Similar Questions

  • What is the best way to show 1000 objects moving in a field?

    Hello. I'm trying to JavaFX 2.0 and higher. I want to create 1000 objects (because now they can be rectangles) and move them randomly (for now). What is the best way to do this? Do I have to create an initial keyframe for each object? I was watching the demo of BrickBreaker. Is all that I need? I'm looking for a simple example. For example: ColorfulCirclesSample. Basically, what I want to do is create 1000 rectangles with random attributes including a vector (direction and speed) and show them using JavaFX 2.x.

    Thanks in advance.

    ServandoC

    Not that this is the best way, but it's an example, you can try:

    import java.util.Random;
    import javafx.animation.*;
    import javafx.application.Application;
    import javafx.event.*;
    import javafx.scene.*;
    import javafx.scene.image.*;
    import javafx.scene.input.KeyEvent;
    import javafx.scene.paint.Color;
    import javafx.scene.transform.Rotate;
    import javafx.stage.Screen;
    import javafx.stage.Stage;
    import javafx.util.Duration;
    
    // animates a 1000 objects (klingons) moving around the scene at random directions and velocity.
    public class ObjectsInMotion extends Application {
      private static Random random = new Random(42);
      private static final int    N_OBJECTS   = 1000;
      private static final int    OBJECT_SIZE = 20;
      private static final Image  KLINGON = new Image("http://icons.mysitemyway.com/wp-content/gallery/green-jelly-icons-transport-travel/038998-green-jelly-icon-transport-travel-star-trek-sc43.png", OBJECT_SIZE, OBJECT_SIZE, true, true);
      public static void main(String[] args) { launch(args); }
      @Override public void start(final Stage stage) throws Exception {
        // initialize the stage to fill the screen with klingons.
        stage.setTitle("Starboard bow");
        stage.setFullScreen(true);
        final double screenWidth    = Screen.getPrimary().getBounds().getWidth();
        final double screenHeight   = Screen.getPrimary().getBounds().getHeight();
        final Group objects = new Group(constructObjects(N_OBJECTS, OBJECT_SIZE, (int) screenWidth, (int) screenHeight));
        stage.setScene(new Scene(objects, screenWidth, screenHeight, Color.MIDNIGHTBLUE.darker().darker().darker()));
        stage.show();
    
        // press any key to exit the program.
        stage.getScene().setOnKeyTyped(new EventHandler() {
          @Override public void handle(KeyEvent event) {
            stage.close();
          }
        });
    
        // move the klingons around according to their motion vectors.
        final Timeline timeline = new Timeline(
          new KeyFrame(
            new Duration(1000/30), // update the klingon's motion 30 times a second.
            new EventHandler() {
              @Override public void handle(ActionEvent event) {
                for (Node n: objects.getChildren()) {
                  // apply the motion vector for this object to determine the object's new location.
                  MotionVector vector = (MotionVector) n.getUserData();
                  double tx = n.getTranslateX() + vector.velocity * Math.cos(Math.toRadians(vector.angle));
                  double ty = n.getTranslateY() + vector.velocity * Math.sin(Math.toRadians(vector.angle));
    
                  // wrap the objects around when they fall off the starfield.
                  if (tx + n.getLayoutX() > screenWidth)  tx -= screenWidth;
                  if (tx + n.getLayoutX() < 0)            tx += screenWidth;
                  if (ty + n.getLayoutY() > screenHeight) ty -= screenHeight;
                  if (ty + n.getLayoutY() < 0)            ty += screenHeight;
    
                  // update the object co-ordinates.
                  n.setTranslateX(tx);
                  n.setTranslateY(ty);
                }
              }
            }
          )
        );
        timeline.setRate(5);
        timeline.getCurrentRate();
        timeline.setCycleCount(Animation.INDEFINITE);
        timeline.play();
      }
    
      // construct an array of n objects of rectangular size spaced randomly within a field of width and height.
      private Node[] constructObjects(final int n, final int size, final int width, final int height) {
        Node[] nodes = new Node[n];
        for (int i = 0; i < n; i++) {
          ImageView node = new ImageView(KLINGON);
          node.setLayoutX(random.nextInt(width  - size / 2));
          node.setLayoutY(random.nextInt(height - size / 2));
          MotionVector vector = new MotionVector();
          node.setUserData(vector);
          // rotate the klingon to align with the motion vector accounting for the klingon image initially pointing south-west.
          node.getTransforms().add(new Rotate(vector.angle + 225, node.getFitWidth() / 2, node.getFitHeight() / 2));
          nodes[i] = node;
        }
    
        return nodes;
      }
    
      // polar co-ordinates of a motion vector.
      class MotionVector {
        final double velocity = random.nextDouble();
        final double angle    = random.nextDouble() * 360;
      }
    }
    
  • Best way to retrieve the object named?  best way to get a named object?

    Inside of my loop, where I get my XML objects I added a code to draw and add the mask:

    var myMask:MovieClip = new MovieClip();

    / / width height x color settings play etc etc.

    myMask.name = '-NAME' + i; set the NAME

    myContainer.addChild (myMask);

    myContainer.mask = myMask;

    the mask looks good on the scene.

    now since I the name I want to use for another purpose such as move

    now I want to call real myMask

    I get my number 'num' of the other function, which works very well

    function applyMask(num:int):void {}

    need to call myMask("NAME-"+num)

    }

    I tried myContainer.getChildByName

    have you tried: var hide: myContainer = getChildByName ("NAME-" + String (num)) as myContainer;

    I traced to the options I can think of me, but all the results found no property.

    hmm I know that I do not use the right method of appeal? So what is the best way to call my named object?

    I think that the use...

    var theMask:MovieClip = myContainer.getChildByName ("NAME-" + String (num));

    would work, where you can use theMask to target.  Another approach to this would be to store each mask in a table so that you can just use the table to target the...

    var maskArray:Array = new Array();

    var myMask:MovieClip = new MovieClip();

    maskArray [i] = myMask;

    myContainer.addChild (myMask);

    myContainer.mask = myMask;

    Note: When first name you the object you should convert I have a string as well... myMask.name = "- NAME" + String (i); ".  at least I have is already a string

  • What is the best way to get several updates fail to install

    I have 32 updates that have failed to install.  How is the best way to go back and get to install them?

    You receive errors related to updates?

    1. Open Windows Update by clicking the Start button, all programs and then click Windows Update.
    2. In the left pane, click view update history.
      http://Windows.Microsoft.com/en-us/Windows-Vista/see-which-Windows-updates-are-installed
    3. Find an update for Windows that has failed to install, and then double-click the update to view more information.
      Updates that have failed to install will display failed under status, next to the name of update.
    4. In the Windows Update dialog box, next to the details of the error, review the error code for the update has failed.
    5. Follow the links in the Windows Update dialog box under more information or help and Support to resolve the problem, then try to reinstall updates by using Windows Update in Control Panel or by mail with the error code and maybe someone may be able to help others.

    Windows update General troubleshooting

    Suggestions:

    How to reset the Windows Update settings?
    http://support.Microsoft.com/kb/971058

    Diagnose and automatically fix common problems with Windows Update
    http://support.Microsoft.com/mats/windows_update/

    Cannot install updates in Windows Vista, Windows 7, Windows Server 2008 and Windows Server 2008 R2
    http://support.Microsoft.com/kb/2509997

    Or try to install the updates in a clean boot state, and run Windows Update: http://support.microsoft.com/kb/929135

  • What is the best way to merge several projects with a project?

    Hi guys,.

    I want to merge 4 my project in a project.

    What is the best way to do it?

    Thank you

    Max

    Import some sequences of other projects via the media browser.

  • Best way to connect several hard disks

    HI - since getting my new Mac Pro, I worked with two hard drives of 12 to promised Pegasus 2 Raid-5.  They have been great.  But my video player started to get crazy and so I bought two backup drives WD - 8 to, one to save the key on each PP2 files.  Unfortunately, it was too late to save the video player, as one of the bays failed.  Because it's Raid-5 and with the amazing and patient Vincent promise eSupport, I replaced the failed drive Bay and am now waiting while he rebuilds (if all goes well, without any loss of data).  Then it will get saved.

    Until it became clear that a bad drive Bay was probably underlying computer freezing, loss of images in video playback, etc., I was wondering if there was some sort of best practices for fixing of external drives.  With Thunderbolt, you can chain; But what to what?  Is there a limit any?  Can I plug two disks promise, then the one closest to you on the computer?  Must the WDs be connected in the same way, each to each, and the other to the computer?  Should there be just a Garland of four disks?   ????   In the old days, you had to look at how much energy was used during the USB and Firewire connection, but the true even for love at first sight?

    Surely you'd be recognizing any indication on how best to connect several hard disks.

    Thank you!

    There are 3 unique bus in the Mac Pro black cylinder. Better reactivity is with your readers spread between three buses, keeping in mind that video display takes nearly half a ThunderBolt Bus itself.

    You can use USB-3 for your backup drives - just keep in mind, it is only a sufficient bandwidth behind the USB to operate a chain of reading and writing of full tilt. If you simultaneously use devices more than that, you can start to see some cuts of your maximum transfer rate.

  • Best way to 'bend' an object

    I have a custom rectangular object, I want to bend along a path of arcing.  My goal is to take 3 of my custom rectangular objects and bend each other along an arc that roughly 1/3 of a circle (~ 120 degrees) and position them so that they form a phase 3, the pie chart of cycle.

    Any suggestions?

    Thank you!

    SD,

    ... end of the arrow is distorted in the process.  So, I'm looking for a way around this problem...

    You can get past by and get the straigt arrowheads by:

    (1) create three concentric circles: two to form trees of the arrow, the third at least the size to hold the extreme parts of the arrowheads.

    (2) create the shape of the triangular end, like a triangle, to duplicate and train the arrowheads;

    ((3) place 2) while its base extends equal amounts before the circles of the tree at the same horizontal level as the Center;

    ((4) select 3) and the circle outside and copies rotation 120 degrees twice in order to have the three arrows pointing one way;

    (5) remove the outer circle;

    (6) group, select all and reflect a copy horizontally in order to also have the arrows opposite;

    (7) turn the copy to get the gap want between the arrow points;

    (8) select all and Pathfinder > divide;

    (9) remove the parts between the arrow points;

    (10) merge forms forming each double arrows / color / be it;

    (11) rotate the batch to the final direction.

    (9)-10) you can ungroup (enough) or use the direct Selection tool.

  • Best way to manage several libraries?

    Before you begin to offer suggestions of third party such as PowerPhotos, please bear with me for a moment.

    Somewhere, I have about 55 000 photos/videos in my library to iCloud. While I would ideally like to keep everything in a library for the sake of not having to deal with faces/places/sites/keywords etc in a library, I find it a little less than ideal since it takes much of the storage space on my iPad/iPhone a lot that slows in things turn especially when you access the photos on iOS app.

    Unless someone knows a way to prevent my iOS Photos storage support (even on the options of 128 GB is too), or a way to create a separate library iCloud while having faces, etc. are available for iCloud library and library Non-iCloud, I'm out of ideas, in addition to having 2 libraries of Photos , which one is for iCloud, one for my older media and must manage the faces and all other metadata for the two.

    I can imagine now... having to build a routine just to move a library b periodically library stuff. What a nightmare. In any case, someone noticed this? Thanks in advance!

    Somewhere, I have about 55 000 photos/videos in my library to iCloud.

    How do you use iCloud photo library?  Are you using more than one Mac and iCloud photo library to keep your Mac in sync?  Or you want to iCloud library to synchronize with your iOS devices?

    I need iCloud library mainly to have the same photo on every Mac library, but 40000 photos is proved be too much for my iPad. This is simply no funny, if all the photos on the iPad are fuzzy because they are optimized and need to download. Because I didn't reduce the iCloud photo library and must synchronize mac manually, I now keep a large library in iCloud, but disabled iCloud photo library on the iPad. Synchronize the albums selected from my great library to the iPad via iTunes, I ignore the blurry photos on the iPhone (it still uses iCloud photo library), but four Macs still have a single library, synchronized with iCloud Photos.

    The albums selected to the iPad with iTunes Photo sync sync's always better than iCloud photo library, at least for my library.  I do most of my organization with smart Albums and iCloud library does not synchronize the smart albums to the iPhone and iPad. So, all my smart albums are missing on the iPhone, also the albums of faces.  iTunes however synchronizes all smart albums and albums of faces, and all photos are stored in full resolution. I can browse the photos immediately, even in offline mode.

    If you do need iCloud photo library only to synchronize your favorite photos on your iPad or iPhone, but not to another Mac, I would indeed create a second library just to iCloud. There is a problem - your photo library system can synchronize with iCloud. If your iCloud photo library must contain all the photos that you want to access from other applications.

    A drastic method of having only a part of your library to download on iCloud library would be to have a joint photo referenced and managed library.  Only photos stored in your library of Photos download to iCloud photo library, not the pictures referenced externally. Referenced photos require more work and are risky, but they are not well supported in Photos.

    It is best to move photos between two libraries, one for iCloud and a local library.

  • Best way to disable several plots on XY-graph?

    Hi all

    I need to hear here. I have an XY Chart with several plots.

    Here's how the VI would work.

    1. start of program, no parcels or scale is shown.

    2. several buttons are available to select who are plotting to TURN (corresponding scale is also ON / OFF).

    What I have now is to transmit the data to the first graph with all plots and invisible scale.

    I did it using the graphics property ActPlot, ActYscl and PlotVisble nodes, but I had to for this

    through each ActPlot/ActYscl. There are therefore several knots of property in all directions as

    in the figure below.

    My questions are the following:

    1. a lot of knots of property would require more memory or CPU resources?

    I do a lot of similar manipulation on the graphics property (cursors, scale, color, etc.). I'm worried

    the end result is a program that really doesn't do much, but a lot of memory/CPU hog resources.

    2. is there a better way to do it? Perhaps a property node that turns off all

    visible at once?

    I read in another post that suggests to use a loop to turn off one by one. I can

    certainly do it, but it would be a better way?

    Any suggestion or the part of the thought is appreciated!

    Thank you

    CC

    Certainly you must change the data that you pass to the chart, especially when working with lots of data. Simple reason: memory usage.

    Visibility of switching does not reduce the amount of data that you pass to the curve (that copy for display) as a result, you'll probably lose a lot of memory.

    But if you want to display all data at once and only give the possibility to hide the small amounts of data, the approach with the 'visible' property node is OK, but...

    hope this helps,

    Norbert

    EDIT: If you want to change multiple properties at the same time, you must include a control panel (Control Panel-property) defer updates.

  • What is the best way to create several hundred copies of a file?

    Hello

    I am trying to create several hundred copies of a file.  The files will be used as other views on a product pages of the site.  Each product has a unique image of the hand and several other unique images (view left view right, etc.).  However, I have about 3 images I want to use as the alternate images for each product.  Here's the 4oo px wide JPEG (registered for the web).  So I would like to have 'altimage1.jpg', 'altimage2.jpg' and 'altimage3.jpg' to have actually several hundred copies.  I can then rename the lot to the bridge or LR.  The final image must have the same name of the product code, with a suffix picture ID.  So after I renamed "altimage1.jpg", it will be "IPID-001-t' the next copy of the same file will be 'IPID-002-t', and the next copy will be ' IPID - 003 - t ' etc, where (IPID-00) is the product code, and (-t) is the identifier which places the work in the right place with the download FTP."

    I wish there was a way to assign the three Images of spares for all products with a few keystrokes, but it is not as simple as that.

    Thank you

    Looks like stocks, layers and layers of comps is the road I'll take.

  • best way to send server objects and recreate step?

    I want to send an object and its properties (that have been manipulated) on my server. I then intend to recreate this object and automatically create a screenshot of the object (I don't want to make on the client side). I intend to use POST and some php for each property that has changed and then load data into an as3 script on the server side. I would like to than this side script server to automatically take the object and create a server image side - is anyway to do all this while asking does not have any input (of what I have learned, flash requires a prompt before saving a file)? I haven't used flex, can be used here?

    Is there a better way to do it? I am open to any suggestions!

    I misunderstood.  Yes, you will need to run your as3 swf that will load data and save an image on the server.

  • Best way to encode several digital inputs of choice / binary indicators

    Hello.

    I need some suggestions.

    We have several libraries API (to control our material) written in C and distributed as a dll.  For many of them, we have a library of LabVIEW VIs wrapping (using the call library function node).

    We have several functions in which the entry (in the original C library) is an unsigned integer, which is supposed to be several flags ORed together (each value one bit).

    I've seen more than one title, that this interface has been transferred to the wrapper live

    1 digital input.  User must understand and use it exactly like the C programmer

    2 try to make more enjoyable - an entry that is a table, which appears on the front panel, as a sort of list box multiple choice of entry (internally in the block diagram that is used to create the correct entry to the C function)

    I think there are others, but this is what I remember right now.  When I saw option number 2 (looking at the front) I thought it was much more enjoyable. clearer and more intuitive (the user can select choice named, no, not strange %valeurs hexa%, etc.).  However when I put on a block and tried to wire diagram, I had to provide an array of numbers; I had no idea what the values were supposed to be.  Option 2 seems so much better for a user interface, but for an API, I think it's actually worse.

    What do you see, if you were a programmer building my functions into your application?

    Thank you.

    Batya

    Since each value is a bit simple, I would say that the wrapper have Boolean values in the connector pane and convert it internally to the correct bit field. Another option is to use a cluster of Boolean, but which may be less friendly to the user of the API. I suggest you do this only if you have several options.

  • Best way to synchronize several FPGAs

    I have several PXI-7833R FPGA and I need all the AIs to be sampled at the same time (through all FPGA). As I taste all the individual channels to HAVE, I have data (write to the DMA) buffer, scan it and are looking for a trigger defined by the user in a different loop. Once I discovered this in a single channel, I save all FPGA data. Regarding the timing of sampling, I had started, to an FPGA, to send a signal on the PXI trigger line to tell others to try, but I guess that it does not sync. If I founded the ensemble of distinct FPGAS screw off the clock, PXI, how synchronize loops to the sample to the same clock time?

    Thank you

    Hello

    There is a very good example comes with FPGA LV named 'Master-slave of RIO - R Series.lvproj'. Just use the Finder for example to open it.

    It shows how to use the lines of PXI trigger for synchronization of the different measures on multiple FPGAs.

    Hope this helps,

    Christian

  • What is the best way to coordinate several modules loading.

    I have a number of resource modules I want to load before loading my main user interface module.

    I do now, but to make sure that all loaded OK, I need to establish a chain of Event.COMPLETE reminders for each resource module loading.

    In other languages (threads), I set a flag and run a wait on my main loop before loading the user interface module.

    Is it a good compact way wait n modules to load in Flex?

    I don't think that you need a string if the load order is not serious.  Just keep a

    Dictionary of them, then remove them from the dictionary because they charge.  Then

    Run a quick test of the dictionary has all the elements to the left.

  • Best way to blur an object in a video?

    I have a video clip with a product in what we cannot show.  What is the the more easy/quick way to blend the product using AE logo?  The logo moves in the shot, I have to be able to move the blur with her.

    Thank you.

    Is this correct?

    For the most part, but you will need to add a step:

    7. turn on the switch setting on your solid layer, so it blurs the hidden itme and caterpillars underneath, not the solid itself.

    For info on follow-up, see this section in the help files.

    Mylenium

Maybe you are looking for

  • How can I override blocking of internet explore my download to XP?

    I just restored a fifteen year old computer. It runs on Windows XP. When I go on internet explore and try to download Firefox, I get messages from security. I tried to substitute the blocking by going to security tools, but nothing works.

  • Cannot open Firefox even after deleting all files and profiles of school boards.

    My computer auto-installé the new Firefox version 40.0.2 (and later 40.0.3) and the browser does not open. It worked and I have not received any error message. I tried every fix I can find here, and even manually, I deleted all of my profiles, folder

  • Cannot find where the cookies in control 38.0.5

    I am running Firefox 38.0.5 and received a warning from Wordpress I need ed to enable cookies. Unfortunately, all configuration options have changed and I can not find anywhere the cookies and the setting is without a doubt is no longer under the pro

  • Versions of access desktop via Boot Camp?

    Hello My Training Institute offers students free access to MS Office, but only to the PC (Office 365 and downloadable Office 2013) version. I'm a Mac user, so this seriously limited my access to the office, which is a large part of the training. I gu

  • Impossible to fully install LabVIEW 2010 on WinXP SP3

    Hello I tried many times today to install all OR Developer Suite 2010 helps install disks. I catalogged all items that not have installed. LV 2010 works but I don't know if everything works. Here are the elements and the order in which I wasn't able