Best way to MouseDrag multiple objects around a scene.

So I am having a little trouble trying to drag 3 Box's in a scene.
Originally I had it set up where each was relocated to an x,y translated Z and set to a HWD. Then I figured I would, instead of the mouse click on the box itself, be in the root. From there I would look through all of the root.getChildren() then made that see if it contained the x,y position.
Then from knowing which of my root Children I clicked I did root.getChildren.get(current).setOnDragged to figure out which one was dragged.
The code itself worked except for finding which box I was on.
The issue I find is that I onyl have getX, getSceneX, and getScreenX. X, and SceneX produce the same value, and ScreenX is useless. I tried then to do event.getX() - root.getLayoutX() to make the contains function to work, but it wasn't working and would require me to change up more things. getLayoutX() was = 0 since I didn't set the root location, only the locations of the box's.
From there I kept wondering if there was a better way. Then I thought maybe to loop through every 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 it keeps only registering the last one in the list, so it just loops and that's it.
So what I want to know is, what would be the best way to figure out what object I'm in?
Originally I use the contains(Swing) but Swing is different, and now especially since we can register mouseEvents to each node, shouldn't we know exactly which one we are on, just by looping through each of them? I figure that's easier than having to check every single mouse position contained within, especially if I have 10000 things to check?
Edited by: KonradZuse on Mar 18, 2013 8:05 PM

I slightly modified your code for 3D.
- added a pointlight
- added a phong material
- the rectangle changed to a box
- the circle changed to a sphere
- add scene.setCamera(new PerspectiveCamera(false));
Without the last line it is not working.
I tested it with javafx8.0 build 80 Netbean7.3
import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Polygon;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.PerspectiveCamera;
import javafx.scene.PointLight;
import javafx.scene.paint.PhongMaterial;
import javafx.scene.shape.Box;
import javafx.scene.shape.DrawMode;
import javafx.scene.shape.Sphere;
public class DraggingShapes3D extends Application {
    @Override
    public void start(Stage primaryStage) {
        PointLight pointLight = new PointLight(Color.ANTIQUEWHITE);    
        pointLight.setTranslateX(800);    
        pointLight.setTranslateY(-100);  
        pointLight.setTranslateZ(-1000);
        PhongMaterial material = new PhongMaterial();
        material.setDiffuseColor(Color.LIGHTGRAY);
        material.setSpecularColor(Color.rgb(30, 30, 30));
        Box box = new Box(200, 200, 200);
        box.setMaterial(material);
        box.setTranslateX(100);
        box.setTranslateY(100);
        box.setDrawMode(DrawMode.FILL);
        box.addEventHandler(MouseEvent.ANY, new DragShapeHandler());
        Group root = new Group();
        Sphere sphere = new Sphere(100);
        sphere.setTranslateX(400);
        sphere.setTranslateY(100);
        sphere.setMaterial(material);
        sphere.addEventHandler(MouseEvent.ANY, new DragShapeHandler());
        root.getChildren().addAll(box, sphere);
         root.getChildren().addAll(pointLight);
        Scene scene = new Scene(root, 800, 800, true);
        scene.setCamera(new PerspectiveCamera(false));
        primaryStage.setScene(scene);
        primaryStage.show();
    public static void main(String[] args) {
        launch(args);
    class DragShapeHandler implements EventHandler<MouseEvent> {
        private double sceneAnchorX;
        private double sceneAnchorY;
        @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();
                Node node = (Node) event.getSource();
                node.setTranslateX(node.getTranslateX() + x - sceneAnchorX);
                node.setTranslateY(node.getTranslateY() + y - sceneAnchorY);
                sceneAnchorX = x;
                sceneAnchorY = y;
}

Similar Messages

  • What's the best way to send multiple objects with a message?

    I'm considering using an ObjectMessage and storing a Map as the object. Each
              of the objects I need to send will be bound in this Map. Is this the correct
              approach?
              Also, if this is the correct approach, where should I store the constants
              for the Map keys? If I put them in the MDB consumer, it ties the client to
              the consumer and vicea versa. I guess I could declare them in my main
              interface.
              Thanks,
              Bob
              

    OK.
              But for what it's forth, if you were to need to put a Map in an
              ObjectMessage, you might find that MapMessage gives you similiar (if not
              better) functionality, the resulting message will be smaller, and your
              system may perform better. The various implementations of java.util.Map are
              pretty hefty objects to serialize, whereas a MapMessage (at least, the
              MapMessage from BEA JMS) has been optimized to be pretty compact and fast.
              On the other hand, the only kinds of objects you can put in a MapMessage are
              Java primitive types (int, String, and so forth), whereas in a java.util.Map
              you can put any kind of object.
              greg
              "Bob Lee" <[email protected]> wrote in message
              news:[email protected]...
              > Nevermind. I'm using a Command pattern.
              >
              > Bob
              >
              > "Bob Lee" <[email protected]> wrote in message
              > news:[email protected]...
              > > I'm considering using an ObjectMessage and storing a Map as the object.
              > Each
              > > of the objects I need to send will be bound in this Map. Is this the
              > correct
              > > approach?
              > >
              > > Also, if this is the correct approach, where should I store the
              constants
              > > for the Map keys? If I put them in the MDB consumer, it ties the client
              to
              > > the consumer and vicea versa. I guess I could declare them in my main
              > > interface.
              > >
              > > Thanks,
              > > Bob
              > >
              > >
              >
              >
              

  • What is the best way to sync multiple collections of contacts among multiple users?

    (I originally submitted this question under the "Mac OS X Technologies" section, but got no response. I'm submitting a duplicate here because this is where all the smart folks are! My apologies that my question is only partially related to OS X Server . . . )
    What is the best way to sync multiple collections of contacts among multiple users on iOS and OS X?
    For example, suppose I have three collections of contacts: Bob's, Sally's, and Common. I want Bob to be able to access and sync Bob's contacts and Common contacts, and Sally to access and sync Sally's contacts and Common contacts. Bob and Sally never need to access or sync each other's contacts. Bob and Sally would both sync and share contacts in Common.
    How would I best implement this? It's my understanding I have three options for managing contacts across iOS and OS X: 1. iCloud accounts, 2. Install OS X server, or 3. Install and manage Darwin CardDAV directly. Which method would best support what I wish to do?
    I am a seasoned Unix geek well versed in the terminal, so I am prepared to get my hands dirty as much as necessary to achieve what I want. Also, it is sufficient if syncing takes place over WiFi on the local network, in fact, that is desirable versus syncing over the cloud.

    Thanks for your reply Nick101. I see my example was oversimplified. When I say "multiple groups of contacts over multiple users" I'm really referring to N groups of contacts over N users.
    So I need to add Fred, who can access and sync Bob's contacts, Sally's contacts, and Common contacts, as well as Fred's contacts. Can I do it with OS X server?
    You mention you keep your and your partner's contacts administered locally. What keeps you from administering them through OS X server as well?
    I am guessing this can all somehow be accomplished with multiple contact accounts, but I can't find any information on the web explicitly describing this.

  • Best way to do a Object which holds a collection of another object type.

    I'm writing a caching object to store another object. The cache is only valid for a session, so I want a store the data in a nested table.
    I have try to simplify my example down to its core.
    How do I make this work and what is the best to index the index the items stored for fastest retrieval.
    CREATE OR REPLACE TYPE ty_item AS OBJECT (
    id_object VARCHAR2 (18),
    ORDER MEMBER FUNCTION compare (other ty_item)
    RETURN INTEGER
    CREATE OR REPLACE TYPE BODY ty_item
    AS
    ORDER MEMBER FUNCTION compare (other ty_item)
    RETURN INTEGER
    IS
    BEGIN
    IF SELF.id_object < other.id_object
    THEN
    RETURN -1;
    ELSIF SELF.id_object > other.id_object
    THEN
    RETURN 1;
    ELSE
    RETURN 0;
    END IF;
    END;
    END;
    CREATE OR REPLACE TYPE ty_item_store AS TABLE OF ty_item;
    CREATE OR REPLACE TYPE ty_item_holder AS OBJECT (
    CACHE ty_item_store,
    MEMBER FUNCTION get (p_id_object IN VARCHAR2)
    RETURN REF ty_item,
    MEMBER FUNCTION find (p_id_object IN VARCHAR2)
    RETURN REF ty_item,
    MEMBER FUNCTION ADD (p_id_object IN VARCHAR2)
    RETURN REF ty_item
    CREATE OR REPLACE TYPE BODY ty_item_holder
    AS
    MEMBER FUNCTION get (p_id_object IN VARCHAR2)
    RETURN REF ty_item
    IS
    rtn REF ty_item;
    BEGIN
    rtn := find (p_id_object);
    IF rtn IS NULL
    THEN
    rtn := ADD (p_id_object);
    END IF;
    RETURN rtn;
    END;
    MEMBER FUNCTION find (p_id_object IN VARCHAR2)
    RETURN REF ty_item
    IS
    rtn ty_item;
    BEGIN
    SELECT VALUE (ch)
    INTO rtn
    FROM CACHE ch
    WHERE ch.id_object = p_id_object;
    RETURN rtn;
    END;
    MEMBER FUNCTION ADD (p_id_object IN VARCHAR2)
    RETURN REF ty_item
    IS
    item ty_item;
    BEGIN
    item := ty_item (p_id_object);
    INSERT INTO CACHE
    VALUES (item);
    END;
    END;
    /

    Best way to do a Object which holds a collection of another object type. The best place for data in a database is.. no real surprise.. in tables. If that data is temporary of nature, global temporary tables cater for that.
    Storing/caching data using PL/SQL requires very expensive private process memory (PGA) from the server. This does not scale.
    I'm writing a caching object to store another object. Irrespective of how l33t your haxor skillz are, you will not be able to code as a sophisticated, performant and scalable PL/SQL data cache, as what already exists (as the database buffer cache) in Oracle.
    The cache is only valid for a session, so I want a store the data in a nested table.Not sure how you take one (session local data) to mean the other (oh, let's use a nested table).
    Session local data can be done using PL/SQL static variables. Can be done using name-value pairs residing in a context (Oracle namespace). Can be done using a global temporary table.
    The choice is dependent on the requirements that need to be addressed. However, the term +"caching+" has very specific connotations that say that a global temporary table is likely the best suited candidate.

  • What is the best way to manage multiple ipods using the same itunes?

    Hi Everyone
    i am trying to manage three different ipods through the one Itunes, all with very different tastes, not sure if I am doing it the best or easiest way so does anybody have a simple solution on what you're supposed to do, to keep it all simple!
    Cheers
    Liv

    If you have created a new Windows user account you need to log out and then log back in with your original user name. By default each Windows profile will have an independent iTunes library.
    If instead you managed to create a new library within the same profile. click the icon to start iTunes and immediately press and hold down the shift key, keep holding until asked to create or choose a library. Click Choose and navigte back to your original which should be at <User's Music>\iTunes.
    Your question as posed was:
    What is the best way to manage multiple iPods using the same iTunes {library}?
    in which case Selected Playlists is probably the best approach. Simply create a playlist for each device, Alice's iPod, Bob's iPhone etc. and sync the device with the appropriate list.
    tt2

  • Best Way to Aggregate Multiple Announcement Apps and Possibly External RSS Feed

    Hello,
    I have two separate announcement apps (one in sub-site A, and one is sub-site B). I am trying to create a webpart that will display content from both apps together.
    I have tried to setup a CSWP and have been able to set the query to pull in the data (Although it shows expired announcements, which I would need to eliminate). Now, I am trying to customize the display of the CSWP, including the property mapping values
    to display the announcement title (currently working with the URL as a link) and body (truncated like the announcement summary view if possible).
    How can I get the body from the announcement to display? The 'body' field isn't listed as an option in the drop down list of mapping values. Do I need to toggle an option on the separate announcement apps, create a column, map a field, or some combination?
    Also, I'd like to know if it is possible to add in an external RSS feed. Or, if there is a completely different way to approach and accomplish this, please let me know.
    Thank you

    Hi,
    To display the “Body” field of Announcements list properly in Content Search Web Part, you can take a look at this blog about how to customize the display template for a good
    start:
    http://social.technet.microsoft.com/Forums/en-US/bf0eb4de-445f-435a-8c88-1826bfb3aae5/best-way-to-aggregate-multiple-announcement-apps-and-possibly-external-rss-feed?forum=sharepointdevelopment
    If there are more complex needs in customization, the two links below would be helpful:
    http://blogs.technet.com/b/sharepoint_quick_reads/archive/2013/09/03/3588171.aspx
    http://blogs.technet.com/b/tothesharepoint/archive/2013/05/28/stage-11-upload-and-apply-display-templates-to-the-content-search-web-part.aspx
    Also, if you have several questions, it is recommended to post them in each single thread to make others in this forum easier to focus on one issue in one thread.
    Best regards
    Patrick Liang
    TechNet Community Support

  • Best way to achieve multiple paths with quizzes using Captivate 6?

    I’m looking for the best way to achieve multiple paths and quizzes using Captivate 6.
    Here is the scenario: The learner watches general slides 1 – 3 and then chooses between Path A, Path B, or both paths combined.  If they choose Path A then they watch the A portion only and take the A Quiz only. Same happens for Path B and for the two paths combined. The learner would only have to go one path to complete the course.
    What I’m finding is Captivate only has one Quiz results page (even if you create two separate quizzes, it merges them). I was trying to avoid having three separate projects for the same module to keep it simple. I see if I have three separate projects I could use the Multi-SCO Packager to merge them for use on my Moodle LMS. But wait, I don't have the elearning suite, so I don't have access to the Multi-SCO Packager...
    My question is: What is the best approach way to accomplish this goal? Any recommendations?
    Message was edited by: austingina

    Captivate 6 has Branch Aware quizzing.  Turn on that option in Quiz Settings and then your Quiz Results page should only show results for the branch your user visits.

  • Best Ways to Handle Multiple Users

    First post....heres my question. Can anyone help me determine the best way to handle multiple users in itunes? Some Background:
    My family shares one computer. We have on folder on the hard drive where we keep all our music files. I got an ipod and itunes and added some of the music to itunes and have pretty much used itunes for my music.
    Now my girlfriend got an ipod and I am hoping to somehow keep her music away from mine so to speak. So that I can keep synching my ipod without adding a bunch of music I dont want.
    Is there a way to handle this? So thankfull for any help!

    There is an apple article on this here:
    http://docs.info.apple.com/article.html?artnum=300432
    It sounds as though method 1 would be best for you.
    Also see how to keep the music files in one place to avoid duplication:
    http://docs.info.apple.com/article.html?artnum=93195

  • Is there a Tool or function (in Illustrator or InDesign) that selects any shape and "punches" a "hole" of that shape all the way down through multiple objects to the paper or artboard?

    Is there a Tool or function (in Illustrator or InDesign) that selects any shape and “punches” a “hole” of that shape all the way down through multiple objects to the paper or artboard?

    In Illustrator, group the objects that you want to punch through, and use the transparency pallet.

  • Best way to make a object details page

    I have a dataTable, built with a sessionBean List. We have to make a link "show detail" in each row, and redirect to a new jsp showing selected row object details.
    Whats the best way to retrive the object selected?
    a commandLink with param (haschcode value) and search in list isn`t possible because is a sessionBean..
    I have some ideas but not with JSF....
    thanks

    1) Bind h:dataTable to an UIData property in main backing bean.
    2) Add a h:commandButton or h:commandLink to a column and bind it with an action method in main backing bean.
    3) In the main backing bean action method simply retrieve the row object byRowObject selectedRowObject = (RowObject) uiDataProperty.getRowData();and navigate to some display details page.
    4) In the display details page just access the data by #{mainManagedBean.selectedRowObject.someProperty} and so on.
    Detailed examples can be found here: [http://balusc.blogspot.com/2006/06/using-datatables.html].

  • Best way to validate multiple entity objects with each other

    I have the following scenario.
    There is one entity object with the following fields.
    Name
    Start Date
    End Date
    My requirement is to validate the dates in the entity do not overlap.
    What is the best way to achieve the same.
    This validation should be fired when we commit, since the user should be allowed to change the dates freely between entities.(Validation should not kick off when the current row changes)
    Thanks

    For this to achieve there is a concept called Effective Dated Entity Objects in Oracle ADF.
    Official ADF Documentation: http://docs.oracle.com/cd/E37975_01/web.111240/e16182/bcentities.htm#ADFFD20110
    Some blogs to help you
    http://one-size-doesnt-fit-all.blogspot.co.uk/2008/11/jdev11g-new-feature-effective-dated.html
    http://adfblogs.blogspot.co.uk/2011/09/understanding-effective-dated-entities.html
    Regards,
    Peddi.

  • What is the best way to send multiple pdf files to my ipad

    what is the best way or app to send multiple pdf files to my ipad, so that I can then combine them into one folder

    I have the app Readdle Docs. It allows you to move PDF files to your device and to move them around on your device. Might check it out. ( I think there's an iPad version of the app, but I have the iPhone version and it works, just not as pretty)
    THere's also Goodreader, but I don't have experience with it to know if it has folder abilities.

  • What is the best way to have multiple devices on the same account so we can still share the same library.  Right now I have 7 and I believe it's causing them to malfunction.

    I have multiple devices on the same itunes library and they all starting to have the same issues.  Not recognizing numbers previously stored, not sending/receiving tests.  Do I need to get everyone separate itunes accounts? 

    What is the best way to set up itunes on our home network? 
    One iTunes library per person.  One iTunes account per person.
    If people wish to share songs, they can make copies.
    When the inevitable day comes when the kids get older, you will not have to come back here and post asking how all that stuff can get separated!

  • Best way to merge multiple iPhoto libraries from several external hard drives into one, while deleting duplicates?

    Problem: My wife and I both have MacBook Pros (MBPs).  We take a lot of pictures and import them into iPhoto.  When the storage capacity of our MBPs gets full, I have been moving our iPhoto libraries into external hard drives, which are now multiple (3 or 4).  The problem I now realize we have been making, is that once the iPhoto libraries were copied onto the external hard drives, we were only deleting about half of the photos in each iPhoto library remaining in our MBPs (because we wanted to keep some of the important ones in our hard drives).  Once the storage capacities of our MBPs got full again, I would repeat the whole process again and again.  In essence I now have several large iPhoto libraries (each about 80 GB), each with multiple duplicate photos, divided among several external hard drives.  And I am running out of space on my hard drive again.  So what is the best way to:
    a)  merge all of these iPhoto libraries into just one, while simultaneously being able to delete all the duplicates?  (or would you not recommend this?)
    b)  prevent this from happening again?
    Thanks.  BTW I am using OS X Mountain Lion 10.8.5 and iPhoto 8.1.2 (2009)

    If you have Aperture 3.3 or later and iPhoto 9.3 or later you can merge libraries with Aperture.
    Otherwise the only way to merge Libraries is with the paid ($30) version of iPhoto Library Manager
    The Library Manager app can be set avoid duplicates.

  • Best way to organise multiple large clips and hundreds of subclips

    Situation
    I have the task of producing a suite of short 2 minute videos comprising highlights of several hours of footage in multiple large files.
    I want to extract and manage the highlights in a non-destructive way and organise them according to subject matter.
    I would then use these in several projects to create the highlights videos required.
    I am using Adobe CC, so it's CS6.
    My approach so far is to:
    1. Import all the footage into a single project as individual large clips
    2. Scrub through each clip, set in/outs and extract to subclip, store in subject matter bin
    My questions:
    1.  if I go back to the original footage and edit it, it doesn't seem to flow through to the subclips. How do I make the subclips inherit the attributes of their parent? (e.g. could be sound, colour, etc)
    2. how do I access these highlights bins from another project?
    3. is this the best way to handle my situation?
    Thanks for your input.
    Ric

    I suppose applying the effects to the source clip and rendering out a new source file is one way of doing it.  Just be very careful that you don't compress the output.  And, of course, it will double the amount of hard drive space.  I'd still make all the sub-clips first and use the "paste attributes" command.  I think you can even lasso a whole bunch of clips and paste attributes to all of them at once (they have to be in the timeline, though - not the project panel).
    It shouldn't take an awful lot of hard drive space to duplicate projects.  Just duplicate the "prproj" file, not the whole projects folder (and certainly not the source material).
    Here's a screen shot of my set-up for a complicated, 5-camera shoot of a play:
    The original project (syncing all the cameras up) is 1 MB, each successive archive gets a little bigger but the current project is only 3.8 MB.  I would imagine if you are deleting bins and sequences for the mini-projects, the prproj file would actually get smaller than the original master.
    Okay.. so here's the mantra about non-tape based video... First you back up the card (including the complete folder structure) onto an archive drive.  Next you copy this folder onto an external or RAID or other "real" archive drive.  Then (and only then) do you start editing the material!
    Ideally, you need at least three, physically separate harddrives (not partitions) in an editing station (this is true Windows or Mac).  One drive for the operating system and applications only (no media or projects or anything!).  One for working projects (each project in its own folder) where everything except the source video is stored.  And finally one for the source video.  On my system my OS drive is Tardis ('cuz I'm a geek!).  I have a Projects drive for projects (duh!) a Scratch drive for working video files and an Archive for "finished" projects waiting delivery and back-back-ups of my SD cards.

Maybe you are looking for

  • How can i make my HP stream 14 have more memory?.....

    - i would like to first apologize for my ignorance on this subject. i am a computer noob, and dont really know anything about it .  I have a HP stream 14 amd quad core laptop (with the beats audio)  2mb cache. and it runs on windows 8. has processor

  • Learning Solution: Instructor / Tutor iView(s) not working in Portal

    Hi all . . . We just installed the Instructor/Tutor package in our sandbox portal.  I gave the role to myself so that I could see the Instruction and Tutoring tab. Yet, when I click on Work Overview to see the Instructor's Work Center iView, it throw

  • File opened in external editor not stored with referenced files

    If I open a referenced raw file in an external editor (CS2) and work on the image adding layers etc., the image is not stored where I have all the other referenced files. It gets stored in the Aperture Library. Is there a way around this. I want to k

  • P45 diamond mobo does not power up

    Hello,       I recently purchased a P45 diamond mobo from Newegg, and the mobo didn't work when I received it. The only thing it would do was display a red light at LED 1, which according to the book means it's on standby? I talked to Newegg and they

  • Shape of textframe indesign

    hi i develop an indesign extension with CS extension builder 2 and flashbuilder 4.6. how to retrieve the shape (rectangle, oval, polygon...) of a textframe, i don't find any properties in textframe class ? thanks Simon