• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Design issue - resources handling

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
While trying to find my first "dream" job after graduating from university I'm working on various "petty" projects.
Right now I'm trying to create swing application that imitate Acrobat Reader. Manipulating PDFs is no problem (already have hang of iText), I already put together GUI, but I'm not clear on how shall I share/handle some tasks.
My interface consist of 3 main component: JToolBar on top with buttons, JPanel on left to show thumbnails and JPanel on right to function as main display are for single page.
All these three are grouped under main panel.
Now imagine that you click "Open File" button, you retrieve the PDF document you wish to work with (this is no problem at all to this point)
- the application need to keep file path to the document stored somewhere
- need to call relevant methods and populate all 3 component (display page count in tool bar, display thumbnails on left and show first page in main display area)
Similar scenario will repeat when ever any other button is pressed, once document opened, and all 3 components need to be updated.

I know I will need to provide and abstract class whit all methods for document manipulation and the 3 components will be based upon this class. Also use of custom addListeners and fireEvents is expected. Just not sure how to kick of.
Can anyone help out?
 
Peter Miklosko
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Worked out my solution, and sweet-toned with help of chapter 2 from Head First Design Patterns.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Peter Miklosko wrote:Worked out my solution, and sweet-toned with help of chapter 2 from Head First Design Patterns.

Well done, but please tell us how ou sorted it, so everybody here can learn.
 
Peter Miklosko
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Well done, but please tell us how ou sorted it, so everybody here can learn.


Nothing special really.
Having 3 classes that needs to be updated depending on event: ToolBar, Thumbnail, SingleView
Plus having class, MainPanel, that group above GUI components.

I known that I will need to create some "data" class to "house" some operations, store and share file path once selected, plus provide facilities for adding/removing/notifying listeners. On other hand there was need for some interfaces to dictate some classes.

  • At the start I created StatusListener interface with methods fileToOpen(), fileToSave(), fileToClose(). This interface is implemented in that 3 classes(ToolBar, Thumbnail, SingleView) so once event occur they will be notified and do they business depending on each class.
  • Then I created StatusEvent interface with add/remove/notify for each of StatusListener interface methods. The interface is implemented in "data" class called Manager. Manager class provide behind scene operations that are triggered by toolbar, but not strictly related only to toolbar (sort of general management for all 3 main components). On top of that it does work as safe-keeper of file path or current "working" file.
  • Each of the 3 classes has a need to register its listeners with Manager class(here is where I made mistake in first place, a dumb mistake of providing each class with own instance of Manager). MainPanel as direct grouping component is well suited for creating new instance of Manager class and passing references to ToolBar, Thumbnail, SingleView as it is adding them in layout.

  •  
    Campbell Ritchie
    Marshal
    Posts: 79177
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Thank you.
     
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic