Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-23-2008, 07:20 PM
Member
 
Join Date: Nov 2008
Posts: 3
Rep Power: 0
SebScoFr is on a distinguished road
Default [SOLVED] Netbeans Desktop App & JProgressBar
Hi everyone,

I've been looking for solutions for my problem on the internet for hours without any success so I hope someone here can help me.

I'm working on an encryption program on Java implementing the RSA algorithm.
I'm using a NetBeans Desktop Application to develop this application.

Since the encryption process might take a while depending on which files the user wants to encrypt, I'm using a Task that realizes the process in another thread within the doInBackground() method.

Everything works fine except that I'd like to display the process progress in the progress bar provided by default in the desktop application. But for some reasons, nothing happens

Here is the code:

Generated by Netbeans, no need to modify it (?)
Code:
public class RSAProject extends FrameView {
    
    public RSAProject(SingleFrameApplication app) {
        super(app);
 
        initComponents();
 
        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(true);
 
        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            @Override
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                System.out.println(propertyName);
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }
The button which start the Task
Code:
private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {
    this.startEncrypt().execute;
}
And the Task itself
Code:
    @Action
    public Task startEncrypt() {
        return new StartEncryptTask(getApplication());
    }
 
    private class StartEncryptTask extends Task<Void, Void> {
        StartEncryptTask(org.jdesktop.application.Application app) {
            super(app);
        }
        
        @Override
        protected Void doInBackground() {
            try {
                //specific code for encryption
            }
            catch(java.lang.Exception e) {
                //specific code for exceptions
            }
 
            return null;
        }
        
        protected void succeeded() {
        }
    }
Theorically the TaskMonitor should react when a new Task occurs
I must be missing something

Any help will be more than welcome!

-Sebastien
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 11-23-2008, 07:37 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 1,018
Rep Power: 3
Nicholas Jordan is on a distinguished road
Question how to determine task length?
Okay, so how do we determine how long RSA will take on this:
Code:
    final java.lang.String[][] RevisedProgram=
    {
        {"class HellWorldApp extends HellWorld"},
        {"{"},
        {"    public HelloWorldApp()"},
        {"    {"},
        {"         super();//"},
        {"    }"},
        {"    // main method, standard entry point for system to lauch application."},
        {"    public static void main(String[] args)"},
        {"    {"},
        {"        System.out.println(\"With blinding applied, the decryption time is no longer correlated to the value of the input ciphertext and so the timing attack fails.\"); // Display string."},
        {"    }"},
        {"}"},
    };
Not being difficult, it is just that I do not see how we can set some upper bound for task completion ...
__________________
Introduction to Programming Using Java.
Cybercartography: A new theoretical construct proposed by D.R. Fraser Taylor

Last edited by Nicholas Jordan; 11-23-2008 at 08:03 PM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-23-2008, 10:15 PM
Member
 
Join Date: Nov 2008
Posts: 3
Rep Power: 0
SebScoFr is on a distinguished road
Default
Well I'm not sure what you're talking about but I though that this code generated by netbeans for a Desktop Application should follow the task progress and update the progress bar:

Code:
TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            @Override
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                System.out.println(propertyName);
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String)(evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer)(evt.getNewValue());
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
I might be wrong, and if it's the case, any idea how to do it?

Thanks
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-28-2008, 12:00 AM
Member
 
Join Date: Nov 2008
Posts: 3
Rep Power: 0
SebScoFr is on a distinguished road
Default
The task wasn't actually recognized by the TaskMonitor, here is what I've done

The button which start the Task
Code:
private void startButtonActionPerformed(java.awt.event.ActionEvent evt) {
    this.startEncrypt();
}
And the Task
Code:
    @Action
    public Task startEncrypt() {
        StartEncryptTask task = new StartEncryptTask(org.jdesktop.application.Application.getInstance());

        ApplicationContext C = getApplication().getContext();
        TaskMonitor M = C.getTaskMonitor();
        TaskService S = C.getTaskService();
        S.execute(task);
        M.setForegroundTask(task);

        return task;
    }
 
    private class StartEncryptTask extends Task<Void, Void> {
        StartEncryptTask(org.jdesktop.application.Application app) {
            super(app);
        }
        
        @Override
        protected Void doInBackground() {
            try {
                //specific code for encryption
            }
            catch(java.lang.Exception e) {
                //specific code for exceptions
            }
 
            return null;
        }
        
        protected void succeeded() {
        }
    }
Hope that can help
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deployment of JRE 6 u7 to desktop pc / Configuration rrathbun New To Java 0 09-12-2008 09:37 PM
three tier Desktop Application newmember AWT / Swing 0 07-27-2008 04:10 PM
Desktop search in java hellosubs New To Java 0 06-15-2008 04:33 PM
Spliting desktop nagarte AWT / Swing 5 05-05-2008 01:56 PM
k5n Desktop Calendar 0.9.0 levent Java Announcements 0 06-02-2007 08:13 AM


All times are GMT +2. The time now is 04:24 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org