• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Doubts with design

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.

I need some advice on how to implement some things with Swing. I'll use three examples:

  • I've implemented a file tree. I get the directory contents in the model when getChildCount is called. getChildCount starts a thread to not freeze de interface and get the minimum data needed to sort the children putting the directories first. Then I start a new thread in the model to get more data about the files like the content type to be use in the renderer to show the associated icon (this improves the perceived load speed of the directory).
  • In a similar way I add items to a custom table model for audio items and then I start a thread in the model to get the files metadata (author, title, length, ...)
  • I'm going to develop a YouTube player and I'll use a JList to show a list of results when you make a search. I want to add a thumbnail for every list item obtained from the url provided in the search result page.

  • What I wanted to know is if it is sane doing things like these in the model or if it would be better to take another approach like getting the data in external to the model threads and then invoking the methods (add, remove, value changed, etc.) in the model. As done right now is very comfortable, but I read frequently that the model only should store the data and nothing more.

    Thanks in advance.

    Greetings.
     
    Bartender
    Posts: 5167
    11
    Netbeans IDE Opera Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    I would do all that background loading in a class or classes whose only connection with Swing would be to hold a SwingPropertyChangeSupport as a private member, to which it/they forward add/removePropertyChangeListener(...) calls. Then fire a property change whenever there is new data that should be updated in the view.

    The propertyChange(...) method in the listener(s) would retrieve the new data and update the view.

    Disclaimer: I'm not a professional so there may be a better way to go about this.
     
    Johan Carson
    Greenhorn
    Posts: 6
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi.

    I'm not an expert either, just doing this for fun. I don't quite understand what you mean, but I'll investigate about that to compare it with my current way of doing stuff like these. Thanks for the hint.

    Greetings.
     
    Darryl Burke
    Bartender
    Posts: 5167
    11
    Netbeans IDE Opera Java
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Basically, something like this (typed here, may have typos or other absurdities)
     
    Johan Carson
    Greenhorn
    Posts: 6
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Hi.

    OK, I now understand it. I knew PropertyChangeSupport but not SwingPropertyChangeSupport and it's an interesting class because it fires the events in the EDT. Thank you again.

    Greetings.
    reply
      Bookmark Topic Watch Topic
    • New Topic