2 Replies Latest reply on Apr 11, 2013 9:05 PM by KonradZuse

    Which of my approach's to this layout of books on a bookcase is better?

      Okay so I am creating a program that has any number of shelves, with items on the shelves.

      I want to be able to move all of the items on the shelf, if the shelf is clicked, and if the bookshelf is moved, I want everything to move. There can be many bookshelves as well as shelves, and books.

      So what I want to know is what is the best approach to go through this?

      I originally added all of the items to a "shelf group" with that shelf, and would move the entire group when clicked and dragging the shelf. I did the same with contents inside the bookshelf, so it works. this was done with an added EventHandler.

      My issue is that I can have 1000's of books, and tons of shelves, as well as many bookshelves. I also want to be able to move each book in and out of groups. Originally I would just remove the node, and then add it back when I found out which area I was in, but it seems like Group is funky with "space" as it's just for children. I was thinking about using a pane, but I'm not too sure how that works either....

      The other method is the original method that another coder used in the first version of this program.

      They would basically compare each book with the shelf "#" and make sure it's within that #'s space. If the shelf height is 12" then it would have to be within that 12" space. We also need to move multiple books, which would be done using that statement, and looping through every shelf.

      In my opinion I told the person that we have the tools to make it easier, so why not use them? The word "Overhead" always comes up. Now normally it seems in this day and age "overhead" is something that isn't really looked at, but that calls for TONS of BAD coding practices. I don't want to have bad practices, but I figure if FX is mostly based on these "layout containers" of the "Parent" class, why aren't we using them? I just don't want to bloat the code with having 200 panes at once and slowing the entire program down. This person comes from Visual Basic 6, as well as many "oldschool" languages, so they are still trying to understand that Java has so much power, but they are scared of the overhead of that power. I again say what's the point of the tool, if we cannot use it. If we have 1 hammer and 1 nail, we wont need to use our hands to smash it in, but if we have 2000 hammers and 1 nail... there's a little issue :p.

      Edited by: KonradZuse on Apr 10, 2013 1:15 PM

      Edited by: KonradZuse on Apr 11, 2013 11:53 AM
        • 1. Re: What's the best approach to this layout of books on a bookshelf
          You will note that you are getting no responses. This can be because of numerous reasons:

          - you are asking for the BEST approach - nobody is qualified to determine what the BEST is. Perhaps you will want to lower your standards and ask for an approach that works
          - your "question" contains a lot of useless baggage and now it is as bloated as the code you only mention but fail to present; I would keep it to the point if you want people to take the time to read it

          If you want help improving code, I'm afraid you'll have to actually come up with the code so people can have a look at it and pass out pointers. It doesn't have to be the original code, but then you'll have to make the effort to create a small compilable and runnable example that shows what you're talking about. When you do post that, use \
           tags to make it readable.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                
          • 2. Re: What's the best approach to this layout of books on a bookshelf
            I was asking for the "Best approach" of the 2 choices I've given, but thanks for the insight.

            One approach is (granted I just made this code up on the fly, it's basically what I need).
            Box[] b = new Box[1000];//1000 books
            Box[] s = new Box[50]; // 50 shelves
            Box[] d = new Box[10]; // 10 bookcase displays
            from here we would now assign a new group based on the displays
            Group[] dGroup = new Group[10];
            Group[] sGroup = new Group[50];
            for(int i = 0; i < d.length; i++)
            etc.  So if shelves 1-10 are in display 1 then it will be added to group 1 that also contains the display, within that group of shelves is another group per shelf to hold the books.
            then I did
            f[i].addEventHandler(MouseEvent.ANY, new DragShapeHandler(f[i]));
            etc and add events to every group, and book.  This is the important part IMO since I now can do things like.
            shelf1.addEventHandler(MouseEvent.ANY, new DragShapeHandler(shelfgroup)); so when I click the shelf it will move anything within the group, if I click a book only a book will move, and if I click a display it will move.
            Everything WORKS.  Originally I just made a few box's, added them to a group, and then added each group to each other like so(Code I already had for tests).
            Group s1 = new Group (shelf,f,c,e,b,a,m); //each random letter is the name of a face, there are 2 shelves, and those shelves are added to the display.
            Group s2 = new Group(shelf2,q,w,r,t,u);
            Group dis = new Group(s1, s2,display);

            Group root = new Group(dis);


            shelf.addEventHandler(MouseEvent.ANY, new DragShapeHandler(s1));
            shelf2.addEventHandler(MouseEvent.ANY, new DragShapeHandler(s2));
            display.addEventFilter(MouseEvent.ANY, new DragShapeHandler(dis));
            What i want to know is how much overhead will making so many groups have?  Is it "preffered"
            The other method we spoke of was assigning a value to each shelf, and that would be called the "bookShelf" and every book will be given that number.
            From there looping through each face and then determining if it's within the area that "shelf" encompases.
            So lets sya I have a 10 foot high shelf area, and I have some books piled up?
            I would have to do 
            shelf.height + shelf.area
              and then see if that book is contained within the area.  Then I would have to loop on EVERY book when moving the shelf to make sure it's actually on the shelf, which is why the group idea is so much easier.
            So again, basically I want to figure out what is the "BETTER" approach in trying to be able to move objects with ease, while maybe having thousands of books, and such.
            Edited by: KonradZuse on Apr 11, 2013 11:54 AM
            Edited by: KonradZuse on Apr 11, 2013 11:59 AM
            Edited by: KonradZuse on Apr 11, 2013 11:59 AM
            Edited by: KonradZuse on Apr 11, 2013 2:05 PM