Currently I'm creating application to work with PDF documents, just for challenge. I want to know if there is better solution to my idea of possible approach.

I broke down application GUI to four main components toolbar with image icons, jpanel for thumbnail preview, jpanel for single page view and main jpanel which group them together. Layout is same to traditional Acrobat Read and can be seen in attachment [attach]10534[/attach].

Now toolbar, thumbnail and single view panels need access and has to share a "PDFObject".( The PDFObject will of course have all necessary access methods.) What is bugging me is where would be best place to keep PDFObject. So far I can only thing of the main panel as best choice for "safe-keeper" and use parent-child relation of GUI components to manipulate PDFObject.

DO you approve or disapprove? How shall I go about this task?

If I am not wrong, you want to show pdf objects - Box, Resources, Images. Am I right?

Even though the PDF document is something you "see", it is not, truely, part of the view (IMHO), it is the Data, and I would handle it as such and have all actions that affect it run through the controller.

Just my two cents. ;-)

This is not question how to display content of PDF (already have background with iText).

The question is of best programming practice. Where to place this "PDFObject" so it will be most convenient to access and adhere principles of OO programming.

Which is exactly what Masijade seems to be addressing, except he did not go into much detail. At the very least, you'd need your PDF data in a separate class, and a simple "controller" that provided access to the data.

Which is exactly what Masijade seems to be addressing, except he did not go into much detail. At the very least, you'd need your PDF data in a separate class, and a simple "controller" that provided access to the data.

My reply was direct to adatapost. All 3 posts been spaced in minutes :D

masijade would you be kind and expand on your suggestion?

Make a data class with methods for the varying actions that might taken on the PDFObject and give it also an addListener and fireEvent methods. The "Panel" class to display the PDF will be added as a Listener to the data object so that it can actually display everything that changes. Then I would make an abstract class with varying methods for calling the "data" methods and I would make all of my swing listeners extend this class. Those swing listeners then simply need to call the method from the abstract class which will then call the "data" method.

If you wanted to be complete, you would have the normal Swing and listeners running in the main (and of course event thread), the "panel" class in another thread (using invokeLater, or invokeAndWait to display the changes), and the "data" class in a third thread, with a synced queue between the listeners and the "data", and use wait/notify between the "data" and the "panel" classes.

This is gone be more of challenge then I expected. Well, lets see what can I do about it!

Thank you for advise masijade.

Make a data class with methods for the varying actions that might taken on the PDFObject and give it also an addListener and fireEvent methods. The "Panel" class to display the PDF will be added as a Listener to the data object so that it can actually display everything that changes. Then I would make an abstract class with varying methods for calling the "data" methods and I would make all of my swing listeners extend this class. Those swing listeners then simply need to call the method from the abstract class which will then call the "data" method.

If you wanted to be complete, you would have the normal Swing and listeners running in the main (and of course event thread), the "panel" class in another thread (using invokeLater, or invokeAndWait to display the changes), and the "data" class in a third thread, with a synced queue between the listeners and the "data", and use wait/notify between the "data" and the "panel" classes.

Sorted!

Well I had small help from Eric Freeman , Elisabeth Freeman, Bert Bates, Kathy Sierra and their chapter 2 in Head First Design Patterns ;)
With your advice I came very close to my current deployment that was little adjusted after reading that chapter from the book.

Thanx masijade

commented: Congrats +15

;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.