Netbeans FileChangeListener Delays?

This part of POVRay-Netbeans Platform integration tutorial is a good start to learn about FileChangeListener and WeakListener. This morning I tried implementing them on my own application.

Below is a capture of my app.

filechangelistener
le wild prtscr appears

 

Basically my app is an “image spreader” which contains empty square(s), to which you can drag-n-drop an image from palette (top-right side) to draw that particular image inside the square (left topcomponent). The app also provides a simple image editor to edit those images on palette (center topcomponent with checkerboard background).

Relative path is used to draw the image on the spreader, so it makes sense if we edit an image on the image editor, any change on that image should be instantly updated on the spreader. Thus, a FileChangeListener is needed on the FileObject representing the image.

Imitating the code from the aforementioned tutorial, all went well and the events are fired properly. Except I have to switch our focus to another application window first before go back to my app. This delay is both OK and frustating.

Below is the capture after I saved the edited image.

filechangelistener-before
the image on the left should be updated, too

 

So I was looking back to the javadoc and found this passage :

When attached to a file it listens for file changes (due to saving from inside NetBeans) and for deletes and renames.

It’s exactly what I have overlooked : the change must be fired inside Netbeans. It means that after we’re done writing image to the disk (I use ImageIO.write) we have to trigger the FileEvent manually (I use FileObject.refresh()). Now the functionality works as expected.

RTFM never failed me.

 

This entry was posted in netbeans platform. Bookmark the permalink.

Comments are closed.