3

I am developing a java application which will be graphically depicting and organizing hundreds of objects. Each of these objects is loaded in from a SQL database, for use in this program.

I plan to keep a local copy of all the data, retrived through a JDBC connection, and then sort it locally (Likely with Merge Sort as that is my favorite)

How would you recommend I store the data locally? Ideally, it would be very easy to traverse, sort and compare to the source Database.

Currently, I have objects called Ideas which are populated from the database. Then, to display them, I create the same number of IdeaGraphics objects and add them to the appropriate JPanels. This can be quite slow at times.

Peaches491
  • 1,239
  • 15
  • 27
  • How to store them locally (I assume you mean in memory) depends mostly on how you access them. If it is geometrical/spatial objects that you will access in different regions of some space, then a quadtree may be suitable. If you access objects by some key then a map/dictionary is more suitable etc. etc. If you need scalability in displaying lots of graphical objects, you probably want to draw them yourself onto the panel rather than creating a lot of controls. – Anders Forsgren Aug 08 '11 at 15:54
  • I do want to represent them graphically, but I need to be able to click on each one individually. Would i just have to do the pixel math to figure out which one was clicked? – Peaches491 Aug 08 '11 at 17:43
  • Yes, as suggested you will just have a custom panel which draws your objects. When the user clicks you can calculate which object was clicked. – Anders Forsgren Aug 08 '11 at 20:35

3 Answers3

3

You can implement the Comparator interface and use Collections.sort(), a modified mergesort, as shown here.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
3

Maybe you already did that but it's not so clear in your question:

You can get almost as many instances of your data class (Ideas) but it's not the same at all with graphic classes. Limit the number of widgets and graphics to 1.

Build your own custom JPanel class, give it a list of Ideas and override the paintComponent method to draw all items in the list.

If your visible area is large, double buffer it.

Snicolas
  • 37,840
  • 15
  • 114
  • 173
1

I disagree with that and not good idea to holding lots of data in local Memory, with idea to simulate, excelent optimalized preprocesor from Sql Engine (most of todays engines), then basically faster as best EndUser PC

and if you have some WHATEVER permisions to the Database, then there are still exist option(s) to loading data from DbEngine to the Embedded database (on Memory), maybe to H2 or maybe JavaDB

mKorbel
  • 109,525
  • 20
  • 134
  • 319