• 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

Process method not being executed eventhough publish is being called

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm working with a scanning application and there is a random problem where the pages don't get displayed in the GUI when scanned. The document does not need to contain multiple pages, the example is on a one page document. Once the problem occurrs, it will continue to happen on each document thereafter until the application is exited and restarted. I've added a bunch of log messages in the code to see what's happening and the publish() method is executed, but I never see the log messages for the process() method. I took over on this project a few months ago and have been learning swing on my own. I've been searching the web for clues, but to no avail. I've enjoyed reading some of the posts on this website and decided to create my post here. The code and log file are below.

//Code from GUI
JButton appendButton = new JButton("Append");
appendButton.setToolTipText("This will append inserted pages to the end of the file.");
appendButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (scanner == null || scanner.isDone()) {
insert = false;
replace = false;
pdfViewer.postMessage("Appending page...");
user.getLog().debug(":initializeLayout:Append action");
scanner = new Scanner();
user.getLog().debug(":initializeLayout:Append action after instaniate Scanner()");
scanner.execute();
user.getLog().debug(":initializeLayout:Append action after scanner.execute");
pdfViewer.postMessage("Appending complete...");

} else {
JOptionPane.showMessageDialog(null,"Currently Appending... Please wait");
}
}
});

//SwingWorker object
public class Scanner extends SwingWorker<Void,BufferedImage> {

public Scanner() {

}

@Override
public Void doInBackground() {
Source source = null;
try {
source = SourceManager.instance().getDefaultSource();
user.getLog().debug(":Scanner:doInBackground:source name:" + source.getSourceName());

if (source == null) return null;
source.setMinimumExceptionEnabled(false);
source.open();
//Set source options

user.getLog().debug(":Scanner:doInBackground:adf");
do {
BufferedImage image = source.acquireImageAsBufferedImage();
user.getLog().debug(":Scanner:doInBackground:adf:retrieved image:" + image);
publish(image);
user.getLog().debug(":Scanner:doInBackground:adf:publish");
} while (source.hasMoreImages());
user.getLog().debug(":Scanner:doInBackground:adf:all images acquired.");
source.close();

user.getLog().debug(":Scanner:doInBackground:saveLastAcquiredImageIntoFile");
source.saveLastAcquiredImageIntoFile("C:/temp.tif");
user.getLog().debug(":Scanner:doInBackground:saved image");

} catch(JTwainException jte) {
user.getLog().error(UserSession.stack2string(jte));

} catch(Exception e) {
user.getLog().error(UserSession.stack2string(e));

} finally {
user.getLog().debug(":Scanner:doInBackground:finally");
SourceManager.closeSourceManager();
}
user.getLog().debug(":Scanner:doInBackground:source = null");
source = null;
user.getLog().debug(":Scanner:doInBackground:done");
return null;
} //doInBackground


@Override
protected void process(List<BufferedImage> images) {
try {
BufferedImage image = images.get(images.size() -1);
ScannedImage scannedImage = new ScannedImage(ImageUtility.bufferedImage2bytes(image), false, false);
user.getLog().debug(":Scanner:process:scannedImage done, check if");
user.getLog().debug(":Scanner:process:addImage");
imageColl.addImage(scannedImage);
user.getLog().debug(":Scanner:process:addImage done");
user.getLog().debug(":Scanner:process:getImage");
imageColl.getImage(imageColl.getCurrentPage());
unSaved = true;

} catch (ImageUtilityException iue) {
user.getLog().error(UserSession.stack2string(iue));
}
user.getLog().debug(":Scanner:process done");
} //process
} //Scanner

//Log - there should be some Scanner:process log messages and there are not
01:53:52 DEBUG ocEditer$16:initializeLayout:Scan action unsaved = false
01:53:53 DEBUG ocEditer$Scanner:Scanner:doInBackground:source name:FUJITSU fi-4340Cd
01:53:54 DEBUG ocEditer$Scanner:Scanner:doInBackground:source state:4
01:53:54 DEBUG ocEditer$Scanner:Scanner:doInBackground:adf
01:54:00 DEBUG ocEditer$Scanner:Scanner:doInBackground:adf:retrieved image
01:54:00 DEBUG ocEditer$Scanner:Scanner:doInBackground:adf:publish
01:54:00 DEBUG ocEditer$Scanner:Scanner:doInBackground:adf:all images acquired.
01:54:00 DEBUG ocEditer$Scanner:Scanner:doInBackground:saveLastAcquiredImageIntoFile
01:54:00 DEBUG ocEditer$Scanner:Scanner:doInBackground:saved image
01:54:00 DEBUG ocEditer$Scanner:Scanner:doInBackground:finally
01:54:00 DEBUG ocEditer$Scanner:Scanner:doInBackground:source = null
01:54:00 DEBUG ocEditer$Scanner:Scanner:doInBackground:done
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What if you used a for-each loop in the process method to iterate through all the images. Perhaps something like so (warning: not compiled nor tested):


Also, please use code tags when posting code (see the FAQs).

Much luck!
 
April Easton
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That seemed to help most of my problem. The rest of the problem is that I'm getting a null value for the image I just scanned. I've contacted the vendor for that problem. Thank you a bunch for your help.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic